/[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 814 by wylder, Thu Dec 22 19:26:35 2005 UTC revision 1187 by iliev, Wed May 16 14:22:26 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 Christian Schoenebeck                              *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
 //#include "../common/global.h"  
27    
28  #include <fcntl.h>  #include <fcntl.h>
29    
30  #if HAVE_SQLITE3  #if ! HAVE_SQLITE3
31  # include "sqlite3.h"  #define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built."
32  #endif  #endif
33    
34  #include "../engines/EngineFactory.h"  #include "../engines/EngineFactory.h"
# Line 66  LSCPServer::LSCPServer(Sampler* pSampler Line 65  LSCPServer::LSCPServer(Sampler* pSampler
65      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
66      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
67      this->pSampler = pSampler;      this->pSampler = pSampler;
68        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT");
69        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO");
70        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT");
71        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO");
72      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
75      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
76      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
77        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT");
78        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO");
79        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");
80        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
81        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
82        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");
83        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT");
84        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO");
85        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT");
86        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
87      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
88      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
89        LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
90      hSocket = -1;      hSocket = -1;
91  }  }
92    
# Line 80  LSCPServer::~LSCPServer() { Line 94  LSCPServer::~LSCPServer() {
94      if (hSocket >= 0) close(hSocket);      if (hSocket >= 0) close(hSocket);
95  }  }
96    
97    void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
98        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
99    }
100    
101    void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
102        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
103    }
104    
105    void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) {
106        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
107    }
108    
109    void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
110        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
111    }
112    
113    void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
114        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program));
115    }
116    
117    void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) {
118        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount));
119    }
120    
121    void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) {
122        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId));
123    }
124    
125    void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
126        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount));
127    }
128    
129    void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) {
130        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount));
131    }
132    
133    void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) {
134        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount));
135    }
136    
137    void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) {
138        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData));
139    }
140    
141    void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) {
142        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
143    }
144    
145    #if HAVE_SQLITE3
146    void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
147        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir));
148    }
149    
150    void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {
151        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir));
152    }
153    
154    void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {
155        Dir = "'" + Dir + "'";
156        NewName = "'" + NewName + "'";
157        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));
158    }
159    
160    void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {
161        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir));
162    }
163    
164    void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) {
165        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr));
166    }
167    void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
168        Instr = "'" + Instr + "'";
169        NewName = "'" + NewName + "'";
170        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName));
171    }
172    #endif // HAVE_SQLITE3
173    
174    
175  /**  /**
176   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
177   * accepting socket connections, if the server is already initialized then   * accepting socket connections, if the server is already initialized then
# Line 120  int LSCPServer::Main() { Line 212  int LSCPServer::Main() {
212    
213      listen(hSocket, 1);      listen(hSocket, 1);
214      Initialized.Set(true);      Initialized.Set(true);
215        
216        // Registering event listeners
217        pSampler->AddChannelCountListener(&eventHandler);
218        pSampler->AddAudioDeviceCountListener(&eventHandler);
219        pSampler->AddMidiDeviceCountListener(&eventHandler);
220        pSampler->AddVoiceCountListener(&eventHandler);
221        pSampler->AddStreamCountListener(&eventHandler);
222        pSampler->AddBufferFillListener(&eventHandler);
223        pSampler->AddTotalVoiceCountListener(&eventHandler);
224        pSampler->AddFxSendCountListener(&eventHandler);
225        MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
226        MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
227        MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
228        MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);
229    #if HAVE_SQLITE3
230        InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler);
231    #endif
232      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
233      sockaddr_in client;      sockaddr_in client;
234      int length = sizeof(client);      int length = sizeof(client);
# Line 140  int LSCPServer::Main() { Line 248  int LSCPServer::Main() {
248                  if ((*itEngineChannel)->StatusChanged()) {                  if ((*itEngineChannel)->StatusChanged()) {
249                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
250                  }                  }
251    
252                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
253                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
254                        if(fxs != NULL && fxs->IsInfoChanged()) {
255                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
256                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
257                            fxs->SetInfoChanged(false);
258                        }
259                    }
260              }              }
261          }          }
262    
# Line 151  int LSCPServer::Main() { Line 268  int LSCPServer::Main() {
268  #else  #else
269                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
270  #endif  #endif
                 bufferedNotifies.erase(iterNotify);  
271          }          }
272            bufferedNotifies.clear();
273          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
274    
275          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
# Line 322  bool LSCPServer::GetLSCPCommand( std::ve Line 439  bool LSCPServer::GetLSCPCommand( std::ve
439                                  continue; //Ignore CR                                  continue; //Ignore CR
440                          if (c == '\n') {                          if (c == '\n') {
441                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
442                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
443                                  return true; //Complete command was read                                  return true; //Complete command was read
444                          }                          }
445                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
# Line 427  String LSCPServer::CreateAudioOutputDevi Line 544  String LSCPServer::CreateAudioOutputDevi
544          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
545          // search for the created device to get its index          // search for the created device to get its index
546          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
547          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");          if (index == -1) throw Exception("Internal error: could not find created audio output device.");
548          result = index; // success          result = index; // success
549      }      }
550      catch (LinuxSamplerException e) {      catch (Exception e) {
551          result.Error(e);          result.Error(e);
552      }      }
553      return result.Produce();      return result.Produce();
# Line 443  String LSCPServer::CreateMidiInputDevice Line 560  String LSCPServer::CreateMidiInputDevice
560          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
561          // search for the created device to get its index          // search for the created device to get its index
562          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
563          if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device.");          if (index == -1) throw Exception("Internal error: could not find created midi input device.");
564          result = index; // success          result = index; // success
565      }      }
566      catch (LinuxSamplerException e) {      catch (Exception e) {
567          result.Error(e);          result.Error(e);
568      }      }
569      return result.Produce();      return result.Produce();
# Line 457  String LSCPServer::DestroyAudioOutputDev Line 574  String LSCPServer::DestroyAudioOutputDev
574      LSCPResultSet result;      LSCPResultSet result;
575      try {      try {
576          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
577          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
578          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
579          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
580      }      }
581      catch (LinuxSamplerException e) {      catch (Exception e) {
582          result.Error(e);          result.Error(e);
583      }      }
584      return result.Produce();      return result.Produce();
# Line 472  String LSCPServer::DestroyMidiInputDevic Line 589  String LSCPServer::DestroyMidiInputDevic
589      LSCPResultSet result;      LSCPResultSet result;
590      try {      try {
591          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
592          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
593          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
594          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
595      }      }
596      catch (LinuxSamplerException e) {      catch (Exception e) {
597          result.Error(e);          result.Error(e);
598      }      }
599      return result.Produce();      return result.Produce();
600  }  }
601    
602    EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) {
603        SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
604        if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
605    
606        EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
607        if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
608    
609        return pEngineChannel;        
610    }
611    
612  /**  /**
613   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
614   */   */
# Line 490  String LSCPServer::LoadInstrument(String Line 617  String LSCPServer::LoadInstrument(String
617      LSCPResultSet result;      LSCPResultSet result;
618      try {      try {
619          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
620          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
621          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
622          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
623          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
624              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
625          if (bBackground) {          if (bBackground) {
626              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
627                id.FileName = Filename;
628                id.Index    = uiInstrument;
629                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
630          }          }
631          else {          else {
632              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 505  String LSCPServer::LoadInstrument(String Line 635  String LSCPServer::LoadInstrument(String
635              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
636          }          }
637      }      }
638      catch (LinuxSamplerException e) {      catch (Exception e) {
639           result.Error(e);           result.Error(e);
640      }      }
641      return result.Produce();      return result.Produce();
# Line 520  String LSCPServer::SetEngineType(String Line 650  String LSCPServer::SetEngineType(String
650      LSCPResultSet result;      LSCPResultSet result;
651      try {      try {
652          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
653          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
654          LockRTNotify();          LockRTNotify();
655          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
656          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
657          UnlockRTNotify();          UnlockRTNotify();
658      }      }
659      catch (LinuxSamplerException e) {      catch (Exception e) {
660           result.Error(e);           result.Error(e);
661      }      }
662      return result.Produce();      return result.Produce();
# Line 564  String LSCPServer::ListChannels() { Line 694  String LSCPServer::ListChannels() {
694   */   */
695  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
696      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
697        LockRTNotify();
698      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
699        UnlockRTNotify();
700      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
701      return result.Produce();      return result.Produce();
702  }  }
# Line 586  String LSCPServer::RemoveChannel(uint ui Line 718  String LSCPServer::RemoveChannel(uint ui
718   */   */
719  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
720      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
721      LSCPResultSet result("1");      LSCPResultSet result;
722        try {
723            int n = EngineFactory::AvailableEngineTypes().size();
724            result.Add(n);
725        }
726        catch (Exception e) {
727            result.Error(e);
728        }
729      return result.Produce();      return result.Produce();
730  }  }
731    
# Line 595  String LSCPServer::GetAvailableEngines() Line 734  String LSCPServer::GetAvailableEngines()
734   */   */
735  String LSCPServer::ListAvailableEngines() {  String LSCPServer::ListAvailableEngines() {
736      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
737      LSCPResultSet result("\'GIG\'");      LSCPResultSet result;
738        try {
739            String s = EngineFactory::AvailableEngineTypesAsString();
740            result.Add(s);
741        }
742        catch (Exception e) {
743            result.Error(e);
744        }
745      return result.Produce();      return result.Produce();
746  }  }
747    
# Line 606  String LSCPServer::ListAvailableEngines( Line 752  String LSCPServer::ListAvailableEngines(
752  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
753      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
754      LSCPResultSet result;      LSCPResultSet result;
755        LockRTNotify();
756      try {      try {
757          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
758          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
759          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
760          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
761      }      }
762      catch (LinuxSamplerException e) {      catch (Exception e) {
763           result.Error(e);           result.Error(e);
764      }      }
765        UnlockRTNotify();
766      return result.Produce();      return result.Produce();
767  }  }
768    
# Line 627  String LSCPServer::GetChannelInfo(uint u Line 775  String LSCPServer::GetChannelInfo(uint u
775      LSCPResultSet result;      LSCPResultSet result;
776      try {      try {
777          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
778          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
779          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
780    
781          //Defaults values          //Defaults values
# Line 641  String LSCPServer::GetChannelInfo(uint u Line 789  String LSCPServer::GetChannelInfo(uint u
789          String AudioRouting;          String AudioRouting;
790          int Mute = 0;          int Mute = 0;
791          bool Solo = false;          bool Solo = false;
792            String MidiInstrumentMap = "NONE";
793    
794          if (pEngineChannel) {          if (pEngineChannel) {
795              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 658  String LSCPServer::GetChannelInfo(uint u Line 807  String LSCPServer::GetChannelInfo(uint u
807              }              }
808              Mute = pEngineChannel->GetMute();              Mute = pEngineChannel->GetMute();
809              Solo = pEngineChannel->GetSolo();              Solo = pEngineChannel->GetSolo();
810                if (pEngineChannel->UsesNoMidiInstrumentMap())
811                    MidiInstrumentMap = "NONE";
812                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
813                    MidiInstrumentMap = "DEFAULT";
814                else
815                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
816          }          }
817    
818          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 679  String LSCPServer::GetChannelInfo(uint u Line 834  String LSCPServer::GetChannelInfo(uint u
834          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
835          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
836          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
837            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
838      }      }
839      catch (LinuxSamplerException e) {      catch (Exception e) {
840           result.Error(e);           result.Error(e);
841      }      }
842      return result.Produce();      return result.Produce();
# Line 695  String LSCPServer::GetVoiceCount(uint ui Line 851  String LSCPServer::GetVoiceCount(uint ui
851      LSCPResultSet result;      LSCPResultSet result;
852      try {      try {
853          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
854          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
855          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
856          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
857          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
858          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
859      }      }
860      catch (LinuxSamplerException e) {      catch (Exception e) {
861           result.Error(e);           result.Error(e);
862      }      }
863      return result.Produce();      return result.Produce();
# Line 716  String LSCPServer::GetStreamCount(uint u Line 872  String LSCPServer::GetStreamCount(uint u
872      LSCPResultSet result;      LSCPResultSet result;
873      try {      try {
874          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
875          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
876          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
877          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
878          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
879          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
880      }      }
881      catch (LinuxSamplerException e) {      catch (Exception e) {
882           result.Error(e);           result.Error(e);
883      }      }
884      return result.Produce();      return result.Produce();
# Line 737  String LSCPServer::GetBufferFill(fill_re Line 893  String LSCPServer::GetBufferFill(fill_re
893      LSCPResultSet result;      LSCPResultSet result;
894      try {      try {
895          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
896          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
897          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
898          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
899          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
900          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
901          else {          else {
902              switch (ResponseType) {              switch (ResponseType) {
# Line 751  String LSCPServer::GetBufferFill(fill_re Line 907  String LSCPServer::GetBufferFill(fill_re
907                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
908                      break;                      break;
909                  default:                  default:
910                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
911              }              }
912          }          }
913      }      }
914      catch (LinuxSamplerException e) {      catch (Exception e) {
915           result.Error(e);           result.Error(e);
916      }      }
917      return result.Produce();      return result.Produce();
# Line 768  String LSCPServer::GetAvailableAudioOutp Line 924  String LSCPServer::GetAvailableAudioOutp
924          int n = AudioOutputDeviceFactory::AvailableDrivers().size();          int n = AudioOutputDeviceFactory::AvailableDrivers().size();
925          result.Add(n);          result.Add(n);
926      }      }
927      catch (LinuxSamplerException e) {      catch (Exception e) {
928          result.Error(e);          result.Error(e);
929      }      }
930      return result.Produce();      return result.Produce();
# Line 781  String LSCPServer::ListAvailableAudioOut Line 937  String LSCPServer::ListAvailableAudioOut
937          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
938          result.Add(s);          result.Add(s);
939      }      }
940      catch (LinuxSamplerException e) {      catch (Exception e) {
941          result.Error(e);          result.Error(e);
942      }      }
943      return result.Produce();      return result.Produce();
# Line 794  String LSCPServer::GetAvailableMidiInput Line 950  String LSCPServer::GetAvailableMidiInput
950          int n = MidiInputDeviceFactory::AvailableDrivers().size();          int n = MidiInputDeviceFactory::AvailableDrivers().size();
951          result.Add(n);          result.Add(n);
952      }      }
953      catch (LinuxSamplerException e) {      catch (Exception e) {
954          result.Error(e);          result.Error(e);
955      }      }
956      return result.Produce();      return result.Produce();
# Line 807  String LSCPServer::ListAvailableMidiInpu Line 963  String LSCPServer::ListAvailableMidiInpu
963          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
964          result.Add(s);          result.Add(s);
965      }      }
966      catch (LinuxSamplerException e) {      catch (Exception e) {
967          result.Error(e);          result.Error(e);
968      }      }
969      return result.Produce();      return result.Produce();
# Line 831  String LSCPServer::GetMidiInputDriverInf Line 987  String LSCPServer::GetMidiInputDriverInf
987              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
988          }          }
989      }      }
990      catch (LinuxSamplerException e) {      catch (Exception e) {
991          result.Error(e);          result.Error(e);
992      }      }
993      return result.Produce();      return result.Produce();
# Line 855  String LSCPServer::GetAudioOutputDriverI Line 1011  String LSCPServer::GetAudioOutputDriverI
1011              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1012          }          }
1013      }      }
1014      catch (LinuxSamplerException e) {      catch (Exception e) {
1015          result.Error(e);          result.Error(e);
1016      }      }
1017      return result.Produce();      return result.Produce();
# Line 882  String LSCPServer::GetMidiInputDriverPar Line 1038  String LSCPServer::GetMidiInputDriverPar
1038          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1039          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1040      }      }
1041      catch (LinuxSamplerException e) {      catch (Exception e) {
1042          result.Error(e);          result.Error(e);
1043      }      }
1044      return result.Produce();      return result.Produce();
# Line 909  String LSCPServer::GetAudioOutputDriverP Line 1065  String LSCPServer::GetAudioOutputDriverP
1065          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1066          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1067      }      }
1068      catch (LinuxSamplerException e) {      catch (Exception e) {
1069          result.Error(e);          result.Error(e);
1070      }      }
1071      return result.Produce();      return result.Produce();
# Line 922  String LSCPServer::GetAudioOutputDeviceC Line 1078  String LSCPServer::GetAudioOutputDeviceC
1078          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
1079          result.Add(count); // success          result.Add(count); // success
1080      }      }
1081      catch (LinuxSamplerException e) {      catch (Exception e) {
1082          result.Error(e);          result.Error(e);
1083      }      }
1084      return result.Produce();      return result.Produce();
# Line 935  String LSCPServer::GetMidiInputDeviceCou Line 1091  String LSCPServer::GetMidiInputDeviceCou
1091          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
1092          result.Add(count); // success          result.Add(count); // success
1093      }      }
1094      catch (LinuxSamplerException e) {      catch (Exception e) {
1095          result.Error(e);          result.Error(e);
1096      }      }
1097      return result.Produce();      return result.Produce();
# Line 954  String LSCPServer::GetAudioOutputDevices Line 1110  String LSCPServer::GetAudioOutputDevices
1110          }          }
1111          result.Add(s);          result.Add(s);
1112      }      }
1113      catch (LinuxSamplerException e) {      catch (Exception e) {
1114          result.Error(e);          result.Error(e);
1115      }      }
1116      return result.Produce();      return result.Produce();
# Line 973  String LSCPServer::GetMidiInputDevices() Line 1129  String LSCPServer::GetMidiInputDevices()
1129          }          }
1130          result.Add(s);          result.Add(s);
1131      }      }
1132      catch (LinuxSamplerException e) {      catch (Exception e) {
1133          result.Error(e);          result.Error(e);
1134      }      }
1135      return result.Produce();      return result.Produce();
# Line 984  String LSCPServer::GetAudioOutputDeviceI Line 1140  String LSCPServer::GetAudioOutputDeviceI
1140      LSCPResultSet result;      LSCPResultSet result;
1141      try {      try {
1142          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1143          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1144          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1145          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1146          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 993  String LSCPServer::GetAudioOutputDeviceI Line 1149  String LSCPServer::GetAudioOutputDeviceI
1149              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1150          }          }
1151      }      }
1152      catch (LinuxSamplerException e) {      catch (Exception e) {
1153          result.Error(e);          result.Error(e);
1154      }      }
1155      return result.Produce();      return result.Produce();
# Line 1004  String LSCPServer::GetMidiInputDeviceInf Line 1160  String LSCPServer::GetMidiInputDeviceInf
1160      LSCPResultSet result;      LSCPResultSet result;
1161      try {      try {
1162          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1163          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1164          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1165          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1166          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 1013  String LSCPServer::GetMidiInputDeviceInf Line 1169  String LSCPServer::GetMidiInputDeviceInf
1169              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1170          }          }
1171      }      }
1172      catch (LinuxSamplerException e) {      catch (Exception e) {
1173          result.Error(e);          result.Error(e);
1174      }      }
1175      return result.Produce();      return result.Produce();
# Line 1024  String LSCPServer::GetMidiInputPortInfo( Line 1180  String LSCPServer::GetMidiInputPortInfo(
1180      try {      try {
1181          // get MIDI input device          // get MIDI input device
1182          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1183          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1184          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1185    
1186          // get MIDI port          // get MIDI port
1187          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1188          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1189    
1190          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1191          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 1038  String LSCPServer::GetMidiInputPortInfo( Line 1194  String LSCPServer::GetMidiInputPortInfo(
1194              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1195          }          }
1196      }      }
1197      catch (LinuxSamplerException e) {      catch (Exception e) {
1198          result.Error(e);          result.Error(e);
1199      }      }
1200      return result.Produce();      return result.Produce();
# Line 1050  String LSCPServer::GetAudioOutputChannel Line 1206  String LSCPServer::GetAudioOutputChannel
1206      try {      try {
1207          // get audio output device          // get audio output device
1208          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1209          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1210          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1211    
1212          // get audio channel          // get audio channel
1213          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1214          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1215    
1216          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1217          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1064  String LSCPServer::GetAudioOutputChannel Line 1220  String LSCPServer::GetAudioOutputChannel
1220              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1221          }          }
1222      }      }
1223      catch (LinuxSamplerException e) {      catch (Exception e) {
1224          result.Error(e);          result.Error(e);
1225      }      }
1226      return result.Produce();      return result.Produce();
# Line 1076  String LSCPServer::GetMidiInputPortParam Line 1232  String LSCPServer::GetMidiInputPortParam
1232      try {      try {
1233          // get MIDI input device          // get MIDI input device
1234          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1235          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no midi input device with index " + ToString(DeviceId) + ".");
1236          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1237    
1238          // get midi port          // get midi port
1239          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1240          if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");          if (!pPort) throw Exception("Midi input device does not have port " + ToString(PortId) + ".");
1241    
1242          // get desired port parameter          // get desired port parameter
1243          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1244          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw Exception("Midi port does not provide a parameter '" + ParameterName + "'.");
1245          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1246    
1247          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1097  String LSCPServer::GetMidiInputPortParam Line 1253  String LSCPServer::GetMidiInputPortParam
1253          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1254          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1255      }      }
1256      catch (LinuxSamplerException e) {      catch (Exception e) {
1257          result.Error(e);          result.Error(e);
1258      }      }
1259      return result.Produce();      return result.Produce();
# Line 1109  String LSCPServer::GetAudioOutputChannel Line 1265  String LSCPServer::GetAudioOutputChannel
1265      try {      try {
1266          // get audio output device          // get audio output device
1267          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1268          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1269          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1270    
1271          // get audio channel          // get audio channel
1272          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1273          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1274    
1275          // get desired audio channel parameter          // get desired audio channel parameter
1276          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1277          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw Exception("Audio channel does not provide a parameter '" + ParameterName + "'.");
1278          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1279    
1280          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1130  String LSCPServer::GetAudioOutputChannel Line 1286  String LSCPServer::GetAudioOutputChannel
1286          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1287          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1288      }      }
1289      catch (LinuxSamplerException e) {      catch (Exception e) {
1290          result.Error(e);          result.Error(e);
1291      }      }
1292      return result.Produce();      return result.Produce();
# Line 1142  String LSCPServer::SetAudioOutputChannel Line 1298  String LSCPServer::SetAudioOutputChannel
1298      try {      try {
1299          // get audio output device          // get audio output device
1300          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1301          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1302          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1303    
1304          // get audio channel          // get audio channel
1305          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1306          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1307    
1308          // get desired audio channel parameter          // get desired audio channel parameter
1309          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1310          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");          if (!parameters.count(ParamKey)) throw Exception("Audio channel does not provide a parameter '" + ParamKey + "'.");
1311          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1312    
1313          // set new channel parameter value          // set new channel parameter value
1314          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1315            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1316      }      }
1317      catch (LinuxSamplerException e) {      catch (Exception e) {
1318          result.Error(e);          result.Error(e);
1319      }      }
1320      return result.Produce();      return result.Produce();
# Line 1168  String LSCPServer::SetAudioOutputDeviceP Line 1325  String LSCPServer::SetAudioOutputDeviceP
1325      LSCPResultSet result;      LSCPResultSet result;
1326      try {      try {
1327          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1328          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1329          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1330          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1331          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1332          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1333            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1334      }      }
1335      catch (LinuxSamplerException e) {      catch (Exception e) {
1336          result.Error(e);          result.Error(e);
1337      }      }
1338      return result.Produce();      return result.Produce();
# Line 1185  String LSCPServer::SetMidiInputDevicePar Line 1343  String LSCPServer::SetMidiInputDevicePar
1343      LSCPResultSet result;      LSCPResultSet result;
1344      try {      try {
1345          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1346          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1347          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1348          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1349          if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1350          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1351            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1352      }      }
1353      catch (LinuxSamplerException e) {      catch (Exception e) {
1354          result.Error(e);          result.Error(e);
1355      }      }
1356      return result.Produce();      return result.Produce();
# Line 1203  String LSCPServer::SetMidiInputPortParam Line 1362  String LSCPServer::SetMidiInputPortParam
1362      try {      try {
1363          // get MIDI input device          // get MIDI input device
1364          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1365          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1366          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1367    
1368          // get MIDI port          // get MIDI port
1369          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1370          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1371    
1372          // set port parameter value          // set port parameter value
1373          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1374          if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1375          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1376            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1377      }      }
1378      catch (LinuxSamplerException e) {      catch (Exception e) {
1379          result.Error(e);          result.Error(e);
1380      }      }
1381      return result.Produce();      return result.Produce();
# Line 1230  String LSCPServer::SetAudioOutputChannel Line 1390  String LSCPServer::SetAudioOutputChannel
1390      LSCPResultSet result;      LSCPResultSet result;
1391      try {      try {
1392          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1393          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1394          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1395          if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));          if (!pEngineChannel) throw Exception("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1396          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));          if (!pSamplerChannel->GetAudioOutputDevice()) throw Exception("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1397          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1398      }      }
1399      catch (LinuxSamplerException e) {      catch (Exception e) {
1400           result.Error(e);           result.Error(e);
1401      }      }
1402      return result.Produce();      return result.Produce();
# Line 1245  String LSCPServer::SetAudioOutputChannel Line 1405  String LSCPServer::SetAudioOutputChannel
1405  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1406      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1407      LSCPResultSet result;      LSCPResultSet result;
1408        LockRTNotify();
1409      try {      try {
1410          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1411          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1412          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1413          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));
1414          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1415          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1416      }      }
1417      catch (LinuxSamplerException e) {      catch (Exception e) {
1418           result.Error(e);           result.Error(e);
1419      }      }
1420        UnlockRTNotify();
1421      return result.Produce();      return result.Produce();
1422  }  }
1423    
1424  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1425      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1426      LSCPResultSet result;      LSCPResultSet result;
1427        LockRTNotify();
1428      try {      try {
1429          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1430          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1431          // Driver type name aliasing...          // Driver type name aliasing...
1432          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1433          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1286  String LSCPServer::SetAudioOutputType(St Line 1449  String LSCPServer::SetAudioOutputType(St
1449          }          }
1450          // Must have a device...          // Must have a device...
1451          if (pDevice == NULL)          if (pDevice == NULL)
1452              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1453          // Set it as the current channel device...          // Set it as the current channel device...
1454          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1455      }      }
1456      catch (LinuxSamplerException e) {      catch (Exception e) {
1457           result.Error(e);           result.Error(e);
1458      }      }
1459        UnlockRTNotify();
1460      return result.Produce();      return result.Produce();
1461  }  }
1462    
# Line 1301  String LSCPServer::SetMIDIInputPort(uint Line 1465  String LSCPServer::SetMIDIInputPort(uint
1465      LSCPResultSet result;      LSCPResultSet result;
1466      try {      try {
1467          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1468          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1469          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1470      }      }
1471      catch (LinuxSamplerException e) {      catch (Exception e) {
1472           result.Error(e);           result.Error(e);
1473      }      }
1474      return result.Produce();      return result.Produce();
# Line 1315  String LSCPServer::SetMIDIInputChannel(u Line 1479  String LSCPServer::SetMIDIInputChannel(u
1479      LSCPResultSet result;      LSCPResultSet result;
1480      try {      try {
1481          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1482          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1483          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1484      }      }
1485      catch (LinuxSamplerException e) {      catch (Exception e) {
1486           result.Error(e);           result.Error(e);
1487      }      }
1488      return result.Produce();      return result.Produce();
# Line 1329  String LSCPServer::SetMIDIInputDevice(ui Line 1493  String LSCPServer::SetMIDIInputDevice(ui
1493      LSCPResultSet result;      LSCPResultSet result;
1494      try {      try {
1495          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1496          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1497          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1498          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1499          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1500          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1501      }      }
1502      catch (LinuxSamplerException e) {      catch (Exception e) {
1503           result.Error(e);           result.Error(e);
1504      }      }
1505      return result.Produce();      return result.Produce();
# Line 1346  String LSCPServer::SetMIDIInputType(Stri Line 1510  String LSCPServer::SetMIDIInputType(Stri
1510      LSCPResultSet result;      LSCPResultSet result;
1511      try {      try {
1512          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1513          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1514          // Driver type name aliasing...          // Driver type name aliasing...
1515          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1516          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1370  String LSCPServer::SetMIDIInputType(Stri Line 1534  String LSCPServer::SetMIDIInputType(Stri
1534          }          }
1535          // Must have a device...          // Must have a device...
1536          if (pDevice == NULL)          if (pDevice == NULL)
1537              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1538          // Set it as the current channel device...          // Set it as the current channel device...
1539          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1540      }      }
1541      catch (LinuxSamplerException e) {      catch (Exception e) {
1542           result.Error(e);           result.Error(e);
1543      }      }
1544      return result.Produce();      return result.Produce();
# Line 1389  String LSCPServer::SetMIDIInput(uint MID Line 1553  String LSCPServer::SetMIDIInput(uint MID
1553      LSCPResultSet result;      LSCPResultSet result;
1554      try {      try {
1555          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1556          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1557          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1558          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1559          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1560          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1561      }      }
1562      catch (LinuxSamplerException e) {      catch (Exception e) {
1563           result.Error(e);           result.Error(e);
1564      }      }
1565      return result.Produce();      return result.Produce();
# Line 1410  String LSCPServer::SetVolume(double dVol Line 1574  String LSCPServer::SetVolume(double dVol
1574      LSCPResultSet result;      LSCPResultSet result;
1575      try {      try {
1576          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1577          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1578          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1579          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1580          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1581      }      }
1582      catch (LinuxSamplerException e) {      catch (Exception e) {
1583           result.Error(e);           result.Error(e);
1584      }      }
1585      return result.Produce();      return result.Produce();
# Line 1429  String LSCPServer::SetChannelMute(bool b Line 1593  String LSCPServer::SetChannelMute(bool b
1593      LSCPResultSet result;      LSCPResultSet result;
1594      try {      try {
1595          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1596          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1597    
1598          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1599          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1600    
1601          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1602          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
1603      } catch (LinuxSamplerException e) {      } catch (Exception e) {
1604          result.Error(e);          result.Error(e);
1605      }      }
1606      return result.Produce();      return result.Produce();
# Line 1450  String LSCPServer::SetChannelSolo(bool b Line 1614  String LSCPServer::SetChannelSolo(bool b
1614      LSCPResultSet result;      LSCPResultSet result;
1615      try {      try {
1616          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1617          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1618    
1619          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1620          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1621    
1622          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1623          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
1624            
1625          pEngineChannel->SetSolo(bSolo);          pEngineChannel->SetSolo(bSolo);
1626            
1627          if(!oldSolo && bSolo) {          if(!oldSolo && bSolo) {
1628              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1629              if(!hadSoloChannel) MuteNonSoloChannels();              if(!hadSoloChannel) MuteNonSoloChannels();
1630          }          }
1631            
1632          if(oldSolo && !bSolo) {          if(oldSolo && !bSolo) {
1633              if(!HasSoloChannel()) UnmuteChannels();              if(!HasSoloChannel()) UnmuteChannels();
1634              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1635          }          }
1636      } catch (LinuxSamplerException e) {      } catch (Exception e) {
1637          result.Error(e);          result.Error(e);
1638      }      }
1639      return result.Produce();      return result.Produce();
# Line 1522  void  LSCPServer::UnmuteChannels() { Line 1686  void  LSCPServer::UnmuteChannels() {
1686      }      }
1687  }  }
1688    
1689    String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name, bool bModal) {
1690        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1691    
1692        midi_prog_index_t idx;
1693        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1694        idx.midi_bank_lsb = MidiBank & 0x7f;
1695        idx.midi_prog     = MidiProg;
1696    
1697        MidiInstrumentMapper::entry_t entry;
1698        entry.EngineName      = EngineType;
1699        entry.InstrumentFile  = InstrumentFile;
1700        entry.InstrumentIndex = InstrumentIndex;
1701        entry.LoadMode        = LoadMode;
1702        entry.Volume          = Volume;
1703        entry.Name            = Name;
1704    
1705        LSCPResultSet result;
1706        try {
1707            // PERSISTENT mapping commands might block for a long time, so in
1708            // that case we add/replace the mapping in another thread in case
1709            // the NON_MODAL argument was supplied, non persistent mappings
1710            // should return immediately, so we don't need to do that for them
1711            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1712            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1713        } catch (Exception e) {
1714            result.Error(e);
1715        }
1716        return result.Produce();
1717    }
1718    
1719    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1720        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1721    
1722        midi_prog_index_t idx;
1723        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1724        idx.midi_bank_lsb = MidiBank & 0x7f;
1725        idx.midi_prog     = MidiProg;
1726    
1727        LSCPResultSet result;
1728        try {
1729            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1730        } catch (Exception e) {
1731            result.Error(e);
1732        }
1733        return result.Produce();
1734    }
1735    
1736    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1737        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1738        LSCPResultSet result;
1739        try {
1740            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1741        } catch (Exception e) {
1742            result.Error(e);
1743        }
1744        return result.Produce();
1745    }
1746    
1747    
1748    String LSCPServer::GetAllMidiInstrumentMappings() {
1749        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1750        LSCPResultSet result;
1751        std::vector<int> maps = MidiInstrumentMapper::Maps();
1752        int totalMappings = 0;
1753        for (int i = 0; i < maps.size(); i++) {
1754            try {
1755                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1756            } catch (Exception e) { /*NOOP*/ }
1757        }
1758        result.Add(totalMappings);
1759        return result.Produce();
1760    }
1761    
1762    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1763        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1764        LSCPResultSet result;
1765        try {
1766            midi_prog_index_t idx;
1767            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1768            idx.midi_bank_lsb = MidiBank & 0x7f;
1769            idx.midi_prog     = MidiProg;
1770    
1771            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1772            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1773            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1774            else { // found
1775                result.Add("NAME", iter->second.Name);
1776                result.Add("ENGINE_NAME", iter->second.EngineName);
1777                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1778                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1779                String instrumentName;
1780                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1781                if (pEngine) {
1782                    if (pEngine->GetInstrumentManager()) {
1783                        InstrumentManager::instrument_id_t instrID;
1784                        instrID.FileName = iter->second.InstrumentFile;
1785                        instrID.Index    = iter->second.InstrumentIndex;
1786                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1787                    }
1788                    EngineFactory::Destroy(pEngine);
1789                }
1790                result.Add("INSTRUMENT_NAME", instrumentName);
1791                switch (iter->second.LoadMode) {
1792                    case MidiInstrumentMapper::ON_DEMAND:
1793                        result.Add("LOAD_MODE", "ON_DEMAND");
1794                        break;
1795                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1796                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1797                        break;
1798                    case MidiInstrumentMapper::PERSISTENT:
1799                        result.Add("LOAD_MODE", "PERSISTENT");
1800                        break;
1801                    default:
1802                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1803                }
1804                result.Add("VOLUME", iter->second.Volume);
1805            }
1806        } catch (Exception e) {
1807            result.Error(e);
1808        }
1809        return result.Produce();
1810    }
1811    
1812    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1813        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1814        LSCPResultSet result;
1815        try {
1816            String s;
1817            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1818            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1819            for (; iter != mappings.end(); iter++) {
1820                if (s.size()) s += ",";
1821                s += "{" + ToString(MidiMapID) + ","
1822                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1823                         + ToString(int(iter->first.midi_prog)) + "}";
1824            }
1825            result.Add(s);
1826        } catch (Exception e) {
1827            result.Error(e);
1828        }
1829        return result.Produce();
1830    }
1831    
1832    String LSCPServer::ListAllMidiInstrumentMappings() {
1833        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1834        LSCPResultSet result;
1835        try {
1836            std::vector<int> maps = MidiInstrumentMapper::Maps();
1837            String s;
1838            for (int i = 0; i < maps.size(); i++) {
1839                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1840                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1841                for (; iter != mappings.end(); iter++) {
1842                    if (s.size()) s += ",";
1843                    s += "{" + ToString(maps[i]) + ","
1844                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1845                             + ToString(int(iter->first.midi_prog)) + "}";
1846                }
1847            }
1848            result.Add(s);
1849        } catch (Exception e) {
1850            result.Error(e);
1851        }
1852        return result.Produce();
1853    }
1854    
1855    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1856        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1857        LSCPResultSet result;
1858        try {
1859            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1860        } catch (Exception e) {
1861            result.Error(e);
1862        }
1863        return result.Produce();
1864    }
1865    
1866    String LSCPServer::ClearAllMidiInstrumentMappings() {
1867        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1868        LSCPResultSet result;
1869        try {
1870            std::vector<int> maps = MidiInstrumentMapper::Maps();
1871            for (int i = 0; i < maps.size(); i++)
1872                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1873        } catch (Exception e) {
1874            result.Error(e);
1875        }
1876        return result.Produce();
1877    }
1878    
1879    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1880        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1881        LSCPResultSet result;
1882        try {
1883            int MapID = MidiInstrumentMapper::AddMap(MapName);
1884            result = LSCPResultSet(MapID);
1885        } catch (Exception e) {
1886            result.Error(e);
1887        }
1888        return result.Produce();
1889    }
1890    
1891    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1892        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1893        LSCPResultSet result;
1894        try {
1895            MidiInstrumentMapper::RemoveMap(MidiMapID);
1896        } catch (Exception e) {
1897            result.Error(e);
1898        }
1899        return result.Produce();
1900    }
1901    
1902    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1903        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1904        LSCPResultSet result;
1905        try {
1906            MidiInstrumentMapper::RemoveAllMaps();
1907        } catch (Exception e) {
1908            result.Error(e);
1909        }
1910        return result.Produce();
1911    }
1912    
1913    String LSCPServer::GetMidiInstrumentMaps() {
1914        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1915        LSCPResultSet result;
1916        try {
1917            result.Add(MidiInstrumentMapper::Maps().size());
1918        } catch (Exception e) {
1919            result.Error(e);
1920        }
1921        return result.Produce();
1922    }
1923    
1924    String LSCPServer::ListMidiInstrumentMaps() {
1925        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1926        LSCPResultSet result;
1927        try {
1928            std::vector<int> maps = MidiInstrumentMapper::Maps();
1929            String sList;
1930            for (int i = 0; i < maps.size(); i++) {
1931                if (sList != "") sList += ",";
1932                sList += ToString(maps[i]);
1933            }
1934            result.Add(sList);
1935        } catch (Exception e) {
1936            result.Error(e);
1937        }
1938        return result.Produce();
1939    }
1940    
1941    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1942        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1943        LSCPResultSet result;
1944        try {
1945            result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1946            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
1947        } catch (Exception e) {
1948            result.Error(e);
1949        }
1950        return result.Produce();
1951    }
1952    
1953    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
1954        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
1955        LSCPResultSet result;
1956        try {
1957            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
1958        } catch (Exception e) {
1959            result.Error(e);
1960        }
1961        return result.Produce();
1962    }
1963    
1964    /**
1965     * Set the MIDI instrument map the given sampler channel shall use for
1966     * handling MIDI program change messages. There are the following two
1967     * special (negative) values:
1968     *
1969     *    - (-1) :  set to NONE (ignore program changes)
1970     *    - (-2) :  set to DEFAULT map
1971     */
1972    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
1973        dmsg(2,("LSCPServer: SetChannelMap()\n"));
1974        LSCPResultSet result;
1975        try {
1976            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1977            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1978    
1979            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1980            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1981    
1982            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
1983            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
1984            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
1985        } catch (Exception e) {
1986            result.Error(e);
1987        }
1988        return result.Produce();
1989    }
1990    
1991    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
1992        dmsg(2,("LSCPServer: CreateFxSend()\n"));
1993        LSCPResultSet result;
1994        try {
1995            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
1996            
1997            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
1998            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
1999    
2000            result = LSCPResultSet(pFxSend->Id()); // success
2001        } catch (Exception e) {
2002            result.Error(e);
2003        }
2004        return result.Produce();
2005    }
2006    
2007    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
2008        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
2009        LSCPResultSet result;
2010        try {
2011            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2012    
2013            FxSend* pFxSend = NULL;
2014            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2015                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2016                    pFxSend = pEngineChannel->GetFxSend(i);
2017                    break;
2018                }
2019            }
2020            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2021            pEngineChannel->RemoveFxSend(pFxSend);
2022        } catch (Exception e) {
2023            result.Error(e);
2024        }
2025        return result.Produce();
2026    }
2027    
2028    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
2029        dmsg(2,("LSCPServer: GetFxSends()\n"));
2030        LSCPResultSet result;
2031        try {
2032            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2033    
2034            result.Add(pEngineChannel->GetFxSendCount());
2035        } catch (Exception e) {
2036            result.Error(e);
2037        }
2038        return result.Produce();
2039    }
2040    
2041    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
2042        dmsg(2,("LSCPServer: ListFxSends()\n"));
2043        LSCPResultSet result;
2044        String list;
2045        try {
2046            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2047    
2048            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2049                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
2050                if (list != "") list += ",";
2051                list += ToString(pFxSend->Id());
2052            }
2053            result.Add(list);
2054        } catch (Exception e) {
2055            result.Error(e);
2056        }
2057        return result.Produce();
2058    }
2059    
2060    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2061        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2062    
2063        FxSend* pFxSend = NULL;
2064        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2065            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2066                pFxSend = pEngineChannel->GetFxSend(i);
2067                break;
2068            }
2069        }
2070        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2071        return pFxSend;
2072    }
2073    
2074    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2075        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2076        LSCPResultSet result;
2077        try {
2078            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2079            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2080            
2081            // gather audio routing informations
2082            String AudioRouting;
2083            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
2084                if (AudioRouting != "") AudioRouting += ",";
2085                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2086            }
2087    
2088            // success
2089            result.Add("NAME", pFxSend->Name());
2090            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2091            result.Add("LEVEL", ToString(pFxSend->Level()));
2092            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2093        } catch (Exception e) {
2094            result.Error(e);
2095        }
2096        return result.Produce();
2097    }
2098    
2099    String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2100        dmsg(2,("LSCPServer: SetFxSendName()\n"));
2101        LSCPResultSet result;
2102        try {
2103            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2104    
2105            pFxSend->SetName(Name);
2106            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2107        } catch (Exception e) {
2108            result.Error(e);
2109        }
2110        return result.Produce();
2111    }
2112    
2113    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2114        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2115        LSCPResultSet result;
2116        try {
2117            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2118    
2119            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2120            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2121        } catch (Exception e) {
2122            result.Error(e);
2123        }
2124        return result.Produce();
2125    }
2126    
2127    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2128        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2129        LSCPResultSet result;
2130        try {
2131            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2132    
2133            pFxSend->SetMidiController(MidiController);
2134            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2135        } catch (Exception e) {
2136            result.Error(e);
2137        }
2138        return result.Produce();
2139    }
2140    
2141    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2142        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2143        LSCPResultSet result;
2144        try {
2145            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2146    
2147            pFxSend->SetLevel((float)dLevel);
2148            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2149        } catch (Exception e) {
2150            result.Error(e);
2151        }
2152        return result.Produce();
2153    }
2154    
2155  /**  /**
2156   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2157   */   */
# Line 1530  String LSCPServer::ResetChannel(uint uiS Line 2160  String LSCPServer::ResetChannel(uint uiS
2160      LSCPResultSet result;      LSCPResultSet result;
2161      try {      try {
2162          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2163          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2164          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2165          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2166          pEngineChannel->Reset();          pEngineChannel->Reset();
2167      }      }
2168      catch (LinuxSamplerException e) {      catch (Exception e) {
2169           result.Error(e);           result.Error(e);
2170      }      }
2171      return result.Produce();      return result.Produce();
# Line 1560  String LSCPServer::GetServerInfo() { Line 2190  String LSCPServer::GetServerInfo() {
2190      LSCPResultSet result;      LSCPResultSet result;
2191      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
2192      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2193      result.Add("PROTOCOL_VERSION", "1.0");      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2194    #if HAVE_SQLITE3
2195        result.Add("INSTRUMENTS_DB_SUPPORT", "yes");
2196    #else
2197        result.Add("INSTRUMENTS_DB_SUPPORT", "no");
2198    #endif
2199        
2200      return result.Produce();      return result.Produce();
2201  }  }
2202    
# Line 1584  String LSCPServer::GetTotalVoiceCountMax Line 2220  String LSCPServer::GetTotalVoiceCountMax
2220      return result.Produce();      return result.Produce();
2221  }  }
2222    
2223    String LSCPServer::GetGlobalVolume() {
2224        LSCPResultSet result;
2225        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2226        return result.Produce();
2227    }
2228    
2229    String LSCPServer::SetGlobalVolume(double dVolume) {
2230        LSCPResultSet result;
2231        try {
2232            if (dVolume < 0) throw Exception("Volume may not be negative");
2233            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2234            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2235        } catch (Exception e) {
2236            result.Error(e);
2237        }
2238        return result.Produce();
2239    }
2240    
2241  /**  /**
2242   * Will be called by the parser to subscribe a client (frontend) on the   * Will be called by the parser to subscribe a client (frontend) on the
2243   * server for receiving event messages.   * server for receiving event messages.
# Line 1610  String LSCPServer::UnsubscribeNotificati Line 2264  String LSCPServer::UnsubscribeNotificati
2264      return result.Produce();      return result.Produce();
2265  }  }
2266    
2267  static int select_callback(void * lscpResultSet, int argc,  String LSCPServer::AddDbInstrumentDirectory(String Dir) {
2268                          char **argv, char **azColName)      dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str()));
2269  {      LSCPResultSet result;
2270      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;  #if HAVE_SQLITE3
2271      resultSet->Add(argc, argv);      try {
2272      return 0;          InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir);
2273        } catch (Exception e) {
2274             result.Error(e);
2275        }
2276    #else
2277        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2278    #endif
2279        return result.Produce();
2280    }
2281    
2282    String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) {
2283        dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force));
2284        LSCPResultSet result;
2285    #if HAVE_SQLITE3
2286        try {
2287            InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force);
2288        } catch (Exception e) {
2289             result.Error(e);
2290        }
2291    #else
2292        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2293    #endif
2294        return result.Produce();
2295    }
2296    
2297    String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2298        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2299        LSCPResultSet result;
2300    #if HAVE_SQLITE3
2301        try {
2302            result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2303        } catch (Exception e) {
2304             result.Error(e);
2305        }
2306    #else
2307        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2308    #endif
2309        return result.Produce();
2310    }
2311    
2312    String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2313        dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2314        LSCPResultSet result;
2315    #if HAVE_SQLITE3
2316        try {
2317            String list;
2318            StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2319    
2320            for (int i = 0; i < dirs->size(); i++) {
2321                if (list != "") list += ",";
2322                list += "'" + dirs->at(i) + "'";
2323            }
2324    
2325            result.Add(list);
2326        } catch (Exception e) {
2327             result.Error(e);
2328        }
2329    #else
2330        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2331    #endif
2332        return result.Produce();
2333    }
2334    
2335    String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) {
2336        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str()));
2337        LSCPResultSet result;
2338    #if HAVE_SQLITE3
2339        try {
2340            DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2341    
2342            result.Add("DESCRIPTION", info.Description);
2343            result.Add("CREATED", info.Created);
2344            result.Add("MODIFIED", info.Modified);
2345        } catch (Exception e) {
2346             result.Error(e);
2347        }
2348    #else
2349        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2350    #endif
2351        return result.Produce();
2352    }
2353    
2354    String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) {
2355        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str()));
2356        LSCPResultSet result;
2357    #if HAVE_SQLITE3
2358        try {
2359            InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name);
2360        } catch (Exception e) {
2361             result.Error(e);
2362        }
2363    #else
2364        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2365    #endif
2366        return result.Produce();
2367    }
2368    
2369    String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) {
2370        dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2371        LSCPResultSet result;
2372    #if HAVE_SQLITE3
2373        try {
2374            InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst);
2375        } catch (Exception e) {
2376             result.Error(e);
2377        }
2378    #else
2379        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2380    #endif
2381        return result.Produce();
2382    }
2383    
2384    String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2385        dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2386        LSCPResultSet result;
2387    #if HAVE_SQLITE3
2388        try {
2389            InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2390        } catch (Exception e) {
2391             result.Error(e);
2392        }
2393    #else
2394        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2395    #endif
2396        return result.Produce();
2397    }
2398    
2399    String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2400        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str()));
2401        LSCPResultSet result;
2402    #if HAVE_SQLITE3
2403        try {
2404            InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2405        } catch (Exception e) {
2406             result.Error(e);
2407        }
2408    #else
2409        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2410    #endif
2411        return result.Produce();
2412    }
2413    
2414    String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) {
2415        dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index));
2416        LSCPResultSet result;
2417    #if HAVE_SQLITE3
2418        try {
2419            InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index);
2420        } catch (Exception e) {
2421             result.Error(e);
2422        }
2423    #else
2424        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2425    #endif
2426        return result.Produce();
2427    }
2428    
2429    String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) {
2430        dmsg(2,("LSCPServer: AddDbInstrumentsFlat(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str()));
2431        LSCPResultSet result;
2432    #if HAVE_SQLITE3
2433        try {
2434            InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true);
2435        } catch (Exception e) {
2436             result.Error(e);
2437        }
2438    #else
2439        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2440    #endif
2441        return result.Produce();
2442    }
2443    
2444    String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) {
2445        dmsg(2,("LSCPServer: AddDbInstrumentsNonrecursive(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str()));
2446        LSCPResultSet result;
2447    #if HAVE_SQLITE3
2448        try {
2449            InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir);
2450        } catch (Exception e) {
2451             result.Error(e);
2452        }
2453    #else
2454        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2455    #endif
2456        return result.Produce();
2457    }
2458    
2459    String LSCPServer::RemoveDbInstrument(String Instr) {
2460        dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str()));
2461        LSCPResultSet result;
2462    #if HAVE_SQLITE3
2463        try {
2464            InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr);
2465        } catch (Exception e) {
2466             result.Error(e);
2467        }
2468    #else
2469        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2470    #endif
2471        return result.Produce();
2472    }
2473    
2474    String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2475        dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2476        LSCPResultSet result;
2477    #if HAVE_SQLITE3
2478        try {
2479            result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
2480        } catch (Exception e) {
2481             result.Error(e);
2482        }
2483    #else
2484        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2485    #endif
2486        return result.Produce();
2487    }
2488    
2489    String LSCPServer::GetDbInstruments(String Dir, bool Recursive) {
2490        dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2491        LSCPResultSet result;
2492    #if HAVE_SQLITE3
2493        try {
2494            String list;
2495            StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2496    
2497            for (int i = 0; i < instrs->size(); i++) {
2498                if (list != "") list += ",";
2499                list += "'" + instrs->at(i) + "'";
2500            }
2501    
2502            result.Add(list);
2503        } catch (Exception e) {
2504             result.Error(e);
2505        }
2506    #else
2507        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2508    #endif
2509        return result.Produce();
2510    }
2511    
2512    String LSCPServer::GetDbInstrumentInfo(String Instr) {
2513        dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str()));
2514        LSCPResultSet result;
2515    #if HAVE_SQLITE3
2516        try {
2517            DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr);
2518    
2519            result.Add("INSTRUMENT_FILE", info.InstrFile);
2520            result.Add("INSTRUMENT_NR", info.InstrNr);
2521            result.Add("FORMAT_FAMILY", info.FormatFamily);
2522            result.Add("FORMAT_VERSION", info.FormatVersion);
2523            result.Add("SIZE", (int)info.Size);
2524            result.Add("CREATED", info.Created);
2525            result.Add("MODIFIED", info.Modified);
2526            result.Add("DESCRIPTION", FilterEndlines(info.Description));
2527            result.Add("IS_DRUM", info.IsDrum);
2528            result.Add("PRODUCT", FilterEndlines(info.Product));
2529            result.Add("ARTISTS", FilterEndlines(info.Artists));
2530            result.Add("KEYWORDS", FilterEndlines(info.Keywords));
2531        } catch (Exception e) {
2532             result.Error(e);
2533        }
2534    #else
2535        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2536    #endif
2537        return result.Produce();
2538  }  }
2539    
2540  String LSCPServer::QueryDatabase(String query) {  String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2541        dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str()));
2542      LSCPResultSet result;      LSCPResultSet result;
2543  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2544      char* zErrMsg = NULL;      try {
2545      sqlite3 *db;          InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name);
2546      String selectStr = "SELECT " + query;      } catch (Exception e) {
2547             result.Error(e);
2548        }
2549    #else
2550        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2551    #endif
2552        return result.Produce();
2553    }
2554    
2555      int rc = sqlite3_open("linuxsampler.db", &db);  String LSCPServer::MoveDbInstrument(String Instr, String Dst) {
2556      if (rc == SQLITE_OK)      dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2557      {      LSCPResultSet result;
2558              rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);  #if HAVE_SQLITE3
2559        try {
2560            InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst);
2561        } catch (Exception e) {
2562             result.Error(e);
2563      }      }
2564      if ( rc != SQLITE_OK )  #else
2565      {      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2566              result.Error(String(zErrMsg), rc);  #endif
2567        return result.Produce();
2568    }
2569    
2570    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2571        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2572        LSCPResultSet result;
2573    #if HAVE_SQLITE3
2574        try {
2575            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2576        } catch (Exception e) {
2577             result.Error(e);
2578      }      }
     sqlite3_close(db);  
2579  #else  #else
2580      result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2581  #endif  #endif
2582      return result.Produce();      return result.Produce();
2583  }  }
2584    
2585    String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2586        dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str()));
2587        LSCPResultSet result;
2588    #if HAVE_SQLITE3
2589        try {
2590            InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc);
2591        } catch (Exception e) {
2592             result.Error(e);
2593        }
2594    #else
2595        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2596    #endif
2597        return result.Produce();
2598    }
2599    
2600    String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2601        dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2602        LSCPResultSet result;
2603    #if HAVE_SQLITE3
2604        try {
2605            SearchQuery Query;
2606            std::map<String,String>::iterator iter;
2607            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2608                if (iter->first.compare("NAME") == 0) {
2609                    Query.Name = iter->second;
2610                } else if (iter->first.compare("CREATED") == 0) {
2611                    Query.SetCreated(iter->second);
2612                } else if (iter->first.compare("MODIFIED") == 0) {
2613                    Query.SetModified(iter->second);
2614                } else if (iter->first.compare("DESCRIPTION") == 0) {
2615                    Query.Description = iter->second;
2616                } else {
2617                    throw Exception("Unknown search criteria: " + iter->first);
2618                }
2619            }
2620    
2621            String list;
2622            StringListPtr pDirectories =
2623                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2624    
2625            for (int i = 0; i < pDirectories->size(); i++) {
2626                if (list != "") list += ",";
2627                list += "'" + pDirectories->at(i) + "'";
2628            }
2629    
2630            result.Add(list);
2631        } catch (Exception e) {
2632             result.Error(e);
2633        }
2634    #else
2635        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2636    #endif
2637        return result.Produce();
2638    }
2639    
2640    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2641        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2642        LSCPResultSet result;
2643    #if HAVE_SQLITE3
2644        try {
2645            SearchQuery Query;
2646            std::map<String,String>::iterator iter;
2647            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2648                if (iter->first.compare("NAME") == 0) {
2649                    Query.Name = iter->second;
2650                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2651                    Query.SetFormatFamilies(iter->second);
2652                } else if (iter->first.compare("SIZE") == 0) {
2653                    Query.SetSize(iter->second);
2654                } else if (iter->first.compare("CREATED") == 0) {
2655                    Query.SetCreated(iter->second);
2656                } else if (iter->first.compare("MODIFIED") == 0) {
2657                    Query.SetModified(iter->second);
2658                } else if (iter->first.compare("DESCRIPTION") == 0) {
2659                    Query.Description = iter->second;
2660                } else if (iter->first.compare("IS_DRUM") == 0) {
2661                    if (!strcasecmp(iter->second.c_str(), "true")) {
2662                        Query.InstrType = SearchQuery::DRUM;
2663                    } else {
2664                        Query.InstrType = SearchQuery::CHROMATIC;
2665                    }
2666                } else if (iter->first.compare("PRODUCT") == 0) {
2667                     Query.Product = iter->second;
2668                } else if (iter->first.compare("ARTISTS") == 0) {
2669                     Query.Artists = iter->second;
2670                } else if (iter->first.compare("KEYWORDS") == 0) {
2671                     Query.Keywords = iter->second;
2672                } else {
2673                    throw Exception("Unknown search criteria: " + iter->first);
2674                }
2675            }
2676    
2677            String list;
2678            StringListPtr pInstruments =
2679                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2680    
2681            for (int i = 0; i < pInstruments->size(); i++) {
2682                if (list != "") list += ",";
2683                list += "'" + pInstruments->at(i) + "'";
2684            }
2685    
2686            result.Add(list);
2687        } catch (Exception e) {
2688             result.Error(e);
2689        }
2690    #else
2691        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2692    #endif
2693        return result.Produce();
2694    }
2695    
2696    
2697  /**  /**
2698   * Will be called by the parser to enable or disable echo mode; if echo   * Will be called by the parser to enable or disable echo mode; if echo
2699   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1652  String LSCPServer::SetEcho(yyparse_param Line 2705  String LSCPServer::SetEcho(yyparse_param
2705      try {      try {
2706          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
2707          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
2708          else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");          else throw Exception("Not a boolean value, must either be 0 or 1");
2709      }      }
2710      catch (LinuxSamplerException e) {      catch (Exception e) {
2711           result.Error(e);           result.Error(e);
2712      }      }
2713      return result.Produce();      return result.Produce();
2714  }  }
2715    
2716    String LSCPServer::FilterEndlines(String s) {
2717        String s2 = s;
2718        for (int i = 0; i < s2.length(); i++) {
2719            if (s2.at(i) == '\r') s2.at(i) = ' ';
2720            else if (s2.at(i) == '\n') s2.at(i) = ' ';
2721        }
2722        
2723        return s2;
2724    }

Legend:
Removed from v.814  
changed lines
  Added in v.1187

  ViewVC Help
Powered by ViewVC