/[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 185 by senkov, Wed Jul 7 02:49:51 2004 UTC revision 337 by senkov, Sun Jan 9 02:26:29 2005 UTC
# Line 25  Line 25 
25  #include "lscpevent.h"  #include "lscpevent.h"
26    
27  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
28  #include "../audiodriver/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
29  #include "../mididriver/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
30    
31  /**  /**
32   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
# Line 43  Line 43 
43   */   */
44  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
45  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
46  std::vector<int> LSCPServer::hSessions = std::vector<int>();  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();
47  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
48  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
49  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 = std::map< LSCPEvent::event_t, std::list<int> >();
# Line 61  LSCPServer::LSCPServer(Sampler* pSampler Line 61  LSCPServer::LSCPServer(Sampler* pSampler
61      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
62  }  }
63    
64    /**
65     * Blocks the calling thread until the LSCP Server is initialized and
66     * accepting socket connections, if the server is already initialized then
67     * this method will return immediately.
68     * @param TimeoutSeconds     - optional: max. wait time in seconds
69     *                             (default: 0s)
70     * @param TimeoutNanoSeconds - optional: max wait time in nano seconds
71     *                             (default: 0ns)
72     * @returns  0 on success, a value less than 0 if timeout exceeded
73     */
74    int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) {
75        return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds);
76    }
77    
78  int LSCPServer::Main() {  int LSCPServer::Main() {
79      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      int hSocket = socket(AF_INET, SOCK_STREAM, 0);
80      if (hSocket < 0) {      if (hSocket < 0) {
# Line 74  int LSCPServer::Main() { Line 88  int LSCPServer::Main() {
88      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
89    
90      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
91          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";
92          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
93          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
94          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
95                        std::cerr << "gave up!" << std::endl;
96                        close(hSocket);
97                        //return -1;
98                        exit(EXIT_FAILURE);
99                    }
100                    else sleep(1); // sleep 1s
101                }
102                else break; // success
103            }
104      }      }
105    
106      listen(hSocket, 1);      listen(hSocket, 1);
107      dmsg(1,("LSCPServer: Server running.\n")); // server running      Initialized.Set(true);
108    
109      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
110      sockaddr_in client;      sockaddr_in client;
111      int length = sizeof(client);      int length = sizeof(client);
     struct timeval tv;  
     tv.tv_sec = 30;  
     tv.tv_usec = 0;  
112      FD_ZERO(&fdSet);      FD_ZERO(&fdSet);
113      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
114      int maxSessions = hSocket;      int maxSessions = hSocket;
   
     // Parser initialization  
     yyparse_param_t yyparse_param;  
     yyparse_param.pServer = this;  
