/[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 475 by schoenebeck, Thu Mar 17 23:56:56 2005 UTC revision 1108 by iliev, Thu Mar 22 20:39:04 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 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_channels, "CHANNELS");      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");
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_info, "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 97  int LSCPServer::Main() { Line 113  int LSCPServer::Main() {
113          exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
114      }      }
115    
     SocketAddress.sin_family      = AF_INET;  
     SocketAddress.sin_port        = htons(LSCP_PORT);  
     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);  
   
116      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
117          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...";
118          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 139  int LSCPServer::Main() {
139      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
140      int maxSessions = hSocket;      int maxSessions = hSocket;
141    
142        timeval timeout;
143    
144      while (true) {      while (true) {
145          fd_set selectSet = fdSet;          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
146          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          {
147                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
148                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
149                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
150                for (; itEngineChannel != itEnd; ++itEngineChannel) {
151                    if ((*itEngineChannel)->StatusChanged()) {
152                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
153                    }
154    
155                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
156                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
157                        if(fxs != NULL && fxs->IsInfoChanged()) {
158                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
159                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
160                            fxs->SetInfoChanged(false);
161                        }
162                    }
163                }
164            }
165    
166            //Now let's deliver late notifies (if any)
167            NotifyBufferMutex.Lock();
168            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
169    #ifdef MSG_NOSIGNAL
170                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
171    #else
172                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
173    #endif
174            }
175            bufferedNotifies.clear();
176            NotifyBufferMutex.Unlock();
177    
178            fd_set selectSet = fdSet;
179            timeout.tv_sec  = 0;
180            timeout.tv_usec = 100000;
181    
182            int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
183    
184          if (retval == 0)          if (retval == 0)
185                  continue; //Nothing try again                  continue; //Nothing try again
186          if (retval == -1) {          if (retval == -1) {
# Line 189  int LSCPServer::Main() { Line 240  int LSCPServer::Main() {
240                          break;                          break;
241                  }                  }
242          }          }
   
         //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();  
