/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1763 by iliev, Wed Sep 3 17:18:51 2008 UTC revision 1781 by iliev, Mon Sep 29 18:21:21 2008 UTC
# Line 22  Line 22 
22   ***************************************************************************/   ***************************************************************************/
23    
24  #include <algorithm>  #include <algorithm>
25    #include <string>
26    
27  #include "lscpserver.h"  #include "lscpserver.h"
28  #include "lscpresultset.h"  #include "lscpresultset.h"
# Line 42  Line 43 
43  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
44  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
45    
46    namespace LinuxSampler {
47    
48  /**  /**
49   * Returns a copy of the given string where all special characters are   * Returns a copy of the given string where all special characters are
# Line 1133  String LSCPServer::GetVoiceCount(uint ui Line 1135  String LSCPServer::GetVoiceCount(uint ui
1135      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
1136      LSCPResultSet result;      LSCPResultSet result;
1137      try {      try {
1138          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");  
1139          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1140          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
1141      }      }
# Line 1154  String LSCPServer::GetStreamCount(uint u Line 1153  String LSCPServer::GetStreamCount(uint u
1153      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
1154      LSCPResultSet result;      LSCPResultSet result;
1155      try {      try {
1156          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1157          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1158          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
1159      }      }
# Line 1175  String LSCPServer::GetBufferFill(fill_re Line 1171  String LSCPServer::GetBufferFill(fill_re
1171      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
1172      LSCPResultSet result;      LSCPResultSet result;
1173      try {      try {
1174          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1175          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1176          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
1177          else {          else {
# Line 1856  String LSCPServer::SetVolume(double dVol Line 1849  String LSCPServer::SetVolume(double dVol
1849      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1850      LSCPResultSet result;      LSCPResultSet result;
1851      try {      try {
1852          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1853          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1854      }      }
1855      catch (Exception e) {      catch (Exception e) {
# Line 1875  String LSCPServer::SetChannelMute(bool b Line 1865  String LSCPServer::SetChannelMute(bool b
1865      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1866      LSCPResultSet result;      LSCPResultSet result;
1867      try {      try {
1868          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1869    
1870          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1871          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
# Line 1896  String LSCPServer::SetChannelSolo(bool b Line 1882  String LSCPServer::SetChannelSolo(bool b
1882      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1883      LSCPResultSet result;      LSCPResultSet result;
1884      try {      try {
1885          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1886    
1887          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1888          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
# Line 2253  String LSCPServer::SetChannelMap(uint ui Line 2235  String LSCPServer::SetChannelMap(uint ui
2235      dmsg(2,("LSCPServer: SetChannelMap()\n"));      dmsg(2,("LSCPServer: SetChannelMap()\n"));
2236      LSCPResultSet result;      LSCPResultSet result;
2237      try {      try {
2238          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2239    
2240          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
2241          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
# Line 2436  String LSCPServer::EditSamplerChannelIns Line 2414  String LSCPServer::EditSamplerChannelIns
2414      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2415      LSCPResultSet result;      LSCPResultSet result;
2416      try {      try {
2417          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
2418          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2419          Engine* pEngine = pEngineChannel->GetEngine();          Engine* pEngine = pEngineChannel->GetEngine();
2420          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
# Line 2454  String LSCPServer::EditSamplerChannelIns Line 2429  String LSCPServer::EditSamplerChannelIns
2429      return result.Produce();      return result.Produce();
2430  }  }
2431    
2432    String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) {
2433        dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2));
2434        LSCPResultSet result;
2435        try {
2436            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2437    
2438            if (Arg1 > 127 || Arg2 > 127) {
2439                throw Exception("Invalid MIDI message");
2440            }
2441    
2442            VirtualMidiDevice* pMidiDevice = NULL;
2443            std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin();
2444            for (; iter != eventHandler.channelMidiListeners.end(); ++iter) {
2445                if ((*iter).pEngineChannel == pEngineChannel) {
2446                    pMidiDevice = (*iter).pMidiListener;
2447                    break;
2448                }
2449            }
2450            
2451            if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device");
2452    
2453            if (MidiMsg == "NOTE_ON") {
2454                pMidiDevice->SendNoteOnToDevice(Arg1, Arg2);
2455                bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2);
2456                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2457            } else if (MidiMsg == "NOTE_OFF") {
2458                pMidiDevice->SendNoteOffToDevice(Arg1, Arg2);
2459                bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2);
2460                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2461            } else {
2462                throw Exception("Unknown MIDI message type: " + MidiMsg);
2463            }
2464        } catch (Exception e) {
2465            result.Error(e);
2466        }
2467        return result.Produce();
2468    }
2469    
2470  /**  /**
2471   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2472   */   */
# Line 2461  String LSCPServer::ResetChannel(uint uiS Line 2474  String LSCPServer::ResetChannel(uint uiS
2474      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
2475      LSCPResultSet result;      LSCPResultSet result;
2476      try {      try {
2477          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
2478          pEngineChannel->Reset();          pEngineChannel->Reset();
2479      }      }
2480      catch (Exception e) {      catch (Exception e) {
# Line 2671  String LSCPServer::GetFileInstrumentInfo Line 2681  String LSCPServer::GetFileInstrumentInfo
2681                  result.Add("FORMAT_VERSION", info.FormatVersion);                  result.Add("FORMAT_VERSION", info.FormatVersion);
2682                  result.Add("PRODUCT", info.Product);                  result.Add("PRODUCT", info.Product);
2683                  result.Add("ARTISTS", info.Artists);                  result.Add("ARTISTS", info.Artists);
2684    
2685                    std::stringstream ss;
2686                    bool b = false;
2687                    for (int i = 0; i < 128; i++) {
2688                        if (info.KeyBindings[i]) {
2689                            if (b) ss << ',';
2690                            ss << i; b = true;
2691                        }
2692                    }
2693                    result.Add("KEY_BINDINGS", ss.str());
2694    
2695                    b = false;
2696                    std::stringstream ss2;
2697                    for (int i = 0; i < 128; i++) {
2698                        if (info.KeySwitchBindings[i]) {
2699                            if (b) ss2 << ',';
2700                            ss2 << i; b = true;
2701                        }
2702                    }
2703                    result.Add("KEYSWITCH_BINDINGS", ss2.str());
2704                  // no more need to ask other engine types                  // no more need to ask other engine types
2705                  bFound = true;                  bFound = true;
2706              } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));              } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));
# Line 2903  String LSCPServer::AddDbInstruments(Stri Line 2933  String LSCPServer::AddDbInstruments(Stri
2933      return result.Produce();      return result.Produce();
2934  }  }
2935    
2936  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) {
2937      dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));      dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground, insDir));
2938      LSCPResultSet result;      LSCPResultSet result;
2939  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2940      try {      try {
2941          int id;          int id;
2942          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2943          if (ScanMode.compare("RECURSIVE") == 0) {          if (ScanMode.compare("RECURSIVE") == 0) {
2944             id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);              id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir);
2945          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2946             id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);              id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir);
2947          } else if (ScanMode.compare("FLAT") == 0) {          } else if (ScanMode.compare("FLAT") == 0) {
2948             id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);              id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir);
2949          } else {          } else {
2950              throw Exception("Unknown scan mode: " + ScanMode);              throw Exception("Unknown scan mode: " + ScanMode);
2951          }          }
# Line 3259  String LSCPServer::SetEcho(yyparse_param Line 3289  String LSCPServer::SetEcho(yyparse_param
3289      }      }
3290      return result.Produce();      return result.Produce();
3291  }  }
3292    
3293    }

Legend:
Removed from v.1763  
changed lines
  Added in v.1781

  ViewVC Help
Powered by ViewVC