/[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 1897 by persson, Sun May 10 09:31:51 2009 UTC revision 2534 by schoenebeck, Sun Mar 9 21:34:03 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 43  Line 43 
43  #include "../engines/EngineChannelFactory.h"  #include "../engines/EngineChannelFactory.h"
44  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
45  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
46    #include "../effects/EffectFactory.h"
47    
48  namespace LinuxSampler {  namespace LinuxSampler {
49    
50    String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param, bool possibilities);
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 96  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 137  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 442  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 510  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 585  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 603  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 617  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 630  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 641  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 690  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 715  extern yyparse_param_t* GetCurrentYaccSe Line 716  extern yyparse_param_t* GetCurrentYaccSe
716  }  }
717    
718  /**  /**
719     * Generate the relevant LSCP documentation reference section if necessary.
720     * The documentation section for the currently active command on the LSCP
721     * shell's command line will be encoded in a special format, specifically for
722     * the LSCP shell application.
723     *
724     * @param line - current LSCP command line
725     * @param param - reentrant Bison parser parameters
726     *
727     * @return encoded reference string or empty string if nothing shall be sent
728     *         to LSCP shell (client) at this point
729     */
730    String LSCPServer::generateLSCPDocReply(const String& line, yyparse_param_t* param) {
731        String result;
732        lscp_ref_entry_t* ref = lscp_reference_for_command(line.c_str());
733        // Pointer comparison works here, since the function above always
734        // returns the same constant pointer for the respective LSCP
735        // command ... Only send the LSCP reference section to the client if
736        // another LSCP reference section became relevant now:
737        if (ref != param->pLSCPDocRef) {
738            param->pLSCPDocRef = ref;
739            if (ref) { // send a new LSCP doc section to client ...
740                result += "SHD:" + ToString(LSCP_SHD_MATCH) + ":" + String(ref->name) + "\n";
741                result += String(ref->section) + "\n";
742                result += "."; // dot line marks the end of the text for client
743            } else { // inform client that no LSCP doc section matches right now ...
744                result = "SHD:" + ToString(LSCP_SHD_NO_MATCH);
745            }
746        }
747        dmsg(4,("LSCP doc reply -> '%s'\n", result.c_str()));
748        return result;
749    }
750    
751    /**
752   * Will be called to try to read the command from the socket   * Will be called to try to read the command from the socket
753   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
754   * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.   * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.
755   */   */
756  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
757          int socket = (*iter).hSession;          int socket = (*iter).hSession;
758            int result;
759          char c;          char c;
760          int i = 0;          std::vector<char> input;
761    
762            // first get as many character as possible and add it to the 'input' buffer
763          while (true) {          while (true) {
764                  #if defined(WIN32)                  #if defined(WIN32)
765                  int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now                  result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now
766                  #else                  #else
767                  int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now                  result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now
768                  #endif                  #endif
769                  if (result == 0) { //socket was selected, so 0 here means client has closed the connection                  if (result == 1) input.push_back(c);
770                          CloseConnection(iter);                  else break; // end of input or some error
771                          break;                  if (c == '\n') break; // process line by line
772                  }          }
773                  if (result == 1) {  
774                          if (c == '\r')          // process input buffer
775                                  continue; //Ignore CR          for (int i = 0; i < input.size(); ++i) {
776                          if (c == '\n') {                  c = input[i];
777                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                  if (c == '\r') continue; //Ignore CR
778                                  bufferedCommands[socket] += "\r\n";                  if (c == '\n') {
779                                  return true; //Complete command was read                          // only if the other side is the LSCP shell application:
780                            // check the current (incomplete) command line for syntax errors,
781                            // possible completions and report everything back to the shell
782                            if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {
783                                    String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false);
784                                    if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n");
785                            }
786                            // if other side is LSCP shell application, send the relevant LSCP
787                            // documentation section of the current command line (if necessary)
788                            if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) {
789                                    String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter));
790                                    if (!s.empty()) AnswerClient(s + "\n");
791                            }
792                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
793                            bufferedCommands[socket] += "\r\n";
794                            return true; //Complete command was read
795                    } else if (c == 2) { // custom ASCII code usage for moving cursor left (LSCP shell)
796                            if (iter->iCursorOffset + bufferedCommands[socket].size() > 0)
797                                    iter->iCursorOffset--;
798                    } else if (c == 3) { // custom ASCII code usage for moving cursor right (LSCP shell)
799                            if (iter->iCursorOffset < 0) iter->iCursorOffset++;
800                    } else {
801                            size_t cursorPos = bufferedCommands[socket].size() + iter->iCursorOffset;
802                            // backspace character - should only happen with shell
803                            if (c == '\b') {
804                                    if (!bufferedCommands[socket].empty() && cursorPos > 0)
805                                            bufferedCommands[socket].erase(cursorPos - 1, 1);
806                            } else { // append (or insert) new character (at current cursor position) ...
807                                    if (cursorPos >= 0)
808                                            bufferedCommands[socket].insert(cursorPos, String(1,c)); // insert
809                                    else
810                                            bufferedCommands[socket] += c; // append
811                          }                          }
                         bufferedCommands[socket] += c;  