243      }      }
244  }  }
245    
# Line 243  void LSCPServer::SendLSCPNotify( LSCPEve Line 286  void LSCPServer::SendLSCPNotify( LSCPEve
286          while (true) {          while (true) {
287                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
288                          for(;iter != end; iter++)                          for(;iter != end; iter++)
289    #ifdef MSG_NOSIGNAL
290                                    send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
291    #else
292                                  send(*iter, notify.c_str(), notify.size(), 0);                                  send(*iter, notify.c_str(), notify.size(), 0);
293    #endif
294                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
295                          break;                          break;
296                  } else {                  } else {
# Line 295  bool LSCPServer::GetLSCPCommand( std::ve Line 342  bool LSCPServer::GetLSCPCommand( std::ve
342                                  continue; //Ignore CR                                  continue; //Ignore CR
343                          if (c == '\n') {                          if (c == '\n') {
344                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
345                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
346                                  return true; //Complete command was read                                  return true; //Complete command was read
347                          }                          }
348                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
# Line 352  void LSCPServer::AnswerClient(String Ret Line 399  void LSCPServer::AnswerClient(String Ret
399      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
400      if (currentSocket != -1) {      if (currentSocket != -1) {
401              NotifyMutex.Lock();              NotifyMutex.Lock();
402    #ifdef MSG_NOSIGNAL
403                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
404    #else
405              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
406    #endif
407              NotifyMutex.Unlock();              NotifyMutex.Unlock();
408      }      }
409  }  }
# Line 396  String LSCPServer::CreateAudioOutputDevi Line 447  String LSCPServer::CreateAudioOutputDevi
447          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
448          // search for the created device to get its index          // search for the created device to get its index
449          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
450          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.");
451          result = index; // success          result = index; // success
452      }      }
453      catch (LinuxSamplerException e) {      catch (Exception e) {
454          result.Error(e);          result.Error(e);
455      }      }
456      return result.Produce();      return result.Produce();
# Line 412  String LSCPServer::CreateMidiInputDevice Line 463  String LSCPServer::CreateMidiInputDevice
463          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
464          // search for the created device to get its index          // search for the created device to get its index
465          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
466          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.");
467          result = index; // success          result = index; // success
468      }      }
469      catch (LinuxSamplerException e) {      catch (Exception e) {
470          result.Error(e);          result.Error(e);
471      }      }
472      return result.Produce();      return result.Produce();
# Line 426  String LSCPServer::DestroyAudioOutputDev Line 477  String LSCPServer::DestroyAudioOutputDev
477      LSCPResultSet result;      LSCPResultSet result;
478      try {      try {
479          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
480          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) + ".");
481          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
482          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
483      }      }
484      catch (LinuxSamplerException e) {      catch (Exception e) {
485          result.Error(e);          result.Error(e);
486      }      }
487      return result.Produce();      return result.Produce();
# Line 441  String LSCPServer::DestroyMidiInputDevic Line 492  String LSCPServer::DestroyMidiInputDevic
492      LSCPResultSet result;      LSCPResultSet result;
493      try {      try {
494          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
495          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) + ".");
496          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
497          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
498      }      }
499      catch (LinuxSamplerException e) {      catch (Exception e) {
500          result.Error(e);          result.Error(e);
501      }      }
502      return result.Produce();      return result.Produce();
# Line 459  String LSCPServer::LoadInstrument(String Line 510  String LSCPServer::LoadInstrument(String
510      LSCPResultSet result;      LSCPResultSet result;
511      try {      try {
512          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
513          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
514          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
515          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
516          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
517              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
518          if (bBackground) {          if (bBackground) {
519              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
520                id.FileName = Filename;
521                id.Index    = uiInstrument;
522                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
523          }          }
524          else {          else {
525              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 474  String LSCPServer::LoadInstrument(String Line 528  String LSCPServer::LoadInstrument(String
528              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
529          }          }
530      }      }
531      catch (LinuxSamplerException e) {      catch (Exception e) {
532           result.Error(e);           result.Error(e);
533      }      }
534      return result.Produce();      return result.Produce();
# Line 485  String LSCPServer::LoadInstrument(String Line 539  String LSCPServer::LoadInstrument(String
539   * sampler channel.   * sampler channel.
540   */   */
541  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
542      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));
543      LSCPResultSet result;      LSCPResultSet result;
544      try {      try {
545          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
546          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
547          LockRTNotify();          LockRTNotify();
548          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
549            if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
550          UnlockRTNotify();          UnlockRTNotify();
551      }      }
552      catch (LinuxSamplerException e) {      catch (Exception e) {
553           result.Error(e);           result.Error(e);
554      }      }
555      return result.Produce();      return result.Produce();
# Line 532  String LSCPServer::ListChannels() { Line 587  String LSCPServer::ListChannels() {
587   */   */
588  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
589      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
590        LockRTNotify();
591      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
592        UnlockRTNotify();
593      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
594      return result.Produce();      return result.Produce();
595  }  }
# Line 550  String LSCPServer::RemoveChannel(uint ui Line 607  String LSCPServer::RemoveChannel(uint ui
607  }  }
608    
609  /**  /**
610   * Will be called by the parser to get all available engines.   * Will be called by the parser to get the amount of all available engines.
611   */   */
612  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
613      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
614      LSCPResultSet result("GigEngine");      LSCPResultSet result;
615        try {
616            int n = EngineFactory::AvailableEngineTypes().size();
617            result.Add(n);
618        }
619        catch (Exception e) {
620            result.Error(e);
621        }
622        return result.Produce();
623    }
624    
625    /**
626     * Will be called by the parser to get a list of all available engines.
627     */
628    String LSCPServer::ListAvailableEngines() {
629        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
630        LSCPResultSet result;
631        try {
632            String s = EngineFactory::AvailableEngineTypesAsString();
633            result.Add(s);
634        }
635        catch (Exception e) {
636            result.Error(e);
637        }
638      return result.Produce();      return result.Produce();
639  }  }
640    
# Line 565  String LSCPServer::GetAvailableEngines() Line 645  String LSCPServer::GetAvailableEngines()
645  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
646      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
647      LSCPResultSet result;      LSCPResultSet result;
648        LockRTNotify();
649      try {      try {
650          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
651          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
652          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
653          delete pEngine;          EngineFactory::Destroy(pEngine);
654      }      }
655      catch (LinuxSamplerException e) {      catch (Exception e) {
656           result.Error(e);           result.Error(e);
657      }      }
658        UnlockRTNotify();
659      return result.Produce();      return result.Produce();
660  }  }
661    
# Line 586  String LSCPServer::GetChannelInfo(uint u Line 668  String LSCPServer::GetChannelInfo(uint u
668      LSCPResultSet result;      LSCPResultSet result;
669      try {      try {
670          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
671          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
672          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
673    
674          //Defaults values          //Defaults values
# Line 598  String LSCPServer::GetChannelInfo(uint u Line 680  String LSCPServer::GetChannelInfo(uint u
680          int InstrumentStatus = -1;          int InstrumentStatus = -1;
681          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
682          String AudioRouting;          String AudioRouting;
683            int Mute = 0;
684            bool Solo = false;
685            String MidiInstrumentMap;
686    
687          if (pEngineChannel) {          if (pEngineChannel) {
688              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 613  String LSCPServer::GetChannelInfo(uint u Line 698  String LSCPServer::GetChannelInfo(uint u
698                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
699                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
700              }              }
701                Mute = pEngineChannel->GetMute();
702                Solo = pEngineChannel->GetSolo();
703                if (pEngineChannel->UsesNoMidiInstrumentMap())
704                    MidiInstrumentMap = "NONE";
705                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
706                    MidiInstrumentMap = "DEFAULT";
707                else
708                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
709          }          }
710    
711          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 625  String LSCPServer::GetChannelInfo(uint u Line 718  String LSCPServer::GetChannelInfo(uint u
718    
719          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
720          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
721          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");
722          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
723    
724          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
725          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
726          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", InstrumentName);
727          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
728            result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
729            result.Add("SOLO", Solo);
730            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
731      }      }
732      catch (LinuxSamplerException e) {      catch (Exception e) {
733           result.Error(e);           result.Error(e);
734      }      }
735      return result.Produce();      return result.Produce();
# Line 648  String LSCPServer::GetVoiceCount(uint ui Line 744  String LSCPServer::GetVoiceCount(uint ui
744      LSCPResultSet result;      LSCPResultSet result;
745      try {      try {
746          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
747          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
748          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
749          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
750            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
751          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
752      }      }
753      catch (LinuxSamplerException e) {      catch (Exception e) {
754           result.Error(e);           result.Error(e);
755      }      }
756      return result.Produce();      return result.Produce();
# Line 668  String LSCPServer::GetStreamCount(uint u Line 765  String LSCPServer::GetStreamCount(uint u
765      LSCPResultSet result;      LSCPResultSet result;
766      try {      try {
767          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
768          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
769          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
770          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
771            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
772          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
773      }      }
774      catch (LinuxSamplerException e) {      catch (Exception e) {
775           result.Error(e);           result.Error(e);
776      }      }
777      return result.Produce();      return result.Produce();
# Line 688  String LSCPServer::GetBufferFill(fill_re Line 786  String LSCPServer::GetBufferFill(fill_re
786      LSCPResultSet result;      LSCPResultSet result;
787      try {      try {
788          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
789          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
790          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
791          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
792            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
793          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
794          else {          else {
795              switch (ResponseType) {              switch (ResponseType) {
# Line 701  String LSCPServer::GetBufferFill(fill_re Line 800  String LSCPServer::GetBufferFill(fill_re
800                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
801                      break;                      break;
802                  default:                  default:
803                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
804              }              }
805          }          }
806      }      }
807      catch (LinuxSamplerException e) {      catch (Exception e) {
808           result.Error(e);           result.Error(e);
809      }      }
810      return result.Produce();      return result.Produce();
# Line 715  String LSCPServer::GetAvailableAudioOutp Line 814  String LSCPServer::GetAvailableAudioOutp
814      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
815      LSCPResultSet result;      LSCPResultSet result;
816      try {      try {
817            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
818            result.Add(n);
819        }
820        catch (Exception e) {
821            result.Error(e);
822        }
823        return result.Produce();
824    }
825    
826    String LSCPServer::ListAvailableAudioOutputDrivers() {
827        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
828        LSCPResultSet result;
829        try {
830          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
831          result.Add(s);          result.Add(s);
832      }      }
833      catch (LinuxSamplerException e) {      catch (Exception e) {
834          result.Error(e);          result.Error(e);
835      }      }
836      return result.Produce();      return result.Produce();
# Line 728  String LSCPServer::GetAvailableMidiInput Line 840  String LSCPServer::GetAvailableMidiInput
840      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
841      LSCPResultSet result;      LSCPResultSet result;
842      try {      try {
843            int n = MidiInputDeviceFactory::AvailableDrivers().size();
844            result.Add(n);
845        }
846        catch (Exception e) {
847            result.Error(e);
848        }
849        return result.Produce();
850    }
851    
852    String LSCPServer::ListAvailableMidiInputDrivers() {
853        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
854        LSCPResultSet result;
855        try {
856          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
857          result.Add(s);          result.Add(s);
858      }      }
859      catch (LinuxSamplerException e) {      catch (Exception e) {
860          result.Error(e);          result.Error(e);
861      }      }
862      return result.Produce();      return result.Produce();
# Line 755  String LSCPServer::GetMidiInputDriverInf Line 880  String LSCPServer::GetMidiInputDriverInf
880              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
881          }          }
882      }      }
883      catch (LinuxSamplerException e) {      catch (Exception e) {
884          result.Error(e);          result.Error(e);
885      }      }
886      return result.Produce();      return result.Produce();
# Line 779  String LSCPServer::GetAudioOutputDriverI Line 904  String LSCPServer::GetAudioOutputDriverI
904              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
905          }          }
906      }      }
907      catch (LinuxSamplerException e) {      catch (Exception e) {
908          result.Error(e);          result.Error(e);
909      }      }
910      return result.Produce();      return result.Produce();
# Line 806  String LSCPServer::GetMidiInputDriverPar Line 931  String LSCPServer::GetMidiInputDriverPar
931          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
932          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
933      }      }
934      catch (LinuxSamplerException e) {      catch (Exception e) {
935          result.Error(e);          result.Error(e);
936      }      }
937      return result.Produce();      return result.Produce();
# Line 833  String LSCPServer::GetAudioOutputDriverP Line 958  String LSCPServer::GetAudioOutputDriverP
958          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
959          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
960      }      }
961      catch (LinuxSamplerException e) {      catch (Exception e) {
962          result.Error(e);          result.Error(e);
963      }      }
964      return result.Produce();      return result.Produce();
# Line 846  String LSCPServer::GetAudioOutputDeviceC Line 971  String LSCPServer::GetAudioOutputDeviceC
971          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
972          result.Add(count); // success          result.Add(count); // success
973      }      }
974      catch (LinuxSamplerException e) {      catch (Exception e) {
975          result.Error(e);          result.Error(e);
976      }      }
977      return result.Produce();      return result.Produce();
# Line 859  String LSCPServer::GetMidiInputDeviceCou Line 984  String LSCPServer::GetMidiInputDeviceCou
984          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
985          result.Add(count); // success          result.Add(count); // success
986      }      }
987      catch (LinuxSamplerException e) {      catch (Exception e) {
988          result.Error(e);          result.Error(e);
989      }      }
990      return result.Produce();      return result.Produce();
# Line 878  String LSCPServer::GetAudioOutputDevices Line 1003  String LSCPServer::GetAudioOutputDevices
1003          }          }
1004          result.Add(s);          result.Add(s);
1005      }      }
1006      catch (LinuxSamplerException e) {      catch (Exception e) {
1007          result.Error(e);          result.Error(e);
1008      }      }
1009      return result.Produce();      return result.Produce();
# Line 897  String LSCPServer::GetMidiInputDevices() Line 1022  String LSCPServer::GetMidiInputDevices()
1022          }          }
1023          result.Add(s);          result.Add(s);
1024      }      }
1025      catch (LinuxSamplerException e) {      catch (Exception e) {
1026          result.Error(e);          result.Error(e);
1027      }      }
1028      return result.Produce();      return result.Produce();
# Line 908  String LSCPServer::GetAudioOutputDeviceI Line 1033  String LSCPServer::GetAudioOutputDeviceI
1033      LSCPResultSet result;      LSCPResultSet result;
1034      try {      try {
1035          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1036          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) + ".");
1037          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1038          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1039          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 917  String LSCPServer::GetAudioOutputDeviceI Line 1042  String LSCPServer::GetAudioOutputDeviceI
1042              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1043          }          }
1044      }      }
1045      catch (LinuxSamplerException e) {      catch (Exception e) {
1046          result.Error(e);          result.Error(e);
1047      }      }
1048      return result.Produce();      return result.Produce();
# Line 928  String LSCPServer::GetMidiInputDeviceInf Line 1053  String LSCPServer::GetMidiInputDeviceInf
1053      LSCPResultSet result;      LSCPResultSet result;
1054      try {      try {
1055          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1056          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) + ".");
1057          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1058          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1059          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 937  String LSCPServer::GetMidiInputDeviceInf Line 1062  String LSCPServer::GetMidiInputDeviceInf
1062              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1063          }          }
1064      }      }
1065      catch (LinuxSamplerException e) {      catch (Exception e) {
1066          result.Error(e);          result.Error(e);
1067      }      }
1068      return result.Produce();      return result.Produce();
# Line 948  String LSCPServer::GetMidiInputPortInfo( Line 1073  String LSCPServer::GetMidiInputPortInfo(
1073      try {      try {
1074          // get MIDI input device          // get MIDI input device
1075          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1076          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) + ".");
1077          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1078    
1079          // get MIDI port          // get MIDI port
1080          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1081          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) + ".");
1082    
1083          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1084          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 962  String LSCPServer::GetMidiInputPortInfo( Line 1087  String LSCPServer::GetMidiInputPortInfo(
1087              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1088          }          }
1089      }      }
1090      catch (LinuxSamplerException e) {      catch (Exception e) {
1091          result.Error(e);          result.Error(e);
1092      }      }
1093      return result.Produce();      return result.Produce();
# Line 974  String LSCPServer::GetAudioOutputChannel Line 1099  String LSCPServer::GetAudioOutputChannel
1099      try {      try {
1100          // get audio output device          // get audio output device
1101          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1102          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) + ".");
1103          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1104    
1105          // get audio channel          // get audio channel
1106          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1107          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) + ".");
1108    
1109          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1110          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 988  String LSCPServer::GetAudioOutputChannel Line 1113  String LSCPServer::GetAudioOutputChannel
1113              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1114          }          }
1115      }      }
1116      catch (LinuxSamplerException e) {      catch (Exception e) {
1117          result.Error(e);          result.Error(e);
1118      }      }
1119      return result.Produce();      return result.Produce();
# Line 1000  String LSCPServer::GetMidiInputPortParam Line 1125  String LSCPServer::GetMidiInputPortParam
1125      try {      try {
1126          // get MIDI input device          // get MIDI input device
1127          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1128          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) + ".");
1129          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1130    
1131          // get midi port          // get midi port
1132          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1133          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) + ".");
1134    
1135          // get desired port parameter          // get desired port parameter
1136          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1137          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 + "'.");
1138          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1139    
1140          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1021  String LSCPServer::GetMidiInputPortParam Line 1146  String LSCPServer::GetMidiInputPortParam
1146          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1147          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1148      }      }
1149      catch (LinuxSamplerException e) {      catch (Exception e) {
1150          result.Error(e);          result.Error(e);
1151      }      }
1152      return result.Produce();      return result.Produce();
# Line 1033  String LSCPServer::GetAudioOutputChannel Line 1158  String LSCPServer::GetAudioOutputChannel
1158      try {      try {
1159          // get audio output device          // get audio output device
1160          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1161          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) + ".");
1162          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1163    
1164          // get audio channel          // get audio channel
1165          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1166          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) + ".");
1167    
1168          // get desired audio channel parameter          // get desired audio channel parameter
1169          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1170          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 + "'.");
1171          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1172    
1173          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1054  String LSCPServer::GetAudioOutputChannel Line 1179  String LSCPServer::GetAudioOutputChannel
1179          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1180          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1181      }      }
1182      catch (LinuxSamplerException e) {      catch (Exception e) {
1183          result.Error(e);          result.Error(e);
1184      }      }
1185      return result.Produce();      return result.Produce();
# Line 1066  String LSCPServer::SetAudioOutputChannel Line 1191  String LSCPServer::SetAudioOutputChannel
1191      try {      try {
1192          // get audio output device          // get audio output device
1193          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1194          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) + ".");
1195          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1196    
1197          // get audio channel          // get audio channel
1198          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1199          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) + ".");
1200    
1201          // get desired audio channel parameter          // get desired audio channel parameter
1202          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1203          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 + "'.");
1204          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1205    
1206          // set new channel parameter value          // set new channel parameter value
1207          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1208            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1209      }      }
1210      catch (LinuxSamplerException e) {      catch (Exception e) {
1211          result.Error(e);          result.Error(e);
1212      }      }
1213      return result.Produce();      return result.Produce();
# Line 1092  String LSCPServer::SetAudioOutputDeviceP Line 1218  String LSCPServer::SetAudioOutputDeviceP
1218      LSCPResultSet result;      LSCPResultSet result;
1219      try {      try {
1220          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1221          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) + ".");
1222          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1223          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1224          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 + "'");
1225          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1226            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1227      }      }
1228      catch (LinuxSamplerException e) {      catch (Exception e) {
1229          result.Error(e);          result.Error(e);
1230      }      }
1231      return result.Produce();      return result.Produce();
# Line 1109  String LSCPServer::SetMidiInputDevicePar Line 1236  String LSCPServer::SetMidiInputDevicePar
1236      LSCPResultSet result;      LSCPResultSet result;
1237      try {      try {
1238          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1239          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) + ".");
1240          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1241          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1242          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 + "'");
1243          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1244            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1245      }      }
1246      catch (LinuxSamplerException e) {      catch (Exception e) {
1247          result.Error(e);          result.Error(e);
1248      }      }
1249      return result.Produce();      return result.Produce();
# Line 1127  String LSCPServer::SetMidiInputPortParam Line 1255  String LSCPServer::SetMidiInputPortParam
1255      try {      try {
1256          // get MIDI input device          // get MIDI input device
1257          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1258          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) + ".");
1259          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1260    
1261          // get MIDI port          // get MIDI port
1262          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1263          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) + ".");
1264    
1265          // set port parameter value          // set port parameter value
1266          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1267          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 + "'");
1268          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1269            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1270      }      }
1271      catch (LinuxSamplerException e) {      catch (Exception e) {
1272          result.Error(e);          result.Error(e);
1273      }      }
1274      return result.Produce();      return result.Produce();
# Line 1154  String LSCPServer::SetAudioOutputChannel Line 1283  String LSCPServer::SetAudioOutputChannel
1283      LSCPResultSet result;      LSCPResultSet result;
1284      try {      try {
1285          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1286          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1287          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1288          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));
1289          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));
1290          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1291      }      }
1292      catch (LinuxSamplerException e) {      catch (Exception e) {
1293           result.Error(e);           result.Error(e);
1294      }      }
1295      return result.Produce();      return result.Produce();
# Line 1169  String LSCPServer::SetAudioOutputChannel Line 1298  String LSCPServer::SetAudioOutputChannel
1298  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1299      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1300      LSCPResultSet result;      LSCPResultSet result;
1301        LockRTNotify();
1302      try {      try {
1303          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1304          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1305          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1306          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));
1307          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1308          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1309      }      }
1310      catch (LinuxSamplerException e) {      catch (Exception e) {
1311           result.Error(e);           result.Error(e);
1312      }      }
1313        UnlockRTNotify();
1314      return result.Produce();      return result.Produce();
1315  }  }
1316    
1317  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1318      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));
1319      LSCPResultSet result;      LSCPResultSet result;
1320        LockRTNotify();
1321      try {      try {
1322          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1323          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1324          // Driver type name aliasing...          // Driver type name aliasing...
1325          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1326          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1210  String LSCPServer::SetAudioOutputType(St Line 1342  String LSCPServer::SetAudioOutputType(St
1342          }          }
1343          // Must have a device...          // Must have a device...
1344          if (pDevice == NULL)          if (pDevice == NULL)
1345              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1346          // Set it as the current channel device...          // Set it as the current channel device...
1347          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1348      }      }
1349      catch (LinuxSamplerException e) {      catch (Exception e) {
1350           result.Error(e);           result.Error(e);
1351      }      }
1352        UnlockRTNotify();
1353      return result.Produce();      return result.Produce();
1354  }  }
1355    
# Line 1225  String LSCPServer::SetMIDIInputPort(uint Line 1358  String LSCPServer::SetMIDIInputPort(uint
1358      LSCPResultSet result;      LSCPResultSet result;
1359      try {      try {
1360          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1361          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1362          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1363      }      }
1364      catch (LinuxSamplerException e) {      catch (Exception e) {
1365           result.Error(e);           result.Error(e);
1366      }      }
1367      return result.Produce();      return result.Produce();
# Line 1239  String LSCPServer::SetMIDIInputChannel(u Line 1372  String LSCPServer::SetMIDIInputChannel(u
1372      LSCPResultSet result;      LSCPResultSet result;
1373      try {      try {
1374          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1375          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1376          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1377      }      }
1378      catch (LinuxSamplerException e) {      catch (Exception e) {
1379           result.Error(e);           result.Error(e);
1380      }      }
1381      return result.Produce();      return result.Produce();
# Line 1253  String LSCPServer::SetMIDIInputDevice(ui Line 1386  String LSCPServer::SetMIDIInputDevice(ui
1386      LSCPResultSet result;      LSCPResultSet result;
1387      try {      try {
1388          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1389          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1390          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1391          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));
1392          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1393          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1394      }      }
1395      catch (LinuxSamplerException e) {      catch (Exception e) {
1396           result.Error(e);           result.Error(e);
1397      }      }
1398      return result.Produce();      return result.Produce();
# Line 1270  String LSCPServer::SetMIDIInputType(Stri Line 1403  String LSCPServer::SetMIDIInputType(Stri
1403      LSCPResultSet result;      LSCPResultSet result;
1404      try {      try {
1405          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1406          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1407          // Driver type name aliasing...          // Driver type name aliasing...
1408          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1409          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1294  String LSCPServer::SetMIDIInputType(Stri Line 1427  String LSCPServer::SetMIDIInputType(Stri
1427          }          }
1428          // Must have a device...          // Must have a device...
1429          if (pDevice == NULL)          if (pDevice == NULL)
1430              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1431          // Set it as the current channel device...          // Set it as the current channel device...
1432          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1433      }      }
1434      catch (LinuxSamplerException e) {      catch (Exception e) {
1435           result.Error(e);           result.Error(e);
1436      }      }
1437      return result.Produce();      return result.Produce();
# Line 1313  String LSCPServer::SetMIDIInput(uint MID Line 1446  String LSCPServer::SetMIDIInput(uint MID
1446      LSCPResultSet result;      LSCPResultSet result;
1447      try {      try {
1448          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1449          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1450          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1451          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));
1452          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1453          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1454      }      }
1455      catch (LinuxSamplerException e) {      catch (Exception e) {
1456           result.Error(e);           result.Error(e);
1457      }      }
1458      return result.Produce();      return result.Produce();
# Line 1334  String LSCPServer::SetVolume(double dVol Line 1467  String LSCPServer::SetVolume(double dVol
1467      LSCPResultSet result;      LSCPResultSet result;
1468      try {      try {
1469          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1470          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1471          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1472          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1473          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1474      }      }
1475      catch (LinuxSamplerException e) {      catch (Exception e) {
1476           result.Error(e);           result.Error(e);
1477      }      }
1478      return result.Produce();      return result.Produce();
1479  }  }
1480    
1481  /**  /**
1482     * Will be called by the parser to mute/unmute particular sampler channel.
1483     */
1484    String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) {
1485        dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1486        LSCPResultSet result;
1487        try {
1488            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1489            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1490    
1491            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1492            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1493    
1494            if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1495            else pEngineChannel->SetMute(1);
1496        } catch (Exception e) {
1497            result.Error(e);
1498        }
1499        return result.Produce();
1500    }
1501    
1502    /**
1503     * Will be called by the parser to solo particular sampler channel.
1504     */
1505    String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) {
1506        dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1507        LSCPResultSet result;
1508        try {
1509            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1510            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1511    
1512            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1513            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1514    
1515            bool oldSolo = pEngineChannel->GetSolo();
1516            bool hadSoloChannel = HasSoloChannel();
1517    
1518            pEngineChannel->SetSolo(bSolo);
1519    
1520            if(!oldSolo && bSolo) {
1521                if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1522                if(!hadSoloChannel) MuteNonSoloChannels();
1523            }
1524    
1525            if(oldSolo && !bSolo) {
1526                if(!HasSoloChannel()) UnmuteChannels();
1527                else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1528            }
1529        } catch (Exception e) {
1530            result.Error(e);
1531        }
1532        return result.Produce();
1533    }
1534    
1535    /**
1536     * Determines whether there is at least one solo channel in the channel list.
1537     *
1538     * @returns true if there is at least one solo channel in the channel list,
1539     * false otherwise.
1540     */
1541    bool LSCPServer::HasSoloChannel() {
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->GetSolo()) return true;
1547        }
1548    
1549        return false;
1550    }
1551    
1552    /**
1553     * Mutes all unmuted non-solo channels. Notice that the channels are muted
1554     * with -1 which indicates that they are muted because of the presence
1555     * of a solo channel(s). Channels muted with -1 will be automatically unmuted
1556     * when there are no solo channels left.
1557     */
1558    void LSCPServer::MuteNonSoloChannels() {
1559        dmsg(2,("LSCPServer: MuteNonSoloChannels()\n"));
1560        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1561        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1562        for (; iter != channels.end(); iter++) {
1563            EngineChannel* c = iter->second->GetEngineChannel();
1564            if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1);
1565        }
1566    }
1567    
1568    /**
1569     * Unmutes all channels that are muted because of the presence
1570     * of a solo channel(s).
1571     */
1572    void  LSCPServer::UnmuteChannels() {
1573        dmsg(2,("LSCPServer: UnmuteChannels()\n"));
1574        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1575        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1576        for (; iter != channels.end(); iter++) {
1577            EngineChannel* c = iter->second->GetEngineChannel();
1578            if(c && c->GetMute() == -1) c->SetMute(0);
1579        }
1580    }
1581    
1582    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) {
1583        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1584    
1585        midi_prog_index_t idx;
1586        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1587        idx.midi_bank_lsb = MidiBank & 0x7f;
1588        idx.midi_prog     = MidiProg;
1589    
1590        MidiInstrumentMapper::entry_t entry;
1591        entry.EngineName      = EngineType;
1592        entry.InstrumentFile  = InstrumentFile;
1593        entry.InstrumentIndex = InstrumentIndex;
1594        entry.LoadMode        = LoadMode;
1595        entry.Volume          = Volume;
1596        entry.Name            = Name;
1597    
1598        LSCPResultSet result;
1599        try {
1600            // PERSISTENT mapping commands might block for a long time, so in
1601            // that case we add/replace the mapping in another thread in case
1602            // the NON_MODAL argument was supplied, non persistent mappings
1603            // should return immediately, so we don't need to do that for them
1604            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1605            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1606        } catch (Exception e) {
1607            result.Error(e);
1608        }
1609        return result.Produce();
1610    }
1611    
1612    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1613        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1614    
1615        midi_prog_index_t idx;
1616        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1617        idx.midi_bank_lsb = MidiBank & 0x7f;
1618        idx.midi_prog     = MidiProg;
1619    
1620        LSCPResultSet result;
1621        try {
1622            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1623        } catch (Exception e) {
1624            result.Error(e);
1625        }
1626        return result.Produce();
1627    }
1628    
1629    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1630        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1631        LSCPResultSet result;
1632        try {
1633            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1634        } catch (Exception e) {
1635            result.Error(e);
1636        }
1637        return result.Produce();
1638    }
1639    
1640    
1641    String LSCPServer::GetAllMidiInstrumentMappings() {
1642        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1643        LSCPResultSet result;
1644        std::vector<int> maps = MidiInstrumentMapper::Maps();
1645        int totalMappings = 0;
1646        for (int i = 0; i < maps.size(); i++) {
1647            try {
1648                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1649            } catch (Exception e) { /*NOOP*/ }
1650        }
1651        result.Add(totalMappings);
1652        return result.Produce();
1653    }
1654    
1655    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1656        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1657        LSCPResultSet result;
1658        try {
1659            midi_prog_index_t idx;
1660            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1661            idx.midi_bank_lsb = MidiBank & 0x7f;
1662            idx.midi_prog     = MidiProg;
1663    
1664            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1665            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1666            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1667            else { // found
1668                result.Add("NAME", iter->second.Name);
1669                result.Add("ENGINE_NAME", iter->second.EngineName);
1670                result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);
1671                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1672                String instrumentName;
1673                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1674                if (pEngine) {
1675                    if (pEngine->GetInstrumentManager()) {
1676                        InstrumentManager::instrument_id_t instrID;
1677                        instrID.FileName = iter->second.InstrumentFile;
1678                        instrID.Index    = iter->second.InstrumentIndex;
1679                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1680                    }
1681                    EngineFactory::Destroy(pEngine);
1682                }
1683                result.Add("INSTRUMENT_NAME", instrumentName);
1684                switch (iter->second.LoadMode) {
1685                    case MidiInstrumentMapper::ON_DEMAND:
1686                        result.Add("LOAD_MODE", "ON_DEMAND");
1687                        break;
1688                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1689                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1690                        break;
1691                    case MidiInstrumentMapper::PERSISTENT:
1692                        result.Add("LOAD_MODE", "PERSISTENT");
1693                        break;
1694                    default:
1695                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1696                }
1697                result.Add("VOLUME", iter->second.Volume);
1698            }
1699        } catch (Exception e) {
1700            result.Error(e);
1701        }
1702        return result.Produce();
1703    }
1704    
1705    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1706        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1707        LSCPResultSet result;
1708        try {
1709            String s;
1710            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1711            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1712            for (; iter != mappings.end(); iter++) {
1713                if (s.size()) s += ",";
1714                s += "{" + ToString(MidiMapID) + ","
1715                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1716                         + ToString(int(iter->first.midi_prog)) + "}";
1717            }
1718            result.Add(s);
1719        } catch (Exception e) {
1720            result.Error(e);
1721        }
1722        return result.Produce();
1723    }
1724    
1725    String LSCPServer::ListAllMidiInstrumentMappings() {
1726        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1727        LSCPResultSet result;
1728        try {
1729            std::vector<int> maps = MidiInstrumentMapper::Maps();
1730            String s;
1731            for (int i = 0; i < maps.size(); i++) {
1732                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1733                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1734                for (; iter != mappings.end(); iter++) {
1735                    if (s.size()) s += ",";
1736                    s += "{" + ToString(maps[i]) + ","
1737                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1738                             + ToString(int(iter->first.midi_prog)) + "}";
1739                }
1740            }
1741            result.Add(s);
1742        } catch (Exception e) {
1743            result.Error(e);
1744        }
1745        return result.Produce();
1746    }
1747    
1748    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1749        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1750        LSCPResultSet result;
1751        try {
1752            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1753        } catch (Exception e) {
1754            result.Error(e);
1755        }
1756        return result.Produce();
1757    }
1758    
1759    String LSCPServer::ClearAllMidiInstrumentMappings() {
1760        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1761        LSCPResultSet result;
1762        try {
1763            std::vector<int> maps = MidiInstrumentMapper::Maps();
1764            for (int i = 0; i < maps.size(); i++)
1765                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1766        } catch (Exception e) {
1767            result.Error(e);
1768        }
1769        return result.Produce();
1770    }
1771    
1772    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1773        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1774        LSCPResultSet result;
1775        try {
1776            int MapID = MidiInstrumentMapper::AddMap(MapName);
1777            result = LSCPResultSet(MapID);
1778        } catch (Exception e) {
1779            result.Error(e);
1780        }
1781        return result.Produce();
1782    }
1783    
1784    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1785        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1786        LSCPResultSet result;
1787        try {
1788            MidiInstrumentMapper::RemoveMap(MidiMapID);
1789        } catch (Exception e) {
1790            result.Error(e);
1791        }
1792        return result.Produce();
1793    }
1794    
1795    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1796        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1797        LSCPResultSet result;
1798        try {
1799            MidiInstrumentMapper::RemoveAllMaps();
1800        } catch (Exception e) {
1801            result.Error(e);
1802        }
1803        return result.Produce();
1804    }
1805    
1806    String LSCPServer::GetMidiInstrumentMaps() {
1807        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1808        LSCPResultSet result;
1809        try {
1810            result.Add(MidiInstrumentMapper::Maps().size());
1811        } catch (Exception e) {
1812            result.Error(e);
1813        }
1814        return result.Produce();
1815    }
1816    
1817    String LSCPServer::ListMidiInstrumentMaps() {
1818        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1819        LSCPResultSet result;
1820        try {
1821            std::vector<int> maps = MidiInstrumentMapper::Maps();
1822            String sList;
1823            for (int i = 0; i < maps.size(); i++) {
1824                if (sList != "") sList += ",";
1825                sList += ToString(maps[i]);
1826            }
1827            result.Add(sList);
1828        } catch (Exception e) {
1829            result.Error(e);
1830        }
1831        return result.Produce();
1832    }
1833    
1834    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1835        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1836        LSCPResultSet result;
1837        try {
1838            result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1839        } catch (Exception e) {
1840            result.Error(e);
1841        }
1842        return result.Produce();
1843    }
1844    
1845    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
1846        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
1847        LSCPResultSet result;
1848        try {
1849            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
1850        } catch (Exception e) {
1851            result.Error(e);
1852        }
1853        return result.Produce();
1854    }
1855    
1856    /**
1857     * Set the MIDI instrument map the given sampler channel shall use for
1858     * handling MIDI program change messages. There are the following two
1859     * special (negative) values:
1860     *
1861     *    - (-1) :  set to NONE (ignore program changes)
1862     *    - (-2) :  set to DEFAULT map
1863     */
1864    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
1865        dmsg(2,("LSCPServer: SetChannelMap()\n"));
1866        LSCPResultSet result;
1867        try {
1868            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1869            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1870    
1871            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1872            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1873    
1874            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
1875            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
1876            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
1877        } catch (Exception e) {
1878            result.Error(e);
1879        }
1880        return result.Produce();
1881    }
1882    
1883    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
1884        dmsg(2,("LSCPServer: CreateFxSend()\n"));
1885        LSCPResultSet result;
1886        try {
1887            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1888            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1889    
1890            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1891            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1892    
1893            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
1894            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
1895    
1896            result = LSCPResultSet(pFxSend->Id()); // success
1897        } catch (Exception e) {
1898            result.Error(e);
1899        }
1900        return result.Produce();
1901    }
1902    
1903    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
1904        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
1905        LSCPResultSet result;
1906        try {
1907            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1908            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1909    
1910            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1911            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1912    
1913            FxSend* pFxSend = NULL;
1914            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1915                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
1916                    pFxSend = pEngineChannel->GetFxSend(i);
1917                    break;
1918                }
1919            }
1920            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
1921            pEngineChannel->RemoveFxSend(pFxSend);
1922        } catch (Exception e) {
1923            result.Error(e);
1924        }
1925        return result.Produce();
1926    }
1927    
1928    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
1929        dmsg(2,("LSCPServer: GetFxSends()\n"));
1930        LSCPResultSet result;
1931        try {
1932            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1933            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1934    
1935            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1936            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1937    
1938            result.Add(pEngineChannel->GetFxSendCount());
1939        } catch (Exception e) {
1940            result.Error(e);
1941        }
1942        return result.Produce();
1943    }
1944    
1945    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
1946        dmsg(2,("LSCPServer: ListFxSends()\n"));
1947        LSCPResultSet result;
1948        String list;
1949        try {
1950            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1951            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1952    
1953            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1954            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1955    
1956            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1957                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
1958                if (list != "") list += ",";
1959                list += ToString(pFxSend->Id());
1960            }
1961            result.Add(list);
1962        } catch (Exception e) {
1963            result.Error(e);
1964        }
1965        return result.Produce();
1966    }
1967    
1968    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
1969        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
1970        LSCPResultSet result;
1971        try {
1972            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1973            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1974    
1975            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1976            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
1977    
1978            FxSend* pFxSend = NULL;
1979            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
1980                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
1981                    pFxSend = pEngineChannel->GetFxSend(i);
1982                    break;
1983                }
1984            }
1985            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
1986    
1987            // gather audio routing informations
1988            String AudioRouting;
1989            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
1990                if (AudioRouting != "") AudioRouting += ",";
1991                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
1992            }
1993    
1994            // success
1995            result.Add("NAME", pFxSend->Name());
1996            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
1997            result.Add("LEVEL", ToString(pFxSend->Level()));
1998            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
1999        } catch (Exception e) {
2000            result.Error(e);
2001        }
2002        return result.Produce();
2003    }
2004    
2005    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2006        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2007        LSCPResultSet result;
2008        try {
2009            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2010            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2011    
2012            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2013            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2014    
2015            FxSend* pFxSend = NULL;
2016            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2017                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2018                    pFxSend = pEngineChannel->GetFxSend(i);
2019                    break;
2020                }
2021            }
2022            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2023    
2024            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2025            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2026        } catch (Exception e) {
2027            result.Error(e);
2028        }
2029        return result.Produce();
2030    }
2031    
2032    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2033        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2034        LSCPResultSet result;
2035        try {
2036            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2037            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2038    
2039            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2040            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2041    
2042            FxSend* pFxSend = NULL;
2043            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2044                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2045                    pFxSend = pEngineChannel->GetFxSend(i);
2046                    break;
2047                }
2048            }
2049            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2050    
2051            pFxSend->SetMidiController(MidiController);
2052            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2053        } catch (Exception e) {
2054            result.Error(e);
2055        }
2056        return result.Produce();
2057    }
2058    
2059    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2060        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2061        LSCPResultSet result;
2062        try {
2063            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2064            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2065    
2066            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2067            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2068    
2069            FxSend* pFxSend = NULL;
2070            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2071                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2072                    pFxSend = pEngineChannel->GetFxSend(i);
2073                    break;
2074                }
2075            }
2076            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2077    
2078            pFxSend->SetLevel((float)dLevel);
2079            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2080        } catch (Exception e) {
2081            result.Error(e);
2082        }
2083        return result.Produce();
2084    }
2085    
2086    /**
2087   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2088   */   */
2089  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
# Line 1353  String LSCPServer::ResetChannel(uint uiS Line 2091  String LSCPServer::ResetChannel(uint uiS
2091      LSCPResultSet result;      LSCPResultSet result;
2092      try {      try {
2093          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2094          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2095          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2096          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2097          pEngineChannel->GetEngine()->Reset();          pEngineChannel->Reset();
2098      }      }
2099      catch (LinuxSamplerException e) {      catch (Exception e) {
2100           result.Error(e);           result.Error(e);
2101      }      }
2102      return result.Produce();      return result.Produce();
# Line 1375  String LSCPServer::ResetSampler() { Line 2113  String LSCPServer::ResetSampler() {
2113  }  }
2114    
2115  /**  /**
2116     * Will be called by the parser to return general informations about this
2117     * sampler.
2118     */
2119    String LSCPServer::GetServerInfo() {
2120        dmsg(2,("LSCPServer: GetServerInfo()\n"));
2121        LSCPResultSet result;
2122        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
2123        result.Add("VERSION", VERSION);
2124        result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2125        return result.Produce();
2126    }
2127    
2128    /**
2129     * Will be called by the parser to return the current number of all active voices.
2130     */
2131    String LSCPServer::GetTotalVoiceCount() {
2132        dmsg(2,("LSCPServer: GetTotalVoiceCount()\n"));
2133        LSCPResultSet result;
2134        result.Add(pSampler->GetVoiceCount());
2135        return result.Produce();
2136    }
2137    
2138    /**
2139     * Will be called by the parser to return the maximum number of voices.
2140     */
2141    String LSCPServer::GetTotalVoiceCountMax() {
2142        dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
2143        LSCPResultSet result;
2144        result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);
2145        return result.Produce();
2146    }
2147    
2148    String LSCPServer::GetGlobalVolume() {
2149        LSCPResultSet result;
2150        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2151        return result.Produce();
2152    }
2153    
2154    String LSCPServer::SetGlobalVolume(double dVolume) {
2155        LSCPResultSet result;
2156        try {
2157            if (dVolume < 0) throw Exception("Volume may not be negative");
2158            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2159            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2160        } catch (Exception e) {
2161            result.Error(e);
2162        }
2163        return result.Produce();
2164    }
2165    
2166    /**
2167   * Will be called by the parser to subscribe a client (frontend) on the   * Will be called by the parser to subscribe a client (frontend) on the
2168   * server for receiving event messages.   * server for receiving event messages.
2169   */   */
# Line 1442  String LSCPServer::SetEcho(yyparse_param Line 2231  String LSCPServer::SetEcho(yyparse_param
2231      try {      try {
2232          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
2233          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
2234          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");
2235      }      }
2236      catch (LinuxSamplerException e) {      catch (Exception e) {
2237           result.Error(e);           result.Error(e);
2238      }      }
2239      return result.Produce();      return result.Produce();

Legend:
Removed from v.475  
changed lines
  Added in v.1108

  ViewVC Help
Powered by ViewVC