/[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 1133 by iliev, Mon Mar 26 08:27:06 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"
27  //#include "../common/global.h"  #include "../common/global.h"
28    
29  #include <fcntl.h>  #include <fcntl.h>
30    
# Line 66  LSCPServer::LSCPServer(Sampler* pSampler Line 66  LSCPServer::LSCPServer(Sampler* pSampler
66      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
67      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
68      this->pSampler = pSampler;      this->pSampler = pSampler;
69        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT");
70        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO");
71        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT");
72        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
75      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
76      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
77      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
78        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT");
79        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO");
80        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");
81        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
82        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
83        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");
84      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
85      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
86        LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
87      hSocket = -1;      hSocket = -1;
88  }  }
89    
# Line 80  LSCPServer::~LSCPServer() { Line 91  LSCPServer::~LSCPServer() {
91      if (hSocket >= 0) close(hSocket);      if (hSocket >= 0) close(hSocket);
92  }  }
93    
94    void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
95        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
96    }
97    
98    void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
99        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
100    }
101    
102    void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) {
103        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
104    }
105    
106    void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
107        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
108    }
109    
110    void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
111        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program));
112    }
113    
114    void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) {
115        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount));
116    }
117    
118    void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) {
119        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId));
120    }
121    
122    void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
123        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount));
124    }
125    
126    void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) {
127        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount));
128    }
129    
130    void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) {
131        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount));
132    }
133    
134    void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) {
135        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData));
136    }
137    
138    void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) {
139        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
140    }
141    
142    
143  /**  /**
144   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
145   * 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 180  int LSCPServer::Main() {
180    
181      listen(hSocket, 1);      listen(hSocket, 1);
182      Initialized.Set(true);      Initialized.Set(true);
183        
184        // Registering event listeners
185        pSampler->AddChannelCountListener(&eventHandler);
186        pSampler->AddAudioDeviceCountListener(&eventHandler);
187        pSampler->AddMidiDeviceCountListener(&eventHandler);
188        pSampler->AddVoiceCountListener(&eventHandler);
189        pSampler->AddStreamCountListener(&eventHandler);
190        pSampler->AddBufferFillListener(&eventHandler);
191        pSampler->AddTotalVoiceCountListener(&eventHandler);
192        pSampler->AddFxSendCountListener(&eventHandler);
193        MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
194        MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
195        MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
196        MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);
197    
198      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
199      sockaddr_in client;      sockaddr_in client;
# Line 128  int LSCPServer::Main() { Line 202  int LSCPServer::Main() {
202      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
203      int maxSessions = hSocket;      int maxSessions = hSocket;
204    
205        timeval timeout;
206    
207      while (true) {      while (true) {
208          fd_set selectSet = fdSet;          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
209          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          {
210                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
211                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
212                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
213                for (; itEngineChannel != itEnd; ++itEngineChannel) {
214                    if ((*itEngineChannel)->StatusChanged()) {
215                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
216                    }
217    
218                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
219                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
220                        if(fxs != NULL && fxs->IsInfoChanged()) {
221                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
222                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
223                            fxs->SetInfoChanged(false);
224                        }
225                    }
226                }
227            }
228    
229            //Now let's deliver late notifies (if any)
230            NotifyBufferMutex.Lock();
231            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
232    #ifdef MSG_NOSIGNAL
233                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
234    #else
235                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
236    #endif
237            }
238            bufferedNotifies.clear();
239            NotifyBufferMutex.Unlock();
240    
241            fd_set selectSet = fdSet;
242            timeout.tv_sec  = 0;
243            timeout.tv_usec = 100000;
244    
245            int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
246    
247          if (retval == 0)          if (retval == 0)
248                  continue; //Nothing try again                  continue; //Nothing try again
249          if (retval == -1) {          if (retval == -1) {
# Line 190  int LSCPServer::Main() { Line 303  int LSCPServer::Main() {
303                          break;                          break;
304                  }                  }
305          }          }
   
         // 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();  
306      }      }
307  }  }
308    
# Line 256  void LSCPServer::SendLSCPNotify( LSCPEve Line 349  void LSCPServer::SendLSCPNotify( LSCPEve
349          while (true) {          while (true) {
350                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
351                          for(;iter != end; iter++)                          for(;iter != end; iter++)
352    #ifdef MSG_NOSIGNAL
353                                  send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);                                  send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
354    #else
355                                    send(*iter, notify.c_str(), notify.size(), 0);
356    #endif
357                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
358                          break;                          break;
359                  } else {                  } else {
# Line 308  bool LSCPServer::GetLSCPCommand( std::ve Line 405  bool LSCPServer::GetLSCPCommand( std::ve
405                                  continue; //Ignore CR                                  continue; //Ignore CR
406                          if (c == '\n') {                          if (c == '\n') {
407                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
408                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
409                                  return true; //Complete command was read                                  return true; //Complete command was read
410                          }                          }
411                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
# Line 365  void LSCPServer::AnswerClient(String Ret Line 462  void LSCPServer::AnswerClient(String Ret
462      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
463      if (currentSocket != -1) {      if (currentSocket != -1) {
464              NotifyMutex.Lock();              NotifyMutex.Lock();
465    #ifdef MSG_NOSIGNAL
466              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
467    #else
468                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
469    #endif
470              NotifyMutex.Unlock();              NotifyMutex.Unlock();
471      }      }
472  }  }
# Line 409  String LSCPServer::CreateAudioOutputDevi Line 510  String LSCPServer::CreateAudioOutputDevi
510          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
511          // search for the created device to get its index          // search for the created device to get its index
512          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
513          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.");
514          result = index; // success          result = index; // success
515      }      }
516      catch (LinuxSamplerException e) {      catch (Exception e) {
517          result.Error(e);          result.Error(e);
518      }      }
519      return result.Produce();      return result.Produce();
# Line 425  String LSCPServer::CreateMidiInputDevice Line 526  String LSCPServer::CreateMidiInputDevice
526          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
527          // search for the created device to get its index          // search for the created device to get its index
528          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
529          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.");
530          result = index; // success          result = index; // success
531      }      }
532      catch (LinuxSamplerException e) {      catch (Exception e) {
533          result.Error(e);          result.Error(e);
534      }      }
535      return result.Produce();      return result.Produce();
# Line 439  String LSCPServer::DestroyAudioOutputDev Line 540  String LSCPServer::DestroyAudioOutputDev
540      LSCPResultSet result;      LSCPResultSet result;
541      try {      try {
542          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
543          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) + ".");
544          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
545          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
546      }      }
547      catch (LinuxSamplerException e) {      catch (Exception e) {
548          result.Error(e);          result.Error(e);
549      }      }
550      return result.Produce();      return result.Produce();
# Line 454  String LSCPServer::DestroyMidiInputDevic Line 555  String LSCPServer::DestroyMidiInputDevic
555      LSCPResultSet result;      LSCPResultSet result;
556      try {      try {
557          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
558          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) + ".");
559          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
560          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
561      }      }
562      catch (LinuxSamplerException e) {      catch (Exception e) {
563          result.Error(e);          result.Error(e);
564      }      }
565      return result.Produce();      return result.Produce();
# Line 472  String LSCPServer::LoadInstrument(String Line 573  String LSCPServer::LoadInstrument(String
573      LSCPResultSet result;      LSCPResultSet result;
574      try {      try {
575          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
576          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
577          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
578          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
579          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
580              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
581          if (bBackground) {          if (bBackground) {
582              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
583                id.FileName = Filename;
584                id.Index    = uiInstrument;
585                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
586          }          }
587          else {          else {
588              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 487  String LSCPServer::LoadInstrument(String Line 591  String LSCPServer::LoadInstrument(String
591              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
592          }          }
593      }      }
594      catch (LinuxSamplerException e) {      catch (Exception e) {
595           result.Error(e);           result.Error(e);
596      }      }
597      return result.Produce();      return result.Produce();
# Line 502  String LSCPServer::SetEngineType(String Line 606  String LSCPServer::SetEngineType(String
606      LSCPResultSet result;      LSCPResultSet result;
607      try {      try {
608          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
609          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
610          LockRTNotify();          LockRTNotify();
611          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
612          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
613          UnlockRTNotify();          UnlockRTNotify();
614      }      }
615      catch (LinuxSamplerException e) {      catch (Exception e) {
616           result.Error(e);           result.Error(e);
617      }      }
618      return result.Produce();      return result.Produce();
# Line 546  String LSCPServer::ListChannels() { Line 650  String LSCPServer::ListChannels() {
650   */   */
651  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
652      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
653        LockRTNotify();
654      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
655        UnlockRTNotify();
656      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
657      return result.Produce();      return result.Produce();
658  }  }
# Line 568  String LSCPServer::RemoveChannel(uint ui Line 674  String LSCPServer::RemoveChannel(uint ui
674   */   */
675  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
676      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
677      LSCPResultSet result("1");      LSCPResultSet result;
678        try {
679            int n = EngineFactory::AvailableEngineTypes().size();
680            result.Add(n);
681        }
682        catch (Exception e) {
683            result.Error(e);
684        }
685      return result.Produce();      return result.Produce();
686  }  }
687    
# Line 577  String LSCPServer::GetAvailableEngines() Line 690  String LSCPServer::GetAvailableEngines()
690   */   */
691  String LSCPServer::ListAvailableEngines() {  String LSCPServer::ListAvailableEngines() {
692      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
693      LSCPResultSet result("\'GIG\'");      LSCPResultSet result;
694        try {
695            String s = EngineFactory::AvailableEngineTypesAsString();
696            result.Add(s);
697        }
698        catch (Exception e) {
699            result.Error(e);
700        }
701      return result.Produce();      return result.Produce();
702  }  }
703    
# Line 588  String LSCPServer::ListAvailableEngines( Line 708  String LSCPServer::ListAvailableEngines(
708  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
709      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
710      LSCPResultSet result;      LSCPResultSet result;
711        LockRTNotify();
712      try {      try {
713          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
714          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
715          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
716          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
717      }      }
718      catch (LinuxSamplerException e) {      catch (Exception e) {
719           result.Error(e);           result.Error(e);
720      }      }
721        UnlockRTNotify();
722      return result.Produce();      return result.Produce();
723  }  }
724    
# Line 609  String LSCPServer::GetChannelInfo(uint u Line 731  String LSCPServer::GetChannelInfo(uint u
731      LSCPResultSet result;      LSCPResultSet result;
732      try {      try {
733          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
734          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
735          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
736    
737          //Defaults values          //Defaults values
# Line 623  String LSCPServer::GetChannelInfo(uint u Line 745  String LSCPServer::GetChannelInfo(uint u
745          String AudioRouting;          String AudioRouting;
746          int Mute = 0;          int Mute = 0;
747          bool Solo = false;          bool Solo = false;
748            String MidiInstrumentMap = "NONE";
749    
750          if (pEngineChannel) {          if (pEngineChannel) {
751              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 640  String LSCPServer::GetChannelInfo(uint u Line 763  String LSCPServer::GetChannelInfo(uint u
763              }              }
764              Mute = pEngineChannel->GetMute();              Mute = pEngineChannel->GetMute();
765              Solo = pEngineChannel->GetSolo();              Solo = pEngineChannel->GetSolo();
766                if (pEngineChannel->UsesNoMidiInstrumentMap())
767                    MidiInstrumentMap = "NONE";
768                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
769                    MidiInstrumentMap = "DEFAULT";
770                else
771                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
772          }          }
773    
774          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 661  String LSCPServer::GetChannelInfo(uint u Line 790  String LSCPServer::GetChannelInfo(uint u
790          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
791          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
792          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
793            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
794      }      }
795      catch (LinuxSamplerException e) {      catch (Exception e) {
796           result.Error(e);           result.Error(e);
797      }      }
798      return result.Produce();      return result.Produce();
# Line 677  String LSCPServer::GetVoiceCount(uint ui Line 807  String LSCPServer::GetVoiceCount(uint ui
807      LSCPResultSet result;      LSCPResultSet result;
808      try {      try {
809          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
810          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
811          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
812          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
813          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");
814          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
815      }      }
816      catch (LinuxSamplerException e) {      catch (Exception e) {
817           result.Error(e);           result.Error(e);
818      }      }
819      return result.Produce();      return result.Produce();
# Line 698  String LSCPServer::GetStreamCount(uint u Line 828  String LSCPServer::GetStreamCount(uint u
828      LSCPResultSet result;      LSCPResultSet result;
829      try {      try {
830          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
831          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
832          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
833          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
834          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");
835          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
836      }      }
837      catch (LinuxSamplerException e) {      catch (Exception e) {
838           result.Error(e);           result.Error(e);
839      }      }
840      return result.Produce();      return result.Produce();
# Line 719  String LSCPServer::GetBufferFill(fill_re Line 849  String LSCPServer::GetBufferFill(fill_re
849      LSCPResultSet result;      LSCPResultSet result;
850      try {      try {
851          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
852          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
853          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
854          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
855          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");
856          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
857          else {          else {
858              switch (ResponseType) {              switch (ResponseType) {
# Line 733  String LSCPServer::GetBufferFill(fill_re Line 863  String LSCPServer::GetBufferFill(fill_re
863                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
864                      break;                      break;
865                  default:                  default:
866                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
867              }              }
868          }          }
869      }      }
870      catch (LinuxSamplerException e) {      catch (Exception e) {
871           result.Error(e);           result.Error(e);
872      }      }
873      return result.Produce();      return result.Produce();
# Line 750  String LSCPServer::GetAvailableAudioOutp Line 880  String LSCPServer::GetAvailableAudioOutp
880          int n = AudioOutputDeviceFactory::AvailableDrivers().size();          int n = AudioOutputDeviceFactory::AvailableDrivers().size();
881          result.Add(n);          result.Add(n);
882      }      }
883      catch (LinuxSamplerException e) {      catch (Exception e) {
884          result.Error(e);          result.Error(e);
885      }      }
886      return result.Produce();      return result.Produce();
# Line 763  String LSCPServer::ListAvailableAudioOut Line 893  String LSCPServer::ListAvailableAudioOut
893          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
894          result.Add(s);          result.Add(s);
895      }      }
896      catch (LinuxSamplerException e) {      catch (Exception e) {
897          result.Error(e);          result.Error(e);
898      }      }
899      return result.Produce();      return result.Produce();
# Line 776  String LSCPServer::GetAvailableMidiInput Line 906  String LSCPServer::GetAvailableMidiInput
906          int n = MidiInputDeviceFactory::AvailableDrivers().size();          int n = MidiInputDeviceFactory::AvailableDrivers().size();
907          result.Add(n);          result.Add(n);
908      }      }
909      catch (LinuxSamplerException e) {      catch (Exception e) {
910          result.Error(e);          result.Error(e);
911      }      }
912      return result.Produce();      return result.Produce();
# Line 789  String LSCPServer::ListAvailableMidiInpu Line 919  String LSCPServer::ListAvailableMidiInpu
919          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
920          result.Add(s);          result.Add(s);
921      }      }
922      catch (LinuxSamplerException e) {      catch (Exception e) {
923          result.Error(e);          result.Error(e);
924      }      }
925      return result.Produce();      return result.Produce();
# Line 813  String LSCPServer::GetMidiInputDriverInf Line 943  String LSCPServer::GetMidiInputDriverInf
943              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
944          }          }
945      }      }
946      catch (LinuxSamplerException e) {      catch (Exception e) {
947          result.Error(e);          result.Error(e);
948      }      }
949      return result.Produce();      return result.Produce();
# Line 837  String LSCPServer::GetAudioOutputDriverI Line 967  String LSCPServer::GetAudioOutputDriverI
967              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
968          }          }
969      }      }
970      catch (LinuxSamplerException e) {      catch (Exception e) {
971          result.Error(e);          result.Error(e);
972      }      }
973      return result.Produce();      return result.Produce();
# Line 864  String LSCPServer::GetMidiInputDriverPar Line 994  String LSCPServer::GetMidiInputDriverPar
994          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
995          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
996      }      }
997      catch (LinuxSamplerException e) {      catch (Exception e) {
998          result.Error(e);          result.Error(e);
999      }      }
1000      return result.Produce();      return result.Produce();
# Line 891  String LSCPServer::GetAudioOutputDriverP Line 1021  String LSCPServer::GetAudioOutputDriverP
1021          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1022          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1023      }      }
1024      catch (LinuxSamplerException e) {      catch (Exception e) {
1025          result.Error(e);          result.Error(e);
1026      }      }
1027      return result.Produce();      return result.Produce();
# Line 904  String LSCPServer::GetAudioOutputDeviceC Line 1034  String LSCPServer::GetAudioOutputDeviceC
1034          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
1035          result.Add(count); // success          result.Add(count); // success
1036      }      }
1037      catch (LinuxSamplerException e) {      catch (Exception e) {
1038          result.Error(e);          result.Error(e);
1039      }      }
1040      return result.Produce();      return result.Produce();
# Line 917  String LSCPServer::GetMidiInputDeviceCou Line 1047  String LSCPServer::GetMidiInputDeviceCou
1047          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
1048          result.Add(count); // success          result.Add(count); // success
1049      }      }
1050      catch (LinuxSamplerException e) {      catch (Exception e) {
1051          result.Error(e);          result.Error(e);
1052      }      }
1053      return result.Produce();      return result.Produce();
# Line 936  String LSCPServer::GetAudioOutputDevices Line 1066  String LSCPServer::GetAudioOutputDevices
1066          }          }
1067          result.Add(s);          result.Add(s);
1068      }      }
1069      catch (LinuxSamplerException e) {      catch (Exception e) {
1070          result.Error(e);          result.Error(e);
1071      }      }
1072      return result.Produce();      return result.Produce();
# Line 955  String LSCPServer::GetMidiInputDevices() Line 1085  String LSCPServer::GetMidiInputDevices()
1085          }          }
1086          result.Add(s);          result.Add(s);
1087      }      }
1088      catch (LinuxSamplerException e) {      catch (Exception e) {
1089          result.Error(e);          result.Error(e);
1090      }      }
1091      return result.Produce();      return result.Produce();
# Line 966  String LSCPServer::GetAudioOutputDeviceI Line 1096  String LSCPServer::GetAudioOutputDeviceI
1096      LSCPResultSet result;      LSCPResultSet result;
1097      try {      try {
1098          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1099          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) + ".");
1100          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1101          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1102          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 975  String LSCPServer::GetAudioOutputDeviceI Line 1105  String LSCPServer::GetAudioOutputDeviceI
1105              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1106          }          }
1107      }      }
1108      catch (LinuxSamplerException e) {      catch (Exception e) {
1109          result.Error(e);          result.Error(e);
1110      }      }
1111      return result.Produce();      return result.Produce();
# Line 986  String LSCPServer::GetMidiInputDeviceInf Line 1116  String LSCPServer::GetMidiInputDeviceInf
1116      LSCPResultSet result;      LSCPResultSet result;
1117      try {      try {
1118          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1119          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) + ".");
1120          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1121          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1122          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 995  String LSCPServer::GetMidiInputDeviceInf Line 1125  String LSCPServer::GetMidiInputDeviceInf
1125              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1126          }          }
1127      }      }
1128      catch (LinuxSamplerException e) {      catch (Exception e) {
1129          result.Error(e);          result.Error(e);
1130      }      }
1131      return result.Produce();      return result.Produce();
# Line 1006  String LSCPServer::GetMidiInputPortInfo( Line 1136  String LSCPServer::GetMidiInputPortInfo(
1136      try {      try {
1137          // get MIDI input device          // get MIDI input device
1138          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1139          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) + ".");
1140          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1141    
1142          // get MIDI port          // get MIDI port
1143          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1144          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) + ".");
1145    
1146          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1147          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 1020  String LSCPServer::GetMidiInputPortInfo( Line 1150  String LSCPServer::GetMidiInputPortInfo(
1150              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1151          }          }
1152      }      }
1153      catch (LinuxSamplerException e) {      catch (Exception e) {
1154          result.Error(e);          result.Error(e);
1155      }      }
1156      return result.Produce();      return result.Produce();
# Line 1032  String LSCPServer::GetAudioOutputChannel Line 1162  String LSCPServer::GetAudioOutputChannel
1162      try {      try {
1163          // get audio output device          // get audio output device
1164          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1165          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) + ".");
1166          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1167    
1168          // get audio channel          // get audio channel
1169          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1170          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) + ".");
1171    
1172          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1173          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1046  String LSCPServer::GetAudioOutputChannel Line 1176  String LSCPServer::GetAudioOutputChannel
1176              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1177          }          }
1178      }      }
1179      catch (LinuxSamplerException e) {      catch (Exception e) {
1180          result.Error(e);          result.Error(e);
1181      }      }
1182      return result.Produce();      return result.Produce();
# Line 1058  String LSCPServer::GetMidiInputPortParam Line 1188  String LSCPServer::GetMidiInputPortParam
1188      try {      try {
1189          // get MIDI input device          // get MIDI input device
1190          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1191          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) + ".");
1192          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1193    
1194          // get midi port          // get midi port
1195          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1196          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) + ".");
1197    
1198          // get desired port parameter          // get desired port parameter
1199          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1200          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 + "'.");
1201          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1202    
1203          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1079  String LSCPServer::GetMidiInputPortParam Line 1209  String LSCPServer::GetMidiInputPortParam
1209          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1210          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1211      }      }
1212      catch (LinuxSamplerException e) {      catch (Exception e) {
1213          result.Error(e);          result.Error(e);
1214      }      }
1215      return result.Produce();      return result.Produce();
# Line 1091  String LSCPServer::GetAudioOutputChannel Line 1221  String LSCPServer::GetAudioOutputChannel
1221      try {      try {
1222          // get audio output device          // get audio output device
1223          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1224          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) + ".");
1225          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1226    
1227          // get audio channel          // get audio channel
1228          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1229          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) + ".");
1230    
1231          // get desired audio channel parameter          // get desired audio channel parameter
1232          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1233          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 + "'.");
1234          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1235    
1236          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1112  String LSCPServer::GetAudioOutputChannel Line 1242  String LSCPServer::GetAudioOutputChannel
1242          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1243          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1244      }      }
1245      catch (LinuxSamplerException e) {      catch (Exception e) {
1246          result.Error(e);          result.Error(e);
1247      }      }
1248      return result.Produce();      return result.Produce();
# Line 1124  String LSCPServer::SetAudioOutputChannel Line 1254  String LSCPServer::SetAudioOutputChannel
1254      try {      try {
1255          // get audio output device          // get audio output device
1256          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1257          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) + ".");
1258          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1259    
1260          // get audio channel          // get audio channel
1261          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1262          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) + ".");
1263    
1264          // get desired audio channel parameter          // get desired audio channel parameter
1265          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1266          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 + "'.");
1267          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1268    
1269          // set new channel parameter value          // set new channel parameter value
1270          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1271            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1272      }      }
1273      catch (LinuxSamplerException e) {      catch (Exception e) {
1274          result.Error(e);          result.Error(e);
1275      }      }
1276      return result.Produce();      return result.Produce();
# Line 1150  String LSCPServer::SetAudioOutputDeviceP Line 1281  String LSCPServer::SetAudioOutputDeviceP
1281      LSCPResultSet result;      LSCPResultSet result;
1282      try {      try {
1283          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1284          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) + ".");
1285          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1286          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1287          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 + "'");
1288          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1289            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1290      }      }
1291      catch (LinuxSamplerException e) {      catch (Exception e) {
1292          result.Error(e);          result.Error(e);
1293      }      }
1294      return result.Produce();      return result.Produce();
# Line 1167  String LSCPServer::SetMidiInputDevicePar Line 1299  String LSCPServer::SetMidiInputDevicePar
1299      LSCPResultSet result;      LSCPResultSet result;
1300      try {      try {
1301          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1302          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) + ".");
1303          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1304          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1305          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 + "'");
1306          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1307            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1308      }      }
1309      catch (LinuxSamplerException e) {      catch (Exception e) {
1310          result.Error(e);          result.Error(e);
1311      }      }
1312      return result.Produce();      return result.Produce();
# Line 1185  String LSCPServer::SetMidiInputPortParam Line 1318  String LSCPServer::SetMidiInputPortParam
1318      try {      try {
1319          // get MIDI input device          // get MIDI input device
1320          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1321          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) + ".");
1322          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1323    
1324          // get MIDI port          // get MIDI port
1325          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1326          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) + ".");
1327    
1328          // set port parameter value          // set port parameter value
1329          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1330          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 + "'");
1331          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1332            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1333      }      }
1334      catch (LinuxSamplerException e) {      catch (Exception e) {
1335          result.Error(e);          result.Error(e);
1336      }      }
1337      return result.Produce();      return result.Produce();
# Line 1212  String LSCPServer::SetAudioOutputChannel Line 1346  String LSCPServer::SetAudioOutputChannel
1346      LSCPResultSet result;      LSCPResultSet result;
1347      try {      try {
1348          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1349          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1350          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1351          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));
1352          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));
1353          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1354      }      }
1355      catch (LinuxSamplerException e) {      catch (Exception e) {
1356           result.Error(e);           result.Error(e);
1357      }      }
1358      return result.Produce();      return result.Produce();
# Line 1227  String LSCPServer::SetAudioOutputChannel Line 1361  String LSCPServer::SetAudioOutputChannel
1361  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1362      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1363      LSCPResultSet result;      LSCPResultSet result;
1364        LockRTNotify();
1365      try {      try {
1366          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1367          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1368          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1369          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));
1370          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1371          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1372      }      }
1373      catch (LinuxSamplerException e) {      catch (Exception e) {
1374           result.Error(e);           result.Error(e);
1375      }      }
1376        UnlockRTNotify();
1377      return result.Produce();      return result.Produce();
1378  }  }
1379    
1380  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1381      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));
1382      LSCPResultSet result;      LSCPResultSet result;
1383        LockRTNotify();
1384      try {      try {
1385          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1386          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1387          // Driver type name aliasing...          // Driver type name aliasing...
1388          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1389          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1268  String LSCPServer::SetAudioOutputType(St Line 1405  String LSCPServer::SetAudioOutputType(St
1405          }          }
1406          // Must have a device...          // Must have a device...
1407          if (pDevice == NULL)          if (pDevice == NULL)
1408              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1409          // Set it as the current channel device...          // Set it as the current channel device...
1410          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1411      }      }
1412      catch (LinuxSamplerException e) {      catch (Exception e) {
1413           result.Error(e);           result.Error(e);
1414      }      }
1415        UnlockRTNotify();
1416      return result.Produce();      return result.Produce();
1417  }  }
1418    
# Line 1283  String LSCPServer::SetMIDIInputPort(uint Line 1421  String LSCPServer::SetMIDIInputPort(uint
1421      LSCPResultSet result;      LSCPResultSet result;
1422      try {      try {
1423          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1424          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1425          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1426      }      }
1427      catch (LinuxSamplerException e) {      catch (Exception e) {
1428           result.Error(e);           result.Error(e);
1429      }      }
1430      return result.Produce();      return result.Produce();
# Line 1297  String LSCPServer::SetMIDIInputChannel(u Line 1435  String LSCPServer::SetMIDIInputChannel(u
1435      LSCPResultSet result;      LSCPResultSet result;
1436      try {      try {
1437          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1438          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1439          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1440      }      }
1441      catch (LinuxSamplerException e) {      catch (Exception e) {
1442           result.Error(e);           result.Error(e);
1443      }      }
1444      return result.Produce();      return result.Produce();
# Line 1311  String LSCPServer::SetMIDIInputDevice(ui Line 1449  String LSCPServer::SetMIDIInputDevice(ui
1449      LSCPResultSet result;      LSCPResultSet result;
1450      try {      try {
1451          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1452          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1453          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1454          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));
1455          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1456          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1457      }      }
1458      catch (LinuxSamplerException e) {      catch (Exception e) {
1459           result.Error(e);           result.Error(e);
1460      }      }
1461      return result.Produce();      return result.Produce();
# Line 1328  String LSCPServer::SetMIDIInputType(Stri Line 1466  String LSCPServer::SetMIDIInputType(Stri
1466      LSCPResultSet result;      LSCPResultSet result;
1467      try {      try {
1468          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1469          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1470          // Driver type name aliasing...          // Driver type name aliasing...
1471          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1472          // 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 1490  String LSCPServer::SetMIDIInputType(Stri
1490          }          }
1491          // Must have a device...          // Must have a device...
1492          if (pDevice == NULL)          if (pDevice == NULL)
1493              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1494          // Set it as the current channel device...          // Set it as the current channel device...
1495          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1496      }      }
1497      catch (LinuxSamplerException e) {      catch (Exception e) {
1498           result.Error(e);           result.Error(e);
1499      }      }
1500      return result.Produce();      return result.Produce();
# Line 1371  String LSCPServer::SetMIDIInput(uint MID Line 1509  String LSCPServer::SetMIDIInput(uint MID
1509      LSCPResultSet result;      LSCPResultSet result;
1510      try {      try {
1511          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1512          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1513          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1514          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));
1515          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1516          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1517      }      }
1518      catch (LinuxSamplerException e) {      catch (Exception e) {
1519           result.Error(e);           result.Error(e);
1520      }      }
1521      return result.Produce();      return result.Produce();
# Line 1392  String LSCPServer::SetVolume(double dVol Line 1530  String LSCPServer::SetVolume(double dVol
1530      LSCPResultSet result;      LSCPResultSet result;
1531      try {      try {
1532          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1533          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1534          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1535          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1536          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1537      }      }
1538      catch (LinuxSamplerException e) {      catch (Exception e) {
1539           result.Error(e);           result.Error(e);
1540      }      }
1541      return result.Produce();      return result.Produce();
# Line 1411  String LSCPServer::SetChannelMute(bool b Line 1549  String LSCPServer::SetChannelMute(bool b
1549      LSCPResultSet result;      LSCPResultSet result;
1550      try {      try {
1551          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1552          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1553    
1554          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1555          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1556    
1557          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1558          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
1559      } catch (LinuxSamplerException e) {      } catch (Exception e) {
1560          result.Error(e);          result.Error(e);
1561      }      }
1562      return result.Produce();      return result.Produce();
# Line 1432  String LSCPServer::SetChannelSolo(bool b Line 1570  String LSCPServer::SetChannelSolo(bool b
1570      LSCPResultSet result;      LSCPResultSet result;
1571      try {      try {
1572          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1573          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1574    
1575          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1576          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1577    
1578          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1579          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
1580            
1581          pEngineChannel->SetSolo(bSolo);          pEngineChannel->SetSolo(bSolo);
1582            
1583          if(!oldSolo && bSolo) {          if(!oldSolo && bSolo) {
1584              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1585              if(!hadSoloChannel) MuteNonSoloChannels();              if(!hadSoloChannel) MuteNonSoloChannels();
1586          }          }
1587            
1588          if(oldSolo && !bSolo) {          if(oldSolo && !bSolo) {
1589              if(!HasSoloChannel()) UnmuteChannels();              if(!HasSoloChannel()) UnmuteChannels();
1590              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1591          }          }
1592      } catch (LinuxSamplerException e) {      } catch (Exception e) {
1593          result.Error(e);          result.Error(e);
1594      }      }
1595      return result.Produce();      return result.Produce();
# Line 1504  void  LSCPServer::UnmuteChannels() { Line 1642  void  LSCPServer::UnmuteChannels() {
1642      }      }
1643  }  }
1644    
1645    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) {
1646        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1647    
1648        midi_prog_index_t idx;
1649        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1650        idx.midi_bank_lsb = MidiBank & 0x7f;
1651        idx.midi_prog     = MidiProg;
1652    
1653        MidiInstrumentMapper::entry_t entry;
1654        entry.EngineName      = EngineType;
1655        entry.InstrumentFile  = InstrumentFile;
1656        entry.InstrumentIndex = InstrumentIndex;
1657        entry.LoadMode        = LoadMode;
1658        entry.Volume          = Volume;
1659        entry.Name            = Name;
1660    
1661        LSCPResultSet result;
1662        try {
1663            // PERSISTENT mapping commands might block for a long time, so in
1664            // that case we add/replace the mapping in another thread in case
1665            // the NON_MODAL argument was supplied, non persistent mappings
1666            // should return immediately, so we don't need to do that for them
1667            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1668            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1669        } catch (Exception e) {
1670            result.Error(e);
1671        }
1672        return result.Produce();
1673    }
1674    
1675    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1676        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1677    
1678        midi_prog_index_t idx;
1679        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1680        idx.midi_bank_lsb = MidiBank & 0x7f;
1681        idx.midi_prog     = MidiProg;
1682    
1683        LSCPResultSet result;
1684        try {
1685            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1686        } catch (Exception e) {
1687            result.Error(e);
1688        }
1689        return result.Produce();
1690    }
1691    
1692    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1693        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1694        LSCPResultSet result;
1695        try {
1696            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1697        } catch (Exception e) {
1698            result.Error(e);
1699        }
1700        return result.Produce();
1701    }
1702    
1703    
1704    String LSCPServer::GetAllMidiInstrumentMappings() {
1705        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1706        LSCPResultSet result;
1707        std::vector<int> maps = MidiInstrumentMapper::Maps();
1708        int totalMappings = 0;
1709        for (int i = 0; i < maps.size(); i++) {
1710            try {
1711                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1712            } catch (Exception e) { /*NOOP*/ }
1713        }
1714        result.Add(totalMappings);
1715        return result.Produce();
1716    }
1717    
1718    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1719        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1720        LSCPResultSet result;
1721        try {
1722            midi_prog_index_t idx;
1723            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1724            idx.midi_bank_lsb = MidiBank & 0x7f;
1725            idx.midi_prog     = MidiProg;
1726    
1727            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1728            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1729            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1730            else { // found
1731                result.Add("NAME", iter->second.Name);
1732                result.Add("ENGINE_NAME", iter->second.EngineName);
1733                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1734                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1735                String instrumentName;
1736                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1737                if (pEngine) {
1738                    if (pEngine->GetInstrumentManager()) {
1739                        InstrumentManager::instrument_id_t instrID;
1740                        instrID.FileName = iter->second.InstrumentFile;
1741                        instrID.Index    = iter->second.InstrumentIndex;
1742                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1743                    }
1744                    EngineFactory::Destroy(pEngine);
1745                }
1746                result.Add("INSTRUMENT_NAME", instrumentName);
1747                switch (iter->second.LoadMode) {
1748                    case MidiInstrumentMapper::ON_DEMAND:
1749                        result.Add("LOAD_MODE", "ON_DEMAND");
1750                        break;
1751                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1752                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1753                        break;
1754                    case MidiInstrumentMapper::PERSISTENT:
1755                        result.Add("LOAD_MODE", "PERSISTENT");
1756                        break;
1757                    default:
1758                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1759                }
1760                result.Add("VOLUME", iter->second.Volume);
1761            }
1762        } catch (Exception e) {
1763            result.Error(e);
1764        }
1765        return result.Produce();
1766    }
1767    
1768    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1769        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1770        LSCPResultSet result;
1771        try {
1772            String s;
1773            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1774            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1775            for (; iter != mappings.end(); iter++) {
1776                if (s.size()) s += ",";
1777                s += "{" + ToString(MidiMapID) + ","
1778                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1779                         + ToString(int(iter->first.midi_prog)) + "}";
1780            }
1781            result.Add(s);
1782        } catch (Exception e) {
1783            result.Error(e);
1784        }
1785        return result.Produce();
1786    }
1787    
1788    String LSCPServer::ListAllMidiInstrumentMappings() {
1789        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1790        LSCPResultSet result;
1791        try {
1792            std::vector<int> maps = MidiInstrumentMapper::Maps();
1793            String s;
1794            for (int i = 0; i < maps.size(); i++) {
1795                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1796                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1797                for (; iter != mappings.end(); iter++) {
1798                    if (s.size()) s += ",";
1799                    s += "{" + ToString(maps[i]) + ","
1800                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1801                             + ToString(int(iter->first.midi_prog)) + "}";
1802                }
1803            }
1804            result.Add(s);
1805        } catch (Exception e) {
1806            result.Error(e);
1807        }
1808        return result.Produce();
1809    }
1810    
1811    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1812        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1813        LSCPResultSet result;
1814        try {
1815            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1816        } catch (Exception e) {
1817            result.Error(e);
1818        }
1819        return result.Produce();
1820    }
1821    
1822    String LSCPServer::ClearAllMidiInstrumentMappings() {
1823        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1824        LSCPResultSet result;
1825        try {
1826            std::vector<int> maps = MidiInstrumentMapper::Maps();
1827            for (int i = 0; i < maps.size(); i++)
1828                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1829        } catch (Exception e) {
1830            result.Error(e);
1831        }
1832        return result.Produce();
1833    }
1834    
1835    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1836        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1837        LSCPResultSet result;
1838        try {
1839            int MapID = MidiInstrumentMapper::AddMap(MapName);
1840            result = LSCPResultSet(MapID);
1841        } catch (Exception e) {
1842            result.Error(e);
1843        }
1844        return result.Produce();
1845    }
1846    
1847    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1848        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1849        LSCPResultSet result;
1850        try {
1851            MidiInstrumentMapper::RemoveMap(MidiMapID);
1852        } catch (Exception e) {
1853            result.Error(e);
1854        }
1855        return result.Produce();
1856    }
1857    
1858    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1859        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1860        LSCPResultSet result;
1861        try {
1862            MidiInstrumentMapper::RemoveAllMaps();
1863        } catch (Exception e) {
1864            result.Error(e);
1865        }
1866        return result.Produce();
1867    }
1868    
1869    String LSCPServer::GetMidiInstrumentMaps() {
1870        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1871        LSCPResultSet result;
1872        try {
1873            result.Add(MidiInstrumentMapper::Maps().size());
1874        } catch (Exception e) {
1875            result.Error(e);
1876        }
1877        return result.Produce();
1878    }
1879    
1880    String LSCPServer::ListMidiInstrumentMaps() {
1881        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1882        LSCPResultSet result;
1883        try {
1884            std::vector<int> maps = MidiInstrumentMapper::Maps();
1885            String sList;
1886            for (int i = 0; i < maps.size(); i++) {
1887                if (sList != "") sList += ",";
1888                sList += ToString(maps[i]);
1889            }
1890            result.Add(sList);
1891        } catch (Exception e) {
1892            result.Error(e);
1893        }
1894        return result.Produce();
1895    }
1896    
1897    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1898        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1899        LSCPResultSet result;
1900        try {
1901            result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1902        } catch (Exception e) {
1903            result.Error(e);
1904        }
1905        return result.Produce();
1906    }
1907    
1908    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
1909        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
1910        LSCPResultSet result;
1911        try {
1912            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
1913        } catch (Exception e) {
1914            result.Error(e);
1915        }
1916        return result.Produce();
1917    }
1918    
1919    /**
1920     * Set the MIDI instrument map the given sampler channel shall use for
1921     * handling MIDI program change messages. There are the following two
1922     * special (negative) values:
1923     *
1924     *    - (-1) :  set to NONE (ignore program changes)
1925     *    - (-2) :  set to DEFAULT map
1926     */
1927    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
1928        dmsg(2,("LSCPServer: SetChannelMap()\n"));
1929        LSCPResultSet result;
1930        try {
1931            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1932            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1933    
1934            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1935            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1936    
1937            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
1938            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
1939            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
1940        } catch (Exception e) {
1941            result.Error(e);
1942        }
1943        return result.Produce();
1944    }
1945    
1946    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
1947        dmsg(2,("LSCPServer: CreateFxSend()\n"));
1948        LSCPResultSet result;
1949        try {
1950            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1951            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1952    
1953            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1954            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1955    
1956            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
1957            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
1958    
1959            result = LSCPResultSet(pFxSend->Id()); // success
1960        } catch (Exception e) {
1961            result.Error(e);
1962        }
1963        return result.Produce();
1964    }
1965    
1966    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
1967        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
1968        LSCPResultSet result;
1969        try {
1970            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1971            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1972    
1973            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1974            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1975    
1976            FxSend* pFxSend = NULL;
1977            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1978                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
1979                    pFxSend = pEngineChannel->GetFxSend(i);
1980                    break;
1981                }
1982            }
1983            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
1984            pEngineChannel->RemoveFxSend(pFxSend);
1985        } catch (Exception e) {
1986            result.Error(e);
1987        }
1988        return result.Produce();
1989    }
1990    
1991    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
1992        dmsg(2,("LSCPServer: GetFxSends()\n"));
1993        LSCPResultSet result;
1994        try {
1995            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1996            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1997    
1998            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1999            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2000    
2001            result.Add(pEngineChannel->GetFxSendCount());
2002        } catch (Exception e) {
2003            result.Error(e);
2004        }
2005        return result.Produce();
2006    }
2007    
2008    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
2009        dmsg(2,("LSCPServer: ListFxSends()\n"));
2010        LSCPResultSet result;
2011        String list;
2012        try {
2013            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2014            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2015    
2016            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2017            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2018    
2019            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2020                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
2021                if (list != "") list += ",";
2022                list += ToString(pFxSend->Id());
2023            }
2024            result.Add(list);
2025        } catch (Exception e) {
2026            result.Error(e);
2027        }
2028        return result.Produce();
2029    }
2030    
2031    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2032        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2033        LSCPResultSet result;
2034        try {
2035            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2036            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2037    
2038            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2039            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2040    
2041            FxSend* pFxSend = NULL;
2042            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2043                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2044                    pFxSend = pEngineChannel->GetFxSend(i);
2045                    break;
2046                }
2047            }
2048            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2049    
2050            // gather audio routing informations
2051            String AudioRouting;
2052            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
2053                if (AudioRouting != "") AudioRouting += ",";
2054                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2055            }
2056    
2057            // success
2058            result.Add("NAME", pFxSend->Name());
2059            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2060            result.Add("LEVEL", ToString(pFxSend->Level()));
2061            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2062        } catch (Exception e) {
2063            result.Error(e);
2064        }
2065        return result.Produce();
2066    }
2067    
2068    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2069        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2070        LSCPResultSet result;
2071        try {
2072            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2073            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2074    
2075            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2076            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2077    
2078            FxSend* pFxSend = NULL;
2079            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2080                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2081                    pFxSend = pEngineChannel->GetFxSend(i);
2082                    break;
2083                }
2084            }
2085            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2086    
2087            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2088            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2089        } catch (Exception e) {
2090            result.Error(e);
2091        }
2092        return result.Produce();
2093    }
2094    
2095    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2096        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2097        LSCPResultSet result;
2098        try {
2099            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2100            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2101    
2102            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2103            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2104    
2105            FxSend* pFxSend = NULL;
2106            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2107                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2108                    pFxSend = pEngineChannel->GetFxSend(i);
2109                    break;
2110                }
2111            }
2112            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2113    
2114            pFxSend->SetMidiController(MidiController);
2115            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2116        } catch (Exception e) {
2117            result.Error(e);
2118        }
2119        return result.Produce();
2120    }
2121    
2122    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2123        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2124        LSCPResultSet result;
2125        try {
2126            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2127            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2128    
2129            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2130            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2131    
2132            FxSend* pFxSend = NULL;
2133            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2134                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2135                    pFxSend = pEngineChannel->GetFxSend(i);
2136                    break;
2137                }
2138            }
2139            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2140    
2141            pFxSend->SetLevel((float)dLevel);
2142            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2143        } catch (Exception e) {
2144            result.Error(e);
2145        }
2146        return result.Produce();
2147    }
2148    
2149  /**  /**
2150   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2151   */   */
# Line 1512  String LSCPServer::ResetChannel(uint uiS Line 2154  String LSCPServer::ResetChannel(uint uiS
2154      LSCPResultSet result;      LSCPResultSet result;
2155      try {      try {
2156          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2157          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2158          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2159          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2160          pEngineChannel->Reset();          pEngineChannel->Reset();
2161      }      }
2162      catch (LinuxSamplerException e) {      catch (Exception e) {
2163           result.Error(e);           result.Error(e);
2164      }      }
2165      return result.Produce();      return result.Produce();
# Line 1542  String LSCPServer::GetServerInfo() { Line 2184  String LSCPServer::GetServerInfo() {
2184      LSCPResultSet result;      LSCPResultSet result;
2185      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
2186      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2187      result.Add("PROTOCOL_VERSION", "1.0");      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2188      return result.Produce();      return result.Produce();
2189  }  }
2190    
# Line 1566  String LSCPServer::GetTotalVoiceCountMax Line 2208  String LSCPServer::GetTotalVoiceCountMax
2208      return result.Produce();      return result.Produce();
2209  }  }
2210    
2211    String LSCPServer::GetGlobalVolume() {
2212        LSCPResultSet result;
2213        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2214        return result.Produce();
2215    }
2216    
2217    String LSCPServer::SetGlobalVolume(double dVolume) {
2218        LSCPResultSet result;
2219        try {
2220            if (dVolume < 0) throw Exception("Volume may not be negative");
2221            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2222            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2223        } catch (Exception e) {
2224            result.Error(e);
2225        }
2226        return result.Produce();
2227    }
2228    
2229  /**  /**
2230   * 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
2231   * server for receiving event messages.   * server for receiving event messages.
# Line 1634  String LSCPServer::SetEcho(yyparse_param Line 2294  String LSCPServer::SetEcho(yyparse_param
2294      try {      try {
2295          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
2296          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
2297          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");
2298      }      }
2299      catch (LinuxSamplerException e) {      catch (Exception e) {
2300           result.Error(e);           result.Error(e);
2301      }      }
2302      return result.Produce();      return result.Produce();

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

  ViewVC Help
Powered by ViewVC