/[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 670 by schoenebeck, Tue Jun 21 18:00:52 2005 UTC revision 1135 by iliev, Thu Mar 29 09:40:45 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");
86        LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
87      hSocket = -1;      hSocket = -1;
88  }  }
89    
# Line 79  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 119  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 127  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 189  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(), 0);  
                 bufferedNotifies.erase(iterNotify);  
         }  
         NotifyBufferMutex.Unlock();  
306      }      }
307  }  }
308    
# Line 255  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);
354    #else
355                                  send(*iter, notify.c_str(), notify.size(), 0);                                  send(*iter, notify.c_str(), notify.size(), 0);
356    #endif
357                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
358                          break;                          break;
359                  } else {                  } else {
# Line 307  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 364  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);
467    #else
468              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
469    #endif
470              NotifyMutex.Unlock();              NotifyMutex.Unlock();
471      }      }
472  }  }
# Line 408  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 424  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 438  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 453  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();
566  }  }
567    
568    EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) {
569        SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
570        if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
571    
572        EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
573        if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
574    
575        return pEngineChannel;        
576    }
577    
578  /**  /**
579   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
580   */   */
# Line 471  String LSCPServer::LoadInstrument(String Line 583  String LSCPServer::LoadInstrument(String
583      LSCPResultSet result;      LSCPResultSet result;
584      try {      try {
585          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
586          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
587          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
588          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
589          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
590              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
591          if (bBackground) {          if (bBackground) {
592              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
593                id.FileName = Filename;
594                id.Index    = uiInstrument;
595                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
596          }          }
597          else {          else {
598              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 486  String LSCPServer::LoadInstrument(String Line 601  String LSCPServer::LoadInstrument(String
601              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
602          }          }
603      }      }
604      catch (LinuxSamplerException e) {      catch (Exception e) {
605           result.Error(e);           result.Error(e);
606      }      }
607      return result.Produce();      return result.Produce();
# Line 497  String LSCPServer::LoadInstrument(String Line 612  String LSCPServer::LoadInstrument(String
612   * sampler channel.   * sampler channel.
613   */   */
614  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
615      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
616      LSCPResultSet result;      LSCPResultSet result;
617      try {      try {
618          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
619          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
620          LockRTNotify();          LockRTNotify();
621          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
622            if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
623          UnlockRTNotify();          UnlockRTNotify();
624      }      }
625      catch (LinuxSamplerException e) {      catch (Exception e) {
626           result.Error(e);           result.Error(e);
627      }      }
628      return result.Produce();      return result.Produce();
# Line 544  String LSCPServer::ListChannels() { Line 660  String LSCPServer::ListChannels() {
660   */   */
661  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
662      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
663        LockRTNotify();
664      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
665        UnlockRTNotify();
666      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
667      return result.Produce();      return result.Produce();
668  }  }
# Line 566  String LSCPServer::RemoveChannel(uint ui Line 684  String LSCPServer::RemoveChannel(uint ui
684   */   */
685  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
686      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
687      LSCPResultSet result("1");      LSCPResultSet result;
688        try {
689            int n = EngineFactory::AvailableEngineTypes().size();
690            result.Add(n);
691        }
692        catch (Exception e) {
693            result.Error(e);
694        }
695      return result.Produce();      return result.Produce();
696  }  }
697    
# Line 575  String LSCPServer::GetAvailableEngines() Line 700  String LSCPServer::GetAvailableEngines()
700   */   */
701  String LSCPServer::ListAvailableEngines() {  String LSCPServer::ListAvailableEngines() {
702      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
703      LSCPResultSet result("\'GIG\'");      LSCPResultSet result;
704        try {
705            String s = EngineFactory::AvailableEngineTypesAsString();
706            result.Add(s);
707        }
708        catch (Exception e) {
709            result.Error(e);
710        }
711      return result.Produce();      return result.Produce();
712  }  }
713    
# Line 586  String LSCPServer::ListAvailableEngines( Line 718  String LSCPServer::ListAvailableEngines(
718  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
719      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
720      LSCPResultSet result;      LSCPResultSet result;
721        LockRTNotify();
722      try {      try {
723          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
724          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
725          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
726          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
727      }      }
728      catch (LinuxSamplerException e) {      catch (Exception e) {
729           result.Error(e);           result.Error(e);
730      }      }
731        UnlockRTNotify();
732      return result.Produce();      return result.Produce();
733  }  }
734    
# Line 607  String LSCPServer::GetChannelInfo(uint u Line 741  String LSCPServer::GetChannelInfo(uint u
741      LSCPResultSet result;      LSCPResultSet result;
742      try {      try {
743          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
744          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
745          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
746    
747          //Defaults values          //Defaults values
# Line 619  String LSCPServer::GetChannelInfo(uint u Line 753  String LSCPServer::GetChannelInfo(uint u
753          int InstrumentStatus = -1;          int InstrumentStatus = -1;
754          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
755          String AudioRouting;          String AudioRouting;
756            int Mute = 0;
757            bool Solo = false;
758            String MidiInstrumentMap = "NONE";
759    
760          if (pEngineChannel) {          if (pEngineChannel) {
761              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 634  String LSCPServer::GetChannelInfo(uint u Line 771  String LSCPServer::GetChannelInfo(uint u
771                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
772                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
773              }              }
774                Mute = pEngineChannel->GetMute();
775                Solo = pEngineChannel->GetSolo();
776                if (pEngineChannel->UsesNoMidiInstrumentMap())
777                    MidiInstrumentMap = "NONE";
778                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
779                    MidiInstrumentMap = "DEFAULT";
780                else
781                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
782          }          }
783    
784          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 646  String LSCPServer::GetChannelInfo(uint u Line 791  String LSCPServer::GetChannelInfo(uint u
791    
792          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
793          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
794          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
795          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
796    
797          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
798          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
799          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", InstrumentName);
800          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
801            result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
802            result.Add("SOLO", Solo);
803            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
804      }      }
805      catch (LinuxSamplerException e) {      catch (Exception e) {
806           result.Error(e);           result.Error(e);
807      }      }
808      return result.Produce();      return result.Produce();
# Line 669  String LSCPServer::GetVoiceCount(uint ui Line 817  String LSCPServer::GetVoiceCount(uint ui
817      LSCPResultSet result;      LSCPResultSet result;
818      try {      try {
819          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
820          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
821          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
822          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
823          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");
824          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
825      }      }
826      catch (LinuxSamplerException e) {      catch (Exception e) {
827           result.Error(e);           result.Error(e);
828      }      }
829      return result.Produce();      return result.Produce();
# Line 690  String LSCPServer::GetStreamCount(uint u Line 838  String LSCPServer::GetStreamCount(uint u
838      LSCPResultSet result;      LSCPResultSet result;
839      try {      try {
840          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
841          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
842          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
843          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
844          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");
845          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
846      }      }
847      catch (LinuxSamplerException e) {      catch (Exception e) {
848           result.Error(e);           result.Error(e);
849      }      }
850      return result.Produce();      return result.Produce();
# Line 711  String LSCPServer::GetBufferFill(fill_re Line 859  String LSCPServer::GetBufferFill(fill_re
859      LSCPResultSet result;      LSCPResultSet result;
860      try {      try {
861          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
862          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
863          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
864          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
865          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");
866          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
867          else {          else {
868              switch (ResponseType) {              switch (ResponseType) {
# Line 725  String LSCPServer::GetBufferFill(fill_re Line 873  String LSCPServer::GetBufferFill(fill_re
873                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
874                      break;                      break;
875                  default:                  default:
876                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
877              }              }
878          }          }
879      }      }
880      catch (LinuxSamplerException e) {      catch (Exception e) {
881           result.Error(e);           result.Error(e);
882      }      }
883      return result.Produce();      return result.Produce();
# Line 742  String LSCPServer::GetAvailableAudioOutp Line 890  String LSCPServer::GetAvailableAudioOutp
890          int n = AudioOutputDeviceFactory::AvailableDrivers().size();          int n = AudioOutputDeviceFactory::AvailableDrivers().size();
891          result.Add(n);          result.Add(n);
892      }      }
893      catch (LinuxSamplerException e) {      catch (Exception e) {
894          result.Error(e);          result.Error(e);
895      }      }
896      return result.Produce();      return result.Produce();
# Line 755  String LSCPServer::ListAvailableAudioOut Line 903  String LSCPServer::ListAvailableAudioOut
903          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
904          result.Add(s);          result.Add(s);
905      }      }
906      catch (LinuxSamplerException e) {      catch (Exception e) {
907          result.Error(e);          result.Error(e);
908      }      }
909      return result.Produce();      return result.Produce();
# Line 768  String LSCPServer::GetAvailableMidiInput Line 916  String LSCPServer::GetAvailableMidiInput
916          int n = MidiInputDeviceFactory::AvailableDrivers().size();          int n = MidiInputDeviceFactory::AvailableDrivers().size();
917          result.Add(n);          result.Add(n);
918      }      }
919      catch (LinuxSamplerException e) {      catch (Exception e) {
920          result.Error(e);          result.Error(e);
921      }      }
922      return result.Produce();      return result.Produce();
# Line 781  String LSCPServer::ListAvailableMidiInpu Line 929  String LSCPServer::ListAvailableMidiInpu
929          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
930          result.Add(s);          result.Add(s);
931      }      }
932      catch (LinuxSamplerException e) {      catch (Exception e) {
933          result.Error(e);          result.Error(e);
934      }      }
935      return result.Produce();      return result.Produce();
# Line 805  String LSCPServer::GetMidiInputDriverInf Line 953  String LSCPServer::GetMidiInputDriverInf
953              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
954          }          }
955      }      }
956      catch (LinuxSamplerException e) {      catch (Exception e) {
957          result.Error(e);          result.Error(e);
958      }      }
959      return result.Produce();      return result.Produce();
# Line 829  String LSCPServer::GetAudioOutputDriverI Line 977  String LSCPServer::GetAudioOutputDriverI
977              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
978          }          }
979      }      }
980      catch (LinuxSamplerException e) {      catch (Exception e) {
981          result.Error(e);          result.Error(e);
982      }      }
983      return result.Produce();      return result.Produce();
# Line 856  String LSCPServer::GetMidiInputDriverPar Line 1004  String LSCPServer::GetMidiInputDriverPar
1004          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1005          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1006      }      }
1007      catch (LinuxSamplerException e) {      catch (Exception e) {
1008          result.Error(e);          result.Error(e);
1009      }      }
1010      return result.Produce();      return result.Produce();
# Line 883  String LSCPServer::GetAudioOutputDriverP Line 1031  String LSCPServer::GetAudioOutputDriverP
1031          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1032          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1033      }      }
1034      catch (LinuxSamplerException e) {      catch (Exception e) {
1035          result.Error(e);          result.Error(e);
1036      }      }
1037      return result.Produce();      return result.Produce();
# Line 896  String LSCPServer::GetAudioOutputDeviceC Line 1044  String LSCPServer::GetAudioOutputDeviceC
1044          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
1045          result.Add(count); // success          result.Add(count); // success
1046      }      }
1047      catch (LinuxSamplerException e) {      catch (Exception e) {
1048          result.Error(e);          result.Error(e);
1049      }      }
1050      return result.Produce();      return result.Produce();
# Line 909  String LSCPServer::GetMidiInputDeviceCou Line 1057  String LSCPServer::GetMidiInputDeviceCou
1057          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
1058          result.Add(count); // success          result.Add(count); // success
1059      }      }
1060      catch (LinuxSamplerException e) {      catch (Exception e) {
1061          result.Error(e);          result.Error(e);
1062      }      }
1063      return result.Produce();      return result.Produce();
# Line 928  String LSCPServer::GetAudioOutputDevices Line 1076  String LSCPServer::GetAudioOutputDevices
1076          }          }
1077          result.Add(s);          result.Add(s);
1078      }      }
1079      catch (LinuxSamplerException e) {      catch (Exception e) {
1080          result.Error(e);          result.Error(e);
1081      }      }
1082      return result.Produce();      return result.Produce();
# Line 947  String LSCPServer::GetMidiInputDevices() Line 1095  String LSCPServer::GetMidiInputDevices()
1095          }          }
1096          result.Add(s);          result.Add(s);
1097      }      }
1098      catch (LinuxSamplerException e) {      catch (Exception e) {
1099          result.Error(e);          result.Error(e);
1100      }      }
1101      return result.Produce();      return result.Produce();
# Line 958  String LSCPServer::GetAudioOutputDeviceI Line 1106  String LSCPServer::GetAudioOutputDeviceI
1106      LSCPResultSet result;      LSCPResultSet result;
1107      try {      try {
1108          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1109          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) + ".");
1110          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1111          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1112          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 967  String LSCPServer::GetAudioOutputDeviceI Line 1115  String LSCPServer::GetAudioOutputDeviceI
1115              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1116          }          }
1117      }      }
1118      catch (LinuxSamplerException e) {      catch (Exception e) {
1119          result.Error(e);          result.Error(e);
1120      }      }
1121      return result.Produce();      return result.Produce();
# Line 978  String LSCPServer::GetMidiInputDeviceInf Line 1126  String LSCPServer::GetMidiInputDeviceInf
1126      LSCPResultSet result;      LSCPResultSet result;
1127      try {      try {
1128          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1129          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) + ".");
1130          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1131          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1132          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 987  String LSCPServer::GetMidiInputDeviceInf Line 1135  String LSCPServer::GetMidiInputDeviceInf
1135              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1136          }          }
1137      }      }
1138      catch (LinuxSamplerException e) {      catch (Exception e) {
1139          result.Error(e);          result.Error(e);
1140      }      }
1141      return result.Produce();      return result.Produce();
# Line 998  String LSCPServer::GetMidiInputPortInfo( Line 1146  String LSCPServer::GetMidiInputPortInfo(
1146      try {      try {
1147          // get MIDI input device          // get MIDI input device
1148          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1149          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) + ".");
1150          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1151    
1152          // get MIDI port          // get MIDI port
1153          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1154          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) + ".");
1155    
1156          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1157          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 1012  String LSCPServer::GetMidiInputPortInfo( Line 1160  String LSCPServer::GetMidiInputPortInfo(
1160              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1161          }          }
1162      }      }
1163      catch (LinuxSamplerException e) {      catch (Exception e) {
1164          result.Error(e);          result.Error(e);
1165      }      }
1166      return result.Produce();      return result.Produce();
# Line 1024  String LSCPServer::GetAudioOutputChannel Line 1172  String LSCPServer::GetAudioOutputChannel
1172      try {      try {
1173          // get audio output device          // get audio output device
1174          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1175          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) + ".");
1176          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1177    
1178          // get audio channel          // get audio channel
1179          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1180          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) + ".");
1181    
1182          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1183          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1038  String LSCPServer::GetAudioOutputChannel Line 1186  String LSCPServer::GetAudioOutputChannel
1186              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1187          }          }
1188      }      }
1189      catch (LinuxSamplerException e) {      catch (Exception e) {
1190          result.Error(e);          result.Error(e);
1191      }      }
1192      return result.Produce();      return result.Produce();
# Line 1050  String LSCPServer::GetMidiInputPortParam Line 1198  String LSCPServer::GetMidiInputPortParam
1198      try {      try {
1199          // get MIDI input device          // get MIDI input device
1200          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1201          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) + ".");
1202          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1203    
1204          // get midi port          // get midi port
1205          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1206          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) + ".");
1207    
1208          // get desired port parameter          // get desired port parameter
1209          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1210          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 + "'.");
1211          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1212    
1213          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1071  String LSCPServer::GetMidiInputPortParam Line 1219  String LSCPServer::GetMidiInputPortParam
1219          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1220          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1221      }      }
1222      catch (LinuxSamplerException e) {      catch (Exception e) {
1223          result.Error(e);          result.Error(e);
1224      }      }
1225      return result.Produce();      return result.Produce();
# Line 1083  String LSCPServer::GetAudioOutputChannel Line 1231  String LSCPServer::GetAudioOutputChannel
1231      try {      try {
1232          // get audio output device          // get audio output device
1233          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1234          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) + ".");
1235          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1236    
1237          // get audio channel          // get audio channel
1238          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1239          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) + ".");
1240    
1241          // get desired audio channel parameter          // get desired audio channel parameter
1242          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1243          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 + "'.");
1244          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1245    
1246          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1104  String LSCPServer::GetAudioOutputChannel Line 1252  String LSCPServer::GetAudioOutputChannel
1252          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1253          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1254      }      }
1255      catch (LinuxSamplerException e) {      catch (Exception e) {
1256          result.Error(e);          result.Error(e);
1257      }      }
1258      return result.Produce();      return result.Produce();
# Line 1116  String LSCPServer::SetAudioOutputChannel Line 1264  String LSCPServer::SetAudioOutputChannel
1264      try {      try {
1265          // get audio output device          // get audio output device
1266          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1267          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) + ".");
1268          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1269    
1270          // get audio channel          // get audio channel
1271          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1272          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) + ".");
1273    
1274          // get desired audio channel parameter          // get desired audio channel parameter
1275          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1276          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 + "'.");
1277          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1278    
1279          // set new channel parameter value          // set new channel parameter value
1280          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1281            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1282      }      }
1283      catch (LinuxSamplerException e) {      catch (Exception e) {
1284          result.Error(e);          result.Error(e);
1285      }      }
1286      return result.Produce();      return result.Produce();
# Line 1142  String LSCPServer::SetAudioOutputDeviceP Line 1291  String LSCPServer::SetAudioOutputDeviceP
1291      LSCPResultSet result;      LSCPResultSet result;
1292      try {      try {
1293          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1294          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) + ".");
1295          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1296          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1297          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 + "'");
1298          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1299            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1300      }      }
1301      catch (LinuxSamplerException e) {      catch (Exception e) {
1302          result.Error(e);          result.Error(e);
1303      }      }
1304      return result.Produce();      return result.Produce();
# Line 1159  String LSCPServer::SetMidiInputDevicePar Line 1309  String LSCPServer::SetMidiInputDevicePar
1309      LSCPResultSet result;      LSCPResultSet result;
1310      try {      try {
1311          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1312          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) + ".");
1313          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1314          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1315          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 + "'");
1316          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1317            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1318      }      }
1319      catch (LinuxSamplerException e) {      catch (Exception e) {
1320          result.Error(e);          result.Error(e);
1321      }      }
1322      return result.Produce();      return result.Produce();
# Line 1177  String LSCPServer::SetMidiInputPortParam Line 1328  String LSCPServer::SetMidiInputPortParam
1328      try {      try {
1329          // get MIDI input device          // get MIDI input device
1330          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1331          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) + ".");
1332          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1333    
1334          // get MIDI port          // get MIDI port
1335          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1336          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) + ".");
1337    
1338          // set port parameter value          // set port parameter value
1339          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1340          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 + "'");
1341          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1342            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1343      }      }
1344      catch (LinuxSamplerException e) {      catch (Exception e) {
1345          result.Error(e);          result.Error(e);
1346      }      }
1347      return result.Produce();      return result.Produce();
# Line 1204  String LSCPServer::SetAudioOutputChannel Line 1356  String LSCPServer::SetAudioOutputChannel
1356      LSCPResultSet result;      LSCPResultSet result;
1357      try {      try {
1358          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1359          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1360          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1361          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));
1362          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));
1363          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1364      }      }
1365      catch (LinuxSamplerException e) {      catch (Exception e) {
1366           result.Error(e);           result.Error(e);
1367      }      }
1368      return result.Produce();      return result.Produce();
# Line 1219  String LSCPServer::SetAudioOutputChannel Line 1371  String LSCPServer::SetAudioOutputChannel
1371  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1372      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1373      LSCPResultSet result;      LSCPResultSet result;
1374        LockRTNotify();
1375      try {      try {
1376          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1377          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1378          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1379          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));
1380          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1381          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1382      }      }
1383      catch (LinuxSamplerException e) {      catch (Exception e) {
1384           result.Error(e);           result.Error(e);
1385      }      }
1386        UnlockRTNotify();
1387      return result.Produce();      return result.Produce();
1388  }  }
1389    
1390  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1391      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));
1392      LSCPResultSet result;      LSCPResultSet result;
1393        LockRTNotify();
1394      try {      try {
1395          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1396          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1397          // Driver type name aliasing...          // Driver type name aliasing...
1398          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1399          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1260  String LSCPServer::SetAudioOutputType(St Line 1415  String LSCPServer::SetAudioOutputType(St
1415          }          }
1416          // Must have a device...          // Must have a device...
1417          if (pDevice == NULL)          if (pDevice == NULL)
1418              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1419          // Set it as the current channel device...          // Set it as the current channel device...
1420          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1421      }      }
1422      catch (LinuxSamplerException e) {      catch (Exception e) {
1423           result.Error(e);           result.Error(e);
1424      }      }
1425        UnlockRTNotify();
1426      return result.Produce();      return result.Produce();
1427  }  }
1428    
# Line 1275  String LSCPServer::SetMIDIInputPort(uint Line 1431  String LSCPServer::SetMIDIInputPort(uint
1431      LSCPResultSet result;      LSCPResultSet result;
1432      try {      try {
1433          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1434          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1435          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1436      }      }
1437      catch (LinuxSamplerException e) {      catch (Exception e) {
1438           result.Error(e);           result.Error(e);
1439      }      }
1440      return result.Produce();      return result.Produce();
# Line 1289  String LSCPServer::SetMIDIInputChannel(u Line 1445  String LSCPServer::SetMIDIInputChannel(u
1445      LSCPResultSet result;      LSCPResultSet result;
1446      try {      try {
1447          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1448          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1449          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1450      }      }
1451      catch (LinuxSamplerException e) {      catch (Exception e) {
1452           result.Error(e);           result.Error(e);
1453      }      }
1454      return result.Produce();      return result.Produce();
# Line 1303  String LSCPServer::SetMIDIInputDevice(ui Line 1459  String LSCPServer::SetMIDIInputDevice(ui
1459      LSCPResultSet result;      LSCPResultSet result;
1460      try {      try {
1461          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1462          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1463          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1464          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));
1465          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1466          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1467      }      }
1468      catch (LinuxSamplerException e) {      catch (Exception e) {
1469           result.Error(e);           result.Error(e);
1470      }      }
1471      return result.Produce();      return result.Produce();
# Line 1320  String LSCPServer::SetMIDIInputType(Stri Line 1476  String LSCPServer::SetMIDIInputType(Stri
1476      LSCPResultSet result;      LSCPResultSet result;
1477      try {      try {
1478          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1479          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1480          // Driver type name aliasing...          // Driver type name aliasing...
1481          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1482          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1344  String LSCPServer::SetMIDIInputType(Stri Line 1500  String LSCPServer::SetMIDIInputType(Stri
1500          }          }
1501          // Must have a device...          // Must have a device...
1502          if (pDevice == NULL)          if (pDevice == NULL)
1503              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1504          // Set it as the current channel device...          // Set it as the current channel device...
1505          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1506      }      }
1507      catch (LinuxSamplerException e) {      catch (Exception e) {
1508           result.Error(e);           result.Error(e);
1509      }      }
1510      return result.Produce();      return result.Produce();
# Line 1363  String LSCPServer::SetMIDIInput(uint MID Line 1519  String LSCPServer::SetMIDIInput(uint MID
1519      LSCPResultSet result;      LSCPResultSet result;
1520      try {      try {
1521          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1522          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1523          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1524          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));
1525          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1526          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1527      }      }
1528      catch (LinuxSamplerException e) {      catch (Exception e) {
1529           result.Error(e);           result.Error(e);
1530      }      }
1531      return result.Produce();      return result.Produce();
# Line 1384  String LSCPServer::SetVolume(double dVol Line 1540  String LSCPServer::SetVolume(double dVol
1540      LSCPResultSet result;      LSCPResultSet result;
1541      try {      try {
1542          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1543          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1544          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1545          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1546          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1547      }      }
1548      catch (LinuxSamplerException e) {      catch (Exception e) {
1549           result.Error(e);           result.Error(e);
1550      }      }
1551      return result.Produce();      return result.Produce();
1552  }  }
1553    
1554  /**  /**
1555     * Will be called by the parser to mute/unmute particular sampler channel.
1556     */
1557    String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) {
1558        dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1559        LSCPResultSet result;
1560        try {
1561            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1562            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1563    
1564            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1565            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1566    
1567            if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1568            else pEngineChannel->SetMute(1);
1569        } catch (Exception e) {
1570            result.Error(e);
1571        }
1572        return result.Produce();
1573    }
1574    
1575    /**
1576     * Will be called by the parser to solo particular sampler channel.
1577     */
1578    String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) {
1579        dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1580        LSCPResultSet result;
1581        try {
1582            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1583            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1584    
1585            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1586            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1587    
1588            bool oldSolo = pEngineChannel->GetSolo();
1589            bool hadSoloChannel = HasSoloChannel();
1590    
1591            pEngineChannel->SetSolo(bSolo);
1592    
1593            if(!oldSolo && bSolo) {
1594                if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1595                if(!hadSoloChannel) MuteNonSoloChannels();
1596            }
1597    
1598            if(oldSolo && !bSolo) {
1599                if(!HasSoloChannel()) UnmuteChannels();
1600                else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1601            }
1602        } catch (Exception e) {
1603            result.Error(e);
1604        }
1605        return result.Produce();
1606    }
1607    
1608    /**
1609     * Determines whether there is at least one solo channel in the channel list.
1610     *
1611     * @returns true if there is at least one solo channel in the channel list,
1612     * false otherwise.
1613     */
1614    bool LSCPServer::HasSoloChannel() {
1615        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1616        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1617        for (; iter != channels.end(); iter++) {
1618            EngineChannel* c = iter->second->GetEngineChannel();
1619            if(c && c->GetSolo()) return true;
1620        }
1621    
1622        return false;
1623    }
1624    
1625    /**
1626     * Mutes all unmuted non-solo channels. Notice that the channels are muted
1627     * with -1 which indicates that they are muted because of the presence
1628     * of a solo channel(s). Channels muted with -1 will be automatically unmuted
1629     * when there are no solo channels left.
1630     */
1631    void LSCPServer::MuteNonSoloChannels() {
1632        dmsg(2,("LSCPServer: MuteNonSoloChannels()\n"));
1633        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1634        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1635        for (; iter != channels.end(); iter++) {
1636            EngineChannel* c = iter->second->GetEngineChannel();
1637            if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1);
1638        }
1639    }
1640    
1641    /**
1642     * Unmutes all channels that are muted because of the presence
1643     * of a solo channel(s).
1644     */
1645    void  LSCPServer::UnmuteChannels() {
1646        dmsg(2,("LSCPServer: UnmuteChannels()\n"));
1647        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1648        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1649        for (; iter != channels.end(); iter++) {
1650            EngineChannel* c = iter->second->GetEngineChannel();
1651            if(c && c->GetMute() == -1) c->SetMute(0);
1652        }
1653    }
1654    
1655    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) {
1656        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1657    
1658        midi_prog_index_t idx;
1659        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1660        idx.midi_bank_lsb = MidiBank & 0x7f;
1661        idx.midi_prog     = MidiProg;
1662    
1663        MidiInstrumentMapper::entry_t entry;
1664        entry.EngineName      = EngineType;
1665        entry.InstrumentFile  = InstrumentFile;
1666        entry.InstrumentIndex = InstrumentIndex;
1667        entry.LoadMode        = LoadMode;
1668        entry.Volume          = Volume;
1669        entry.Name            = Name;
1670    
1671        LSCPResultSet result;
1672        try {
1673            // PERSISTENT mapping commands might block for a long time, so in
1674            // that case we add/replace the mapping in another thread in case
1675            // the NON_MODAL argument was supplied, non persistent mappings
1676            // should return immediately, so we don't need to do that for them
1677            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1678            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1679        } catch (Exception e) {
1680            result.Error(e);
1681        }
1682        return result.Produce();
1683    }
1684    
1685    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1686        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1687    
1688        midi_prog_index_t idx;
1689        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1690        idx.midi_bank_lsb = MidiBank & 0x7f;
1691        idx.midi_prog     = MidiProg;
1692    
1693        LSCPResultSet result;
1694        try {
1695            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1696        } catch (Exception e) {
1697            result.Error(e);
1698        }
1699        return result.Produce();
1700    }
1701    
1702    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1703        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1704        LSCPResultSet result;
1705        try {
1706            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1707        } catch (Exception e) {
1708            result.Error(e);
1709        }
1710        return result.Produce();
1711    }
1712    
1713    
1714    String LSCPServer::GetAllMidiInstrumentMappings() {
1715        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1716        LSCPResultSet result;
1717        std::vector<int> maps = MidiInstrumentMapper::Maps();
1718        int totalMappings = 0;
1719        for (int i = 0; i < maps.size(); i++) {
1720            try {
1721                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1722            } catch (Exception e) { /*NOOP*/ }
1723        }
1724        result.Add(totalMappings);
1725        return result.Produce();
1726    }
1727    
1728    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1729        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1730        LSCPResultSet result;
1731        try {
1732            midi_prog_index_t idx;
1733            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1734            idx.midi_bank_lsb = MidiBank & 0x7f;
1735            idx.midi_prog     = MidiProg;
1736    
1737            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1738            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1739            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1740            else { // found
1741                result.Add("NAME", iter->second.Name);
1742                result.Add("ENGINE_NAME", iter->second.EngineName);
1743                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1744                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1745                String instrumentName;
1746                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1747                if (pEngine) {
1748                    if (pEngine->GetInstrumentManager()) {
1749                        InstrumentManager::instrument_id_t instrID;
1750                        instrID.FileName = iter->second.InstrumentFile;
1751                        instrID.Index    = iter->second.InstrumentIndex;
1752                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1753                    }
1754                    EngineFactory::Destroy(pEngine);
1755                }
1756                result.Add("INSTRUMENT_NAME", instrumentName);
1757                switch (iter->second.LoadMode) {
1758                    case MidiInstrumentMapper::ON_DEMAND:
1759                        result.Add("LOAD_MODE", "ON_DEMAND");
1760                        break;
1761                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1762                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1763                        break;
1764                    case MidiInstrumentMapper::PERSISTENT:
1765                        result.Add("LOAD_MODE", "PERSISTENT");
1766                        break;
1767                    default:
1768                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1769                }
1770                result.Add("VOLUME", iter->second.Volume);
1771            }
1772        } catch (Exception e) {
1773            result.Error(e);
1774        }
1775        return result.Produce();
1776    }
1777    
1778    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1779        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1780        LSCPResultSet result;
1781        try {
1782            String s;
1783            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1784            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1785            for (; iter != mappings.end(); iter++) {
1786                if (s.size()) s += ",";
1787                s += "{" + ToString(MidiMapID) + ","
1788                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1789                         + ToString(int(iter->first.midi_prog)) + "}";
1790            }
1791            result.Add(s);
1792        } catch (Exception e) {
1793            result.Error(e);
1794        }
1795        return result.Produce();
1796    }
1797    
1798    String LSCPServer::ListAllMidiInstrumentMappings() {
1799        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1800        LSCPResultSet result;
1801        try {
1802            std::vector<int> maps = MidiInstrumentMapper::Maps();
1803            String s;
1804            for (int i = 0; i < maps.size(); i++) {
1805                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1806                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1807                for (; iter != mappings.end(); iter++) {
1808                    if (s.size()) s += ",";
1809                    s += "{" + ToString(maps[i]) + ","
1810                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1811                             + ToString(int(iter->first.midi_prog)) + "}";
1812                }
1813            }
1814            result.Add(s);
1815        } catch (Exception e) {
1816            result.Error(e);
1817        }
1818        return result.Produce();
1819    }
1820    
1821    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1822        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1823        LSCPResultSet result;
1824        try {
1825            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1826        } catch (Exception e) {
1827            result.Error(e);
1828        }
1829        return result.Produce();
1830    }
1831    
1832    String LSCPServer::ClearAllMidiInstrumentMappings() {
1833        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1834        LSCPResultSet result;
1835        try {
1836            std::vector<int> maps = MidiInstrumentMapper::Maps();
1837            for (int i = 0; i < maps.size(); i++)
1838                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1839        } catch (Exception e) {
1840            result.Error(e);
1841        }
1842        return result.Produce();
1843    }
1844    
1845    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1846        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1847        LSCPResultSet result;
1848        try {
1849            int MapID = MidiInstrumentMapper::AddMap(MapName);
1850            result = LSCPResultSet(MapID);
1851        } catch (Exception e) {
1852            result.Error(e);
1853        }
1854        return result.Produce();
1855    }
1856    
1857    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1858        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1859        LSCPResultSet result;
1860        try {
1861            MidiInstrumentMapper::RemoveMap(MidiMapID);
1862        } catch (Exception e) {
1863            result.Error(e);
1864        }
1865        return result.Produce();
1866    }
1867    
1868    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1869        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1870        LSCPResultSet result;
1871        try {
1872            MidiInstrumentMapper::RemoveAllMaps();
1873        } catch (Exception e) {
1874            result.Error(e);
1875        }
1876        return result.Produce();
1877    }
1878    
1879    String LSCPServer::GetMidiInstrumentMaps() {
1880        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1881        LSCPResultSet result;
1882        try {
1883            result.Add(MidiInstrumentMapper::Maps().size());
1884        } catch (Exception e) {
1885            result.Error(e);
1886        }
1887        return result.Produce();
1888    }
1889    
1890    String LSCPServer::ListMidiInstrumentMaps() {
1891        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1892        LSCPResultSet result;
1893        try {
1894            std::vector<int> maps = MidiInstrumentMapper::Maps();
1895            String sList;
1896            for (int i = 0; i < maps.size(); i++) {
1897                if (sList != "") sList += ",";
1898                sList += ToString(maps[i]);
1899            }
1900            result.Add(sList);
1901        } catch (Exception e) {
1902            result.Error(e);
1903        }
1904        return result.Produce();
1905    }
1906    
1907    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1908        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1909        LSCPResultSet result;
1910        try {
1911            result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1912            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
1913        } catch (Exception e) {
1914            result.Error(e);
1915        }
1916        return result.Produce();
1917    }
1918    
1919    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
1920        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
1921        LSCPResultSet result;
1922        try {
1923            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
1924        } catch (Exception e) {
1925            result.Error(e);
1926        }
1927        return result.Produce();
1928    }
1929    
1930    /**
1931     * Set the MIDI instrument map the given sampler channel shall use for
1932     * handling MIDI program change messages. There are the following two
1933     * special (negative) values:
1934     *
1935     *    - (-1) :  set to NONE (ignore program changes)
1936     *    - (-2) :  set to DEFAULT map
1937     */
1938    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
1939        dmsg(2,("LSCPServer: SetChannelMap()\n"));
1940        LSCPResultSet result;
1941        try {
1942            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1943            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1944    
1945            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1946            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1947    
1948            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
1949            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
1950            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
1951        } catch (Exception e) {
1952            result.Error(e);
1953        }
1954        return result.Produce();
1955    }
1956    
1957    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
1958        dmsg(2,("LSCPServer: CreateFxSend()\n"));
1959        LSCPResultSet result;
1960        try {
1961            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
1962            
1963            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
1964            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
1965    
1966            result = LSCPResultSet(pFxSend->Id()); // success
1967        } catch (Exception e) {
1968            result.Error(e);
1969        }
1970        return result.Produce();
1971    }
1972    
1973    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
1974        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
1975        LSCPResultSet result;
1976        try {
1977            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
1978    
1979            FxSend* pFxSend = NULL;
1980            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1981                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
1982                    pFxSend = pEngineChannel->GetFxSend(i);
1983                    break;
1984                }
1985            }
1986            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
1987            pEngineChannel->RemoveFxSend(pFxSend);
1988        } catch (Exception e) {
1989            result.Error(e);
1990        }
1991        return result.Produce();
1992    }
1993    
1994    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
1995        dmsg(2,("LSCPServer: GetFxSends()\n"));
1996        LSCPResultSet result;
1997        try {
1998            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
1999    
2000            result.Add(pEngineChannel->GetFxSendCount());
2001        } catch (Exception e) {
2002            result.Error(e);
2003        }
2004        return result.Produce();
2005    }
2006    
2007    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
2008        dmsg(2,("LSCPServer: ListFxSends()\n"));
2009        LSCPResultSet result;
2010        String list;
2011        try {
2012            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2013    
2014            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2015                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
2016                if (list != "") list += ",";
2017                list += ToString(pFxSend->Id());
2018            }
2019            result.Add(list);
2020        } catch (Exception e) {
2021            result.Error(e);
2022        }
2023        return result.Produce();
2024    }
2025    
2026    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2027        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2028    
2029        FxSend* pFxSend = NULL;
2030        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2031            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2032                pFxSend = pEngineChannel->GetFxSend(i);
2033                break;
2034            }
2035        }
2036        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2037        return pFxSend;
2038    }
2039    
2040    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2041        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2042        LSCPResultSet result;
2043        try {
2044            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2045            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2046            
2047            // gather audio routing informations
2048            String AudioRouting;
2049            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
2050                if (AudioRouting != "") AudioRouting += ",";
2051                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2052            }
2053    
2054            // success
2055            result.Add("NAME", pFxSend->Name());
2056            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2057            result.Add("LEVEL", ToString(pFxSend->Level()));
2058            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2059        } catch (Exception e) {
2060            result.Error(e);
2061        }
2062        return result.Produce();
2063    }
2064    
2065    String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2066        dmsg(2,("LSCPServer: SetFxSendName()\n"));
2067        LSCPResultSet result;
2068        try {
2069            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2070    
2071            pFxSend->SetName(Name);
2072            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2073        } catch (Exception e) {
2074            result.Error(e);
2075        }
2076        return result.Produce();
2077    }
2078    
2079    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2080        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2081        LSCPResultSet result;
2082        try {
2083            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2084    
2085            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2086            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2087        } catch (Exception e) {
2088            result.Error(e);
2089        }
2090        return result.Produce();
2091    }
2092    
2093    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2094        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2095        LSCPResultSet result;
2096        try {
2097            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2098    
2099            pFxSend->SetMidiController(MidiController);
2100            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2101        } catch (Exception e) {
2102            result.Error(e);
2103        }
2104        return result.Produce();
2105    }
2106    
2107    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2108        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2109        LSCPResultSet result;
2110        try {
2111            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2112    
2113            pFxSend->SetLevel((float)dLevel);
2114            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2115        } catch (Exception e) {
2116            result.Error(e);
2117        }
2118        return result.Produce();
2119    }
2120    
2121    /**
2122   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2123   */   */
2124  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
# Line 1403  String LSCPServer::ResetChannel(uint uiS Line 2126  String LSCPServer::ResetChannel(uint uiS
2126      LSCPResultSet result;      LSCPResultSet result;
2127      try {      try {
2128          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2129          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2130          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2131          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2132          pEngineChannel->Reset();          pEngineChannel->Reset();
2133      }      }
2134      catch (LinuxSamplerException e) {      catch (Exception e) {
2135           result.Error(e);           result.Error(e);
2136      }      }
2137      return result.Produce();      return result.Produce();
# Line 1433  String LSCPServer::GetServerInfo() { Line 2156  String LSCPServer::GetServerInfo() {
2156      LSCPResultSet result;      LSCPResultSet result;
2157      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
2158      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2159      result.Add("PROTOCOL_VERSION", "1.0");      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2160        return result.Produce();
2161    }
2162    
2163    /**
2164     * Will be called by the parser to return the current number of all active voices.
2165     */
2166    String LSCPServer::GetTotalVoiceCount() {
2167        dmsg(2,("LSCPServer: GetTotalVoiceCount()\n"));
2168        LSCPResultSet result;
2169        result.Add(pSampler->GetVoiceCount());
2170        return result.Produce();
2171    }
2172    
2173    /**
2174     * Will be called by the parser to return the maximum number of voices.
2175     */
2176    String LSCPServer::GetTotalVoiceCountMax() {
2177        dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
2178        LSCPResultSet result;
2179        result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);
2180        return result.Produce();
2181    }
2182    
2183    String LSCPServer::GetGlobalVolume() {
2184        LSCPResultSet result;
2185        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2186        return result.Produce();
2187    }
2188    
2189    String LSCPServer::SetGlobalVolume(double dVolume) {
2190        LSCPResultSet result;
2191        try {
2192            if (dVolume < 0) throw Exception("Volume may not be negative");
2193            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2194            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2195        } catch (Exception e) {
2196            result.Error(e);
2197        }
2198      return result.Produce();      return result.Produce();
2199  }  }
2200    
# Line 1505  String LSCPServer::SetEcho(yyparse_param Line 2266  String LSCPServer::SetEcho(yyparse_param
2266      try {      try {
2267          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
2268          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
2269          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");
2270      }      }
2271      catch (LinuxSamplerException e) {      catch (Exception e) {
2272           result.Error(e);           result.Error(e);
2273      }      }
2274      return result.Produce();      return result.Produce();

Legend:
Removed from v.670  
changed lines
  Added in v.1135

  ViewVC Help
Powered by ViewVC