115    
116      while (true) {      while (true) {
117          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
118          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);
119          if (retval == 0)          if (retval == 0)
120                  continue; //Nothing in 30 seconds, try again                  continue; //Nothing try again
121          if (retval == -1) {          if (retval == -1) {
122                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
123                  close(hSocket);                  close(hSocket);
124                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
125          }          }
126            
127          //Accept new connections now (if any)          //Accept new connections now (if any)
128          if (FD_ISSET(hSocket, &selectSet)) {          if (FD_ISSET(hSocket, &selectSet)) {
129                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);
# Line 121  int LSCPServer::Main() { Line 137  int LSCPServer::Main() {
137                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
138                  }                  }
139    
140                  hSessions.push_back(socket);                  // Parser initialization
141                    yyparse_param_t yyparse_param;
142                    yyparse_param.pServer  = this;
143                    yyparse_param.hSession = socket;
144    
145                    Sessions.push_back(yyparse_param);
146                  FD_SET(socket, &fdSet);                  FD_SET(socket, &fdSet);
147                  if (socket > maxSessions)                  if (socket > maxSessions)
148                          maxSessions = socket;                          maxSessions = socket;
# Line 131  int LSCPServer::Main() { Line 152  int LSCPServer::Main() {
152          }          }
153    
154          //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.
155          for (std::vector<int>::iterator iter = hSessions.begin(); iter !=  hSessions.end(); iter++) {          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {
156                  if (FD_ISSET(*iter, &selectSet)) {      //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
157                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
158                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
159                                  yylex_init(&yyparse_param.pScanner);                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
160                                  currentSocket = *iter;  //a hack                                  restart(NULL, dummy); // restart the 'scanner'
161                                  int result = yyparse(&yyparse_param);                                  currentSocket = (*iter).hSession;  //a hack
162                                    if ((*iter).bVerbose) { // if echo mode enabled
163                                        AnswerClient(bufferedCommands[currentSocket]);
164                                    }
165                                    int result = yyparse(&(*iter));
166                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
167                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
168                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?
# Line 146  int LSCPServer::Main() { Line 171  int LSCPServer::Main() {
171                          }                          }
172                          //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.
173                          //we'll be back if there is data.                          //we'll be back if there is data.
174                          break;                          break;
175                  }                  }
176          }          }
177    
# Line 158  int LSCPServer::Main() { Line 183  int LSCPServer::Main() {
183          }          }
184          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
185      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
186  }  }
187    
188  void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
189          int socket = *iter;          int socket = (*iter).hSession;
190          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));
191          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
192          hSessions.erase(iter);          Sessions.erase(iter);
193          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
194          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)
195          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {
# Line 230  extern int GetLSCPCommand( void *buf, in Line 253  extern int GetLSCPCommand( void *buf, in
253   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
254   * 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.
255   */   */
256  bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
257          int socket = *iter;          int socket = (*iter).hSession;
258          char c;          char c;
259          int i = 0;          int i = 0;
260          while (true) {          while (true) {
# Line 241  bool LSCPServer::GetLSCPCommand( std::ve Line 264  bool LSCPServer::GetLSCPCommand( std::ve
264                          break;                          break;
265                  }                  }
266                  if (result == 1) {                  if (result == 1) {
267                          if (c == '\r')                          if (c == '\r')
268                                  continue; //Ignore CR                                  continue; //Ignore CR
269                          if (c == '\n') {                          if (c == '\n') {
270                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
# Line 268  bool LSCPServer::GetLSCPCommand( std::ve Line 291  bool LSCPServer::GetLSCPCommand( std::ve
291                                          break;                                          break;
292                                  case EAGAIN:                                  case EAGAIN:
293                                          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"));                                          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"));
294                                          break;                                          break;
295                                  case EINTR:                                  case EINTR:
296                                          dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));                                          dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));
297                                          break;                                          break;
298                                  case EFAULT:                                  case EFAULT:
299                                          dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));                                          dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));
300                                          break;                                          break;
301                                  case EINVAL:                                  case EINVAL:
302                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
303                                          break;                                          break;
304                                  case ENOMEM:                                  case ENOMEM:
305                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
306                                          break;                                          break;
307                                  default:                                  default:
308                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
309                                          break;                                          break;
310                          }                          }
311                          CloseConnection(iter);                          CloseConnection(iter);
312                          break;                          break;
313                  }                  }
# Line 376  String LSCPServer::DestroyAudioOutputDev Line 399  String LSCPServer::DestroyAudioOutputDev
399      LSCPResultSet result;      LSCPResultSet result;
400      try {      try {
401          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
402          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
403          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
404          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
405      }      }
# Line 391  String LSCPServer::DestroyMidiInputDevic Line 414  String LSCPServer::DestroyMidiInputDevic
414      LSCPResultSet result;      LSCPResultSet result;
415      try {      try {
416          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
417            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
418          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
419          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
420      }      }
421      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 412  String LSCPServer::LoadInstrument(String Line 435  String LSCPServer::LoadInstrument(String
435          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
436          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
437          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
438          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
439              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device on channel");
440          if (bBackground) {          if (bBackground) {
441              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
# Line 457  String LSCPServer::GetChannels() { Line 480  String LSCPServer::GetChannels() {
480  }  }
481    
482  /**  /**
483     * Will be called by the parser to get the list of sampler channels.
484     */
485    String LSCPServer::ListChannels() {
486        dmsg(2,("LSCPServer: ListChannels()\n"));
487        String list;
488        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
489        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
490        for (; iter != channels.end(); iter++) {
491            if (list != "") list += ",";
492            list += ToString(iter->first);
493        }
494        LSCPResultSet result;
495        result.Add(list);
496        return result.Produce();
497    }
498    
499    /**
500   * Will be called by the parser to add a sampler channel.   * Will be called by the parser to add a sampler channel.
501   */   */
502  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
# Line 494  String LSCPServer::GetEngineInfo(String Line 534  String LSCPServer::GetEngineInfo(String
534      try {      try {
535          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
536              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
537              result.Add(pEngine->Description());              result.Add("DESCRIPTION", pEngine->Description());
538              result.Add(pEngine->Version());              result.Add("VERSION",     pEngine->Version());
539              delete pEngine;              delete pEngine;
540          }          }
541          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
# Line 520  String LSCPServer::GetChannelInfo(uint u Line 560  String LSCPServer::GetChannelInfo(uint u
560    
561          //Defaults values          //Defaults values
562          String EngineName = "NONE";          String EngineName = "NONE";
563          float Volume = 0;          float Volume = 0.0f;
564          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
565          int InstrumentIndex = -1;          int InstrumentIndex = -1;
566          int InstrumentStatus = -1;          int InstrumentStatus = -1;
567            int AudioOutputChannels = 0;
568            String AudioRouting;
569    
570          if (pEngine) {          if (pEngine) {
571              EngineName =  pEngine->EngineName();              EngineName =  pEngine->EngineName();
572                AudioOutputChannels = pEngine->Channels();
573              Volume = pEngine->Volume();              Volume = pEngine->Volume();
574              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus = pEngine->InstrumentStatus();
575              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex = pEngine->InstrumentIndex();
576              if (InstrumentIndex != -1)              if (InstrumentIndex != -1)
577                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
578                for (int chan = 0; chan < pEngine->Channels(); chan++) {
579                    if (AudioRouting != "") AudioRouting += ",";
580                    AudioRouting += ToString(pEngine->OutputChannel(chan));
581                }
582          }          }
583    
584          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 539  String LSCPServer::GetChannelInfo(uint u Line 586  String LSCPServer::GetChannelInfo(uint u
586    
587          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
588          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
589          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
590          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
591    
592          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
593          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
594          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
595            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
596    
597          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
598          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
# Line 704  String LSCPServer::GetAudioOutputDriverI Line 752  String LSCPServer::GetAudioOutputDriverI
752  }  }
753    
754  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
755      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));
756      LSCPResultSet result;      LSCPResultSet result;
757      try {      try {
758          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 713  String LSCPServer::GetMidiInputDriverPar Line 761  String LSCPServer::GetMidiInputDriverPar
761          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
762          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
763          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
764          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
765          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
766          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
767          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
768          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
769            if (oDepends)       result.Add("DEPENDS",       *oDepends);
770            if (oDefault)       result.Add("DEFAULT",       *oDefault);
771            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
772            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
773            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
774      }      }
775      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
776          result.Error(e);          result.Error(e);
# Line 726  String LSCPServer::GetMidiInputDriverPar Line 779  String LSCPServer::GetMidiInputDriverPar
779  }  }
780    
781  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
782      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));
783      LSCPResultSet result;      LSCPResultSet result;
784      try {      try {
785          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 735  String LSCPServer::GetAudioOutputDriverP Line 788  String LSCPServer::GetAudioOutputDriverP
788          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
789          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
790          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
791          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
792          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
793          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
794          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
795          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
796            if (oDepends)       result.Add("DEPENDS",       *oDepends);
797            if (oDefault)       result.Add("DEFAULT",       *oDefault);
798            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
799            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
800            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
801      }      }
802      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
803          result.Error(e);          result.Error(e);
# Line 816  String LSCPServer::GetAudioOutputDeviceI Line 874  String LSCPServer::GetAudioOutputDeviceI
874      LSCPResultSet result;      LSCPResultSet result;
875      try {      try {
876          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
877          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
878          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
879          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
880          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
881          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
882          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 836  String LSCPServer::GetMidiInputDeviceInf Line 894  String LSCPServer::GetMidiInputDeviceInf
894      LSCPResultSet result;      LSCPResultSet result;
895      try {      try {
896          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
897            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
898          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
899          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
900          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
901          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
902          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 854  String LSCPServer::GetMidiInputPortInfo( Line 912  String LSCPServer::GetMidiInputPortInfo(
912      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
913      LSCPResultSet result;      LSCPResultSet result;
914      try {      try {
915            // get MIDI input device
916          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
917            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
918          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
919          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
920          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
921          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
922          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
923          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
924            // return the values of all MIDI port parameters
925            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
926            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
927          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
928              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
929          }          }
# Line 877  String LSCPServer::GetAudioOutputChannel Line 940  String LSCPServer::GetAudioOutputChannel
940      try {      try {
941          // get audio output device          // get audio output device
942          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
943          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
944          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
945    
946          // get audio channel          // get audio channel
# Line 901  String LSCPServer::GetMidiInputPortParam Line 964  String LSCPServer::GetMidiInputPortParam
964      dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));      dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));
965      LSCPResultSet result;      LSCPResultSet result;
966      try {      try {
967          // get audio output device          // get MIDI input device
968          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
969          if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");
970          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
971    
972          // get midi port          // get midi port
973          MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
974          if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");          if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");
975    
976          // get desired port parameter          // get desired port parameter
977          std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
978          if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'.");
979          DeviceCreationParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
980            
981          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
982          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
983          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
984          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
985          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
986          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
987          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
988          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
989      }      }
990      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
991          result.Error(e);          result.Error(e);
# Line 936  String LSCPServer::GetAudioOutputChannel Line 999  String LSCPServer::GetAudioOutputChannel
999      try {      try {
1000          // get audio output device          // get audio output device
1001          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1002          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
1003          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1004    
1005          // get audio channel          // get audio channel
# Line 945  String LSCPServer::GetAudioOutputChannel Line 1008  String LSCPServer::GetAudioOutputChannel
1008    
1009          // get desired audio channel parameter          // get desired audio channel parameter
1010          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1011          if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
1012          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1013    
1014          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 953  String LSCPServer::GetAudioOutputChannel Line 1016  String LSCPServer::GetAudioOutputChannel
1016          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1017          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1018          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1019          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1020          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1021          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1022      }      }
1023      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1024          result.Error(e);          result.Error(e);
# Line 969  String LSCPServer::SetAudioOutputChannel Line 1032  String LSCPServer::SetAudioOutputChannel
1032      try {      try {
1033          // get audio output device          // get audio output device
1034          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1035          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
1036          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1037    
1038          // get audio channel          // get audio channel
# Line 978  String LSCPServer::SetAudioOutputChannel Line 1041  String LSCPServer::SetAudioOutputChannel
1041    
1042          // get desired audio channel parameter          // get desired audio channel parameter
1043          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1044          if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
1045          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1046    
1047          // set new channel parameter value          // set new channel parameter value
# Line 995  String LSCPServer::SetAudioOutputDeviceP Line 1058  String LSCPServer::SetAudioOutputDeviceP
1058      LSCPResultSet result;      LSCPResultSet result;
1059      try {      try {
1060          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1061          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1062          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1063          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1064          if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1065          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1066      }      }
1067      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1012  String LSCPServer::SetMidiInputDevicePar Line 1075  String LSCPServer::SetMidiInputDevicePar
1075      LSCPResultSet result;      LSCPResultSet result;
1076      try {      try {
1077          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1078          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1079          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1080          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1081          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1082          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1083      }      }
1084      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1028  String LSCPServer::SetMidiInputPortParam Line 1091  String LSCPServer::SetMidiInputPortParam
1091      dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));      dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
1092      LSCPResultSet result;      LSCPResultSet result;
1093      try {      try {
1094            // get MIDI input device
1095          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1096            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1097          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1098          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1099          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1100          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1101          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1102          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1103            // set port parameter value
1104            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1105            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1106          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1107      }      }
1108      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1049  String LSCPServer::SetMidiInputPortParam Line 1117  String LSCPServer::SetMidiInputPortParam
1117   */   */
1118  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1119      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));
1120      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1121        try {
1122            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1123            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1124            Engine* pEngine = pSamplerChannel->GetEngine();
1125            if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));
1126            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1127            if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel));
1128            pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1129        }
1130        catch (LinuxSamplerException e) {
1131             result.Error(e);
1132        }
1133        return result.Produce();
1134  }  }
1135    
1136  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1059  String LSCPServer::SetAudioOutputDevice( Line 1140  String LSCPServer::SetAudioOutputDevice(
1140          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1141          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1142          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1143            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1144          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1145          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1146      }      }
1147      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1076  String LSCPServer::SetAudioOutputType(St Line 1157  String LSCPServer::SetAudioOutputType(St
1157          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1158          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1159          // Driver type name aliasing...          // Driver type name aliasing...
1160          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1161          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";                  if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1162          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1163          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1164          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1126  String LSCPServer::SetMIDIInputChannel(u Line 1207  String LSCPServer::SetMIDIInputChannel(u
1207      try {      try {
1208          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1209          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1210          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1211      }      }
1212      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1213           result.Error(e);           result.Error(e);
# Line 1141  String LSCPServer::SetMIDIInputDevice(ui Line 1222  String LSCPServer::SetMIDIInputDevice(ui
1222          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1223          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1224          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1225            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1226          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1227          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1228      }      }
1229      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1158  String LSCPServer::SetMIDIInputType(Stri Line 1239  String LSCPServer::SetMIDIInputType(Stri
1239          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1240          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1241          // Driver type name aliasing...          // Driver type name aliasing...
1242          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1243          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1244          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1245          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1176  String LSCPServer::SetMIDIInputType(Stri Line 1257  String LSCPServer::SetMIDIInputType(Stri
1257              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1258              // Make it with at least one initial port.              // Make it with at least one initial port.
1259              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1260              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1261          }          }
1262          // Must have a device...          // Must have a device...
1263          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1201  String LSCPServer::SetMIDIInput(uint MID Line 1282  String LSCPServer::SetMIDIInput(uint MID
1282          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1283          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1284          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1285            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1286          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1287          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);
         pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);  
1288      }      }
1289      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1290           result.Error(e);           result.Error(e);
# Line 1215  String LSCPServer::SetMIDIInput(uint MID Line 1296  String LSCPServer::SetMIDIInput(uint MID
1296   * Will be called by the parser to change the global volume factor on a   * Will be called by the parser to change the global volume factor on a
1297   * particular sampler channel.   * particular sampler channel.
1298   */   */
1299  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1300      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1301      LSCPResultSet result;      LSCPResultSet result;
1302      try {      try {
1303          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1304          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
1305          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1306          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
1307          pEngine->Volume(Volume);          pEngine->Volume(dVolume);
1308      }      }
1309      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1310           result.Error(e);           result.Error(e);
# Line 1251  String LSCPServer::ResetChannel(uint uiS Line 1332  String LSCPServer::ResetChannel(uint uiS
1332  }  }
1333    
1334  /**  /**
1335     * Will be called by the parser to reset the whole sampler.
1336     */
1337    String LSCPServer::ResetSampler() {
1338        dmsg(2,("LSCPServer: ResetSampler()\n"));
1339        pSampler->Reset();
1340        LSCPResultSet result;
1341        return result.Produce();
1342    }
1343    
1344    /**
1345   * Will be called by the parser to subscribe a client (frontend) on the   * Will be called by the parser to subscribe a client (frontend) on the
1346   * server for receiving event messages.   * server for receiving event messages.
1347   */   */
# Line 1276  String LSCPServer::UnsubscribeNotificati Line 1367  String LSCPServer::UnsubscribeNotificati
1367      return result.Produce();      return result.Produce();
1368  }  }
1369    
1370    /**
1371     * Will be called by the parser to enable or disable echo mode; if echo
1372     * mode is enabled, all commands from the client will (immediately) be
1373     * echoed back to the client.
1374     */
1375    String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) {
1376        dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value));
1377        LSCPResultSet result;
1378        try {
1379            if      (boolean_value == 0) pSession->bVerbose = false;
1380            else if (boolean_value == 1) pSession->bVerbose = true;
1381            else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");
1382        }
1383        catch (LinuxSamplerException e) {
1384             result.Error(e);
1385        }
1386        return result.Produce();
1387    }
1388    
1389  // Instrument loader constructor.  // Instrument loader constructor.
1390  LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)

Legend:
Removed from v.185  
changed lines
  Added in v.337

  ViewVC Help
Powered by ViewVC