812                  }                  }
813                  #if defined(WIN32)                  // only if the other side is the LSCP shell application:
814                  if (result == SOCKET_ERROR) {                  // check the current (incomplete) command line for syntax errors,
815                      int wsa_lasterror = WSAGetLastError();                  // possible completions and report everything back to the shell
816                          if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later.                  if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {
817                                  return false;                          String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), true);
818                          dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror));                          if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1)
819                          CloseConnection(iter);                                  AnswerClient(s + "\n");
                         break;  
820                  }                  }
821                  #else                  // if other side is LSCP shell application, send the relevant LSCP
822                  if (result == -1) {                  // documentation section of the current command line (if necessary)
823                          if (errno == EAGAIN) //Would block, try again later.                  if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) {
824                            String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter));
825                            if (!s.empty()) AnswerClient(s + "\n");
826                    }
827            }
828    
829            // handle network errors ...
830            if (result == 0) { //socket was selected, so 0 here means client has closed the connection
831                    CloseConnection(iter);
832                    return false;
833            }
834            #if defined(WIN32)
835            if (result == SOCKET_ERROR) {
836                    int wsa_lasterror = WSAGetLastError();
837                    if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later.
838                            return false;
839                    dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror));
840                    CloseConnection(iter);
841                    return false;
842            }
843            #else
844            if (result == -1) {
845                    if (errno == EAGAIN) //Would block, try again later.
846                            return false;
847                    switch(errno) {
848                            case EBADF:
849                                    dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n"));
850                                    return false;
851                            case ECONNREFUSED:
852                                    dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n"));
853                                    return false;
854                            case ENOTCONN:
855                                    dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n"));
856                                    return false;
857                            case ENOTSOCK:
858                                    dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n"));
859                                    return false;
860                            case EAGAIN:
861                                    dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));
862                                    return false;
863                            case EINTR:
864                                    dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));
865                                    return false;
866                            case EFAULT:
867                                    dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));
868                                    return false;
869                            case EINVAL:
870                                    dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
871                                    return false;
872                            case ENOMEM:
873                                    dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
874                                    return false;
875                            default:
876                                    dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
877                                  return false;                                  return false;
                         switch(errno) {  
                                 case EBADF:  
                                         dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n"));  
                                         break;  
                                 case ECONNREFUSED:  
                                         dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n"));  
                                         break;  
                                 case ENOTCONN:  
                                         dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n"));  
                                         break;  
                                 case ENOTSOCK:  
                                         dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n"));  
                                         break;  
                                 case EAGAIN:  
                                         dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));  
                                         break;  
                                 case EINTR:  
                                         dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));  
                                         break;  
                                 case EFAULT:  
                                         dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));  
                                         break;  
                                 case EINVAL:  
                                         dmsg(2,("LSCPScanner: Invalid argument passed.\n"));  
                                         break;  
                                 case ENOMEM:  
                                         dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));  
                                         break;  
                                 default:  
                                         dmsg(2,("LSCPScanner: Unknown recv() error.\n"));  
                                         break;  
                         }  
                         CloseConnection(iter);  
                         break;  
