/[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 2135 by schoenebeck, Thu Sep 30 20:00:43 2010 UTC revision 2516 by schoenebeck, Thu Feb 6 21:11:23 2014 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 - 2009 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2014 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 47  Line 47 
47    
48  namespace LinuxSampler {  namespace LinuxSampler {
49    
50    String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param);
51    
52  /**  /**
53   * Returns a copy of the given string where all special characters are   * Returns a copy of the given string where all special characters are
54   * replaced by LSCP escape sequences ("\xHH"). This function shall be used   * replaced by LSCP escape sequences ("\xHH"). This function shall be used
# Line 97  static String _escapeLscpResponse(String Line 99  static String _escapeLscpResponse(String
99   */   */
100  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
101  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
102  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();  std::vector<yyparse_param_t> LSCPServer::Sessions;
103  std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator();  std::vector<yyparse_param_t>::iterator itCurrentSession;
104  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies;
105  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands;
106  std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >();  std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions;
107  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex;
108  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex;
109  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex;
110  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex;
111    
112  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) {  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) {
113      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
# Line 138  LSCPServer::LSCPServer(Sampler* pSampler Line 140  LSCPServer::LSCPServer(Sampler* pSampler
140      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
141      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");
142      LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");      LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");
143        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_count, "EFFECT_INSTANCE_COUNT");
144        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_info, "EFFECT_INSTANCE_INFO");
145        LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_count, "SEND_EFFECT_CHAIN_COUNT");
146        LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_info, "SEND_EFFECT_CHAIN_INFO");
147      hSocket = -1;      hSocket = -1;
148  }  }
149    
# Line 443  int LSCPServer::Main() { Line 449  int LSCPServer::Main() {
449          #endif          #endif
450          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
451          {          {
452                LockGuard lock(EngineChannelFactory::EngineChannelsMutex);
453              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
454              std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();              std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
455              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
# Line 511  int LSCPServer::Main() { Line 518  int LSCPServer::Main() {
518              }              }
519          }          }
520    
521          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
522          NotifyBufferMutex.Lock();          {
523          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {              LockGuard lock(NotifyBufferMutex);
524                for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
525  #ifdef MSG_NOSIGNAL  #ifdef MSG_NOSIGNAL
526                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
527  #else  #else
528                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
529  #endif  #endif
530          }              }
531          bufferedNotifies.clear();              bufferedNotifies.clear();
532          NotifyBufferMutex.Unlock();          }
533    
534          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
535          timeout.tv_sec  = 0;          timeout.tv_sec  = 0;
# Line 586  int LSCPServer::Main() { Line 594  int LSCPServer::Main() {
594          //Something was selected and it was not the hSocket, so it must be some command(s) coming.          //Something was selected and it was not the hSocket, so it must be some command(s) coming.
595          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {
596                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
597                            currentSocket = (*iter).hSession;  //a hack
598                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
599                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
600                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
601                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
                                 currentSocket = (*iter).hSession;  //a hack  
602                                  itCurrentSession = iter; // another hack                                  itCurrentSession = iter; // another hack
603                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
604                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
# Line 604  int LSCPServer::Main() { Line 612  int LSCPServer::Main() {
612                                          CloseConnection(iter);                                          CloseConnection(iter);
613                                  }                                  }
614                          }                          }
615                            currentSocket = -1;     //continuation of a hack
616                          //socket may have been closed, iter may be invalid, get out of the loop for now.                          //socket may have been closed, iter may be invalid, get out of the loop for now.
617                          //we'll be back if there is data.                          //we'll be back if there is data.
618                          break;                          break;
# Line 618  void LSCPServer::CloseConnection( std::v Line 627  void LSCPServer::CloseConnection( std::v
627          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
628          Sessions.erase(iter);          Sessions.erase(iter);
629          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
630          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          {
631          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {              LockGuard lock(SubscriptionMutex);
632                  iter->second.remove(socket);              // Must unsubscribe this socket from all events (if any)
633          }              for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {
634          SubscriptionMutex.Unlock();                  iter->second.remove(socket);
635          NotifyMutex.Lock();              }
636            }
637            LockGuard lock(NotifyMutex);
638          bufferedCommands.erase(socket);          bufferedCommands.erase(socket);
639          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
640          #if defined(WIN32)          #if defined(WIN32)
# Line 631  void LSCPServer::CloseConnection( std::v Line 642  void LSCPServer::CloseConnection( std::v
642          #else          #else
643          close(socket);          close(socket);
644          #endif          #endif
         NotifyMutex.Unlock();  
645  }  }
646    
647  void LSCPServer::CloseAllConnections() {  void LSCPServer::CloseAllConnections() {
# Line 642  void LSCPServer::CloseAllConnections() { Line 652  void LSCPServer::CloseAllConnections() {
652      }      }
653  }  }
654    
 void LSCPServer::LockRTNotify() {  
     RTNotifyMutex.Lock();  
 }  
   
 void LSCPServer::UnlockRTNotify() {  
     RTNotifyMutex.Unlock();  
 }  
   
655  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
656          int subs = 0;          int subs = 0;
657          SubscriptionMutex.Lock();          LockGuard lock(SubscriptionMutex);
658          for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();          for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
659                          iter != events.end(); iter++)                          iter != events.end(); iter++)
660          {          {
661                  subs += eventSubscriptions.count(*iter);                  subs += eventSubscriptions.count(*iter);
662          }          }
         SubscriptionMutex.Unlock();  
