/[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 2531 by schoenebeck, Wed Mar 5 00:02:21 2014 UTC revision 2837 by persson, Sun Aug 23 06:14:00 2015 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 - 2014 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2015 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 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.
# Line 750  bool LSCPServer::GetLSCPCommand( std::ve Line 783  bool LSCPServer::GetLSCPCommand( std::ve
783                                  String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false);                                  String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false);
784                                  if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n");                                  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));                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
793                          bufferedCommands[socket] += "\r\n";                          bufferedCommands[socket] += "\r\n";
794                          return true; //Complete command was read                          return true; //Complete command was read
# Line 772  bool LSCPServer::GetLSCPCommand( std::ve Line 810  bool LSCPServer::GetLSCPCommand( std::ve
810                                          bufferedCommands[socket] += c; // append                                          bufferedCommands[socket] += c; // append
811                          }                          }
812                  }                  }
813                  // only if the other side is the LSCP shell application:                  // Only if the other side (client) is the LSCP shell application:
814                  // check the current (incomplete) command line for syntax errors,                  // The following block takes care about automatic correction, auto
815                  // possible completions and report everything back to the shell                  // completion (and suggestions), LSCP reference documentation, etc.
816                  if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {                  // The "if" statement here is for optimization reasons, so that the
817                          String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), true);                  // heavy LSCP grammar evaluation algorithm is only executed once for an
818                          if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1)                  // entire command line received.
819                                  AnswerClient(s + "\n");                  if (i == input.size() - 1) {
820                            // check the current (incomplete) command line for syntax errors,
821                            // possible completions and report everything back to the shell
822                            if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) {
823                                    String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), true);
824                                    if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1)
825                                            AnswerClient(s + "\n");
826                            }
827                            // if other side is LSCP shell application, send the relevant LSCP
828                            // documentation section of the current command line (if necessary)
829                            if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) {
830                                    String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter));
831                                    if (!s.empty()) AnswerClient(s + "\n");
832                            }
833                  }                  }
834          }          }
835    
# Line 1398  String LSCPServer::GetAudioOutputDriverI Line 1449  String LSCPServer::GetAudioOutputDriverI
1449  }  }
1450    
1451  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
1452      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),int(DependencyList.size())));
1453      LSCPResultSet result;      LSCPResultSet result;
1454      try {      try {
1455          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 1426  String LSCPServer::GetMidiInputDriverPar Line 1477  String LSCPServer::GetMidiInputDriverPar
1477  }  }
1478    
1479  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
1480      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),int(DependencyList.size())));
1481      LSCPResultSet result;      LSCPResultSet result;
1482      try {      try {
1483          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 1583  String LSCPServer::GetMidiInputPortInfo( Line 1634  String LSCPServer::GetMidiInputPortInfo(
1634  }  }
1635    
1636  String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {  String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
1637      dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));      dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%u,ChannelId=%u)\n",DeviceId,ChannelId));
1638      LSCPResultSet result;      LSCPResultSet result;
1639      try {      try {
1640          // get audio output device          // get audio output device
# Line 3102  String LSCPServer::EditSamplerChannelIns Line 3153  String LSCPServer::EditSamplerChannelIns
3153          InstrumentManager::instrument_id_t instrumentID;          InstrumentManager::instrument_id_t instrumentID;
3154          instrumentID.FileName = pEngineChannel->InstrumentFileName();          instrumentID.FileName = pEngineChannel->InstrumentFileName();
3155          instrumentID.Index    = pEngineChannel->InstrumentIndex();          instrumentID.Index    = pEngineChannel->InstrumentIndex();
3156          pInstrumentManager->LaunchInstrumentEditor(instrumentID);          pInstrumentManager->LaunchInstrumentEditor(pEngineChannel, instrumentID);
3157      } catch (Exception e) {      } catch (Exception e) {
3158          result.Error(e);          result.Error(e);
3159      }      }
# Line 4048  String LSCPServer::SetShellAutoCorrect(y Line 4099  String LSCPServer::SetShellAutoCorrect(y
4099          else throw Exception("Not a boolean value, must either be 0 or 1");          else throw Exception("Not a boolean value, must either be 0 or 1");
4100      } catch (Exception e) {      } catch (Exception e) {
4101          result.Error(e);          result.Error(e);
4102        }
4103        return result.Produce();
4104    }
4105    
4106    String LSCPServer::SetShellDoc(yyparse_param_t* pSession, double boolean_value) {
4107        dmsg(2,("LSCPServer: SetShellDoc(val=%f)\n", boolean_value));
4108        LSCPResultSet result;
4109        try {
4110            if      (boolean_value == 0) pSession->bShellSendLSCPDoc = false;
4111            else if (boolean_value == 1) pSession->bShellSendLSCPDoc = true;
4112            else throw Exception("Not a boolean value, must either be 0 or 1");
4113        } catch (Exception e) {
4114            result.Error(e);
4115      }      }
4116      return result.Produce();      return result.Produce();
4117  }  }

Legend:
Removed from v.2531  
changed lines
  Added in v.2837

  ViewVC Help
Powered by ViewVC