878                  }                  }
879                  #endif                  CloseConnection(iter);
880                    return false;
881          }          }
882            #endif
883    
884          return false;          return false;
885  }  }
886    
# Line 803  bool LSCPServer::GetLSCPCommand( std::ve Line 891  bool LSCPServer::GetLSCPCommand( std::ve
891   * @param ReturnMessage - message that will be send to the client   * @param ReturnMessage - message that will be send to the client
892   */   */
893  void LSCPServer::AnswerClient(String ReturnMessage) {  void LSCPServer::AnswerClient(String ReturnMessage) {
894      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage='%s')", ReturnMessage.c_str()));
895      if (currentSocket != -1) {      if (currentSocket != -1) {
896              NotifyMutex.Lock();              LockGuard lock(NotifyMutex);
897    
898            // just if other side is LSCP shell: in case respose is a multi-line
899            // one, then inform client about it before sending the actual mult-line
900            // response
901            if (GetCurrentYaccSession()->bShellInteract) {
902                // check if this is a multi-line response
903                int n = 0;
904                for (int i = 0; i < ReturnMessage.size(); ++i)
905                    if (ReturnMessage[i] == '\n') ++n;
906                if (n >= 2) {
907                    dmsg(2,("LSCP Shell <- expect mult-line response\n"));
908                    String s = LSCP_SHK_EXPECT_MULTI_LINE "\r\n";
909    #ifdef MSG_NOSIGNAL
910                    send(currentSocket, s.c_str(), s.size(), MSG_NOSIGNAL);
911    #else
912                    send(currentSocket, s.c_str(), s.size(), 0);
913    #endif                
914                }
915            }
916    
917  #ifdef MSG_NOSIGNAL  #ifdef MSG_NOSIGNAL
918              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
919  #else  #else
920              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
921  #endif  #endif
             NotifyMutex.Unlock();  
922      }      }
923  }  }
924    
# Line 961  String LSCPServer::SetEngineType(String Line 1068  String LSCPServer::SetEngineType(String
1068      try {      try {
1069          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1070          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1071          LockRTNotify();          LockGuard lock(RTNotifyMutex);
1072          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
1073          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);          if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
         UnlockRTNotify();  
1074      }      }
1075      catch (Exception e) {      catch (Exception e) {
1076           result.Error(e);           result.Error(e);
# Line 1004  String LSCPServer::ListChannels() { Line 1110  String LSCPServer::ListChannels() {
1110   */   */
1111  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
1112      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
1113      LockRTNotify();      SamplerChannel* pSamplerChannel;
1114      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      {
1115      UnlockRTNotify();          LockGuard lock(RTNotifyMutex);
1116            pSamplerChannel = pSampler->AddSamplerChannel();
1117        }
1118      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
1119      return result.Produce();      return result.Produce();
1120  }  }
# Line 1017  String LSCPServer::AddChannel() { Line 1125  String LSCPServer::AddChannel() {
1125  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
1126      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
1127      LSCPResultSet result;      LSCPResultSet result;
1128      LockRTNotify();      {
1129      pSampler->RemoveSamplerChannel(uiSamplerChannel);          LockGuard lock(RTNotifyMutex);
1130      UnlockRTNotify();          pSampler->RemoveSamplerChannel(uiSamplerChannel);
1131        }
1132      return result.Produce();      return result.Produce();
1133  }  }
1134    
# Line 1062  String LSCPServer::ListAvailableEngines( Line 1171  String LSCPServer::ListAvailableEngines(
1171  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
1172      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
1173      LSCPResultSet result;      LSCPResultSet result;
1174      LockRTNotify();      {
1175      try {          LockGuard lock(RTNotifyMutex);
1176          Engine* pEngine = EngineFactory::Create(EngineName);          try {
1177          result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));              Engine* pEngine = EngineFactory::Create(EngineName);
1178          result.Add("VERSION",     pEngine->Version());              result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));
1179          EngineFactory::Destroy(pEngine);              result.Add("VERSION",     pEngine->Version());
1180      }              EngineFactory::Destroy(pEngine);
1181      catch (Exception e) {          }
1182           result.Error(e);          catch (Exception e) {
1183                result.Error(e);
1184            }
1185      }      }
     UnlockRTNotify();  
1186      return result.Produce();      return result.Produce();
1187  }  }
1188    
# Line 1721  String LSCPServer::SetAudioOutputChannel Line 1831  String LSCPServer::SetAudioOutputChannel
1831  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1832      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1833      LSCPResultSet result;      LSCPResultSet result;
1834      LockRTNotify();      {
1835            LockGuard lock(RTNotifyMutex);
1836            try {
1837                SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1838                if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1839                std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1840                if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));
1841                AudioOutputDevice* pDevice = devices[AudioDeviceId];
1842                pSamplerChannel->SetAudioOutputDevice(pDevice);
1843            }
1844            catch (Exception e) {
1845                result.Error(e);
1846            }
1847        }
1848        return result.Produce();
1849    }
1850    
1851    String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1852        dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1853        LSCPResultSet result;
1854        {
1855            LockGuard lock(RTNotifyMutex);
1856            try {
1857                SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1858                if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1859                // Driver type name aliasing...
1860                if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1861                if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1862                // Check if there's one audio output device already created
1863                // for the intended audio driver type (AudioOutputDriver)...
1864                AudioOutputDevice *pDevice = NULL;
1865                std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1866                std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
1867                for (; iter != devices.end(); iter++) {
1868                    if ((iter->second)->Driver() == AudioOutputDriver) {
1869                        pDevice = iter->second;
1870                        break;
1871                    }
1872                }
1873                // If it doesn't exist, create a new one with default parameters...
1874                if (pDevice == NULL) {
1875                    std::map<String,String> params;
1876                    pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
1877                }
1878                // Must have a device...
1879                if (pDevice == NULL)
1880                    throw Exception("Internal error: could not create audio output device.");
1881                // Set it as the current channel device...
1882                pSamplerChannel->SetAudioOutputDevice(pDevice);
1883            }
1884            catch (Exception e) {
1885                result.Error(e);
1886            }
1887        }
1888        return result.Produce();
1889    }
1890    
1891    String LSCPServer::AddChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) {
1892        dmsg(2,("LSCPServer: AddChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort));
1893        LSCPResultSet result;
1894      try {      try {
1895          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1896          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1897          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();  
1898          if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1899          AudioOutputDevice* pDevice = devices[AudioDeviceId];          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1900          pSamplerChannel->SetAudioOutputDevice(pDevice);          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1901    
1902            MidiInputPort* pPort = pDevice->GetPort(MIDIPort);
1903            if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId));
1904    
1905            pSamplerChannel->Connect(pPort);
1906        } catch (Exception e) {
1907            result.Error(e);
1908      }      }
1909      catch (Exception e) {      return result.Produce();
1910           result.Error(e);  }
1911    
1912    String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel) {
1913        dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d)\n",uiSamplerChannel));
1914        LSCPResultSet result;
1915        try {
1916            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1917            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1918            pSamplerChannel->DisconnectAllMidiInputPorts();
1919        } catch (Exception e) {
1920            result.Error(e);
1921      }      }
     UnlockRTNotify();  