663          return subs;          return subs;
664  }  }
665    
666  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
667          SubscriptionMutex.Lock();          LockGuard lock(SubscriptionMutex);
668          if (eventSubscriptions.count(event.GetType()) == 0) {          if (eventSubscriptions.count(event.GetType()) == 0) {
669                  SubscriptionMutex.Unlock();     //Nobody is subscribed to this event                  // Nobody is subscribed to this event
670                  return;                  return;
671          }          }
672          std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin();          std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin();
# Line 691  void LSCPServer::SendLSCPNotify( LSCPEve Line 692  void LSCPServer::SendLSCPNotify( LSCPEve
692                          }                          }
693                  }                  }
694          }          }
         SubscriptionMutex.Unlock();  
695  }  }
696    
697  extern int GetLSCPCommand( void *buf, int max_size ) {  extern int GetLSCPCommand( void *buf, int max_size ) {
# Line 742  bool LSCPServer::GetLSCPCommand( std::ve Line 742  bool LSCPServer::GetLSCPCommand( std::ve
742                                  bufferedCommands[socket] += "\r\n";                                  bufferedCommands[socket] += "\r\n";
743                                  return true; //Complete command was read                                  return true; //Complete command was read
744                          }                          }
745                          bufferedCommands[socket] += c;                          // backspace character - should only happen with shell
746                            if (c == '\b') {
747                                    if (!bufferedCommands[socket].empty()) {
748                                            bufferedCommands[socket] = bufferedCommands[socket].substr(
749                                                    0, bufferedCommands[socket].length() - 1
750                                            );
751                                    }
752                            } else bufferedCommands[socket] += c;
753                            // only if the other side is the LSCP shell application:
754                            // check the current (incomplete) command line for syntax errors,
755                            // possible completions and report everything back to the shell
756                            if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {
757                                    String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter));
758                                    if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n");
759                            }
760                  }                  }
761                  #if defined(WIN32)                  #if defined(WIN32)
762                  if (result == SOCKET_ERROR) {                  if (result == SOCKET_ERROR) {
# Line 804  bool LSCPServer::GetLSCPCommand( std::ve Line 818  bool LSCPServer::GetLSCPCommand( std::ve
818   * @param ReturnMessage - message that will be send to the client   * @param ReturnMessage - message that will be send to the client
819   */   */
820  void LSCPServer::AnswerClient(String ReturnMessage) {  void LSCPServer::AnswerClient(String ReturnMessage) {
821      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage='%s')", ReturnMessage.c_str()));
822      if (currentSocket != -1) {      if (currentSocket != -1) {
823              NotifyMutex.Lock();              LockGuard lock(NotifyMutex);
824    
825            // just if other side is LSCP shell: in case respose is a multi-line
826            // one, then inform client about it before sending the actual mult-line
827            // response
828            if (GetCurrentYaccSession()->bShellInteract) {
829                // check if this is a multi-line response
830                int n = 0;
831                for (int i = 0; i < ReturnMessage.size(); ++i)
832                    if (ReturnMessage[i] == '\n') ++n;
833                if (n >= 2) {
834                    dmsg(2,("LSCP Shell <- expect mult-line response\n"));
835                    String s = LSCP_SHK_EXPECT_MULTI_LINE "\r\n";
836    #ifdef MSG_NOSIGNAL
837                    send(currentSocket, s.c_str(), s.size(), MSG_NOSIGNAL);
838    #else
839                    send(currentSocket, s.c_str(), s.size(), 0);
840    #endif                
841                }
842            }
843    
844  #ifdef MSG_NOSIGNAL  #ifdef MSG_NOSIGNAL
845              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
846  #else  #else
847              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
848  #endif  #endif
             NotifyMutex.Unlock();  
849      }      }
850  }  }
851    
# Line 962  String LSCPServer::SetEngineType(String Line 995  String LSCPServer::SetEngineType(String
995      try {      try {
996          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
997          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
998          LockRTNotify();          LockGuard lock(RTNotifyMutex);
999          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
1000          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
         UnlockRTNotify();  
1001      }      }
1002      catch (Exception e) {      catch (Exception e) {
1003           result.Error(e);           result.Error(e);
# Line 1005  String LSCPServer::ListChannels() { Line 1037  String LSCPServer::ListChannels() {
1037   */   */
1038  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
1039      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
1040      LockRTNotify();      SamplerChannel* pSamplerChannel;
1041      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      {
1042      UnlockRTNotify();          LockGuard lock(RTNotifyMutex);
1043            pSamplerChannel = pSampler->AddSamplerChannel();
1044        }
1045      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
1046      return result.Produce();      return result.Produce();
1047  }  }
# Line 1018  String LSCPServer::AddChannel() { Line 1052  String LSCPServer::AddChannel() {
1052  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
1053      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
1054      LSCPResultSet result;      LSCPResultSet result;
1055      LockRTNotify();      {
1056      pSampler->RemoveSamplerChannel(uiSamplerChannel);          LockGuard lock(RTNotifyMutex);
1057      UnlockRTNotify();          pSampler->RemoveSamplerChannel(uiSamplerChannel);
1058        }
1059      return result.Produce();      return result.Produce();
1060  }  }
1061    
# Line 1063  String LSCPServer::ListAvailableEngines( Line 1098  String LSCPServer::ListAvailableEngines(
1098  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
1099      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
1100      LSCPResultSet result;      LSCPResultSet result;
1101      LockRTNotify();      {
1102      try {          LockGuard lock(RTNotifyMutex);
1103          Engine* pEngine = EngineFactory::Create(EngineName);          try {
1104          result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));              Engine* pEngine = EngineFactory::Create(EngineName);
1105          result.Add("VERSION",     pEngine->Version());              result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));
1106          EngineFactory::Destroy(pEngine);              result.Add("VERSION",     pEngine->Version());
1107      }              EngineFactory::Destroy(pEngine);
1108      catch (Exception e) {          }
1109           result.Error(e);          catch (Exception e) {
1110                result.Error(e);
1111            }
1112      }      }
     UnlockRTNotify();  
