/[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 2138 by schoenebeck, Mon Oct 4 22:11:53 2010 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 - 2010 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, 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 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 716  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 804  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 962  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 1005  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 1018  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 1063  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 1722  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 2393  String LSCPServer::GetFxSendInfo(uint ui Line 2604  String LSCPServer::GetFxSendInfo(uint ui
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("SEND_EFFECT", sEffectRouting);          result.Add("EFFECT", sEffectRouting);
2608      } catch (Exception e) {      } catch (Exception e) {
2609          result.Error(e);          result.Error(e);
2610      }      }
# Line 2610  String LSCPServer::SetEffectInstanceInpu Line 2821  String LSCPServer::SetEffectInstanceInpu
2821              );              );
2822    
2823          pEffectControl->SetValue(dValue);          pEffectControl->SetValue(dValue);
2824            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance));
2825      } catch (Exception e) {      } catch (Exception e) {
2826          result.Error(e);          result.Error(e);
2827      }      }
# Line 2625  String LSCPServer::CreateEffectInstance( Line 2837  String LSCPServer::CreateEffectInstance(
2837              throw Exception("There is no effect with index " + ToString(iEffectIndex));              throw Exception("There is no effect with index " + ToString(iEffectIndex));
2838          Effect* pEffect = EffectFactory::Create(pEffectInfo);          Effect* pEffect = EffectFactory::Create(pEffectInfo);
2839          result = pEffect->ID(); // success          result = pEffect->ID(); // success
2840            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2841      } catch (Exception e) {      } catch (Exception e) {
2842          result.Error(e);          result.Error(e);
2843      }      }
# Line 2671  String LSCPServer::CreateEffectInstance( Line 2884  String LSCPServer::CreateEffectInstance(
2884    
2885          Effect* pEffect = EffectFactory::Create(pEffectInfo);          Effect* pEffect = EffectFactory::Create(pEffectInfo);
2886          result = LSCPResultSet(pEffect->ID());          result = LSCPResultSet(pEffect->ID());
2887            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2888      } catch (Exception e) {      } catch (Exception e) {
2889          result.Error(e);          result.Error(e);
2890      }      }
# Line 2685  String LSCPServer::DestroyEffectInstance Line 2899  String LSCPServer::DestroyEffectInstance
2899          if (!pEffect)          if (!pEffect)
2900              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2901          EffectFactory::Destroy(pEffect);          EffectFactory::Destroy(pEffect);
2902            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2903      } catch (Exception e) {      } catch (Exception e) {
2904          result.Error(e);          result.Error(e);
2905      }      }
# Line 2769  String LSCPServer::AddSendEffectChain(in Line 2984  String LSCPServer::AddSendEffectChain(in
2984          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2985          EffectChain* pEffectChain = pDevice->AddSendEffectChain();          EffectChain* pEffectChain = pDevice->AddSendEffectChain();
2986          result = pEffectChain->ID();          result = pEffectChain->ID();
2987            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
2988      } catch (Exception e) {      } catch (Exception e) {
2989          result.Error(e);          result.Error(e);
2990      }      }
# Line 2782  String LSCPServer::RemoveSendEffectChain Line 2998  String LSCPServer::RemoveSendEffectChain
2998          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2999          if (!devices.count(iAudioOutputDevice))          if (!devices.count(iAudioOutputDevice))
3000              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              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];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
3018          for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {          for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {
3019              EffectChain* pEffectChain = pDevice->SendEffectChain(i);              EffectChain* pEffectChain = pDevice->SendEffectChain(i);
3020              if (pEffectChain->ID() == iSendEffectChain) {              if (pEffectChain->ID() == iSendEffectChain) {
3021                  pDevice->RemoveSendEffectChain(i);                  pDevice->RemoveSendEffectChain(i);
3022                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
3023                  return result.Produce();                  return result.Produce();
3024              }              }
3025          }          }
# Line 2809  static EffectChain* _getSendEffectChain( Line 3042  static EffectChain* _getSendEffectChain(
3042              ToString(iAudioOutputDevice) + "."              ToString(iAudioOutputDevice) + "."
3043          );          );
3044      AudioOutputDevice* pDevice = devices[iAudioOutputDevice];      AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
3045      for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {      EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain);
3046          EffectChain* pEffectChain = pDevice->SendEffectChain(i);      if(pEffectChain != NULL) return pEffectChain;
         if (pEffectChain->ID() == iSendEffectChain) {  
             return pEffectChain;  
         }  
     }  
3047      throw Exception(      throw Exception(
3048          "There is no send effect chain with ID " +          "There is no send effect chain with ID " +
3049          ToString(iSendEffectChain) + " for audio output device " +          ToString(iSendEffectChain) + " for audio output device " +
# Line 2851  String LSCPServer::AppendSendEffectChain Line 3080  String LSCPServer::AppendSendEffectChain
3080          if (!pEffect)          if (!pEffect)
3081              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
3082          pEffectChain->AppendEffect(pEffect);          pEffectChain->AppendEffect(pEffect);
3083            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3084      } catch (Exception e) {      } catch (Exception e) {
3085          result.Error(e);          result.Error(e);
3086      }      }
# Line 2867  String LSCPServer::InsertSendEffectChain Line 3097  String LSCPServer::InsertSendEffectChain
3097          if (!pEffect)          if (!pEffect)
3098              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));
3099          pEffectChain->InsertEffect(pEffect, iEffectChainPosition);          pEffectChain->InsertEffect(pEffect, iEffectChainPosition);
3100            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3101      } catch (Exception e) {      } catch (Exception e) {
3102          result.Error(e);          result.Error(e);
3103      }      }
# Line 2879  String LSCPServer::RemoveSendEffectChain Line 3110  String LSCPServer::RemoveSendEffectChain
3110      try {      try {
3111          EffectChain* pEffectChain =          EffectChain* pEffectChain =
3112              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);              _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);          pEffectChain->RemoveEffect(iEffectChainPosition);
3130            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
3131      } catch (Exception e) {      } catch (Exception e) {
3132          result.Error(e);          result.Error(e);
3133      }      }
# Line 3020  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 3031  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 3043  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 3067  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 3079  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 3293  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 3306  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 3833  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.2138  
changed lines
  Added in v.2534

  ViewVC Help
Powered by ViewVC