1922      return result.Produce();      return result.Produce();
1923  }  }
1924    
1925  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId) {
1926      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));
1927      LSCPResultSet result;      LSCPResultSet result;
     LockRTNotify();  
1928      try {      try {
1929          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1930          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1931          // Driver type name aliasing...  
1932          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1933          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1934          // Check if there's one audio output device already created          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1935          // for the intended audio driver type (AudioOutputDriver)...          
1936          AudioOutputDevice *pDevice = NULL;          std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts();
1937          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          for (int i = 0; i < vPorts.size(); ++i)
1938          std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();              if (vPorts[i]->GetDevice() == pDevice)
1939          for (; iter != devices.end(); iter++) {                  pSamplerChannel->Disconnect(vPorts[i]);
1940              if ((iter->second)->Driver() == AudioOutputDriver) {  
1941                  pDevice = iter->second;      } catch (Exception e) {
1942                  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);  
1943      }      }
1944      catch (Exception e) {      return result.Produce();
1945           result.Error(e);  }
1946    
1947    String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) {
1948        dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort));
1949        LSCPResultSet result;
1950        try {
1951            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1952            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1953    
1954            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1955            if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1956            MidiInputDevice* pDevice = devices[MIDIDeviceId];
1957    
1958            MidiInputPort* pPort = pDevice->GetPort(MIDIPort);
1959            if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId));
1960    
1961            pSamplerChannel->Disconnect(pPort);
1962        } catch (Exception e) {
1963            result.Error(e);
1964        }
1965        return result.Produce();
1966    }
1967    
1968    String LSCPServer::ListChannelMidiInputs(uint uiSamplerChannel) {
1969        dmsg(2,("LSCPServer: ListChannelMidiInputs(uiSamplerChannel=%d)\n",uiSamplerChannel));
1970        LSCPResultSet result;
1971        try {
1972            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1973            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1974            std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts();
1975    
1976            String s;
1977            for (int i = 0; i < vPorts.size(); ++i) {
1978                const int iDeviceID = vPorts[i]->GetDevice()->MidiInputDeviceID();
1979                const int iPortNr   = vPorts[i]->GetPortNumber();
1980                if (s.size()) s += ",";
1981                s += "{" + ToString(iDeviceID) + ","
1982                         + ToString(iPortNr) + "}";
1983            }
1984            result.Add(s);
1985        } catch (Exception e) {
1986            result.Error(e);
1987      }      }
     UnlockRTNotify();  