1113      return result.Produce();      return result.Produce();
1114  }  }
1115    
# Line 1722  String LSCPServer::SetAudioOutputChannel Line 1758  String LSCPServer::SetAudioOutputChannel
1758  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1759      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1760      LSCPResultSet result;      LSCPResultSet result;
1761      LockRTNotify();      {
1762            LockGuard lock(RTNotifyMutex);
1763            try {
1764                SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1765                if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1766                std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1767                if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));
1768                AudioOutputDevice* pDevice = devices[AudioDeviceId];
1769                pSamplerChannel->SetAudioOutputDevice(pDevice);
1770            }
1771            catch (Exception e) {
1772                result.Error(e);
1773            }
1774        }
1775        return result.Produce();
1776    }
1777    
1778    String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1779        dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1780        LSCPResultSet result;
1781        {
1782            LockGuard lock(RTNotifyMutex);
1783            try {
1784                SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1785                if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1786                // Driver type name aliasing...
1787                if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1788                if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1789                // Check if there's one audio output device already created
1790                // for the intended audio driver type (AudioOutputDriver)...
1791                AudioOutputDevice *pDevice = NULL;
1792                std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1793                std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
1794                for (; iter != devices.end(); iter++) {
1795                    if ((iter->second)->Driver() == AudioOutputDriver) {
1796                        pDevice = iter->second;
1797                        break;
1798                    }
1799                }
1800                // If it doesn't exist, create a new one with default parameters...
1801                if (pDevice == NULL) {
1802                    std::map<String,String> params;
1803                    pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
1804                }
1805                // Must have a device...
1806                if (pDevice == NULL)
1807                    throw Exception("Internal error: could not create audio output device.");
1808                // Set it as the current channel device...
1809                pSamplerChannel->SetAudioOutputDevice(pDevice);
1810            }
1811            catch (Exception e) {
1812                result.Error(e);
1813            }
1814        }
1815        return result.Produce();
1816    }
1817    
1818    String LSCPServer::AddChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) {
1819        dmsg(2,("LSCPServer: AddChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort));
1820        LSCPResultSet result;
1821      try {      try {
1822          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1823          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1824          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();  
1825          if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1826          AudioOutputDevice* pDevice = devices[AudioDeviceId];          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1827          pSamplerChannel->SetAudioOutputDevice(pDevice);          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1828    
1829            MidiInputPort* pPort = pDevice->GetPort(MIDIPort);
1830            if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId));
1831    
1832            pSamplerChannel->Connect(pPort);
1833        } catch (Exception e) {
1834            result.Error(e);
1835      }      }
1836      catch (Exception e) {      return result.Produce();
1837           result.Error(e);  }
1838    
1839    String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel) {
1840        dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d)\n",uiSamplerChannel));
1841        LSCPResultSet result;
1842        try {
1843            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1844            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1845            pSamplerChannel->DisconnectAllMidiInputPorts();
1846        } catch (Exception e) {
1847            result.Error(e);
1848      }      }
     UnlockRTNotify();  
1849      return result.Produce();      return result.Produce();
1850  }  }
1851    
1852  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId) {
1853      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d)\n",uiSamplerChannel,MIDIDeviceId));
1854      LSCPResultSet result;      LSCPResultSet result;
     LockRTNotify();  
