/[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 563 by schoenebeck, Sun May 22 20:43:32 2005 UTC revision 947 by schoenebeck, Mon Nov 27 21:34:55 2006 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, 2006 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 33  Line 33 
33  #endif  #endif
34    
35  #include "../engines/EngineFactory.h"  #include "../engines/EngineFactory.h"
36    #include "../engines/EngineChannelFactory.h"
37  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
38  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
39    
# Line 60  Mutex LSCPServer::NotifyBufferMutex = Mu Line 61  Mutex LSCPServer::NotifyBufferMutex = Mu
61  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
62  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
63    
64  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) {
65        SocketAddress.sin_family      = AF_INET;
66        SocketAddress.sin_addr.s_addr = addr;
67        SocketAddress.sin_port        = port;
68      this->pSampler = pSampler;      this->pSampler = pSampler;
69      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
# Line 68  LSCPServer::LSCPServer(Sampler* pSampler Line 72  LSCPServer::LSCPServer(Sampler* pSampler
72      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
75        LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
76      hSocket = -1;      hSocket = -1;
77  }  }
78    
# Line 97  int LSCPServer::Main() { Line 102  int LSCPServer::Main() {
102          exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
103      }      }
104    
     SocketAddress.sin_family      = AF_INET;  
     SocketAddress.sin_port        = htons(LSCP_PORT);  
     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);  
   
105      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
106          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";
107          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
# Line 127  int LSCPServer::Main() { Line 128  int LSCPServer::Main() {
128      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
129      int maxSessions = hSocket;      int maxSessions = hSocket;
130    
131        timeval timeout;
132    
133      while (true) {      while (true) {
134          fd_set selectSet = fdSet;          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
135          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          {
136                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
137                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
138                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
139                for (; itEngineChannel != itEnd; ++itEngineChannel) {
140                    if ((*itEngineChannel)->StatusChanged()) {
141                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
142                    }
143                }
144            }
145    
146            //Now let's deliver late notifies (if any)
147            NotifyBufferMutex.Lock();
148            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
149    #ifdef MSG_NOSIGNAL
150                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
151    #else
152                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
153    #endif
154            }
155            bufferedNotifies.clear();
156            NotifyBufferMutex.Unlock();
157    
158            fd_set selectSet = fdSet;
159            timeout.tv_sec  = 0;
160            timeout.tv_usec = 100000;
161    
162            int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
163    
164          if (retval == 0)          if (retval == 0)
165                  continue; //Nothing try again                  continue; //Nothing try again
166          if (retval == -1) {          if (retval == -1) {
# Line 189  int LSCPServer::Main() { Line 220  int LSCPServer::Main() {
220                          break;                          break;
221                  }                  }
222          }          }
   
         //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();  
