/[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 778 by iliev, Fri Sep 23 06:58:26 2005 UTC revision 1212 by schoenebeck, Tue May 29 23:59:36 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_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
88      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
89      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
90        LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
91      hSocket = -1;      hSocket = -1;
92  }  }
93    
# Line 80  LSCPServer::~LSCPServer() { Line 95  LSCPServer::~LSCPServer() {
95      if (hSocket >= 0) close(hSocket);      if (hSocket >= 0) close(hSocket);
96  }  }
97    
98    void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
99        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
100    }
101    
102    void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
103        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
104    }
105    
106    void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) {
107        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
108    }
109    
110    void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
111        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
112    }
113    
114    void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
115        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program));
116    }
117    
118    void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) {
119        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount));
120    }
121    
122    void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) {
123        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId));
124    }
125    
126    void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
127        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount));
128    }
129    
130    void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) {
131        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount));
132    }
133    
134    void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) {
135        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount));
136    }
137    
138    void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) {
139        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData));
140    }
141    
142    void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) {
143        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
144    }
145    
146    #if HAVE_SQLITE3
147    void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
148        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir));
149    }
150    
151    void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {
152        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir));
153    }
154    
155    void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {
156        Dir = "'" + Dir + "'";
157        NewName = "'" + NewName + "'";
158        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));
159    }
160    
161    void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {
162        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir));
163    }
164    
165    void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) {
166        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr));
167    }
168    
169    void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
170        Instr = "'" + Instr + "'";
171        NewName = "'" + NewName + "'";
172        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName));
173    }
174    
175    void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) {
176        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId));
177    }
178    #endif // HAVE_SQLITE3
179    
180    
181  /**  /**
182   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
183   * 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 218  int LSCPServer::Main() {
218    
219      listen(hSocket, 1);      listen(hSocket, 1);
220      Initialized.Set(true);      Initialized.Set(true);
221        
222        // Registering event listeners
223        pSampler->AddChannelCountListener(&eventHandler);
224        pSampler->AddAudioDeviceCountListener(&eventHandler);
225        pSampler->AddMidiDeviceCountListener(&eventHandler);
226        pSampler->AddVoiceCountListener(&eventHandler);
227        pSampler->AddStreamCountListener(&eventHandler);
228        pSampler->AddBufferFillListener(&eventHandler);
229        pSampler->AddTotalVoiceCountListener(&eventHandler);
230        pSampler->AddFxSendCountListener(&eventHandler);
231        MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
232        MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
233        MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
234        MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);
235    #if HAVE_SQLITE3
236        InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler);
237    #endif
238      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
239      sockaddr_in client;      sockaddr_in client;
240      int length = sizeof(client);      int length = sizeof(client);
# Line 128  int LSCPServer::Main() { Line 242  int LSCPServer::Main() {
242      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
243      int maxSessions = hSocket;      int maxSessions = hSocket;
244    
245        timeval timeout;
246    
247      while (true) {      while (true) {
248          fd_set selectSet = fdSet;          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
249          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          {
250                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
251                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
252                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
253                for (; itEngineChannel != itEnd; ++itEngineChannel) {
254                    if ((*itEngineChannel)->StatusChanged()) {
255                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
256                    }
257    
258                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
259                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
260                        if(fxs != NULL && fxs->IsInfoChanged()) {
261                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
262                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
263                            fxs->SetInfoChanged(false);
264                        }
265                    }
266                }
267            }
268    
269            //Now let's deliver late notifies (if any)
270            NotifyBufferMutex.Lock();
271            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
272    #ifdef MSG_NOSIGNAL
273                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
274    #else
275                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
276    #endif
277            }
278            bufferedNotifies.clear();
279            NotifyBufferMutex.Unlock();
280    
281            fd_set selectSet = fdSet;
282            timeout.tv_sec  = 0;
283            timeout.tv_usec = 100000;
284    
285            int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
286    
287          if (retval == 0)          if (retval == 0)
288                  continue; //Nothing try again                  continue; //Nothing try again
289          if (retval == -1) {          if (retval == -1) {
# Line 190  int LSCPServer::Main() { Line 343  int LSCPServer::Main() {
343                          break;                          break;
344                  }                  }
345          }          }
   
         // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers  
         {  
             std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();  
             std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();  
             std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();  
             for (; itEngineChannel != itEnd; ++itEngineChannel) {  
                 if ((*itEngineChannel)->StatusChanged()) {  
                     SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));  
                 }  
             }  
         }  
   
         //Now let's deliver late notifies (if any)  
         NotifyBufferMutex.Lock();  
         for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {  
                 send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);  
                 bufferedNotifies.erase(iterNotify);  
         }  
         NotifyBufferMutex.Unlock();  
346      }      }
347  }  }
348    
# Line 256  void LSCPServer::SendLSCPNotify( LSCPEve Line 389  void LSCPServer::SendLSCPNotify( LSCPEve
389          while (true) {          while (true) {
390                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
391                          for(;iter != end; iter++)                          for(;iter != end; iter++)
392    #ifdef MSG_NOSIGNAL
393                                  send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);                                  send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
394    #else
395                                    send(*iter, notify.c_str(), notify.size(), 0);
396    #endif
397                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
398                          break;                          break;
399                  } else {                  } else {
# Line 308  bool LSCPServer::GetLSCPCommand( std::ve Line 445  bool LSCPServer::GetLSCPCommand( std::ve
445                                  continue; //Ignore CR                                  continue; //Ignore CR
446                          if (c == '\n') {                          if (c == '\n') {
447                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
448                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
449                                  return true; //Complete command was read                                  return true; //Complete command was read
450                          }                          }
451                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
# Line 365  void LSCPServer::AnswerClient(String Ret Line 502  void LSCPServer::AnswerClient(String Ret
502      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
503      if (currentSocket != -1) {      if (currentSocket != -1) {
504              NotifyMutex.Lock();              NotifyMutex.Lock();
505    #ifdef MSG_NOSIGNAL
506              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
507    #else
508                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
509    #endif
510              NotifyMutex.Unlock();              NotifyMutex.Unlock();
511      }      }
512  }  }
# Line 409  String LSCPServer::CreateAudioOutputDevi Line 550  String LSCPServer::CreateAudioOutputDevi
550          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
551          // search for the created device to get its index          // search for the created device to get its index
552          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
553          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.");
554          result = index; // success          result = index; // success
555      }      }
556      catch (LinuxSamplerException e) {      catch (Exception e) {
557          result.Error(e);          result.Error(e);
558      }      }
559      return result.Produce();      return result.Produce();
# Line 425  String LSCPServer::CreateMidiInputDevice Line 566  String LSCPServer::CreateMidiInputDevice
566          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
567          // search for the created device to get its index          // search for the created device to get its index
568          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
569          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.");
570          result = index; // success          result = index; // success
571      }      }
572      catch (LinuxSamplerException e) {      catch (Exception e) {
573          result.Error(e);          result.Error(e);
574      }      }
575      return result.Produce();      return result.Produce();
# Line 439  String LSCPServer::DestroyAudioOutputDev Line 580  String LSCPServer::DestroyAudioOutputDev
580      LSCPResultSet result;      LSCPResultSet result;
581      try {      try {
582          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
583          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) + ".");
584          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
585          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
586      }      }
587      catch (LinuxSamplerException e) {      catch (Exception e) {
588          result.Error(e);          result.Error(e);
589      }      }
590      return result.Produce();      return result.Produce();
# Line 454  String LSCPServer::DestroyMidiInputDevic Line 595  String LSCPServer::DestroyMidiInputDevic
595      LSCPResultSet result;      LSCPResultSet result;
596      try {      try {
597          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
598          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) + ".");
599          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
600          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
601      }      }
602      catch (LinuxSamplerException e) {      catch (Exception e) {
603          result.Error(e);          result.Error(e);
604      }      }
605      return result.Produce();      return result.Produce();
606  }  }
607    
608    EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) {
609        SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
610        if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
611    
612        EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
613        if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
614    
615        return pEngineChannel;        
616    }
617    
618  /**  /**
619   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
620   */   */
# Line 472  String LSCPServer::LoadInstrument(String Line 623  String LSCPServer::LoadInstrument(String
623      LSCPResultSet result;      LSCPResultSet result;
624      try {      try {
625          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
626          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
627          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
628          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
629          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
630              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
631          if (bBackground) {          if (bBackground) {
632              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
633                id.FileName = Filename;
634                id.Index    = uiInstrument;
635                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
636          }          }
637          else {          else {
638              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 487  String LSCPServer::LoadInstrument(String Line 641  String LSCPServer::LoadInstrument(String
641              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
642          }          }
643      }      }
644      catch (LinuxSamplerException e) {      catch (Exception e) {
645           result.Error(e);           result.Error(e);
646      }      }
647      return result.Produce();      return result.Produce();
# Line 502  String LSCPServer::SetEngineType(String Line 656  String LSCPServer::SetEngineType(String
656      LSCPResultSet result;      LSCPResultSet result;
657      try {      try {
658          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
659          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
660          LockRTNotify();          LockRTNotify();
661          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
662          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
663          UnlockRTNotify();          UnlockRTNotify();
664      }      }
665      catch (LinuxSamplerException e) {      catch (Exception e) {
666           result.Error(e);           result.Error(e);
667      }      }
668      return result.Produce();      return result.Produce();
# Line 546  String LSCPServer::ListChannels() { Line 700  String LSCPServer::ListChannels() {
700   */   */
701  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
702      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
703        LockRTNotify();
704      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
705        UnlockRTNotify();
706      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
707      return result.Produce();      return result.Produce();
708  }  }
# Line 568  String LSCPServer::RemoveChannel(uint ui Line 724  String LSCPServer::RemoveChannel(uint ui
724   */   */
725  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
726      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
727      LSCPResultSet result("1");      LSCPResultSet result;
728        try {
729            int n = EngineFactory::AvailableEngineTypes().size();
730            result.Add(n);
731        }
732        catch (Exception e) {
733            result.Error(e);
734        }
735      return result.Produce();      return result.Produce();
736  }  }
737    
# Line 577  String LSCPServer::GetAvailableEngines() Line 740  String LSCPServer::GetAvailableEngines()
740   */   */
741  String LSCPServer::ListAvailableEngines() {  String LSCPServer::ListAvailableEngines() {
742      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
743      LSCPResultSet result("\'GIG\'");      LSCPResultSet result;
744        try {
745            String s = EngineFactory::AvailableEngineTypesAsString();
746            result.Add(s);
747        }
748        catch (Exception e) {
749            result.Error(e);
750        }
751      return result.Produce();      return result.Produce();
752  }  }
753    
# Line 588  String LSCPServer::ListAvailableEngines( Line 758  String LSCPServer::ListAvailableEngines(
758  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
759      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
760      LSCPResultSet result;      LSCPResultSet result;
761        LockRTNotify();
762      try {      try {
763          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
764          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
765          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
766          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
767      }      }
768      catch (LinuxSamplerException e) {      catch (Exception e) {
769           result.Error(e);           result.Error(e);
770      }      }
771        UnlockRTNotify();
772      return result.Produce();      return result.Produce();
773  }  }
774    
# Line 609  String LSCPServer::GetChannelInfo(uint u Line 781  String LSCPServer::GetChannelInfo(uint u
781      LSCPResultSet result;      LSCPResultSet result;
782      try {      try {
783          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
784          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
785          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
786    
787          //Defaults values          //Defaults values
# Line 623  String LSCPServer::GetChannelInfo(uint u Line 795  String LSCPServer::GetChannelInfo(uint u
795          String AudioRouting;          String AudioRouting;
796          int Mute = 0;          int Mute = 0;
797          bool Solo = false;          bool Solo = false;
798            String MidiInstrumentMap = "NONE";
799    
800          if (pEngineChannel) {          if (pEngineChannel) {
801              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 640  String LSCPServer::GetChannelInfo(uint u Line 813  String LSCPServer::GetChannelInfo(uint u
813              }              }
814              Mute = pEngineChannel->GetMute();              Mute = pEngineChannel->GetMute();
815              Solo = pEngineChannel->GetSolo();              Solo = pEngineChannel->GetSolo();
816                if (pEngineChannel->UsesNoMidiInstrumentMap())
817                    MidiInstrumentMap = "NONE";
818                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
819                    MidiInstrumentMap = "DEFAULT";
820                else
821                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
822          }          }
823    
824          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 661  String LSCPServer::GetChannelInfo(uint u Line 840  String LSCPServer::GetChannelInfo(uint u
840          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
841          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
842          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
843            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
844      }      }
845      catch (LinuxSamplerException e) {      catch (Exception e) {
846           result.Error(e);           result.Error(e);
847      }      }
848      return result.Produce();      return result.Produce();
# Line 677  String LSCPServer::GetVoiceCount(uint ui Line 857  String LSCPServer::GetVoiceCount(uint ui
857      LSCPResultSet result;      LSCPResultSet result;
858      try {      try {
859          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
860          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
861          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
862          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
863          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");
864          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
865      }      }
866      catch (LinuxSamplerException e) {      catch (Exception e) {
867           result.Error(e);           result.Error(e);
868      }      }
869      return result.Produce();      return result.Produce();
# Line 698  String LSCPServer::GetStreamCount(uint u Line 878  String LSCPServer::GetStreamCount(uint u
878      LSCPResultSet result;      LSCPResultSet result;
879      try {      try {
880          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
881          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
882          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
883          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
884          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");
885          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
886      }      }
887      catch (LinuxSamplerException e) {      catch (Exception e) {
888           result.Error(e);           result.Error(e);
889      }      }
890      return result.Produce();      return result.Produce();
# Line 719  String LSCPServer::GetBufferFill(fill_re Line 899  String LSCPServer::GetBufferFill(fill_re
899      LSCPResultSet result;      LSCPResultSet result;
900      try {      try {
901          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
902          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
903          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
904          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
905          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");
906          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
907          else {          else {
908              switch (ResponseType) {              switch (ResponseType) {
# Line 733  String LSCPServer::GetBufferFill(fill_re Line 913  String LSCPServer::GetBufferFill(fill_re
913                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
914                      break;                      break;
915                  default:                  default:
916                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
917              }              }
918          }          }
919      }      }
920      catch (LinuxSamplerException e) {      catch (Exception e) {
921           result.Error(e);           result.Error(e);
922      }      }
923      return result.Produce();      return result.Produce();
# Line 750  String LSCPServer::GetAvailableAudioOutp Line 930  String LSCPServer::GetAvailableAudioOutp
930          int n = AudioOutputDeviceFactory::AvailableDrivers().size();          int n = AudioOutputDeviceFactory::AvailableDrivers().size();
931          result.Add(n);          result.Add(n);
932      }      }
933      catch (LinuxSamplerException e) {      catch (Exception e) {
934          result.Error(e);          result.Error(e);
935      }      }
936      return result.Produce();      return result.Produce();
# Line 763  String LSCPServer::ListAvailableAudioOut Line 943  String LSCPServer::ListAvailableAudioOut
943          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
944          result.Add(s);          result.Add(s);
945      }      }
946      catch (LinuxSamplerException e) {      catch (Exception e) {
947          result.Error(e);          result.Error(e);
948      }      }
949      return result.Produce();      return result.Produce();
# Line 776  String LSCPServer::GetAvailableMidiInput Line 956  String LSCPServer::GetAvailableMidiInput
956          int n = MidiInputDeviceFactory::AvailableDrivers().size();          int n = MidiInputDeviceFactory::AvailableDrivers().size();
957          result.Add(n);          result.Add(n);
958      }      }
959      catch (LinuxSamplerException e) {      catch (Exception e) {
960          result.Error(e);          result.Error(e);
961      }      }
962      return result.Produce();      return result.Produce();
# Line 789  String LSCPServer::ListAvailableMidiInpu Line 969  String LSCPServer::ListAvailableMidiInpu
969          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
970          result.Add(s);          result.Add(s);
971      }      }
972      catch (LinuxSamplerException e) {      catch (Exception e) {
973          result.Error(e);          result.Error(e);
974      }      }
975      return result.Produce();      return result.Produce();
# Line 813  String LSCPServer::GetMidiInputDriverInf Line 993  String LSCPServer::GetMidiInputDriverInf
993              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
994          }          }
995      }      }
996      catch (LinuxSamplerException e) {      catch (Exception e) {
997          result.Error(e);          result.Error(e);
998      }      }
999      return result.Produce();      return result.Produce();
# Line 837  String LSCPServer::GetAudioOutputDriverI Line 1017  String LSCPServer::GetAudioOutputDriverI
1017              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1018          }          }
1019      }      }
1020      catch (LinuxSamplerException e) {      catch (Exception e) {
1021          result.Error(e);          result.Error(e);
1022      }      }
1023      return result.Produce();      return result.Produce();
# Line 864  String LSCPServer::GetMidiInputDriverPar Line 1044  String LSCPServer::GetMidiInputDriverPar
1044          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1045          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1046      }      }
1047      catch (LinuxSamplerException e) {      catch (Exception e) {
1048          result.Error(e);          result.Error(e);
1049      }      }
1050      return result.Produce();      return result.Produce();
# Line 891  String LSCPServer::GetAudioOutputDriverP Line 1071  String LSCPServer::GetAudioOutputDriverP
1071          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1072          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1073      }      }
1074      catch (LinuxSamplerException e) {      catch (Exception e) {
1075          result.Error(e);          result.Error(e);
1076      }      }
1077      return result.Produce();      return result.Produce();
# Line 904  String LSCPServer::GetAudioOutputDeviceC Line 1084  String LSCPServer::GetAudioOutputDeviceC
1084          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
1085          result.Add(count); // success          result.Add(count); // success
1086      }      }
1087      catch (LinuxSamplerException e) {      catch (Exception e) {
1088          result.Error(e);          result.Error(e);
1089      }      }
1090      return result.Produce();      return result.Produce();
# Line 917  String LSCPServer::GetMidiInputDeviceCou Line 1097  String LSCPServer::GetMidiInputDeviceCou
1097          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
1098          result.Add(count); // success          result.Add(count); // success
1099      }      }
1100      catch (LinuxSamplerException e) {      catch (Exception e) {
1101          result.Error(e);          result.Error(e);
1102      }      }
1103      return result.Produce();      return result.Produce();
# Line 936  String LSCPServer::GetAudioOutputDevices Line 1116  String LSCPServer::GetAudioOutputDevices
1116          }          }
1117          result.Add(s);          result.Add(s);
1118      }      }
1119      catch (LinuxSamplerException e) {      catch (Exception e) {
1120          result.Error(e);          result.Error(e);
1121      }      }
1122      return result.Produce();      return result.Produce();
# Line 955  String LSCPServer::GetMidiInputDevices() Line 1135  String LSCPServer::GetMidiInputDevices()
1135          }          }
1136          result.Add(s);          result.Add(s);
1137      }      }
1138      catch (LinuxSamplerException e) {      catch (Exception e) {
1139          result.Error(e);          result.Error(e);
1140      }      }
1141      return result.Produce();      return result.Produce();
# Line 966  String LSCPServer::GetAudioOutputDeviceI Line 1146  String LSCPServer::GetAudioOutputDeviceI
1146      LSCPResultSet result;      LSCPResultSet result;
1147      try {      try {
1148          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1149          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) + ".");
1150          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1151          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1152          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 975  String LSCPServer::GetAudioOutputDeviceI Line 1155  String LSCPServer::GetAudioOutputDeviceI
1155              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1156          }          }
1157      }      }
1158      catch (LinuxSamplerException e) {      catch (Exception e) {
1159          result.Error(e);          result.Error(e);
1160      }      }
1161      return result.Produce();      return result.Produce();
# Line 986  String LSCPServer::GetMidiInputDeviceInf Line 1166  String LSCPServer::GetMidiInputDeviceInf
1166      LSCPResultSet result;      LSCPResultSet result;
1167      try {      try {
1168          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1169          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) + ".");
1170          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1171          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1172          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 995  String LSCPServer::GetMidiInputDeviceInf Line 1175  String LSCPServer::GetMidiInputDeviceInf
1175              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1176          }          }
1177      }      }
1178      catch (LinuxSamplerException e) {      catch (Exception e) {
1179          result.Error(e);          result.Error(e);
1180      }      }
1181      return result.Produce();      return result.Produce();
# Line 1006  String LSCPServer::GetMidiInputPortInfo( Line 1186  String LSCPServer::GetMidiInputPortInfo(
1186      try {      try {
1187          // get MIDI input device          // get MIDI input device
1188          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1189          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) + ".");
1190          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1191    
1192          // get MIDI port          // get MIDI port
1193          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1194          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) + ".");
1195    
1196          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1197          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 1020  String LSCPServer::GetMidiInputPortInfo( Line 1200  String LSCPServer::GetMidiInputPortInfo(
1200              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1201          }          }
1202      }      }
1203      catch (LinuxSamplerException e) {      catch (Exception e) {
1204          result.Error(e);          result.Error(e);
1205      }      }
1206      return result.Produce();      return result.Produce();
# Line 1032  String LSCPServer::GetAudioOutputChannel Line 1212  String LSCPServer::GetAudioOutputChannel
1212      try {      try {
1213          // get audio output device          // get audio output device
1214          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1215          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) + ".");
1216          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1217    
1218          // get audio channel          // get audio channel
1219          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1220          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) + ".");
1221    
1222          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1223          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1046  String LSCPServer::GetAudioOutputChannel Line 1226  String LSCPServer::GetAudioOutputChannel
1226              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1227          }          }
1228      }      }
1229      catch (LinuxSamplerException e) {      catch (Exception e) {
1230          result.Error(e);          result.Error(e);
1231      }      }
1232      return result.Produce();      return result.Produce();
# Line 1058  String LSCPServer::GetMidiInputPortParam Line 1238  String LSCPServer::GetMidiInputPortParam
1238      try {      try {
1239          // get MIDI input device          // get MIDI input device
1240          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1241          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) + ".");
1242          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1243    
1244          // get midi port          // get midi port
1245          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1246          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) + ".");
1247    
1248          // get desired port parameter          // get desired port parameter
1249          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1250          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 + "'.");
1251          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1252    
1253          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1079  String LSCPServer::GetMidiInputPortParam Line 1259  String LSCPServer::GetMidiInputPortParam
1259          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1260          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1261      }      }
1262      catch (LinuxSamplerException e) {      catch (Exception e) {
1263          result.Error(e);          result.Error(e);
1264      }      }
1265      return result.Produce();      return result.Produce();
# Line 1091  String LSCPServer::GetAudioOutputChannel Line 1271  String LSCPServer::GetAudioOutputChannel
1271      try {      try {
1272          // get audio output device          // get audio output device
1273          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1274          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) + ".");
1275          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1276    
1277          // get audio channel          // get audio channel
1278          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1279          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) + ".");
1280    
1281          // get desired audio channel parameter          // get desired audio channel parameter
1282          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1283          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 + "'.");
1284          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1285    
1286          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1112  String LSCPServer::GetAudioOutputChannel Line 1292  String LSCPServer::GetAudioOutputChannel
1292          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1293          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1294      }      }
1295      catch (LinuxSamplerException e) {      catch (Exception e) {
1296          result.Error(e);          result.Error(e);
1297      }      }
1298      return result.Produce();      return result.Produce();
# Line 1124  String LSCPServer::SetAudioOutputChannel Line 1304  String LSCPServer::SetAudioOutputChannel
1304      try {      try {
1305          // get audio output device          // get audio output device
1306          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1307          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) + ".");
1308          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1309    
1310          // get audio channel          // get audio channel
1311          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1312          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) + ".");
1313    
1314          // get desired audio channel parameter          // get desired audio channel parameter
1315          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1316          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 + "'.");
1317          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1318    
1319          // set new channel parameter value          // set new channel parameter value
1320          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1321            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1322      }      }
1323      catch (LinuxSamplerException e) {      catch (Exception e) {
1324          result.Error(e);          result.Error(e);
1325      }      }
1326      return result.Produce();      return result.Produce();
# Line 1150  String LSCPServer::SetAudioOutputDeviceP Line 1331  String LSCPServer::SetAudioOutputDeviceP
1331      LSCPResultSet result;      LSCPResultSet result;
1332      try {      try {
1333          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1334          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) + ".");
1335          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1336          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1337          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 + "'");
1338          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1339            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1340      }      }
1341      catch (LinuxSamplerException e) {      catch (Exception e) {
1342          result.Error(e);          result.Error(e);
1343      }      }
1344      return result.Produce();      return result.Produce();
# Line 1167  String LSCPServer::SetMidiInputDevicePar Line 1349  String LSCPServer::SetMidiInputDevicePar
1349      LSCPResultSet result;      LSCPResultSet result;
1350      try {      try {
1351          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1352          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) + ".");
1353          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1354          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1355          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 + "'");
1356          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1357            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1358      }      }
1359      catch (LinuxSamplerException e) {      catch (Exception e) {
1360          result.Error(e);          result.Error(e);
1361      }      }
1362      return result.Produce();      return result.Produce();
# Line 1185  String LSCPServer::SetMidiInputPortParam Line 1368  String LSCPServer::SetMidiInputPortParam
1368      try {      try {
1369          // get MIDI input device          // get MIDI input device
1370          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1371          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) + ".");
1372          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1373    
1374          // get MIDI port          // get MIDI port
1375          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1376          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) + ".");
1377    
1378          // set port parameter value          // set port parameter value
1379          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1380          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 + "'");
1381          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1382            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1383      }      }
1384      catch (LinuxSamplerException e) {      catch (Exception e) {
1385          result.Error(e);          result.Error(e);
1386      }      }
1387      return result.Produce();      return result.Produce();
# Line 1212  String LSCPServer::SetAudioOutputChannel Line 1396  String LSCPServer::SetAudioOutputChannel
1396      LSCPResultSet result;      LSCPResultSet result;
1397      try {      try {
1398          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1399          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1400          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1401          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));
1402          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));
1403          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1404      }      }
1405      catch (LinuxSamplerException e) {      catch (Exception e) {
1406           result.Error(e);           result.Error(e);
1407      }      }
1408      return result.Produce();      return result.Produce();
# Line 1227  String LSCPServer::SetAudioOutputChannel Line 1411  String LSCPServer::SetAudioOutputChannel
1411  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1412      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1413      LSCPResultSet result;      LSCPResultSet result;
1414        LockRTNotify();
1415      try {      try {
1416          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1417          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1418          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1419          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));
1420          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1421          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1422      }      }
1423      catch (LinuxSamplerException e) {      catch (Exception e) {
1424           result.Error(e);           result.Error(e);
1425      }      }
1426        UnlockRTNotify();
1427      return result.Produce();      return result.Produce();
1428  }  }
1429    
1430  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1431      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));
1432      LSCPResultSet result;      LSCPResultSet result;
1433        LockRTNotify();
1434      try {      try {
1435          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1436          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1437          // Driver type name aliasing...          // Driver type name aliasing...
1438          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1439          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1268  String LSCPServer::SetAudioOutputType(St Line 1455  String LSCPServer::SetAudioOutputType(St
1455          }          }
1456          // Must have a device...          // Must have a device...
1457          if (pDevice == NULL)          if (pDevice == NULL)
1458              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1459          // Set it as the current channel device...          // Set it as the current channel device...
1460          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1461      }      }
1462      catch (LinuxSamplerException e) {      catch (Exception e) {
1463           result.Error(e);           result.Error(e);
1464      }      }
1465        UnlockRTNotify();
1466      return result.Produce();      return result.Produce();
1467  }  }
1468    
# Line 1283  String LSCPServer::SetMIDIInputPort(uint Line 1471  String LSCPServer::SetMIDIInputPort(uint
1471      LSCPResultSet result;      LSCPResultSet result;
1472      try {      try {
1473          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1474          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1475          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1476      }      }
1477      catch (LinuxSamplerException e) {      catch (Exception e) {
1478           result.Error(e);           result.Error(e);
1479      }      }
1480      return result.Produce();      return result.Produce();
# Line 1297  String LSCPServer::SetMIDIInputChannel(u Line 1485  String LSCPServer::SetMIDIInputChannel(u
1485      LSCPResultSet result;      LSCPResultSet result;
1486      try {      try {
1487          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1488          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1489          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1490      }      }
1491      catch (LinuxSamplerException e) {      catch (Exception e) {
1492           result.Error(e);           result.Error(e);
1493      }      }
1494      return result.Produce();      return result.Produce();
# Line 1311  String LSCPServer::SetMIDIInputDevice(ui Line 1499  String LSCPServer::SetMIDIInputDevice(ui
1499      LSCPResultSet result;      LSCPResultSet result;
1500      try {      try {
1501          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1502          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1503          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1504          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));
1505          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1506          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1507      }      }
1508      catch (LinuxSamplerException e) {      catch (Exception e) {
1509           result.Error(e);           result.Error(e);
1510      }      }
1511      return result.Produce();      return result.Produce();
# Line 1328  String LSCPServer::SetMIDIInputType(Stri Line 1516  String LSCPServer::SetMIDIInputType(Stri
1516      LSCPResultSet result;      LSCPResultSet result;
1517      try {      try {
1518          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1519          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1520          // Driver type name aliasing...          // Driver type name aliasing...
1521          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1522          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1352  String LSCPServer::SetMIDIInputType(Stri Line 1540  String LSCPServer::SetMIDIInputType(Stri
1540          }          }
1541          // Must have a device...          // Must have a device...
1542          if (pDevice == NULL)          if (pDevice == NULL)
1543              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1544          // Set it as the current channel device...          // Set it as the current channel device...
1545          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1546      }      }
1547      catch (LinuxSamplerException e) {      catch (Exception e) {
1548           result.Error(e);           result.Error(e);
1549      }      }
1550      return result.Produce();      return result.Produce();
# Line 1371  String LSCPServer::SetMIDIInput(uint MID Line 1559  String LSCPServer::SetMIDIInput(uint MID
1559      LSCPResultSet result;      LSCPResultSet result;
1560      try {      try {
1561          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1562          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1563          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1564          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));
1565          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1566          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1567      }      }
1568      catch (LinuxSamplerException e) {      catch (Exception e) {
1569           result.Error(e);           result.Error(e);
1570      }      }
1571      return result.Produce();      return result.Produce();
# Line 1392  String LSCPServer::SetVolume(double dVol Line 1580  String LSCPServer::SetVolume(double dVol
1580      LSCPResultSet result;      LSCPResultSet result;
1581      try {      try {
1582          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1583          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1584          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1585          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1586          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1587      }      }
1588      catch (LinuxSamplerException e) {      catch (Exception e) {
1589           result.Error(e);           result.Error(e);
1590      }      }
1591      return result.Produce();      return result.Produce();
# Line 1411  String LSCPServer::SetChannelMute(bool b Line 1599  String LSCPServer::SetChannelMute(bool b
1599      LSCPResultSet result;      LSCPResultSet result;
1600      try {      try {
1601          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1602          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1603    
1604          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1605          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1606    
1607          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1608          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
1609      } catch (LinuxSamplerException e) {      } catch (Exception e) {
1610          result.Error(e);          result.Error(e);
1611      }      }
1612      return result.Produce();      return result.Produce();
# Line 1432  String LSCPServer::SetChannelSolo(bool b Line 1620  String LSCPServer::SetChannelSolo(bool b
1620      LSCPResultSet result;      LSCPResultSet result;
1621      try {      try {
1622          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1623          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1624    
1625          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1626          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1627    
1628          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1629          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
1630            
1631          pEngineChannel->SetSolo(bSolo);          pEngineChannel->SetSolo(bSolo);
1632            
1633          if(!oldSolo && bSolo) {          if(!oldSolo && bSolo) {
1634              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1635              if(!hadSoloChannel) MuteNonSoloChannels();              if(!hadSoloChannel) MuteNonSoloChannels();
1636          }          }
1637            
1638          if(oldSolo && !bSolo) {          if(oldSolo && !bSolo) {
1639              if(!HasSoloChannel()) UnmuteChannels();              if(!HasSoloChannel()) UnmuteChannels();
1640              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1641          }          }
1642      } catch (LinuxSamplerException e) {      } catch (Exception e) {
1643          result.Error(e);          result.Error(e);
1644      }      }
1645      return result.Produce();      return result.Produce();
# Line 1504  void  LSCPServer::UnmuteChannels() { Line 1692  void  LSCPServer::UnmuteChannels() {
1692      }      }
1693  }  }
1694    
1695    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) {
1696        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1697    
1698        midi_prog_index_t idx;
1699        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1700        idx.midi_bank_lsb = MidiBank & 0x7f;
1701        idx.midi_prog     = MidiProg;
1702    
1703        MidiInstrumentMapper::entry_t entry;
1704        entry.EngineName      = EngineType;
1705        entry.InstrumentFile  = InstrumentFile;
1706        entry.InstrumentIndex = InstrumentIndex;
1707        entry.LoadMode        = LoadMode;
1708        entry.Volume          = Volume;
1709        entry.Name            = Name;
1710    
1711        LSCPResultSet result;
1712        try {
1713            // PERSISTENT mapping commands might block for a long time, so in
1714            // that case we add/replace the mapping in another thread in case
1715            // the NON_MODAL argument was supplied, non persistent mappings
1716            // should return immediately, so we don't need to do that for them
1717            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1718            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1719        } catch (Exception e) {
1720            result.Error(e);
1721        }
1722        return result.Produce();
1723    }
1724    
1725    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1726        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1727    
1728        midi_prog_index_t idx;
1729        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1730        idx.midi_bank_lsb = MidiBank & 0x7f;
1731        idx.midi_prog     = MidiProg;
1732    
1733        LSCPResultSet result;
1734        try {
1735            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1736        } catch (Exception e) {
1737            result.Error(e);
1738        }
1739        return result.Produce();
1740    }
1741    
1742    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1743        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1744        LSCPResultSet result;
1745        try {
1746            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1747        } catch (Exception e) {
1748            result.Error(e);
1749        }
1750        return result.Produce();
1751    }
1752    
1753    
1754    String LSCPServer::GetAllMidiInstrumentMappings() {
1755        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1756        LSCPResultSet result;
1757        std::vector<int> maps = MidiInstrumentMapper::Maps();
1758        int totalMappings = 0;
1759        for (int i = 0; i < maps.size(); i++) {
1760            try {
1761                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1762            } catch (Exception e) { /*NOOP*/ }
1763        }
1764        result.Add(totalMappings);
1765        return result.Produce();
1766    }
1767    
1768    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1769        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1770        LSCPResultSet result;
1771        try {
1772            midi_prog_index_t idx;
1773            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1774            idx.midi_bank_lsb = MidiBank & 0x7f;
1775            idx.midi_prog     = MidiProg;
1776    
1777            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1778            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1779            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1780            else { // found
1781                result.Add("NAME", iter->second.Name);
1782                result.Add("ENGINE_NAME", iter->second.EngineName);
1783                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1784                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1785                String instrumentName;
1786                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1787                if (pEngine) {
1788                    if (pEngine->GetInstrumentManager()) {
1789                        InstrumentManager::instrument_id_t instrID;
1790                        instrID.FileName = iter->second.InstrumentFile;
1791                        instrID.Index    = iter->second.InstrumentIndex;
1792                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1793                    }
1794                    EngineFactory::Destroy(pEngine);
1795                }
1796                result.Add("INSTRUMENT_NAME", instrumentName);
1797                switch (iter->second.LoadMode) {
1798                    case MidiInstrumentMapper::ON_DEMAND:
1799                        result.Add("LOAD_MODE", "ON_DEMAND");
1800                        break;
1801                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1802                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1803                        break;
1804                    case MidiInstrumentMapper::PERSISTENT:
1805                        result.Add("LOAD_MODE", "PERSISTENT");
1806                        break;
1807                    default:
1808                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1809                }
1810                result.Add("VOLUME", iter->second.Volume);
1811            }
1812        } catch (Exception e) {
1813            result.Error(e);
1814        }
1815        return result.Produce();
1816    }
1817    
1818    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1819        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1820        LSCPResultSet result;
1821        try {
1822            String s;
1823            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1824            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1825            for (; iter != mappings.end(); iter++) {
1826                if (s.size()) s += ",";
1827                s += "{" + ToString(MidiMapID) + ","
1828                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1829                         + ToString(int(iter->first.midi_prog)) + "}";
1830            }
1831            result.Add(s);
1832        } catch (Exception e) {
1833            result.Error(e);
1834        }
1835        return result.Produce();
1836    }
1837    
1838    String LSCPServer::ListAllMidiInstrumentMappings() {
1839        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1840        LSCPResultSet result;
1841        try {
1842            std::vector<int> maps = MidiInstrumentMapper::Maps();
1843            String s;
1844            for (int i = 0; i < maps.size(); i++) {
1845                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1846                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1847                for (; iter != mappings.end(); iter++) {
1848                    if (s.size()) s += ",";
1849                    s += "{" + ToString(maps[i]) + ","
1850                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1851                             + ToString(int(iter->first.midi_prog)) + "}";
1852                }
1853            }
1854            result.Add(s);
1855        } catch (Exception e) {
1856            result.Error(e);
1857        }
1858        return result.Produce();
1859    }
1860    
1861    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1862        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1863        LSCPResultSet result;
1864        try {
1865            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1866        } catch (Exception e) {
1867            result.Error(e);
1868        }
1869        return result.Produce();
1870    }
1871    
1872    String LSCPServer::ClearAllMidiInstrumentMappings() {
1873        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1874        LSCPResultSet result;
1875        try {
1876            std::vector<int> maps = MidiInstrumentMapper::Maps();
1877            for (int i = 0; i < maps.size(); i++)
1878                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1879        } catch (Exception e) {
1880            result.Error(e);
1881        }
1882        return result.Produce();
1883    }
1884    
1885    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1886        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1887        LSCPResultSet result;
1888        try {
1889            int MapID = MidiInstrumentMapper::AddMap(MapName);
1890            result = LSCPResultSet(MapID);
1891        } catch (Exception e) {
1892            result.Error(e);
1893        }
1894        return result.Produce();
1895    }
1896    
1897    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1898        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1899        LSCPResultSet result;
1900        try {
1901            MidiInstrumentMapper::RemoveMap(MidiMapID);
1902        } catch (Exception e) {
1903            result.Error(e);
1904        }
1905        return result.Produce();
1906    }
1907    
1908    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1909        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1910        LSCPResultSet result;
1911        try {
1912            MidiInstrumentMapper::RemoveAllMaps();
1913        } catch (Exception e) {
1914            result.Error(e);
1915        }
1916        return result.Produce();
1917    }
1918    
1919    String LSCPServer::GetMidiInstrumentMaps() {
1920        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1921        LSCPResultSet result;
1922        try {
1923            result.Add(MidiInstrumentMapper::Maps().size());
1924        } catch (Exception e) {
1925            result.Error(e);
1926        }
1927        return result.Produce();
1928    }
1929    
1930    String LSCPServer::ListMidiInstrumentMaps() {
1931        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1932        LSCPResultSet result;
1933        try {
1934            std::vector<int> maps = MidiInstrumentMapper::Maps();
1935            String sList;
1936            for (int i = 0; i < maps.size(); i++) {
1937                if (sList != "") sList += ",";
1938                sList += ToString(maps[i]);
1939            }
1940            result.Add(sList);
1941        } catch (Exception e) {
1942            result.Error(e);
1943        }
1944        return result.Produce();
1945    }
1946    
1947    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1948        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1949        LSCPResultSet result;
1950        try {
1951            result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1952            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
1953        } catch (Exception e) {
1954            result.Error(e);
1955        }
1956        return result.Produce();
1957    }
1958    
1959    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
1960        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
1961        LSCPResultSet result;
1962        try {
1963            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
1964        } catch (Exception e) {
1965            result.Error(e);
1966        }
1967        return result.Produce();
1968    }
1969    
1970    /**
1971     * Set the MIDI instrument map the given sampler channel shall use for
1972     * handling MIDI program change messages. There are the following two
1973     * special (negative) values:
1974     *
1975     *    - (-1) :  set to NONE (ignore program changes)
1976     *    - (-2) :  set to DEFAULT map
1977     */
1978    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
1979        dmsg(2,("LSCPServer: SetChannelMap()\n"));
1980        LSCPResultSet result;
1981        try {
1982            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1983            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1984    
1985            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1986            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1987    
1988            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
1989            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
1990            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
1991        } catch (Exception e) {
1992            result.Error(e);
1993        }
1994        return result.Produce();
1995    }
1996    
1997    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
1998        dmsg(2,("LSCPServer: CreateFxSend()\n"));
1999        LSCPResultSet result;
2000        try {
2001            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2002            
2003            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
2004            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
2005    
2006            result = LSCPResultSet(pFxSend->Id()); // success
2007        } catch (Exception e) {
2008            result.Error(e);
2009        }
2010        return result.Produce();
2011    }
2012    
2013    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
2014        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
2015        LSCPResultSet result;
2016        try {
2017            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2018    
2019            FxSend* pFxSend = NULL;
2020            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2021                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2022                    pFxSend = pEngineChannel->GetFxSend(i);
2023                    break;
2024                }
2025            }
2026            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2027            pEngineChannel->RemoveFxSend(pFxSend);
2028        } catch (Exception e) {
2029            result.Error(e);
2030        }
2031        return result.Produce();
2032    }
2033    
2034    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
2035        dmsg(2,("LSCPServer: GetFxSends()\n"));
2036        LSCPResultSet result;
2037        try {
2038            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2039    
2040            result.Add(pEngineChannel->GetFxSendCount());
2041        } catch (Exception e) {
2042            result.Error(e);
2043        }
2044        return result.Produce();
2045    }
2046    
2047    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
2048        dmsg(2,("LSCPServer: ListFxSends()\n"));
2049        LSCPResultSet result;
2050        String list;
2051        try {
2052            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2053    
2054            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2055                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
2056                if (list != "") list += ",";
2057                list += ToString(pFxSend->Id());
2058            }
2059            result.Add(list);
2060        } catch (Exception e) {
2061            result.Error(e);
2062        }
2063        return result.Produce();
2064    }
2065    
2066    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2067        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2068    
2069        FxSend* pFxSend = NULL;
2070        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2071            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2072                pFxSend = pEngineChannel->GetFxSend(i);
2073                break;
2074            }
2075        }
2076        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2077        return pFxSend;
2078    }
2079    
2080    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2081        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2082        LSCPResultSet result;
2083        try {
2084            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2085            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2086            
2087            // gather audio routing informations
2088            String AudioRouting;
2089            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
2090                if (AudioRouting != "") AudioRouting += ",";
2091                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2092            }
2093    
2094            // success
2095            result.Add("NAME", pFxSend->Name());
2096            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2097            result.Add("LEVEL", ToString(pFxSend->Level()));
2098            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2099        } catch (Exception e) {
2100            result.Error(e);
2101        }
2102        return result.Produce();
2103    }
2104    
2105    String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2106        dmsg(2,("LSCPServer: SetFxSendName()\n"));
2107        LSCPResultSet result;
2108        try {
2109            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2110    
2111            pFxSend->SetName(Name);
2112            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2113        } catch (Exception e) {
2114            result.Error(e);
2115        }
2116        return result.Produce();
2117    }
2118    
2119    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2120        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2121        LSCPResultSet result;
2122        try {
2123            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2124    
2125            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2126            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2127        } catch (Exception e) {
2128            result.Error(e);
2129        }
2130        return result.Produce();
2131    }
2132    
2133    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2134        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2135        LSCPResultSet result;
2136        try {
2137            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2138    
2139            pFxSend->SetMidiController(MidiController);
2140            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2141        } catch (Exception e) {
2142            result.Error(e);
2143        }
2144        return result.Produce();
2145    }
2146    
2147    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2148        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2149        LSCPResultSet result;
2150        try {
2151            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2152    
2153            pFxSend->SetLevel((float)dLevel);
2154            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2155        } catch (Exception e) {
2156            result.Error(e);
2157        }
2158        return result.Produce();
2159    }
2160    
2161    String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
2162        dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2163        LSCPResultSet result;
2164        try {
2165            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2166            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2167            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2168            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2169            Engine* pEngine = pEngineChannel->GetEngine();
2170            InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
2171            if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager");
2172            InstrumentManager::instrument_id_t instrumentID;
2173            instrumentID.FileName = pEngineChannel->InstrumentFileName();
2174            instrumentID.Index    = pEngineChannel->InstrumentIndex();
2175            pInstrumentManager->LaunchInstrumentEditor(instrumentID);
2176        } catch (Exception e) {
2177            result.Error(e);
2178        }
2179        return result.Produce();
2180    }
2181    
2182  /**  /**
2183   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2184   */   */
# Line 1512  String LSCPServer::ResetChannel(uint uiS Line 2187  String LSCPServer::ResetChannel(uint uiS
2187      LSCPResultSet result;      LSCPResultSet result;
2188      try {      try {
2189          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2190          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2191          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2192          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2193          pEngineChannel->Reset();          pEngineChannel->Reset();
2194      }      }
2195      catch (LinuxSamplerException e) {      catch (Exception e) {
2196           result.Error(e);           result.Error(e);
2197      }      }
2198      return result.Produce();      return result.Produce();
# Line 1542  String LSCPServer::GetServerInfo() { Line 2217  String LSCPServer::GetServerInfo() {
2217      LSCPResultSet result;      LSCPResultSet result;
2218      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
2219      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2220      result.Add("PROTOCOL_VERSION", "1.0");      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2221    #if HAVE_SQLITE3
2222        result.Add("INSTRUMENTS_DB_SUPPORT", "yes");
2223    #else
2224        result.Add("INSTRUMENTS_DB_SUPPORT", "no");
2225    #endif
2226        
2227      return result.Produce();      return result.Produce();
2228  }  }
2229    
# Line 1566  String LSCPServer::GetTotalVoiceCountMax Line 2247  String LSCPServer::GetTotalVoiceCountMax
2247      return result.Produce();      return result.Produce();
2248  }  }
2249    
2250    String LSCPServer::GetGlobalVolume() {
2251        LSCPResultSet result;
2252        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2253        return result.Produce();
2254    }
2255    
2256    String LSCPServer::SetGlobalVolume(double dVolume) {
2257        LSCPResultSet result;
2258        try {
2259            if (dVolume < 0) throw Exception("Volume may not be negative");
2260            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2261            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2262        } catch (Exception e) {
2263            result.Error(e);
2264        }
2265        return result.Produce();
2266    }
2267    
2268  /**  /**
2269   * 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
2270   * server for receiving event messages.   * server for receiving event messages.
# Line 1592  String LSCPServer::UnsubscribeNotificati Line 2291  String LSCPServer::UnsubscribeNotificati
2291      return result.Produce();      return result.Produce();
2292  }  }
2293    
2294  static int select_callback(void * lscpResultSet, int argc,  String LSCPServer::AddDbInstrumentDirectory(String Dir) {
2295                          char **argv, char **azColName)      dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str()));
2296  {      LSCPResultSet result;
2297      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;  #if HAVE_SQLITE3
2298      resultSet->Add(argc, argv);      try {
2299      return 0;          InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir);
2300        } catch (Exception e) {
2301             result.Error(e);
2302        }
2303    #else
2304        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2305    #endif
2306        return result.Produce();
2307  }  }
2308    
2309  String LSCPServer::QueryDatabase(String query) {  String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) {
2310        dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force));
2311      LSCPResultSet result;      LSCPResultSet result;
2312  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2313      char* zErrMsg = NULL;      try {
2314      sqlite3 *db;          InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force);
2315      String selectStr = "SELECT " + query;      } catch (Exception e) {
2316             result.Error(e);
2317        }
2318    #else
2319        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2320    #endif
2321        return result.Produce();
2322    }
2323    
2324      int rc = sqlite3_open("linuxsampler.db", &db);  String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2325      if (rc == SQLITE_OK)      dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2326      {      LSCPResultSet result;
2327              rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);  #if HAVE_SQLITE3
2328        try {
2329            result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2330        } catch (Exception e) {
2331             result.Error(e);
2332      }      }
2333      if ( rc != SQLITE_OK )  #else
2334      {      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2335              result.Error(String(zErrMsg), rc);  #endif
2336        return result.Produce();
2337    }
2338    
2339    String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2340        dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2341        LSCPResultSet result;
2342    #if HAVE_SQLITE3
2343        try {
2344            String list;
2345            StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2346    
2347            for (int i = 0; i < dirs->size(); i++) {
2348                if (list != "") list += ",";
2349                list += "'" + dirs->at(i) + "'";
2350            }
2351    
2352            result.Add(list);
2353        } catch (Exception e) {
2354             result.Error(e);
2355      }      }
     sqlite3_close(db);  
2356  #else  #else
2357      result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2358  #endif  #endif
2359      return result.Produce();      return result.Produce();
2360  }  }
2361    
2362    String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) {
2363        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str()));
2364        LSCPResultSet result;
2365    #if HAVE_SQLITE3
2366        try {
2367            DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2368    
2369            result.Add("DESCRIPTION", info.Description);
2370            result.Add("CREATED", info.Created);
2371            result.Add("MODIFIED", info.Modified);
2372        } catch (Exception e) {
2373             result.Error(e);
2374        }
2375    #else
2376        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2377    #endif
2378        return result.Produce();
2379    }
2380    
2381    String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) {
2382        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str()));
2383        LSCPResultSet result;
2384    #if HAVE_SQLITE3
2385        try {
2386            InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name);
2387        } catch (Exception e) {
2388             result.Error(e);
2389        }
2390    #else
2391        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2392    #endif
2393        return result.Produce();
2394    }
2395    
2396    String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) {
2397        dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2398        LSCPResultSet result;
2399    #if HAVE_SQLITE3
2400        try {
2401            InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst);
2402        } catch (Exception e) {
2403             result.Error(e);
2404        }
2405    #else
2406        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2407    #endif
2408        return result.Produce();
2409    }
2410    
2411    String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2412        dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2413        LSCPResultSet result;
2414    #if HAVE_SQLITE3
2415        try {
2416            InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2417        } catch (Exception e) {
2418             result.Error(e);
2419        }
2420    #else
2421        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2422    #endif
2423        return result.Produce();
2424    }
2425    
2426    String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2427        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str()));
2428        LSCPResultSet result;
2429    #if HAVE_SQLITE3
2430        try {
2431            InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2432        } catch (Exception e) {
2433             result.Error(e);
2434        }
2435    #else
2436        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2437    #endif
2438        return result.Produce();
2439    }
2440    
2441    String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2442        dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));
2443        LSCPResultSet result;
2444    #if HAVE_SQLITE3
2445        try {
2446            int id;
2447            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2448            id = db->AddInstruments(DbDir, FilePath, Index, bBackground);
2449            if (bBackground) result = id;
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::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2460        dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));
2461        LSCPResultSet result;
2462    #if HAVE_SQLITE3
2463        try {
2464            int id;
2465            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2466            if (ScanMode.compare("RECURSIVE") == 0) {
2467               id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2468            } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2469               id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2470            } else if (ScanMode.compare("FLAT") == 0) {
2471               id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2472            } else {
2473                throw Exception("Unknown scan mode: " + ScanMode);
2474            }
2475            
2476            if (bBackground) result = id;
2477        } catch (Exception e) {
2478             result.Error(e);
2479        }
2480    #else
2481        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2482    #endif
2483        return result.Produce();
2484    }
2485    
2486    String LSCPServer::RemoveDbInstrument(String Instr) {
2487        dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str()));
2488        LSCPResultSet result;
2489    #if HAVE_SQLITE3
2490        try {
2491            InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr);
2492        } catch (Exception e) {
2493             result.Error(e);
2494        }
2495    #else
2496        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2497    #endif
2498        return result.Produce();
2499    }
2500    
2501    String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2502        dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2503        LSCPResultSet result;
2504    #if HAVE_SQLITE3
2505        try {
2506            result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
2507        } catch (Exception e) {
2508             result.Error(e);
2509        }
2510    #else
2511        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2512    #endif
2513        return result.Produce();
2514    }
2515    
2516    String LSCPServer::GetDbInstruments(String Dir, bool Recursive) {
2517        dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2518        LSCPResultSet result;
2519    #if HAVE_SQLITE3
2520        try {
2521            String list;
2522            StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2523    
2524            for (int i = 0; i < instrs->size(); i++) {
2525                if (list != "") list += ",";
2526                list += "'" + instrs->at(i) + "'";
2527            }
2528    
2529            result.Add(list);
2530        } catch (Exception e) {
2531             result.Error(e);
2532        }
2533    #else
2534        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2535    #endif
2536        return result.Produce();
2537    }
2538    
2539    String LSCPServer::GetDbInstrumentInfo(String Instr) {
2540        dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str()));
2541        LSCPResultSet result;
2542    #if HAVE_SQLITE3
2543        try {
2544            DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr);
2545    
2546            result.Add("INSTRUMENT_FILE", info.InstrFile);
2547            result.Add("INSTRUMENT_NR", info.InstrNr);
2548            result.Add("FORMAT_FAMILY", info.FormatFamily);
2549            result.Add("FORMAT_VERSION", info.FormatVersion);
2550            result.Add("SIZE", (int)info.Size);
2551            result.Add("CREATED", info.Created);
2552            result.Add("MODIFIED", info.Modified);
2553            result.Add("DESCRIPTION", FilterEndlines(info.Description));
2554            result.Add("IS_DRUM", info.IsDrum);
2555            result.Add("PRODUCT", FilterEndlines(info.Product));
2556            result.Add("ARTISTS", FilterEndlines(info.Artists));
2557            result.Add("KEYWORDS", FilterEndlines(info.Keywords));
2558        } catch (Exception e) {
2559             result.Error(e);
2560        }
2561    #else
2562        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2563    #endif
2564        return result.Produce();
2565    }
2566    
2567    String LSCPServer::GetDbInstrumentsJobInfo(int JobId) {
2568        dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId));
2569        LSCPResultSet result;
2570    #if HAVE_SQLITE3
2571        try {
2572            ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId);
2573    
2574            result.Add("FILES_TOTAL", job.FilesTotal);
2575            result.Add("FILES_SCANNED", job.FilesScanned);
2576            result.Add("SCANNING", job.Scanning);
2577            result.Add("STATUS", job.Status);
2578        } catch (Exception e) {
2579             result.Error(e);
2580        }
2581    #else
2582        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2583    #endif
2584        return result.Produce();
2585    }
2586    
2587    String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2588        dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str()));
2589        LSCPResultSet result;
2590    #if HAVE_SQLITE3
2591        try {
2592            InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name);
2593        } catch (Exception e) {
2594             result.Error(e);
2595        }
2596    #else
2597        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2598    #endif
2599        return result.Produce();
2600    }
2601    
2602    String LSCPServer::MoveDbInstrument(String Instr, String Dst) {
2603        dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2604        LSCPResultSet result;
2605    #if HAVE_SQLITE3
2606        try {
2607            InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst);
2608        } catch (Exception e) {
2609             result.Error(e);
2610        }
2611    #else
2612        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2613    #endif
2614        return result.Produce();
2615    }
2616    
2617    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2618        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2619        LSCPResultSet result;
2620    #if HAVE_SQLITE3
2621        try {
2622            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2623        } catch (Exception e) {
2624             result.Error(e);
2625        }
2626    #else
2627        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2628    #endif
2629        return result.Produce();
2630    }
2631    
2632    String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2633        dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str()));
2634        LSCPResultSet result;
2635    #if HAVE_SQLITE3
2636        try {
2637            InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc);
2638        } catch (Exception e) {
2639             result.Error(e);
2640        }
2641    #else
2642        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2643    #endif
2644        return result.Produce();
2645    }
2646    
2647    String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2648        dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2649        LSCPResultSet result;
2650    #if HAVE_SQLITE3
2651        try {
2652            SearchQuery Query;
2653            std::map<String,String>::iterator iter;
2654            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2655                if (iter->first.compare("NAME") == 0) {
2656                    Query.Name = iter->second;
2657                } else if (iter->first.compare("CREATED") == 0) {
2658                    Query.SetCreated(iter->second);
2659                } else if (iter->first.compare("MODIFIED") == 0) {
2660                    Query.SetModified(iter->second);
2661                } else if (iter->first.compare("DESCRIPTION") == 0) {
2662                    Query.Description = iter->second;
2663                } else {
2664                    throw Exception("Unknown search criteria: " + iter->first);
2665                }
2666            }
2667    
2668            String list;
2669            StringListPtr pDirectories =
2670                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2671    
2672            for (int i = 0; i < pDirectories->size(); i++) {
2673                if (list != "") list += ",";
2674                list += "'" + pDirectories->at(i) + "'";
2675            }
2676    
2677            result.Add(list);
2678        } catch (Exception e) {
2679             result.Error(e);
2680        }
2681    #else
2682        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2683    #endif
2684        return result.Produce();
2685    }
2686    
2687    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2688        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2689        LSCPResultSet result;
2690    #if HAVE_SQLITE3
2691        try {
2692            SearchQuery Query;
2693            std::map<String,String>::iterator iter;
2694            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2695                if (iter->first.compare("NAME") == 0) {
2696                    Query.Name = iter->second;
2697                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2698                    Query.SetFormatFamilies(iter->second);
2699                } else if (iter->first.compare("SIZE") == 0) {
2700                    Query.SetSize(iter->second);
2701                } else if (iter->first.compare("CREATED") == 0) {
2702                    Query.SetCreated(iter->second);
2703                } else if (iter->first.compare("MODIFIED") == 0) {
2704                    Query.SetModified(iter->second);
2705                } else if (iter->first.compare("DESCRIPTION") == 0) {
2706                    Query.Description = iter->second;
2707                } else if (iter->first.compare("IS_DRUM") == 0) {
2708                    if (!strcasecmp(iter->second.c_str(), "true")) {
2709                        Query.InstrType = SearchQuery::DRUM;
2710                    } else {
2711                        Query.InstrType = SearchQuery::CHROMATIC;
2712                    }
2713                } else if (iter->first.compare("PRODUCT") == 0) {
2714                     Query.Product = iter->second;
2715                } else if (iter->first.compare("ARTISTS") == 0) {
2716                     Query.Artists = iter->second;
2717                } else if (iter->first.compare("KEYWORDS") == 0) {
2718                     Query.Keywords = iter->second;
2719                } else {
2720                    throw Exception("Unknown search criteria: " + iter->first);
2721                }
2722            }
2723    
2724            String list;
2725            StringListPtr pInstruments =
2726                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2727    
2728            for (int i = 0; i < pInstruments->size(); i++) {
2729                if (list != "") list += ",";
2730                list += "'" + pInstruments->at(i) + "'";
2731            }
2732    
2733            result.Add(list);
2734        } catch (Exception e) {
2735             result.Error(e);
2736        }
2737    #else
2738        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2739    #endif
2740        return result.Produce();
2741    }
2742    
2743    
2744  /**  /**
2745   * 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
2746   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1634  String LSCPServer::SetEcho(yyparse_param Line 2752  String LSCPServer::SetEcho(yyparse_param
2752      try {      try {
2753          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
2754          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
2755          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");
2756      }      }
2757      catch (LinuxSamplerException e) {      catch (Exception e) {
2758           result.Error(e);           result.Error(e);
2759      }      }
2760      return result.Produce();      return result.Produce();
2761  }  }
2762    
2763    String LSCPServer::FilterEndlines(String s) {
2764        String s2 = s;
2765        for (int i = 0; i < s2.length(); i++) {
2766            if (s2.at(i) == '\r') s2.at(i) = ' ';
2767            else if (s2.at(i) == '\n') s2.at(i) = ' ';
2768        }
2769        
2770        return s2;
2771    }

Legend:
Removed from v.778  
changed lines
  Added in v.1212

  ViewVC Help
Powered by ViewVC