1988      return result.Produce();      return result.Produce();
1989  }  }
1990    
# Line 2382  String LSCPServer::GetFxSendInfo(uint ui Line 2594  String LSCPServer::GetFxSendInfo(uint ui
2594              AudioRouting += ToString(pFxSend->DestinationChannel(chan));              AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2595          }          }
2596    
2597            const String sEffectRouting =
2598                (pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0)
2599                    ? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition())
2600                    : "NONE";
2601    
2602          // success          // success
2603          result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));          result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));
2604          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2605          result.Add("LEVEL", ToString(pFxSend->Level()));          result.Add("LEVEL", ToString(pFxSend->Level()));
2606          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2607            result.Add("EFFECT", sEffectRouting);
2608      } catch (Exception e) {      } catch (Exception e) {
2609          result.Error(e);          result.Error(e);
2610      }      }
# Line 2449  String LSCPServer::SetFxSendLevel(uint u Line 2667  String LSCPServer::SetFxSendLevel(uint u
2667      return result.Produce();      return result.Produce();
2668  }  }
2669    
2670    String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) {
2671        dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition));
2672        LSCPResultSet result;
2673        try {
2674            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2675    
2676            pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition);
2677            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2678        } catch (Exception e) {
2679            result.Error(e);
2680        }
2681        return result.Produce();
2682    }
2683    
2684    String LSCPServer::GetAvailableEffects() {
2685        dmsg(2,("LSCPServer: GetAvailableEffects()\n"));
2686        LSCPResultSet result;
2687        try {
2688            int n = EffectFactory::AvailableEffectsCount();
2689            result.Add(n);
2690        }
2691        catch (Exception e) {
2692            result.Error(e);
2693        }
2694        return result.Produce();
2695    }
2696    
2697    String LSCPServer::ListAvailableEffects() {
2698        dmsg(2,("LSCPServer: ListAvailableEffects()\n"));
2699        LSCPResultSet result;
2700        String list;
2701        try {
2702            //FIXME: for now we simply enumerate from 0 .. EffectFactory::AvailableEffectsCount() here, in future we should use unique IDs for effects during the whole sampler session. This issue comes into game when the user forces a reload of available effect plugins
2703            int n = EffectFactory::AvailableEffectsCount();
2704            for (int i = 0; i < n; i++) {
2705                if (i) list += ",";
2706                list += ToString(i);
2707            }
2708        }
2709        catch (Exception e) {
2710            result.Error(e);
2711        }
2712        result.Add(list);
2713        return result.Produce();
2714    }
2715    
2716    String LSCPServer::GetEffectInfo(int iEffectIndex) {
2717        dmsg(2,("LSCPServer: GetEffectInfo(%d)\n", iEffectIndex));
2718        LSCPResultSet result;
2719        try {
2720            EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex);
2721            if (!pEffectInfo)
2722                throw Exception("There is no effect with index " + ToString(iEffectIndex));
2723    
2724            // convert the filename into the correct encoding as defined for LSCP
2725            // (especially in terms of special characters -> escape sequences)
2726    #if WIN32
2727            const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp();
2728    #else
2729            // assuming POSIX
2730            const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp();
2731    #endif
2732    
2733            result.Add("SYSTEM", pEffectInfo->EffectSystem());
2734            result.Add("MODULE", dllFileName);
2735            result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name()));
2736            result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description()));
2737        }
2738        catch (Exception e) {
2739            result.Error(e);
2740        }
2741        return result.Produce();    
2742    }
2743    
2744    String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) {
2745        dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance));
2746        LSCPResultSet result;
2747        try {
2748            Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2749            if (!pEffect)
2750                throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2751    
2752            EffectInfo* pEffectInfo = pEffect->GetEffectInfo();
2753    
2754            // convert the filename into the correct encoding as defined for LSCP
2755            // (especially in terms of special characters -> escape sequences)
2756    #if WIN32
2757            const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp();
2758    #else
2759            // assuming POSIX
2760            const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp();
2761    #endif
2762    
2763            result.Add("SYSTEM", pEffectInfo->EffectSystem());
2764            result.Add("MODULE", dllFileName);
2765            result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name()));
2766            result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description()));
2767            result.Add("INPUT_CONTROLS", ToString(pEffect->InputControlCount()));
2768        }
2769        catch (Exception e) {
2770            result.Error(e);
2771        }
2772        return result.Produce();
2773    }
2774    
2775    String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) {
2776        dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex));
2777        LSCPResultSet result;
2778        try {
2779            Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2780            if (!pEffect)
2781                throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2782    
2783            EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex);
2784            if (!pEffectControl)
2785                throw Exception(
2786                    "Effect instance " + ToString(iEffectInstance) +
2787                    " does not have an input control with index " +
2788                    ToString(iInputControlIndex)
2789                );
2790    
2791            result.Add("DESCRIPTION", _escapeLscpResponse(pEffectControl->Description()));
2792            result.Add("VALUE", pEffectControl->Value());
2793            if (pEffectControl->MinValue())
2794                 result.Add("RANGE_MIN", *pEffectControl->MinValue());
2795            if (pEffectControl->MaxValue())
2796                 result.Add("RANGE_MAX", *pEffectControl->MaxValue());
2797            if (!pEffectControl->Possibilities().empty())
2798                 result.Add("POSSIBILITIES", pEffectControl->Possibilities());
2799            if (pEffectControl->DefaultValue())
2800                 result.Add("DEFAULT", *pEffectControl->DefaultValue());
2801        } catch (Exception e) {
2802            result.Error(e);
2803        }
2804        return result.Produce();
2805    }
2806    
2807    String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) {
2808        dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue));
2809        LSCPResultSet result;
2810        try {
2811            Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2812            if (!pEffect)
2813                throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2814    
2815            EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex);
2816            if (!pEffectControl)
2817                throw Exception(
2818                    "Effect instance " + ToString(iEffectInstance) +
2819                    " does not have an input control with index " +
2820                    ToString(iInputControlIndex)
2821                );
2822    
2823            pEffectControl->SetValue(dValue);
2824            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance));
2825        } catch (Exception e) {
2826            result.Error(e);
2827        }
2828        return result.Produce();
2829    }
2830    
2831    String LSCPServer::CreateEffectInstance(int iEffectIndex) {
2832        dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex));
2833        LSCPResultSet result;
2834        try {
2835            EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex);
2836            if (!pEffectInfo)
2837                throw Exception("There is no effect with index " + ToString(iEffectIndex));
2838            Effect* pEffect = EffectFactory::Create(pEffectInfo);
2839            result = pEffect->ID(); // success
2840            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2841        } catch (Exception e) {
2842            result.Error(e);
2843        }
2844        return result.Produce();
2845    }
2846    
2847    String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) {
2848        dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str()));
2849        LSCPResultSet result;
2850        try {
2851            // to allow loading the same LSCP session file on different systems
2852            // successfully, probably with different effect plugin DLL paths or even
2853            // running completely different operating systems, we do the following
2854            // for finding the right effect:
2855            //
2856            // first try to search for an exact match of the effect plugin DLL
2857            // (a.k.a 'module'), to avoid picking the wrong DLL with the same
2858            // effect name ...
2859            EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_MATCH_EXACTLY);
2860            // ... if no effect with exactly matchin DLL filename was found, then
2861            // try to lower the restrictions of matching the effect plugin DLL
2862            // filename and try again and again ...
2863            if (!pEffectInfo) {
2864                dmsg(2,("no exact module match, trying MODULE_IGNORE_PATH\n"));
2865                pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH);
2866            }
2867            if (!pEffectInfo) {
2868                dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE\n"));
2869                pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE);
2870            }
2871            if (!pEffectInfo) {
2872                dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE | MODULE_IGNORE_EXTENSION\n"));
2873                pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE | EffectFactory::MODULE_IGNORE_EXTENSION);
2874            }
2875            // ... if there was still no effect found, then completely ignore the
2876            // DLL plugin filename argument and just search for the matching effect
2877            // system type and effect name
2878            if (!pEffectInfo) {
2879                dmsg(2,("no module match, trying MODULE_IGNORE_ALL\n"));
2880                pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_ALL);
2881            }
2882            if (!pEffectInfo)
2883                throw Exception("There is no such effect '" + effectSystem + "' '" + module + "' '" + effectName + "'");
2884    
2885            Effect* pEffect = EffectFactory::Create(pEffectInfo);
2886            result = LSCPResultSet(pEffect->ID());
2887            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2888        } catch (Exception e) {
2889            result.Error(e);
2890        }
2891        return result.Produce();
2892    }
2893    
2894    String LSCPServer::DestroyEffectInstance(int iEffectInstance) {
2895        dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance));
2896        LSCPResultSet result;
2897        try {
2898            Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
2899            if (!pEffect)
2900                throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2901            EffectFactory::Destroy(pEffect);
2902            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2903        } catch (Exception e) {
2904            result.Error(e);
2905        }
2906        return result.Produce();
2907    }
2908    
2909    String LSCPServer::GetEffectInstances() {
2910        dmsg(2,("LSCPServer: GetEffectInstances()\n"));
2911        LSCPResultSet result;
2912        try {
2913            int n = EffectFactory::EffectInstancesCount();
2914            result.Add(n);
2915        } catch (Exception e) {
2916            result.Error(e);
2917        }
2918        return result.Produce();
2919    }
2920    
2921    String LSCPServer::ListEffectInstances() {
2922        dmsg(2,("LSCPServer: ListEffectInstances()\n"));
2923        LSCPResultSet result;
2924        String list;
2925        try {
2926            int n = EffectFactory::EffectInstancesCount();
2927            for (int i = 0; i < n; i++) {
2928                Effect* pEffect = EffectFactory::GetEffectInstance(i);
2929                if (i) list += ",";
2930                list += ToString(pEffect->ID());
2931            }
2932        } catch (Exception e) {
2933            result.Error(e);
2934        }
2935        result.Add(list);
2936        return result.Produce();
2937    }
2938    
2939    String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) {
2940        dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice));
2941        LSCPResultSet result;
2942        try {
2943            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2944            if (!devices.count(iAudioOutputDevice))
2945                throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2946            AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2947            int n = pDevice->SendEffectChainCount();
2948            result.Add(n);
2949        } catch (Exception e) {
2950            result.Error(e);
2951        }
2952        return result.Produce();
2953    }
2954    
2955    String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) {
2956        dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice));
2957        LSCPResultSet result;
2958        String list;
2959        try {
2960            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2961            if (!devices.count(iAudioOutputDevice))
2962                throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2963            AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2964            int n = pDevice->SendEffectChainCount();
2965            for (int i = 0; i < n; i++) {
2966                EffectChain* pEffectChain = pDevice->SendEffectChain(i);
2967                if (i) list += ",";
2968                list += ToString(pEffectChain->ID());
2969            }
2970        } catch (Exception e) {
2971            result.Error(e);
2972        }
2973        result.Add(list);
2974        return result.Produce();
2975    }
2976    
2977    String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) {
2978        dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice));
2979        LSCPResultSet result;
2980        try {
2981            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2982            if (!devices.count(iAudioOutputDevice))
2983                throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2984            AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2985            EffectChain* pEffectChain = pDevice->AddSendEffectChain();
2986            result = pEffectChain->ID();
2987            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
2988        } catch (Exception e) {
2989            result.Error(e);
2990        }
2991        return result.Produce();
2992    }
2993    
2994    String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) {
2995        dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain));
2996        LSCPResultSet result;
2997        try {
2998            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2999            if (!devices.count(iAudioOutputDevice))
3000                throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
3001    
3002            std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
3003            std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
3004            std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
3005            for (; itEngineChannel != itEnd; ++itEngineChannel) {
3006                AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice();
3007                if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) {
3008                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
3009                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
3010                        if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) {
3011                            throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index()));
3012                        }
3013                    }
3014                }
3015            }
3016    
3017            AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
3018            for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {
3019                EffectChain* pEffectChain = pDevice->SendEffectChain(i);
3020                if (pEffectChain->ID() == iSendEffectChain) {
3021                    pDevice->RemoveSendEffectChain(i);
3022                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
3023                    return result.Produce();
3024                }
3025            }
3026            throw Exception(
3027                "There is no send effect chain with ID " +
3028                ToString(iSendEffectChain) + " for audio output device " +
3029                ToString(iAudioOutputDevice) + "."
3030            );
3031        } catch (Exception e) {
3032            result.Error(e);
3033        }
3034        return result.Produce();
3035    }
3036    
3037    static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) {
3038        std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
3039        if (!devices.count(iAudioOutputDevice))
3040            throw Exception(
3041                "There is no audio output device with index " +
3042                ToString(iAudioOutputDevice) + "."
3043            );
3044        AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
3045        EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain);
3046        if(pEffectChain != NULL) return pEffectChain;
3047        throw Exception(
3048            "There is no send effect chain with ID " +
3049            ToString(iSendEffectChain) + " for audio output device " +
3050            ToString(iAudioOutputDevice) + "."
3051        );
3052    }
3053    
3054    String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) {
3055        dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain));
3056        LSCPResultSet result;
3057        try {
3058            EffectChain* pEffectChain =
3059                _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3060            String sEffectSequence;
3061            for (int i = 0; i < pEffectChain->EffectCount(); i++) {
3062                if (i) sEffectSequence += ",";
3063                sEffectSequence += ToString(pEffectChain->GetEffect(i)->ID());
3064            }
3065            result.Add("EFFECT_COUNT", pEffectChain->EffectCount());
3066            result.Add("EFFECT_SEQUENCE", sEffectSequence);
3067        } catch (Exception e) {
3068            result.Error(e);
3069        }
3070        return result.Produce();
3071    }
3072    
3073    String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) {
3074        dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance));
3075        LSCPResultSet result;
3076        try {
3077            EffectChain* pEffectChain =
3078                _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3079            Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
3080            if (!pEffect)
3081                throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
3082            pEffectChain->AppendEffect(pEffect);
3083            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3084        } catch (Exception e) {
3085            result.Error(e);
3086        }
3087        return result.Produce();
3088    }
3089    
3090    String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) {
3091        dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance));
3092        LSCPResultSet result;
3093        try {
3094            EffectChain* pEffectChain =
3095                _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3096            Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance);
3097            if (!pEffect)
3098                throw Exception("There is no effect instance with index " + ToString(iEffectInstance));
3099            pEffectChain->InsertEffect(pEffect, iEffectChainPosition);
3100            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3101        } catch (Exception e) {
3102            result.Error(e);
3103        }
3104        return result.Produce();
3105    }
3106    
3107    String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) {
3108        dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition));
3109        LSCPResultSet result;
3110        try {
3111            EffectChain* pEffectChain =
3112                _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
3113    
3114            std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
3115            std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
3116            std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
3117            for (; itEngineChannel != itEnd; ++itEngineChannel) {
3118                AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice();
3119                if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) {
3120                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
3121                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
3122                        if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) {
3123                            throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index()));
3124                        }
3125                    }
3126                }
3127            }
3128    
3129            pEffectChain->RemoveEffect(iEffectChainPosition);
3130            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3131        } catch (Exception e) {
3132            result.Error(e);
3133        }
3134        return result.Produce();
3135    }
3136    
3137  String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {  String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
3138      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
3139      LSCPResultSet result;      LSCPResultSet result;
# Line 2497  String LSCPServer::SendChannelMidiData(S Line 3182  String LSCPServer::SendChannelMidiData(S
3182              pMidiDevice->SendNoteOffToDevice(Arg1, Arg2);              pMidiDevice->SendNoteOffToDevice(Arg1, Arg2);
3183              bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2);              bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2);
3184              if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));              if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
3185            } else if (MidiMsg == "CC") {
3186                pMidiDevice->SendCCToDevice(Arg1, Arg2);
3187                bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2);
3188                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
3189          } else {          } else {
3190              throw Exception("Unknown MIDI message type: " + MidiMsg);              throw Exception("Unknown MIDI message type: " + MidiMsg);
3191          }          }
# Line 2579  String LSCPServer::GetTotalVoiceCount() Line 3268  String LSCPServer::GetTotalVoiceCount()
3268  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
3269      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
3270      LSCPResultSet result;      LSCPResultSet result;
3271      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices());
3272      return result.Produce();      return result.Produce();
3273  }  }
3274    
# Line 2590  String LSCPServer::GetTotalVoiceCountMax Line 3279  String LSCPServer::GetTotalVoiceCountMax
3279  String LSCPServer::GetGlobalMaxVoices() {  String LSCPServer::GetGlobalMaxVoices() {
3280      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
3281      LSCPResultSet result;      LSCPResultSet result;
3282      result.Add(GLOBAL_MAX_VOICES);      result.Add(pSampler->GetGlobalMaxVoices());
3283      return result.Produce();      return result.Produce();
3284  }  }
3285    
# Line 2602  String LSCPServer::SetGlobalMaxVoices(in Line 3291  String LSCPServer::SetGlobalMaxVoices(in
3291      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
3292      LSCPResultSet result;      LSCPResultSet result;
3293      try {      try {
3294          if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");          pSampler->SetGlobalMaxVoices(iVoices);
3295          GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3296          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices())
3297          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));  
3298      } catch (Exception e) {      } catch (Exception e) {
3299          result.Error(e);          result.Error(e);
3300      }      }
# Line 2626  String LSCPServer::SetGlobalMaxVoices(in Line 3308  String LSCPServer::SetGlobalMaxVoices(in
3308  String LSCPServer::GetGlobalMaxStreams() {  String LSCPServer::GetGlobalMaxStreams() {
3309      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
3310      LSCPResultSet result;      LSCPResultSet result;
3311      result.Add(GLOBAL_MAX_STREAMS);      result.Add(pSampler->GetGlobalMaxStreams());
3312      return result.Produce();      return result.Produce();
3313  }  }
3314    
# Line 2638  String LSCPServer::SetGlobalMaxStreams(i Line 3320  String LSCPServer::SetGlobalMaxStreams(i
3320      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
3321      LSCPResultSet result;      LSCPResultSet result;
3322      try {      try {
3323          if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");          pSampler->SetGlobalMaxStreams(iStreams);
3324          GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3325          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams())
3326          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));  
3327      } catch (Exception e) {      } catch (Exception e) {
3328          result.Error(e);          result.Error(e);
3329      }      }
# Line 2852  void LSCPServer::VerifyFile(String Filen Line 3527  void LSCPServer::VerifyFile(String Filen
3527  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {
3528      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
3529      LSCPResultSet result;      LSCPResultSet result;
3530      SubscriptionMutex.Lock();      {
3531      eventSubscriptions[type].push_back(currentSocket);          LockGuard lock(SubscriptionMutex);
3532      SubscriptionMutex.Unlock();          eventSubscriptions[type].push_back(currentSocket);
3533        }
3534      return result.Produce();      return result.Produce();
3535  }  }
3536    
# Line 2865  String LSCPServer::SubscribeNotification Line 3541  String LSCPServer::SubscribeNotification
3541  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {
3542      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
3543      LSCPResultSet result;      LSCPResultSet result;
3544      SubscriptionMutex.Lock();      {
3545      eventSubscriptions[type].remove(currentSocket);          LockGuard lock(SubscriptionMutex);
3546      SubscriptionMutex.Unlock();          eventSubscriptions[type].remove(currentSocket);
3547        }
3548      return result.Produce();      return result.Produce();
3549  }  }
3550    
# Line 3392  String LSCPServer::SetEcho(yyparse_param Line 4069  String LSCPServer::SetEcho(yyparse_param
4069      }      }
4070      return result.Produce();      return result.Produce();
4071  }  }
4072    
4073    String LSCPServer::SetShellInteract(yyparse_param_t* pSession, double boolean_value) {
4074        dmsg(2,("LSCPServer: SetShellInteract(val=%f)\n", boolean_value));
4075        LSCPResultSet result;
4076        try {
4077            if      (boolean_value == 0) pSession->bShellInteract = false;
4078            else if (boolean_value == 1) pSession->bShellInteract = true;
4079            else throw Exception("Not a boolean value, must either be 0 or 1");
4080        } catch (Exception e) {
4081            result.Error(e);
4082        }
4083        return result.Produce();
4084    }
4085    
4086    String LSCPServer::SetShellAutoCorrect(yyparse_param_t* pSession, double boolean_value) {
4087        dmsg(2,("LSCPServer: SetShellAutoCorrect(val=%f)\n", boolean_value));
4088        LSCPResultSet result;
4089        try {
4090            if      (boolean_value == 0) pSession->bShellAutoCorrect = false;
4091            else if (boolean_value == 1) pSession->bShellAutoCorrect = true;
4092            else throw Exception("Not a boolean value, must either be 0 or 1");
4093        } catch (Exception e) {
4094            result.Error(e);
4095        }
4096        return result.Produce();
4097    }
4098    
4099    String LSCPServer::SetShellDoc(yyparse_param_t* pSession, double boolean_value) {
4100        dmsg(2,("LSCPServer: SetShellDoc(val=%f)\n", boolean_value));
4101        LSCPResultSet result;
4102        try {
4103            if      (boolean_value == 0) pSession->bShellSendLSCPDoc = false;
4104            else if (boolean_value == 1) pSession->bShellSendLSCPDoc = true;
4105            else throw Exception("Not a boolean value, must either be 0 or 1");
4106        } catch (Exception e) {
4107            result.Error(e);
4108        }
4109        return result.Produce();
4110    }
4111    
4112  }  }

Legend:
Removed from v.1897  
changed lines
  Added in v.2534

  ViewVC Help
Powered by ViewVC