223      }      }
224  }  }
225    
# Line 243  void LSCPServer::SendLSCPNotify( LSCPEve Line 266  void LSCPServer::SendLSCPNotify( LSCPEve
266          while (true) {          while (true) {
267                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
268                          for(;iter != end; iter++)                          for(;iter != end; iter++)
269    #ifdef MSG_NOSIGNAL
270                                    send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
271    #else
272                                  send(*iter, notify.c_str(), notify.size(), 0);                                  send(*iter, notify.c_str(), notify.size(), 0);
273    #endif
274                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
275                          break;                          break;
276                  } else {                  } else {
# Line 295  bool LSCPServer::GetLSCPCommand( std::ve Line 322  bool LSCPServer::GetLSCPCommand( std::ve
322                                  continue; //Ignore CR                                  continue; //Ignore CR
323                          if (c == '\n') {                          if (c == '\n') {
324                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
325                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
326                                  return true; //Complete command was read                                  return true; //Complete command was read
327                          }                          }
328                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
# Line 352  void LSCPServer::AnswerClient(String Ret Line 379  void LSCPServer::AnswerClient(String Ret
379      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
380      if (currentSocket != -1) {      if (currentSocket != -1) {
381              NotifyMutex.Lock();              NotifyMutex.Lock();
382    #ifdef MSG_NOSIGNAL
383                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
384    #else
385              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
386    #endif
387              NotifyMutex.Unlock();              NotifyMutex.Unlock();
388      }      }
389  }  }
# Line 396  String LSCPServer::CreateAudioOutputDevi Line 427  String LSCPServer::CreateAudioOutputDevi
427          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
428          // search for the created device to get its index          // search for the created device to get its index
429          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
430          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.");
431          result = index; // success          result = index; // success
432      }      }
433      catch (LinuxSamplerException e) {      catch (Exception e) {
434          result.Error(e);          result.Error(e);
435      }      }
436      return result.Produce();      return result.Produce();
# Line 412  String LSCPServer::CreateMidiInputDevice Line 443  String LSCPServer::CreateMidiInputDevice
443          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
444          // search for the created device to get its index          // search for the created device to get its index
445          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
446          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.");
447          result = index; // success          result = index; // success
448      }      }
449      catch (LinuxSamplerException e) {      catch (Exception e) {
450          result.Error(e);          result.Error(e);
451      }      }
452      return result.Produce();      return result.Produce();
# Line 426  String LSCPServer::DestroyAudioOutputDev Line 457  String LSCPServer::DestroyAudioOutputDev
457      LSCPResultSet result;      LSCPResultSet result;
458      try {      try {
459          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
460          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) + ".");
461          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
462          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
463      }      }
464      catch (LinuxSamplerException e) {      catch (Exception e) {
465          result.Error(e);          result.Error(e);
466      }      }
467      return result.Produce();      return result.Produce();
# Line 441  String LSCPServer::DestroyMidiInputDevic Line 472  String LSCPServer::DestroyMidiInputDevic
472      LSCPResultSet result;      LSCPResultSet result;
473      try {      try {
474          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
475          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) + ".");
476          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
477          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
478      }      }
479      catch (LinuxSamplerException e) {      catch (Exception e) {
480          result.Error(e);          result.Error(e);
481      }      }
482      return result.Produce();      return result.Produce();
# Line 459  String LSCPServer::LoadInstrument(String Line 490  String LSCPServer::LoadInstrument(String
490      LSCPResultSet result;      LSCPResultSet result;
491      try {      try {
492          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
493          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
494          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
495          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
496          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
497              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
498          if (bBackground) {          if (bBackground) {
499              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
500                id.FileName = Filename;
501                id.Index    = uiInstrument;
502                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
503          }          }
504          else {          else {
505              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 474  String LSCPServer::LoadInstrument(String Line 508  String LSCPServer::LoadInstrument(String
508              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
509          }          }
510      }      }
511      catch (LinuxSamplerException e) {      catch (Exception e) {
512           result.Error(e);           result.Error(e);
513      }      }
514      return result.Produce();      return result.Produce();
# Line 485  String LSCPServer::LoadInstrument(String Line 519  String LSCPServer::LoadInstrument(String
519   * sampler channel.   * sampler channel.
520   */   */
521  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
522      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));
523      LSCPResultSet result;      LSCPResultSet result;
524      try {      try {
525          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
526          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
527          LockRTNotify();          LockRTNotify();
528          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
529            if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
530          UnlockRTNotify();          UnlockRTNotify();
531      }      }
532      catch (LinuxSamplerException e) {      catch (Exception e) {
533           result.Error(e);           result.Error(e);
534      }      }
535      return result.Produce();      return result.Produce();
# Line 532  String LSCPServer::ListChannels() { Line 567  String LSCPServer::ListChannels() {
567   */   */
568  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
569      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
570        LockRTNotify();
571      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
572        UnlockRTNotify();
573      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
574      return result.Produce();      return result.Produce();
575  }  }
# Line 554  String LSCPServer::RemoveChannel(uint ui Line 591  String LSCPServer::RemoveChannel(uint ui
591   */   */
592  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
593      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
594      LSCPResultSet result("1");      LSCPResultSet result;
595        try {
596            int n = EngineFactory::AvailableEngineTypes().size();
597            result.Add(n);
598        }
599        catch (Exception e) {
600            result.Error(e);
601        }
602      return result.Produce();      return result.Produce();
603  }  }
604    
# Line 563  String LSCPServer::GetAvailableEngines() Line 607  String LSCPServer::GetAvailableEngines()
607   */   */
608  String LSCPServer::ListAvailableEngines() {  String LSCPServer::ListAvailableEngines() {
609      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));      dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
610      LSCPResultSet result("\'GIG\'");      LSCPResultSet result;
611        try {
612            String s = EngineFactory::AvailableEngineTypesAsString();
613            result.Add(s);
614        }
615        catch (Exception e) {
616            result.Error(e);
617        }
618      return result.Produce();      return result.Produce();
619  }  }
620    
# Line 574  String LSCPServer::ListAvailableEngines( Line 625  String LSCPServer::ListAvailableEngines(
625  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
626      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
627      LSCPResultSet result;      LSCPResultSet result;
628        LockRTNotify();
629      try {      try {
630          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
631          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
632          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
633          delete pEngine;          EngineFactory::Destroy(pEngine);
634      }      }
635      catch (LinuxSamplerException e) {      catch (Exception e) {
636           result.Error(e);           result.Error(e);
637      }      }
638        UnlockRTNotify();
639      return result.Produce();      return result.Produce();
640  }  }
641    
# Line 595  String LSCPServer::GetChannelInfo(uint u Line 648  String LSCPServer::GetChannelInfo(uint u
648      LSCPResultSet result;      LSCPResultSet result;
649      try {      try {
650          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
651          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
652          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
653    
654          //Defaults values          //Defaults values
# Line 607  String LSCPServer::GetChannelInfo(uint u Line 660  String LSCPServer::GetChannelInfo(uint u
660          int InstrumentStatus = -1;          int InstrumentStatus = -1;
661          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
662          String AudioRouting;          String AudioRouting;
663            int Mute = 0;
664            bool Solo = false;
665    
666          if (pEngineChannel) {          if (pEngineChannel) {
667              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 622  String LSCPServer::GetChannelInfo(uint u Line 677  String LSCPServer::GetChannelInfo(uint u
677                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
678                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
679              }              }
680                Mute = pEngineChannel->GetMute();
681                Solo = pEngineChannel->GetSolo();
682          }          }
683    
684          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 634  String LSCPServer::GetChannelInfo(uint u Line 691  String LSCPServer::GetChannelInfo(uint u
691    
692          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
693          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
694          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");
695          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
696    
697          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
698          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
699          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", InstrumentName);
700          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
701            result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
702            result.Add("SOLO", Solo);
703      }      }
704      catch (LinuxSamplerException e) {      catch (Exception e) {
705           result.Error(e);           result.Error(e);
706      }      }
707      return result.Produce();      return result.Produce();
# Line 657  String LSCPServer::GetVoiceCount(uint ui Line 716  String LSCPServer::GetVoiceCount(uint ui
716      LSCPResultSet result;      LSCPResultSet result;
717      try {      try {
718          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
719          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
720          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
721          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
722            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
723          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
724      }      }
725      catch (LinuxSamplerException e) {      catch (Exception e) {
726           result.Error(e);           result.Error(e);
727      }      }
728      return result.Produce();      return result.Produce();
# Line 677  String LSCPServer::GetStreamCount(uint u Line 737  String LSCPServer::GetStreamCount(uint u
737      LSCPResultSet result;      LSCPResultSet result;
738      try {      try {
739          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
740          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
741          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
742          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
743            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
744          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
745      }      }
746      catch (LinuxSamplerException e) {      catch (Exception e) {
747           result.Error(e);           result.Error(e);
748      }      }
749      return result.Produce();      return result.Produce();
# Line 697  String LSCPServer::GetBufferFill(fill_re Line 758  String LSCPServer::GetBufferFill(fill_re
758      LSCPResultSet result;      LSCPResultSet result;
759      try {      try {
760          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
761          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
762          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
763          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
764            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
765          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
766          else {          else {
767              switch (ResponseType) {              switch (ResponseType) {
# Line 710  String LSCPServer::GetBufferFill(fill_re Line 772  String LSCPServer::GetBufferFill(fill_re
772                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
773                      break;                      break;
774                  default:                  default:
775                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
776              }              }
777          }          }
778      }      }
779      catch (LinuxSamplerException e) {      catch (Exception e) {
780           result.Error(e);           result.Error(e);
781      }      }
782      return result.Produce();      return result.Produce();
# Line 727  String LSCPServer::GetAvailableAudioOutp Line 789  String LSCPServer::GetAvailableAudioOutp
789          int n = AudioOutputDeviceFactory::AvailableDrivers().size();          int n = AudioOutputDeviceFactory::AvailableDrivers().size();
790          result.Add(n);          result.Add(n);
791      }      }
792      catch (LinuxSamplerException e) {      catch (Exception e) {
793          result.Error(e);          result.Error(e);
794      }      }
795      return result.Produce();      return result.Produce();
# Line 740  String LSCPServer::ListAvailableAudioOut Line 802  String LSCPServer::ListAvailableAudioOut
802          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
803          result.Add(s);          result.Add(s);
804      }      }
805      catch (LinuxSamplerException e) {      catch (Exception e) {
806          result.Error(e);          result.Error(e);
807      }      }
808      return result.Produce();      return result.Produce();
# Line 753  String LSCPServer::GetAvailableMidiInput Line 815  String LSCPServer::GetAvailableMidiInput
815          int n = MidiInputDeviceFactory::AvailableDrivers().size();          int n = MidiInputDeviceFactory::AvailableDrivers().size();
816          result.Add(n);          result.Add(n);
817      }      }
818      catch (LinuxSamplerException e) {      catch (Exception e) {
819          result.Error(e);          result.Error(e);
820      }      }
821      return result.Produce();      return result.Produce();
# Line 766  String LSCPServer::ListAvailableMidiInpu Line 828  String LSCPServer::ListAvailableMidiInpu
828          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
829          result.Add(s);          result.Add(s);
830      }      }
831      catch (LinuxSamplerException e) {      catch (Exception e) {
832          result.Error(e);          result.Error(e);
833      }      }
834      return result.Produce();      return result.Produce();
# Line 790  String LSCPServer::GetMidiInputDriverInf Line 852  String LSCPServer::GetMidiInputDriverInf
852              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
853          }          }
854      }      }
855      catch (LinuxSamplerException e) {      catch (Exception e) {
856          result.Error(e);          result.Error(e);
857      }      }
858      return result.Produce();      return result.Produce();
# Line 814  String LSCPServer::GetAudioOutputDriverI Line 876  String LSCPServer::GetAudioOutputDriverI
876              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
877          }          }
878      }      }
879      catch (LinuxSamplerException e) {      catch (Exception e) {
880          result.Error(e);          result.Error(e);
881      }      }
882      return result.Produce();      return result.Produce();
# Line 841  String LSCPServer::GetMidiInputDriverPar Line 903  String LSCPServer::GetMidiInputDriverPar
903          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
904          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
905      }      }
906      catch (LinuxSamplerException e) {      catch (Exception e) {
907          result.Error(e);          result.Error(e);
908      }      }
909      return result.Produce();      return result.Produce();
# Line 868  String LSCPServer::GetAudioOutputDriverP Line 930  String LSCPServer::GetAudioOutputDriverP
930          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
931          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
932      }      }
933      catch (LinuxSamplerException e) {      catch (Exception e) {
934          result.Error(e);          result.Error(e);
935      }      }
936      return result.Produce();      return result.Produce();
# Line 881  String LSCPServer::GetAudioOutputDeviceC Line 943  String LSCPServer::GetAudioOutputDeviceC
943          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
944          result.Add(count); // success          result.Add(count); // success
945      }      }
946      catch (LinuxSamplerException e) {      catch (Exception e) {
947          result.Error(e);          result.Error(e);
948      }      }
949      return result.Produce();      return result.Produce();
# Line 894  String LSCPServer::GetMidiInputDeviceCou Line 956  String LSCPServer::GetMidiInputDeviceCou
956          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
957          result.Add(count); // success          result.Add(count); // success
958      }      }
959      catch (LinuxSamplerException e) {      catch (Exception e) {
960          result.Error(e);          result.Error(e);
961      }      }
962      return result.Produce();      return result.Produce();
# Line 913  String LSCPServer::GetAudioOutputDevices Line 975  String LSCPServer::GetAudioOutputDevices
975          }          }
976          result.Add(s);          result.Add(s);
977      }      }
978      catch (LinuxSamplerException e) {      catch (Exception e) {
979          result.Error(e);          result.Error(e);
980      }      }
981      return result.Produce();      return result.Produce();
# Line 932  String LSCPServer::GetMidiInputDevices() Line 994  String LSCPServer::GetMidiInputDevices()
994          }          }
995          result.Add(s);          result.Add(s);
996      }      }
997      catch (LinuxSamplerException e) {      catch (Exception e) {
998          result.Error(e);          result.Error(e);
999      }      }
1000      return result.Produce();      return result.Produce();
# Line 943  String LSCPServer::GetAudioOutputDeviceI Line 1005  String LSCPServer::GetAudioOutputDeviceI
1005      LSCPResultSet result;      LSCPResultSet result;
1006      try {      try {
1007          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1008          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) + ".");
1009          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1010          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1011          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 952  String LSCPServer::GetAudioOutputDeviceI Line 1014  String LSCPServer::GetAudioOutputDeviceI
1014              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1015          }          }
1016      }      }
1017      catch (LinuxSamplerException e) {      catch (Exception e) {
1018          result.Error(e);          result.Error(e);
1019      }      }
1020      return result.Produce();      return result.Produce();
# Line 963  String LSCPServer::GetMidiInputDeviceInf Line 1025  String LSCPServer::GetMidiInputDeviceInf
1025      LSCPResultSet result;      LSCPResultSet result;
1026      try {      try {
1027          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1028          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) + ".");
1029          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1030          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1031          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 972  String LSCPServer::GetMidiInputDeviceInf Line 1034  String LSCPServer::GetMidiInputDeviceInf
1034              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1035          }          }
1036      }      }
1037      catch (LinuxSamplerException e) {      catch (Exception e) {
1038          result.Error(e);          result.Error(e);
1039      }      }
1040      return result.Produce();      return result.Produce();
# Line 983  String LSCPServer::GetMidiInputPortInfo( Line 1045  String LSCPServer::GetMidiInputPortInfo(
1045      try {      try {
1046          // get MIDI input device          // get MIDI input device
1047          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1048          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) + ".");
1049          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1050    
1051          // get MIDI port          // get MIDI port
1052          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1053          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) + ".");
1054    
1055          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1056          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 997  String LSCPServer::GetMidiInputPortInfo( Line 1059  String LSCPServer::GetMidiInputPortInfo(
1059              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1060          }          }
1061      }      }
1062      catch (LinuxSamplerException e) {      catch (Exception e) {
1063          result.Error(e);          result.Error(e);
1064      }      }
1065      return result.Produce();      return result.Produce();
# Line 1009  String LSCPServer::GetAudioOutputChannel Line 1071  String LSCPServer::GetAudioOutputChannel
1071      try {      try {
1072          // get audio output device          // get audio output device
1073          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1074          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) + ".");
1075          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1076    
1077          // get audio channel          // get audio channel
1078          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1079          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) + ".");
1080    
1081          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1082          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1023  String LSCPServer::GetAudioOutputChannel Line 1085  String LSCPServer::GetAudioOutputChannel
1085              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1086          }          }
1087      }      }
1088      catch (LinuxSamplerException e) {      catch (Exception e) {
1089          result.Error(e);          result.Error(e);
1090      }      }
1091      return result.Produce();      return result.Produce();
# Line 1035  String LSCPServer::GetMidiInputPortParam Line 1097  String LSCPServer::GetMidiInputPortParam
1097      try {      try {
1098          // get MIDI input device          // get MIDI input device
1099          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1100          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) + ".");
1101          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1102    
1103          // get midi port          // get midi port
1104          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1105          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) + ".");
1106    
1107          // get desired port parameter          // get desired port parameter
1108          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1109          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 + "'.");
1110          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1111    
1112          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1056  String LSCPServer::GetMidiInputPortParam Line 1118  String LSCPServer::GetMidiInputPortParam
1118          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1119          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1120      }      }
1121      catch (LinuxSamplerException e) {      catch (Exception e) {
1122          result.Error(e);          result.Error(e);
1123      }      }
1124      return result.Produce();      return result.Produce();
# Line 1068  String LSCPServer::GetAudioOutputChannel Line 1130  String LSCPServer::GetAudioOutputChannel
1130      try {      try {
1131          // get audio output device          // get audio output device
1132          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1133          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) + ".");
1134          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1135    
1136          // get audio channel          // get audio channel
1137          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1138          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) + ".");
1139    
1140          // get desired audio channel parameter          // get desired audio channel parameter
1141          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1142          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 + "'.");
1143          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1144    
1145          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1089  String LSCPServer::GetAudioOutputChannel Line 1151  String LSCPServer::GetAudioOutputChannel
1151          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1152          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1153      }      }
1154      catch (LinuxSamplerException e) {      catch (Exception e) {
1155          result.Error(e);          result.Error(e);
1156      }      }
1157      return result.Produce();      return result.Produce();
# Line 1101  String LSCPServer::SetAudioOutputChannel Line 1163  String LSCPServer::SetAudioOutputChannel
1163      try {      try {
1164          // get audio output device          // get audio output device
1165          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1166          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) + ".");
1167          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1168    
1169          // get audio channel          // get audio channel
1170          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1171          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) + ".");
1172    
1173          // get desired audio channel parameter          // get desired audio channel parameter
1174          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1175          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 + "'.");
1176          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1177    
1178          // set new channel parameter value          // set new channel parameter value
1179          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1180      }      }
1181      catch (LinuxSamplerException e) {      catch (Exception e) {
1182          result.Error(e);          result.Error(e);
1183      }      }
1184      return result.Produce();      return result.Produce();
# Line 1127  String LSCPServer::SetAudioOutputDeviceP Line 1189  String LSCPServer::SetAudioOutputDeviceP
1189      LSCPResultSet result;      LSCPResultSet result;
1190      try {      try {
1191          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1192          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) + ".");
1193          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1194          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1195          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 + "'");
1196          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1197      }      }
1198      catch (LinuxSamplerException e) {      catch (Exception e) {
1199          result.Error(e);          result.Error(e);
1200      }      }
1201      return result.Produce();      return result.Produce();
# Line 1144  String LSCPServer::SetMidiInputDevicePar Line 1206  String LSCPServer::SetMidiInputDevicePar
1206      LSCPResultSet result;      LSCPResultSet result;
1207      try {      try {
1208          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1209          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) + ".");
1210          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1211          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1212          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 + "'");
1213          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1214      }      }
1215      catch (LinuxSamplerException e) {      catch (Exception e) {
1216          result.Error(e);          result.Error(e);
1217      }      }
1218      return result.Produce();      return result.Produce();
# Line 1162  String LSCPServer::SetMidiInputPortParam Line 1224  String LSCPServer::SetMidiInputPortParam
1224      try {      try {
1225          // get MIDI input device          // get MIDI input device
1226          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1227          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) + ".");
1228          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1229    
1230          // get MIDI port          // get MIDI port
1231          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1232          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) + ".");
1233    
1234          // set port parameter value          // set port parameter value
1235          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1236          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 + "'");
1237          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1238      }      }
1239      catch (LinuxSamplerException e) {      catch (Exception e) {
1240          result.Error(e);          result.Error(e);
1241      }      }
1242      return result.Produce();      return result.Produce();
# Line 1189  String LSCPServer::SetAudioOutputChannel Line 1251  String LSCPServer::SetAudioOutputChannel
1251      LSCPResultSet result;      LSCPResultSet result;
1252      try {      try {
1253          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1254          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1255          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1256          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));
1257          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));
1258          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1259      }      }
1260      catch (LinuxSamplerException e) {      catch (Exception e) {
1261           result.Error(e);           result.Error(e);
1262      }      }
1263      return result.Produce();      return result.Produce();
# Line 1204  String LSCPServer::SetAudioOutputChannel Line 1266  String LSCPServer::SetAudioOutputChannel
1266  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1267      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1268      LSCPResultSet result;      LSCPResultSet result;
1269        LockRTNotify();
1270      try {      try {
1271          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1272          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1273          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1274          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));
1275          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1276          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1277      }      }
1278      catch (LinuxSamplerException e) {      catch (Exception e) {
1279           result.Error(e);           result.Error(e);
1280      }      }
1281        UnlockRTNotify();
1282      return result.Produce();      return result.Produce();
1283  }  }
1284    
1285  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1286      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));
1287      LSCPResultSet result;      LSCPResultSet result;
1288        LockRTNotify();
1289      try {      try {
1290          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1291          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1292          // Driver type name aliasing...          // Driver type name aliasing...
1293          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1294          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1245  String LSCPServer::SetAudioOutputType(St Line 1310  String LSCPServer::SetAudioOutputType(St
1310          }          }
1311          // Must have a device...          // Must have a device...
1312          if (pDevice == NULL)          if (pDevice == NULL)
1313              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1314          // Set it as the current channel device...          // Set it as the current channel device...
1315          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1316      }      }
1317      catch (LinuxSamplerException e) {      catch (Exception e) {
1318           result.Error(e);           result.Error(e);
1319      }      }
1320        UnlockRTNotify();
1321      return result.Produce();      return result.Produce();
1322  }  }
1323    
# Line 1260  String LSCPServer::SetMIDIInputPort(uint Line 1326  String LSCPServer::SetMIDIInputPort(uint
1326      LSCPResultSet result;      LSCPResultSet result;
1327      try {      try {
1328          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1329          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1330          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1331      }      }
1332      catch (LinuxSamplerException e) {      catch (Exception e) {
1333           result.Error(e);           result.Error(e);
1334      }      }
1335      return result.Produce();      return result.Produce();
# Line 1274  String LSCPServer::SetMIDIInputChannel(u Line 1340  String LSCPServer::SetMIDIInputChannel(u
1340      LSCPResultSet result;      LSCPResultSet result;
1341      try {      try {
1342          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1343          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1344          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1345      }      }
1346      catch (LinuxSamplerException e) {      catch (Exception e) {
1347           result.Error(e);           result.Error(e);
1348      }      }
1349      return result.Produce();      return result.Produce();
# Line 1288  String LSCPServer::SetMIDIInputDevice(ui Line 1354  String LSCPServer::SetMIDIInputDevice(ui
1354      LSCPResultSet result;      LSCPResultSet result;
1355      try {      try {
1356          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1357          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1358          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1359          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));
1360          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1361          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1362      }      }
1363      catch (LinuxSamplerException e) {      catch (Exception e) {
1364           result.Error(e);           result.Error(e);
1365      }      }
1366      return result.Produce();      return result.Produce();
# Line 1305  String LSCPServer::SetMIDIInputType(Stri Line 1371  String LSCPServer::SetMIDIInputType(Stri
1371      LSCPResultSet result;      LSCPResultSet result;
1372      try {      try {
1373          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1374          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1375          // Driver type name aliasing...          // Driver type name aliasing...
1376          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1377          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1329  String LSCPServer::SetMIDIInputType(Stri Line 1395  String LSCPServer::SetMIDIInputType(Stri
1395          }          }
1396          // Must have a device...          // Must have a device...
1397          if (pDevice == NULL)          if (pDevice == NULL)
1398              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1399          // Set it as the current channel device...          // Set it as the current channel device...
1400          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1401      }      }
1402      catch (LinuxSamplerException e) {      catch (Exception e) {
1403           result.Error(e);           result.Error(e);
1404      }      }
1405      return result.Produce();      return result.Produce();
# Line 1348  String LSCPServer::SetMIDIInput(uint MID Line 1414  String LSCPServer::SetMIDIInput(uint MID
1414      LSCPResultSet result;      LSCPResultSet result;
1415      try {      try {
1416          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1417          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1418          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1419          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));
1420          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1421          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1422      }      }
1423      catch (LinuxSamplerException e) {      catch (Exception e) {
1424           result.Error(e);           result.Error(e);
1425      }      }
1426      return result.Produce();      return result.Produce();
# Line 1369  String LSCPServer::SetVolume(double dVol Line 1435  String LSCPServer::SetVolume(double dVol
1435      LSCPResultSet result;      LSCPResultSet result;
1436      try {      try {
1437          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1438          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1439          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1440          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1441          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1442      }      }
1443      catch (LinuxSamplerException e) {      catch (Exception e) {
1444           result.Error(e);           result.Error(e);
1445      }      }
1446      return result.Produce();      return result.Produce();
1447  }  }
1448    
1449  /**  /**
1450     * Will be called by the parser to mute/unmute particular sampler channel.
1451     */
1452    String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) {
1453        dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1454        LSCPResultSet result;
1455        try {
1456            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1457            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1458    
1459            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1460            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1461    
1462            if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1463            else pEngineChannel->SetMute(1);
1464        } catch (Exception e) {
1465            result.Error(e);
1466        }
1467        return result.Produce();
1468    }
1469    
1470    /**
1471     * Will be called by the parser to solo particular sampler channel.
1472     */
1473    String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) {
1474        dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1475        LSCPResultSet result;
1476        try {
1477            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1478            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1479    
1480            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1481            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1482    
1483            bool oldSolo = pEngineChannel->GetSolo();
1484            bool hadSoloChannel = HasSoloChannel();
1485            
1486            pEngineChannel->SetSolo(bSolo);
1487            
1488            if(!oldSolo && bSolo) {
1489                if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1490                if(!hadSoloChannel) MuteNonSoloChannels();
1491            }
1492            
1493            if(oldSolo && !bSolo) {
1494                if(!HasSoloChannel()) UnmuteChannels();
1495                else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1496            }
1497        } catch (Exception e) {
1498            result.Error(e);
1499        }
1500        return result.Produce();
1501    }
1502    
1503    /**
1504     * Determines whether there is at least one solo channel in the channel list.
1505     *
1506     * @returns true if there is at least one solo channel in the channel list,
1507     * false otherwise.
1508     */
1509    bool LSCPServer::HasSoloChannel() {
1510        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1511        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1512        for (; iter != channels.end(); iter++) {
1513            EngineChannel* c = iter->second->GetEngineChannel();
1514            if(c && c->GetSolo()) return true;
1515        }
1516    
1517        return false;
1518    }
1519    
1520    /**
1521     * Mutes all unmuted non-solo channels. Notice that the channels are muted
1522     * with -1 which indicates that they are muted because of the presence
1523     * of a solo channel(s). Channels muted with -1 will be automatically unmuted
1524     * when there are no solo channels left.
1525     */
1526    void LSCPServer::MuteNonSoloChannels() {
1527        dmsg(2,("LSCPServer: MuteNonSoloChannels()\n"));
1528        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1529        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1530        for (; iter != channels.end(); iter++) {
1531            EngineChannel* c = iter->second->GetEngineChannel();
1532            if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1);
1533        }
1534    }
1535    
1536    /**
1537     * Unmutes all channels that are muted because of the presence
1538     * of a solo channel(s).
1539     */
1540    void  LSCPServer::UnmuteChannels() {
1541        dmsg(2,("LSCPServer: UnmuteChannels()\n"));
1542        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1543        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1544        for (; iter != channels.end(); iter++) {
1545            EngineChannel* c = iter->second->GetEngineChannel();
1546            if(c && c->GetMute() == -1) c->SetMute(0);
1547        }
1548    }
1549    
1550    String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) {
1551        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1552    
1553        midi_prog_index_t idx;
1554        idx.midi_bank_msb = MidiBankMSB;
1555        idx.midi_bank_lsb = MidiBankLSB;
1556        idx.midi_prog     = MidiProg;
1557    
1558        MidiInstrumentMapper::entry_t entry;
1559        entry.EngineName      = EngineType;
1560        entry.InstrumentFile  = InstrumentFile;
1561        entry.InstrumentIndex = InstrumentIndex;
1562        entry.LoadMode        = LoadMode;
1563        entry.Volume          = Volume;
1564        entry.Name            = Name;
1565    
1566        LSCPResultSet result;
1567        try {
1568            // PERSISTENT mapping commands might bloock for a long time, so in
1569            // that case we add/replace the mapping in another thread
1570            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT);
1571            MidiInstrumentMapper::AddOrReplaceMapping(idx, entry, bInBackground);
1572        } catch (Exception e) {
1573            result.Error(e);
1574        }
1575        return result.Produce();
1576    }
1577    
1578    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg) {
1579        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1580    
1581        midi_prog_index_t idx;
1582        idx.midi_bank_msb = MidiBankMSB;
1583        idx.midi_bank_lsb = MidiBankLSB;
1584        idx.midi_prog     = MidiProg;
1585    
1586        LSCPResultSet result;
1587        try {
1588            MidiInstrumentMapper::RemoveMapping(idx);
1589        } catch (Exception e) {
1590            result.Error(e);
1591        }
1592        return result.Produce();
1593    }
1594    
1595    String LSCPServer::GetMidiIstrumentMappings() {
1596        dmsg(2,("LSCPServer: GetMidiIstrumentMappings()\n"));
1597        LSCPResultSet result;
1598        result.Add(MidiInstrumentMapper::Mappings().size());
1599        return result.Produce();
1600    }
1601    
1602    String LSCPServer::GetMidiInstrumentMapping(uint MidiBankMSB, uint MidiBankLSB, uint MidiProg) {
1603        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1604        LSCPResultSet result;
1605        try {
1606            midi_prog_index_t idx;
1607            idx.midi_bank_msb = MidiBankMSB;
1608            idx.midi_bank_lsb = MidiBankLSB;
1609            idx.midi_prog     = MidiProg;
1610    
1611            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Mappings();
1612            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1613            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1614            else { // found
1615                result.Add("NAME", iter->second.Name);
1616                result.Add("ENGINE_NAME", iter->second.EngineName);
1617                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1618                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1619                String instrumentName;
1620                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1621                if (pEngine) {
1622                    if (pEngine->GetInstrumentManager()) {
1623                        InstrumentManager::instrument_id_t instrID;
1624                        instrID.FileName = iter->second.InstrumentFile;
1625                        instrID.Index    = iter->second.InstrumentIndex;
1626                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1627                    }
1628                    EngineFactory::Destroy(pEngine);
1629                }
1630                result.Add("INSTRUMENT_NAME", instrumentName);
1631                switch (iter->second.LoadMode) {
1632                    case MidiInstrumentMapper::ON_DEMAND:
1633                        result.Add("LOAD_MODE", "ON_DEMAND");
1634                        break;
1635                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1636                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1637                        break;
1638                    case MidiInstrumentMapper::PERSISTENT:
1639                        result.Add("LOAD_MODE", "PERSISTENT");
1640                        break;
1641                    default:
1642                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1643                }
1644                result.Add("VOLUME", iter->second.Volume);
1645            }
1646        } catch (Exception e) {
1647            result.Error(e);
1648        }
1649        return result.Produce();
1650    }
1651    
1652    String LSCPServer::ListMidiInstrumentMappings() {
1653        dmsg(2,("LSCPServer: ListMidiIstrumentMappings()\n"));
1654        LSCPResultSet result;
1655        try {
1656            String s;
1657            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Mappings();
1658            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1659            for (; iter != mappings.end(); iter++) {
1660                if (s.size()) s += ",";
1661                s += "{" + ToString(iter->first.midi_bank_msb) + ","
1662                         + ToString(iter->first.midi_bank_lsb) + ","
1663                         + ToString(iter->first.midi_prog)     + "}";
1664            }
1665            result.Add(s);
1666        } catch (Exception e) {
1667            result.Error(e);
1668        }
1669        return result.Produce();
1670    }
1671    
1672    String LSCPServer::ClearMidiInstrumentMappings() {
1673        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1674        LSCPResultSet result;
1675        try {
1676            MidiInstrumentMapper::RemoveAllMappings();
1677        } catch (Exception e) {
1678            result.Error(e);
1679        }
1680        return result.Produce();
1681    }
1682    
1683    /**
1684   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
1685   */   */
1686  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
# Line 1388  String LSCPServer::ResetChannel(uint uiS Line 1688  String LSCPServer::ResetChannel(uint uiS
1688      LSCPResultSet result;      LSCPResultSet result;
1689      try {      try {
1690          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1691          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1692          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1693          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1694          pEngineChannel->GetEngine()->Reset();          pEngineChannel->Reset();
1695      }      }
1696      catch (LinuxSamplerException e) {      catch (Exception e) {
1697           result.Error(e);           result.Error(e);
1698      }      }
1699      return result.Produce();      return result.Produce();
# Line 1417  String LSCPServer::GetServerInfo() { Line 1717  String LSCPServer::GetServerInfo() {
1717      dmsg(2,("LSCPServer: GetServerInfo()\n"));      dmsg(2,("LSCPServer: GetServerInfo()\n"));
1718      LSCPResultSet result;      LSCPResultSet result;
1719      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1720      result.Add("VERSION", VERSION);          result.Add("VERSION", VERSION);
1721        result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
1722        return result.Produce();
1723    }
1724    
1725    /**
1726     * Will be called by the parser to return the current number of all active voices.
1727     */
1728    String LSCPServer::GetTotalVoiceCount() {
1729        dmsg(2,("LSCPServer: GetTotalVoiceCount()\n"));
1730        LSCPResultSet result;
1731        result.Add(pSampler->GetVoiceCount());
1732        return result.Produce();
1733    }
1734    
1735    /**
1736     * Will be called by the parser to return the maximum number of voices.
1737     */
1738    String LSCPServer::GetTotalVoiceCountMax() {
1739        dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
1740        LSCPResultSet result;
1741        result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);
1742      return result.Produce();      return result.Produce();
1743  }  }
1744    
# Line 1489  String LSCPServer::SetEcho(yyparse_param Line 1810  String LSCPServer::SetEcho(yyparse_param
1810      try {      try {
1811          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
1812          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
1813          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");
1814      }      }
1815      catch (LinuxSamplerException e) {      catch (Exception e) {
1816           result.Error(e);           result.Error(e);
1817      }      }
1818      return result.Produce();      return result.Produce();

Legend:
Removed from v.563  
changed lines
  Added in v.947

  ViewVC Help
Powered by ViewVC