1855      try {      try {
1856          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1857          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1858          // Driver type name aliasing...  
1859          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1860          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1861          // Check if there's one audio output device already created          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1862          // for the intended audio driver type (AudioOutputDriver)...          
1863          AudioOutputDevice *pDevice = NULL;          std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts();
1864          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          for (int i = 0; i < vPorts.size(); ++i)
1865          std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();              if (vPorts[i]->GetDevice() == pDevice)
1866          for (; iter != devices.end(); iter++) {                  pSamplerChannel->Disconnect(vPorts[i]);
1867              if ((iter->second)->Driver() == AudioOutputDriver) {  
1868                  pDevice = iter->second;      } catch (Exception e) {
1869                  break;          result.Error(e);
             }  
         }  
         // If it doesn't exist, create a new one with default parameters...  
         if (pDevice == NULL) {  
             std::map<String,String> params;  
             pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);  
         }  
         // Must have a device...  
         if (pDevice == NULL)  
             throw Exception("Internal error: could not create audio output device.");  
         // Set it as the current channel device...  
         pSamplerChannel->SetAudioOutputDevice(pDevice);  
1870      }      }
1871      catch (Exception e) {      return result.Produce();
1872           result.Error(e);  }
1873    
1874    String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) {
1875        dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort));
1876        LSCPResultSet result;
1877        try {
1878            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1879            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1880    
1881            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1882            if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1883            MidiInputDevice* pDevice = devices[MIDIDeviceId];
1884    
1885            MidiInputPort* pPort = pDevice->GetPort(MIDIPort);
1886            if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId));
1887    
1888            pSamplerChannel->Disconnect(pPort);
1889        } catch (Exception e) {
1890            result.Error(e);
1891        }
1892        return result.Produce();
1893    }
1894    
1895    String LSCPServer::ListChannelMidiInputs(uint uiSamplerChannel) {
1896        dmsg(2,("LSCPServer: ListChannelMidiInputs(uiSamplerChannel=%d)\n",uiSamplerChannel));
1897        LSCPResultSet result;
1898        try {
1899            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1900            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1901            std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts();
1902    
1903            String s;
1904            for (int i = 0; i < vPorts.size(); ++i) {
1905                const int iDeviceID = vPorts[i]->GetDevice()->MidiInputDeviceID();
1906                const int iPortNr   = vPorts[i]->GetPortNumber();
1907                if (s.size()) s += ",";
1908                s += "{" + ToString(iDeviceID) + ","
1909                         + ToString(iPortNr) + "}";
1910            }
1911            result.Add(s);
1912        } catch (Exception e) {
1913            result.Error(e);
1914      }      }
     UnlockRTNotify();  
1915      return result.Produce();      return result.Produce();
1916  }  }
1917    
# Line 2383  String LSCPServer::GetFxSendInfo(uint ui Line 2521  String LSCPServer::GetFxSendInfo(uint ui
2521              AudioRouting += ToString(pFxSend->DestinationChannel(chan));              AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2522          }          }
2523    
2524            const String sEffectRouting =
2525                (pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0)
2526                    ? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition())
2527                    : "NONE";
2528    
2529          // success          // success
2530          result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));          result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));
2531          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2532          result.Add("LEVEL", ToString(pFxSend->Level()));          result.Add("LEVEL", ToString(pFxSend->Level()));
2533          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2534            result.Add("EFFECT", sEffectRouting);
2535      } catch (Exception e) {      } catch (Exception e) {
2536          result.Error(e);          result.Error(e);
2537      }      }
# Line 2450  String LSCPServer::SetFxSendLevel(uint u Line 2594  String LSCPServer::SetFxSendLevel(uint u
2594      return result.Produce();      return result.Produce();
2595  }  }
2596    
2597    String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) {
2598        dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition));
2599        LSCPResultSet result;
2600        try {
2601            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2602    
2603            pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition);
2604            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2605        } catch (Exception e) {
2606            result.Error(e);
2607        }
2608        return result.Produce();
2609    }
2610    
2611  String LSCPServer::GetAvailableEffects() {  String LSCPServer::GetAvailableEffects() {
2612      dmsg(2,("LSCPServer: GetAvailableEffects()\n"));      dmsg(2,("LSCPServer: GetAvailableEffects()\n"));
2613      LSCPResultSet result;      LSCPResultSet result;
# Line 2510  String LSCPServer::GetEffectInfo(int iEf Line 2668  String LSCPServer::GetEffectInfo(int iEf
2668      return result.Produce();          return result.Produce();    
2669  }  }
2670    
2671  String LSCPServer::GetEffectInstanceInfo(int iEffectInstanceIndex) {  String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) {
2672      dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstanceIndex));      dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance));
2673      LSCPResultSet result;      LSCPResultSet result;
2674      try {      try {
2675          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstanceIndex);          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2676          if (!pEffect)          if (!pEffect)
2677              throw Exception("There is no effect instance with index " + ToString(iEffectInstanceIndex));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2678    
2679          EffectInfo* pEffectInfo = pEffect->GetEffectInfo();          EffectInfo* pEffectInfo = pEffect->GetEffectInfo();
2680    
# Line 2541  String LSCPServer::GetEffectInstanceInfo Line 2699  String LSCPServer::GetEffectInstanceInfo
2699      return result.Produce();      return result.Produce();
2700  }  }
2701    
2702  String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstanceIndex, int iInputControlIndex) {  String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) {
2703      dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstanceIndex, iInputControlIndex));      dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex));
2704      LSCPResultSet result;      LSCPResultSet result;
2705      try {      try {
2706          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstanceIndex);          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2707          if (!pEffect)          if (!pEffect)
2708              throw Exception("There is no effect instance with index " + ToString(iEffectInstanceIndex));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2709    
2710          EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex);          EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex);
2711          if (!pEffectControl)          if (!pEffectControl)
2712              throw Exception(              throw Exception(
2713                  "Effect instance " + ToString(iEffectInstanceIndex) +                  "Effect instance " + ToString(iEffectInstance) +
2714                  " does not have an input control with index " +                  " does not have an input control with index " +
2715                  ToString(iInputControlIndex)                  ToString(iInputControlIndex)
2716              );              );
# Line 2573  String LSCPServer::GetEffectInstanceInpu Line 2731  String LSCPServer::GetEffectInstanceInpu
2731      return result.Produce();      return result.Produce();
2732  }  }
2733    
2734  String LSCPServer::SetEffectInstanceInputControl(int iEffectInstanceIndex, int iInputControlIndex, double dValue) {  String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) {
2735      dmsg(2,("LSCPServer: SetEffectInstanceInputControl(%d,%d,%f)\n", iEffectInstanceIndex, iInputControlIndex, dValue));      dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue));
2736      LSCPResultSet result;      LSCPResultSet result;
2737      try {      try {
2738          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstanceIndex);          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2739          if (!pEffect)          if (!pEffect)
2740              throw Exception("There is no effect instance with index " + ToString(iEffectInstanceIndex));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2741    
2742          EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex);          EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex);
2743          if (!pEffectControl)          if (!pEffectControl)
2744              throw Exception(              throw Exception(
2745                  "Effect instance " + ToString(iEffectInstanceIndex) +                  "Effect instance " + ToString(iEffectInstance) +
2746                  " does not have an input control with index " +                  " does not have an input control with index " +
2747                  ToString(iInputControlIndex)                  ToString(iInputControlIndex)
2748              );              );
2749    
2750          pEffectControl->SetValue(dValue);          pEffectControl->SetValue(dValue);
2751            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance));
2752      } catch (Exception e) {      } catch (Exception e) {
2753          result.Error(e);          result.Error(e);
2754      }      }
2755      return result.Produce();      return result.Produce();
2756  }  }
2757    
2758  String LSCPServer::CreateEffectInstance(int index) {  String LSCPServer::CreateEffectInstance(int iEffectIndex) {
2759      dmsg(2,("LSCPServer: CreateEffectInstance()\n"));      dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex));
2760      LSCPResultSet result;      LSCPResultSet result;
2761      try {      try {
2762          EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(index);          EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex);
2763          if (!pEffectInfo)          if (!pEffectInfo)
2764              throw Exception("There is no effect with index " + ToString(index));              throw Exception("There is no effect with index " + ToString(iEffectIndex));
2765          Effect* pEffect = EffectFactory::Create(pEffectInfo);          Effect* pEffect = EffectFactory::Create(pEffectInfo);
2766          result.Add(pEffect->ID());          result = pEffect->ID(); // success
2767            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2768      } catch (Exception e) {      } catch (Exception e) {
2769          result.Error(e);          result.Error(e);
2770      }      }
# Line 2612  String LSCPServer::CreateEffectInstance( Line 2772  String LSCPServer::CreateEffectInstance(
2772  }  }
2773    
2774  String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) {  String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) {
2775      dmsg(2,("LSCPServer: CreateEffectInstance()\n"));      dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str()));
2776      LSCPResultSet result;      LSCPResultSet result;
2777      try {      try {
2778          // to allow loading the same LSCP session file on different systems          // to allow loading the same LSCP session file on different systems
# Line 2651  String LSCPServer::CreateEffectInstance( Line 2811  String LSCPServer::CreateEffectInstance(
2811    
2812          Effect* pEffect = EffectFactory::Create(pEffectInfo);          Effect* pEffect = EffectFactory::Create(pEffectInfo);
2813          result = LSCPResultSet(pEffect->ID());          result = LSCPResultSet(pEffect->ID());
2814            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2815      } catch (Exception e) {      } catch (Exception e) {
2816          result.Error(e);          result.Error(e);
2817      }      }
2818      return result.Produce();      return result.Produce();
2819  }  }
2820    
2821  String LSCPServer::DestroyEffectInstance(int iEffectID) {  String LSCPServer::DestroyEffectInstance(int iEffectInstance) {
2822      dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectID));      dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance));
2823      LSCPResultSet result;      LSCPResultSet result;
2824      try {      try {
2825          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectID);          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2826          if (!pEffect)          if (!pEffect)
2827              throw Exception("There is no effect instance with ID " + ToString(iEffectID));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2828          EffectFactory::Destroy(pEffect);          EffectFactory::Destroy(pEffect);
2829            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2830      } catch (Exception e) {      } catch (Exception e) {
2831          result.Error(e);          result.Error(e);
2832      }      }
# Line 2701  String LSCPServer::ListEffectInstances() Line 2863  String LSCPServer::ListEffectInstances()
2863      return result.Produce();      return result.Produce();
2864  }  }
2865    
2866  String LSCPServer::GetMasterEffectChains(int iAudioOutputDevice) {  String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) {
2867      dmsg(2,("LSCPServer: GetMasterEffectChains(%d)\n", iAudioOutputDevice));      dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice));
2868      LSCPResultSet result;      LSCPResultSet result;
2869      try {      try {
2870          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2871          if (!devices.count(iAudioOutputDevice))          if (!devices.count(iAudioOutputDevice))
2872              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2873          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2874          int n = pDevice->MasterEffectChainCount();          int n = pDevice->SendEffectChainCount();
2875          result.Add(n);          result.Add(n);
2876      } catch (Exception e) {      } catch (Exception e) {
2877          result.Error(e);          result.Error(e);
# Line 2717  String LSCPServer::GetMasterEffectChains Line 2879  String LSCPServer::GetMasterEffectChains
2879      return result.Produce();      return result.Produce();
2880  }  }
2881    
2882  String LSCPServer::ListMasterEffectChains(int iAudioOutputDevice) {  String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) {
2883      dmsg(2,("LSCPServer: ListMasterEffectChains(%d)\n", iAudioOutputDevice));      dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice));
2884      LSCPResultSet result;      LSCPResultSet result;
2885      String list;      String list;
2886      try {      try {
# Line 2726  String LSCPServer::ListMasterEffectChain Line 2888  String LSCPServer::ListMasterEffectChain
2888          if (!devices.count(iAudioOutputDevice))          if (!devices.count(iAudioOutputDevice))
2889              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2890          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2891          int n = pDevice->MasterEffectChainCount();          int n = pDevice->SendEffectChainCount();
2892          for (int i = 0; i < n; i++) {          for (int i = 0; i < n; i++) {
2893              EffectChain* pEffectChain = pDevice->MasterEffectChain(i);              EffectChain* pEffectChain = pDevice->SendEffectChain(i);
2894              if (i) list += ",";              if (i) list += ",";
2895              list += ToString(pEffectChain->ID());              list += ToString(pEffectChain->ID());
2896          }          }
# Line 2739  String LSCPServer::ListMasterEffectChain Line 2901  String LSCPServer::ListMasterEffectChain
2901      return result.Produce();      return result.Produce();
2902  }  }
2903    
2904  String LSCPServer::AddMasterEffectChain(int iAudioOutputDevice) {  String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) {
2905      dmsg(2,("LSCPServer: AddMasterEffectChain(%d)\n", iAudioOutputDevice));      dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice));
2906      LSCPResultSet result;      LSCPResultSet result;
2907      try {      try {
2908          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2909          if (!devices.count(iAudioOutputDevice))          if (!devices.count(iAudioOutputDevice))
2910              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2911          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2912          EffectChain* pEffectChain = pDevice->AddMasterEffectChain();          EffectChain* pEffectChain = pDevice->AddSendEffectChain();
2913          result.Add(pEffectChain->ID());          result = pEffectChain->ID();
2914            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
2915      } catch (Exception e) {      } catch (Exception e) {
2916          result.Error(e);          result.Error(e);
2917      }      }
2918      return result.Produce();      return result.Produce();
2919  }  }
2920    
2921  String LSCPServer::RemoveMasterEffectChain(int iAudioOutputDevice, int iMasterEffectChain) {  String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) {
2922      dmsg(2,("LSCPServer: RemoveMasterEffectChain(%d,%d)\n", iAudioOutputDevice, iMasterEffectChain));      dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain));
2923      LSCPResultSet result;      LSCPResultSet result;
2924      try {      try {
2925          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2926          if (!devices.count(iAudioOutputDevice))          if (!devices.count(iAudioOutputDevice))
2927              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2928    
2929            std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
2930            std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
2931            std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
2932            for (; itEngineChannel != itEnd; ++itEngineChannel) {
2933                AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice();
2934                if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) {
2935                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
2936                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
2937                        if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) {
2938                            throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index()));
2939                        }
2940                    }
2941                }
2942            }
2943    
2944          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2945          for (int i = 0; i < pDevice->MasterEffectChainCount(); i++) {          for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {
2946              EffectChain* pEffectChain = pDevice->MasterEffectChain(i);              EffectChain* pEffectChain = pDevice->SendEffectChain(i);
2947              if (pEffectChain->ID() == iMasterEffectChain) {              if (pEffectChain->ID() == iSendEffectChain) {
2948                  pDevice->RemoveMasterEffectChain(i);                  pDevice->RemoveSendEffectChain(i);
2949                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
2950                  return result.Produce();                  return result.Produce();
2951              }              }
2952          }          }
2953          throw Exception(          throw Exception(
2954              "There is no master effect chain with ID " +              "There is no send effect chain with ID " +
2955              ToString(iMasterEffectChain) + " for audio output device " +              ToString(iSendEffectChain) + " for audio output device " +
2956              ToString(iAudioOutputDevice) + "."              ToString(iAudioOutputDevice) + "."
2957          );          );
2958      } catch (Exception e) {      } catch (Exception e) {
# Line 2781  String LSCPServer::RemoveMasterEffectCha Line 2961  String LSCPServer::RemoveMasterEffectCha
2961      return result.Produce();      return result.Produce();
2962  }  }
2963    
2964  static EffectChain* _getMasterEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iMasterEffectChain) throw (Exception) {  static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) {
2965      std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();      std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2966      if (!devices.count(iAudioOutputDevice))      if (!devices.count(iAudioOutputDevice))
2967          throw Exception(          throw Exception(
# Line 2789  static EffectChain* _getMasterEffectChai Line 2969  static EffectChain* _getMasterEffectChai
2969              ToString(iAudioOutputDevice) + "."              ToString(iAudioOutputDevice) + "."
2970          );          );
2971      AudioOutputDevice* pDevice = devices[iAudioOutputDevice];      AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2972      for (int i = 0; i < pDevice->MasterEffectChainCount(); i++) {      EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain);
2973          EffectChain* pEffectChain = pDevice->MasterEffectChain(i);      if(pEffectChain != NULL) return pEffectChain;
         if (pEffectChain->ID() == iMasterEffectChain) {  
             return pEffectChain;  
         }  
     }  
2974      throw Exception(      throw Exception(
2975          "There is no master effect chain with ID " +          "There is no send effect chain with ID " +
2976          ToString(iMasterEffectChain) + " for audio output device " +          ToString(iSendEffectChain) + " for audio output device " +
2977          ToString(iAudioOutputDevice) + "."          ToString(iAudioOutputDevice) + "."
2978      );      );
2979  }  }
2980    
2981  String LSCPServer::GetMasterEffectChainInfo(int iAudioOutputDevice, int iMasterEffectChain) {  String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) {
2982      dmsg(2,("LSCPServer: GetMasterEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iMasterEffectChain));      dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain));
2983      LSCPResultSet result;      LSCPResultSet result;
2984      try {      try {
2985          EffectChain* pEffectChain =          EffectChain* pEffectChain =
2986              _getMasterEffectChain(pSampler, iAudioOutputDevice, iMasterEffectChain);              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
2987          String sEffectSequence;          String sEffectSequence;
2988          for (int i = 0; i < pEffectChain->EffectCount(); i++) {          for (int i = 0; i < pEffectChain->EffectCount(); i++) {
2989              if (i) sEffectSequence += ",";              if (i) sEffectSequence += ",";
# Line 2821  String LSCPServer::GetMasterEffectChainI Line 2997  String LSCPServer::GetMasterEffectChainI
2997      return result.Produce();      return result.Produce();
2998  }  }
2999    
3000  String LSCPServer::AppendMasterEffectChainEffect(int iAudioOutputDevice, int iMasterEffectChain, int iEffectInstance) {  String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) {
3001      dmsg(2,("LSCPServer: AppendMasterEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iMasterEffectChain, iEffectInstance));      dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance));
3002      LSCPResultSet result;      LSCPResultSet result;
3003      try {      try {
3004          EffectChain* pEffectChain =          EffectChain* pEffectChain =
3005              _getMasterEffectChain(pSampler, iAudioOutputDevice, iMasterEffectChain);              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3006          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
3007          if (!pEffect)          if (!pEffect)
3008              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
3009          pEffectChain->AppendEffect(pEffect);          pEffectChain->AppendEffect(pEffect);
3010            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3011      } catch (Exception e) {      } catch (Exception e) {
3012          result.Error(e);          result.Error(e);
3013      }      }
3014      return result.Produce();      return result.Produce();
3015  }  }
3016    
3017  String LSCPServer::InsertMasterEffectChainEffect(int iAudioOutputDevice, int iMasterEffectChain, int iEffectInstance, int iEffectChainPosition) {  String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) {
3018      dmsg(2,("LSCPServer: InsertMasterEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iMasterEffectChain, iEffectInstance, iEffectChainPosition));      dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance));
3019      LSCPResultSet result;      LSCPResultSet result;
3020      try {      try {
3021          EffectChain* pEffectChain =          EffectChain* pEffectChain =
3022              _getMasterEffectChain(pSampler, iAudioOutputDevice, iMasterEffectChain);              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3023          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);          Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
3024          if (!pEffect)          if (!pEffect)
3025              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));
3026          pEffectChain->InsertEffect(pEffect, iEffectChainPosition);          pEffectChain->InsertEffect(pEffect, iEffectChainPosition);
3027            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3028      } catch (Exception e) {      } catch (Exception e) {
3029          result.Error(e);          result.Error(e);
3030      }      }
3031      return result.Produce();      return result.Produce();
3032  }  }
3033    
3034  String LSCPServer::RemoveMasterEffectChainEffect(int iAudioOutputDevice, int iMasterEffectChain, int iEffectInstance) {  String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) {
3035      dmsg(2,("LSCPServer: RemoveMasterEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iMasterEffectChain, iEffectInstance));      dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition));
3036      LSCPResultSet result;      LSCPResultSet result;
3037      try {      try {
3038          EffectChain* pEffectChain =          EffectChain* pEffectChain =
3039              _getMasterEffectChain(pSampler, iAudioOutputDevice, iMasterEffectChain);              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3040          for (int i = 0; i < pEffectChain->EffectCount(); i++) {  
3041              Effect* pEffect = pEffectChain->GetEffect(i);          std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
3042              if (pEffect->ID() == iEffectInstance) {          std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
3043                  pEffectChain->RemoveEffect(i);          std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
3044                  return result.Produce();          for (; itEngineChannel != itEnd; ++itEngineChannel) {
3045                AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice();
3046                if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) {
3047                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
3048                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
3049                        if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) {
3050                            throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index()));
3051                        }
3052                    }
3053              }              }
3054          }          }
3055          throw Exception(  
3056              "There is no effect instance with index " +          pEffectChain->RemoveEffect(iEffectChainPosition);
3057              ToString(iEffectInstance)          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
         );  
3058      } catch (Exception e) {      } catch (Exception e) {
3059          result.Error(e);          result.Error(e);
3060      }      }
# Line 3010  String LSCPServer::GetTotalVoiceCount() Line 3195  String LSCPServer::GetTotalVoiceCount()
3195  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
3196      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
3197      LSCPResultSet result;      LSCPResultSet result;
3198      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices());
3199      return result.Produce();      return result.Produce();
3200  }  }
3201    
# Line 3021  String LSCPServer::GetTotalVoiceCountMax Line 3206  String LSCPServer::GetTotalVoiceCountMax
3206  String LSCPServer::GetGlobalMaxVoices() {  String LSCPServer::GetGlobalMaxVoices() {
3207      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
3208      LSCPResultSet result;      LSCPResultSet result;
3209      result.Add(GLOBAL_MAX_VOICES);      result.Add(pSampler->GetGlobalMaxVoices());
3210      return result.Produce();      return result.Produce();
3211  }  }
3212    
# Line 3033  String LSCPServer::SetGlobalMaxVoices(in Line 3218  String LSCPServer::SetGlobalMaxVoices(in
3218      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
3219      LSCPResultSet result;      LSCPResultSet result;
3220      try {      try {
3221          if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");          pSampler->SetGlobalMaxVoices(iVoices);
3222          GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3223          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices())
3224          if (engines.size() > 0) {          );
             std::set<Engine*>::iterator iter = engines.begin();  
             std::set<Engine*>::iterator end  = engines.end();  
             for (; iter != end; ++iter) {  
                 (*iter)->SetMaxVoices(iVoices);  
             }  
         }  
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES));  
3225      } catch (Exception e) {      } catch (Exception e) {
3226          result.Error(e);          result.Error(e);
3227      }      }
# Line 3057  String LSCPServer::SetGlobalMaxVoices(in Line 3235  String LSCPServer::SetGlobalMaxVoices(in
3235  String LSCPServer::GetGlobalMaxStreams() {  String LSCPServer::GetGlobalMaxStreams() {
3236      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
3237      LSCPResultSet result;      LSCPResultSet result;
3238      result.Add(GLOBAL_MAX_STREAMS);      result.Add(pSampler->GetGlobalMaxStreams());
3239      return result.Produce();      return result.Produce();
3240  }  }
3241    
# Line 3069  String LSCPServer::SetGlobalMaxStreams(i Line 3247  String LSCPServer::SetGlobalMaxStreams(i
3247      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
3248      LSCPResultSet result;      LSCPResultSet result;
3249      try {      try {
3250          if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");          pSampler->SetGlobalMaxStreams(iStreams);
3251          GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3252          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams())
3253          if (engines.size() > 0) {          );
             std::set<Engine*>::iterator iter = engines.begin();  
             std::set<Engine*>::iterator end  = engines.end();  
             for (; iter != end; ++iter) {  
                 (*iter)->SetMaxDiskStreams(iStreams);  
             }  
         }  
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS));  
3254      } catch (Exception e) {      } catch (Exception e) {
3255          result.Error(e);          result.Error(e);
3256      }      }
# Line 3283  void LSCPServer::VerifyFile(String Filen Line 3454  void LSCPServer::VerifyFile(String Filen
3454  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {
3455      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
3456      LSCPResultSet result;      LSCPResultSet result;
3457      SubscriptionMutex.Lock();      {
3458      eventSubscriptions[type].push_back(currentSocket);          LockGuard lock(SubscriptionMutex);
3459      SubscriptionMutex.Unlock();          eventSubscriptions[type].push_back(currentSocket);
3460        }
3461      return result.Produce();      return result.Produce();
3462  }  }
3463    
# Line 3296  String LSCPServer::SubscribeNotification Line 3468  String LSCPServer::SubscribeNotification
3468  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {
3469      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
3470      LSCPResultSet result;      LSCPResultSet result;
3471      SubscriptionMutex.Lock();      {
3472      eventSubscriptions[type].remove(currentSocket);          LockGuard lock(SubscriptionMutex);
3473      SubscriptionMutex.Unlock();          eventSubscriptions[type].remove(currentSocket);
3474        }
3475      return result.Produce();      return result.Produce();
3476  }  }
3477    
# Line 3823  String LSCPServer::SetEcho(yyparse_param Line 3996  String LSCPServer::SetEcho(yyparse_param
3996      }      }
3997      return result.Produce();      return result.Produce();
3998  }  }
3999    
4000    String LSCPServer::SetShellInteract(yyparse_param_t* pSession, double boolean_value) {
4001        dmsg(2,("LSCPServer: SetShellInteract(val=%f)\n", boolean_value));
4002        LSCPResultSet result;
4003        try {
4004            if      (boolean_value == 0) pSession->bShellInteract = false;
4005            else if (boolean_value == 1) pSession->bShellInteract = true;
4006            else throw Exception("Not a boolean value, must either be 0 or 1");
4007        } catch (Exception e) {
4008            result.Error(e);
4009        }
4010        return result.Produce();
4011    }
4012    
4013    String LSCPServer::SetShellAutoCorrect(yyparse_param_t* pSession, double boolean_value) {
4014        dmsg(2,("LSCPServer: SetShellAutoCorrect(val=%f)\n", boolean_value));
4015        LSCPResultSet result;
4016        try {
4017            if      (boolean_value == 0) pSession->bShellAutoCorrect = false;
4018            else if (boolean_value == 1) pSession->bShellAutoCorrect = true;
4019            else throw Exception("Not a boolean value, must either be 0 or 1");
4020        } catch (Exception e) {
4021            result.Error(e);
4022        }
4023        return result.Produce();
4024    }
4025    
4026  }  }

Legend:
Removed from v.2135  
changed lines
  Added in v.2516

  ViewVC Help
Powered by ViewVC