/[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 209 by schoenebeck, Sun Jul 18 00:29:39 2004 UTC revision 374 by schoenebeck, Sat Feb 12 00:36:08 2005 UTC
# 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> >();
50  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex = Mutex();
51  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex = Mutex();
52  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
53    Mutex LSCPServer::RTNotifyMutex = Mutex();
54    
55  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
56      this->pSampler = pSampler;      this->pSampler = pSampler;
# Line 61  LSCPServer::LSCPServer(Sampler* pSampler Line 62  LSCPServer::LSCPServer(Sampler* pSampler
62      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
63  }  }
64    
65    /**
66     * Blocks the calling thread until the LSCP Server is initialized and
67     * accepting socket connections, if the server is already initialized then
68     * this method will return immediately.
69     * @param TimeoutSeconds     - optional: max. wait time in seconds
70     *                             (default: 0s)
71     * @param TimeoutNanoSeconds - optional: max wait time in nano seconds
72     *                             (default: 0ns)
73     * @returns  0 on success, a value less than 0 if timeout exceeded
74     */
75    int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) {
76        return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds);
77    }
78    
79  int LSCPServer::Main() {  int LSCPServer::Main() {
80      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      int hSocket = socket(AF_INET, SOCK_STREAM, 0);
81      if (hSocket < 0) {      if (hSocket < 0) {
# Line 74  int LSCPServer::Main() { Line 89  int LSCPServer::Main() {
89      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
90    
91      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
92          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...";
93          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
94          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
95          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
96                        std::cerr << "gave up!" << std::endl;
97                        close(hSocket);
98                        //return -1;
99                        exit(EXIT_FAILURE);
100                    }
101                    else sleep(1); // sleep 1s
102                }
103                else break; // success
104            }
105      }      }
106    
107      listen(hSocket, 1);      listen(hSocket, 1);
108      dmsg(1,("LSCPServer: Server running.\n")); // server running      Initialized.Set(true);
109    
110      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
111      sockaddr_in client;      sockaddr_in client;
# Line 90  int LSCPServer::Main() { Line 114  int LSCPServer::Main() {
114      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
115      int maxSessions = hSocket;      int maxSessions = hSocket;
116    
     // Parser initialization  
     yyparse_param_t yyparse_param;  
     yyparse_param.pServer = this;  
   
117      while (true) {      while (true) {
118          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
119          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);
# Line 118  int LSCPServer::Main() { Line 138  int LSCPServer::Main() {
138                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
139                  }                  }
140    
141                  hSessions.push_back(socket);                  // Parser initialization
142                    yyparse_param_t yyparse_param;
143                    yyparse_param.pServer  = this;
144                    yyparse_param.hSession = socket;
145    
146                    Sessions.push_back(yyparse_param);
147                  FD_SET(socket, &fdSet);                  FD_SET(socket, &fdSet);
148                  if (socket > maxSessions)                  if (socket > maxSessions)
149                          maxSessions = socket;                          maxSessions = socket;
# Line 128  int LSCPServer::Main() { Line 153  int LSCPServer::Main() {
153          }          }
154    
155          //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.
156          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++) {
157                  if (FD_ISSET(*iter, &selectSet)) {      //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
158                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
159                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
160                                  yylex_init(&yyparse_param.pScanner);                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
161                                  currentSocket = *iter;  //a hack                                  restart(NULL, dummy); // restart the 'scanner'
162                                  int result = yyparse(&yyparse_param);                                  currentSocket = (*iter).hSession;  //a hack
163                                    if ((*iter).bVerbose) { // if echo mode enabled
164                                        AnswerClient(bufferedCommands[currentSocket]);
165                                    }
166                                    int result = yyparse(&(*iter));
167                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
168                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
169                                  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 155  int LSCPServer::Main() { Line 184  int LSCPServer::Main() {
184          }          }
185          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
186      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
187  }  }
188    
189  void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
190          int socket = *iter;          int socket = (*iter).hSession;
191          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));
192          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
193          hSessions.erase(iter);          Sessions.erase(iter);
194          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
195          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)
196          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 177  void LSCPServer::CloseConnection( std::v Line 204  void LSCPServer::CloseConnection( std::v
204          NotifyMutex.Unlock();          NotifyMutex.Unlock();
205  }  }
206    
207    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
208            int subs = 0;
209            SubscriptionMutex.Lock();
210            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
211                            iter != events.end(); iter++)
212            {
213                    subs += eventSubscriptions.count(*iter);
214            }
215            SubscriptionMutex.Unlock();
216            return subs;
217    }
218    
219  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
220          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
221          if (eventSubscriptions.count(event.GetType()) == 0) {          if (eventSubscriptions.count(event.GetType()) == 0) {
# Line 227  extern int GetLSCPCommand( void *buf, in Line 266  extern int GetLSCPCommand( void *buf, in
266   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
267   * 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.
268   */   */
269  bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
270          int socket = *iter;          int socket = (*iter).hSession;
271          char c;          char c;
272          int i = 0;          int i = 0;
273          while (true) {          while (true) {
# Line 373  String LSCPServer::DestroyAudioOutputDev Line 412  String LSCPServer::DestroyAudioOutputDev
412      LSCPResultSet result;      LSCPResultSet result;
413      try {      try {
414          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
415          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) + ".");
416          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
417          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
418      }      }
# Line 388  String LSCPServer::DestroyMidiInputDevic Line 427  String LSCPServer::DestroyMidiInputDevic
427      LSCPResultSet result;      LSCPResultSet result;
428      try {      try {
429          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
430            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
431          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
432          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
433      }      }
434      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 406  String LSCPServer::LoadInstrument(String Line 445  String LSCPServer::LoadInstrument(String
445      LSCPResultSet result;      LSCPResultSet result;
446      try {      try {
447          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
448          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
449          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
450          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
451          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
452              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
453          if (bBackground) {          if (bBackground) {
454              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
455              pLoadInstrument->StartThread();              pLoadInstrument->StartThread();
# Line 434  String LSCPServer::LoadEngine(String Eng Line 473  String LSCPServer::LoadEngine(String Eng
473          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
474          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
475          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
476          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
477            LockRTNotify();
478          pSamplerChannel->LoadEngine(type);          pSamplerChannel->LoadEngine(type);
479            UnlockRTNotify();
480      }      }
481      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
482           result.Error(e);           result.Error(e);
# Line 486  String LSCPServer::AddChannel() { Line 527  String LSCPServer::AddChannel() {
527  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
528      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
529      LSCPResultSet result;      LSCPResultSet result;
530        LockRTNotify();
531      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
532        UnlockRTNotify();
533      return result.Produce();      return result.Produce();
534  }  }
535    
# Line 508  String LSCPServer::GetEngineInfo(String Line 551  String LSCPServer::GetEngineInfo(String
551      try {      try {
552          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
553              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
554              result.Add(pEngine->Description());              result.Add("DESCRIPTION", pEngine->Description());
555              result.Add(pEngine->Version());              result.Add("VERSION",     pEngine->Version());
556              delete pEngine;              delete pEngine;
557          }          }
558          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
# Line 529  String LSCPServer::GetChannelInfo(uint u Line 572  String LSCPServer::GetChannelInfo(uint u
572      LSCPResultSet result;      LSCPResultSet result;
573      try {      try {
574          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
575          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
576          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
577    
578          //Defaults values          //Defaults values
579          String EngineName = "NONE";          String EngineName = "NONE";
580          float Volume = 0;          float Volume = 0.0f;
581          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
582          int InstrumentIndex = -1;          int InstrumentIndex = -1;
583          int InstrumentStatus = -1;          int InstrumentStatus = -1;
584            int AudioOutputChannels = 0;
585            String AudioRouting;
586    
587          if (pEngine) {          if (pEngine) {
588              EngineName =  pEngine->EngineName();              EngineName =  pEngine->EngineName();
589                AudioOutputChannels = pEngine->Channels();
590              Volume = pEngine->Volume();              Volume = pEngine->Volume();
591              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus = pEngine->InstrumentStatus();
592              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex = pEngine->InstrumentIndex();
593              if (InstrumentIndex != -1)              if (InstrumentIndex != -1)
594                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
595                for (int chan = 0; chan < pEngine->Channels(); chan++) {
596                    if (AudioRouting != "") AudioRouting += ",";
597                    AudioRouting += ToString(pEngine->OutputChannel(chan));
598                }
599          }          }
600    
601          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 553  String LSCPServer::GetChannelInfo(uint u Line 603  String LSCPServer::GetChannelInfo(uint u
603    
604          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
605          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
606          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
607          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
608    
609          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
610          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
611          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
612            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
613    
614          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
615          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
# Line 579  String LSCPServer::GetVoiceCount(uint ui Line 630  String LSCPServer::GetVoiceCount(uint ui
630      LSCPResultSet result;      LSCPResultSet result;
631      try {      try {
632          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
633          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
634          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
635          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
636          result.Add(pEngine->VoiceCount());          result.Add(pEngine->VoiceCount());
637      }      }
638      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 599  String LSCPServer::GetStreamCount(uint u Line 650  String LSCPServer::GetStreamCount(uint u
650      LSCPResultSet result;      LSCPResultSet result;
651      try {      try {
652          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
653          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
654          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
655          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
656          result.Add(pEngine->DiskStreamCount());          result.Add(pEngine->DiskStreamCount());
657      }      }
658      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 619  String LSCPServer::GetBufferFill(fill_re Line 670  String LSCPServer::GetBufferFill(fill_re
670      LSCPResultSet result;      LSCPResultSet result;
671      try {      try {
672          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
673          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
674          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
675          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
676          if (!pEngine->DiskStreamSupported())          if (!pEngine->DiskStreamSupported())
677              result.Add("NA");              result.Add("NA");
678          else {          else {
# Line 718  String LSCPServer::GetAudioOutputDriverI Line 769  String LSCPServer::GetAudioOutputDriverI
769  }  }
770    
771  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
772      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()));
773      LSCPResultSet result;      LSCPResultSet result;
774      try {      try {
775          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 727  String LSCPServer::GetMidiInputDriverPar Line 778  String LSCPServer::GetMidiInputDriverPar
778          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
779          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
780          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
781          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
782          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
783          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
784          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
785          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
786            if (oDepends)       result.Add("DEPENDS",       *oDepends);
787            if (oDefault)       result.Add("DEFAULT",       *oDefault);
788            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
789            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
790            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
791      }      }
792      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
793          result.Error(e);          result.Error(e);
# Line 740  String LSCPServer::GetMidiInputDriverPar Line 796  String LSCPServer::GetMidiInputDriverPar
796  }  }
797    
798  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
799      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()));
800      LSCPResultSet result;      LSCPResultSet result;
801      try {      try {
802          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 749  String LSCPServer::GetAudioOutputDriverP Line 805  String LSCPServer::GetAudioOutputDriverP
805          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
806          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
807          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
808          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
809          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
810          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
811          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
812          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
813            if (oDepends)       result.Add("DEPENDS",       *oDepends);
814            if (oDefault)       result.Add("DEFAULT",       *oDefault);
815            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
816            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
817            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
818      }      }
819      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
820          result.Error(e);          result.Error(e);
# Line 830  String LSCPServer::GetAudioOutputDeviceI Line 891  String LSCPServer::GetAudioOutputDeviceI
891      LSCPResultSet result;      LSCPResultSet result;
892      try {      try {
893          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
894          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) + ".");
895          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
896          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
897          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
898          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
899          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 850  String LSCPServer::GetMidiInputDeviceInf Line 911  String LSCPServer::GetMidiInputDeviceInf
911      LSCPResultSet result;      LSCPResultSet result;
912      try {      try {
913          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
914            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
915          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
916          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
917          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
918          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
919          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 868  String LSCPServer::GetMidiInputPortInfo( Line 929  String LSCPServer::GetMidiInputPortInfo(
929      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
930      LSCPResultSet result;      LSCPResultSet result;
931      try {      try {
932            // get MIDI input device
933          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
934            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
935          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
936          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
937          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
938          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
939          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
940          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
941            // return the values of all MIDI port parameters
942            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
943            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
944          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
945              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
946          }          }
# Line 891  String LSCPServer::GetAudioOutputChannel Line 957  String LSCPServer::GetAudioOutputChannel
957      try {      try {
958          // get audio output device          // get audio output device
959          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
960          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) + ".");
961          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
962    
963          // get audio channel          // get audio channel
964          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
965          if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
966    
967          // return the values of all audio channel parameters          // return the values of all audio channel parameters
968          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 915  String LSCPServer::GetMidiInputPortParam Line 981  String LSCPServer::GetMidiInputPortParam
981      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()));
982      LSCPResultSet result;      LSCPResultSet result;
983      try {      try {
984          // get audio output device          // get MIDI input device
985          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
986          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) + ".");
987          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
988    
989          // get midi port          // get midi port
990          MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
991          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) + ".");
992    
993          // get desired port parameter          // get desired port parameter
994          std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
995          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 + "'.");
996          DeviceCreationParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
997    
998          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
999          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
1000          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1001          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1002          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1003          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1004          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1005          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1006      }      }
1007      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1008          result.Error(e);          result.Error(e);
# Line 950  String LSCPServer::GetAudioOutputChannel Line 1016  String LSCPServer::GetAudioOutputChannel
1016      try {      try {
1017          // get audio output device          // get audio output device
1018          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1019          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) + ".");
1020          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1021    
1022          // get audio channel          // get audio channel
1023          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1024          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1025    
1026          // get desired audio channel parameter          // get desired audio channel parameter
1027          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1028          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 + "'.");
1029          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1030    
1031          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 967  String LSCPServer::GetAudioOutputChannel Line 1033  String LSCPServer::GetAudioOutputChannel
1033          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1034          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1035          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1036          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1037          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1038          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1039      }      }
1040      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1041          result.Error(e);          result.Error(e);
# Line 983  String LSCPServer::SetAudioOutputChannel Line 1049  String LSCPServer::SetAudioOutputChannel
1049      try {      try {
1050          // get audio output device          // get audio output device
1051          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1052          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) + ".");
1053          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1054    
1055          // get audio channel          // get audio channel
1056          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1057          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1058    
1059          // get desired audio channel parameter          // get desired audio channel parameter
1060          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1061          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 + "'.");
1062          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1063    
1064          // set new channel parameter value          // set new channel parameter value
# Line 1009  String LSCPServer::SetAudioOutputDeviceP Line 1075  String LSCPServer::SetAudioOutputDeviceP
1075      LSCPResultSet result;      LSCPResultSet result;
1076      try {      try {
1077          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1078          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) + ".");
1079          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1080          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1081          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 + "'");
1082          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1083      }      }
1084      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1026  String LSCPServer::SetMidiInputDevicePar Line 1092  String LSCPServer::SetMidiInputDevicePar
1092      LSCPResultSet result;      LSCPResultSet result;
1093      try {      try {
1094          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1095          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) + ".");
1096          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1097          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1098          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 + "'");
1099          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1100      }      }
1101      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1042  String LSCPServer::SetMidiInputPortParam Line 1108  String LSCPServer::SetMidiInputPortParam
1108      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()));
1109      LSCPResultSet result;      LSCPResultSet result;
1110      try {      try {
1111            // get MIDI input device
1112          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1113            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1114          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1115          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1116          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1117          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1118          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1119          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1120            // set port parameter value
1121            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1122            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1123          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1124      }      }
1125      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1063  String LSCPServer::SetMidiInputPortParam Line 1134  String LSCPServer::SetMidiInputPortParam
1134   */   */
1135  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1136      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));
1137      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1138        try {
1139            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1140            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1141            Engine* pEngine = pSamplerChannel->GetEngine();
1142            if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));
1143            if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1144            pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1145        }
1146        catch (LinuxSamplerException e) {
1147             result.Error(e);
1148        }
1149        return result.Produce();
1150  }  }
1151    
1152  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1071  String LSCPServer::SetAudioOutputDevice( Line 1154  String LSCPServer::SetAudioOutputDevice(
1154      LSCPResultSet result;      LSCPResultSet result;
1155      try {      try {
1156          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1157          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1158          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1159            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1160          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1161          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1162      }      }
1163      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1088  String LSCPServer::SetAudioOutputType(St Line 1171  String LSCPServer::SetAudioOutputType(St
1171      LSCPResultSet result;      LSCPResultSet result;
1172      try {      try {
1173          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1174          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1175          // Driver type name aliasing...          // Driver type name aliasing...
1176          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1177          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1178          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1179          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1180          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1125  String LSCPServer::SetMIDIInputPort(uint Line 1208  String LSCPServer::SetMIDIInputPort(uint
1208      LSCPResultSet result;      LSCPResultSet result;
1209      try {      try {
1210          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1211          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1212          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1213      }      }
1214      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1139  String LSCPServer::SetMIDIInputChannel(u Line 1222  String LSCPServer::SetMIDIInputChannel(u
1222      LSCPResultSet result;      LSCPResultSet result;
1223      try {      try {
1224          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1225          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1226          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1227      }      }
1228      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1229           result.Error(e);           result.Error(e);
# Line 1153  String LSCPServer::SetMIDIInputDevice(ui Line 1236  String LSCPServer::SetMIDIInputDevice(ui
1236      LSCPResultSet result;      LSCPResultSet result;
1237      try {      try {
1238          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1239          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1240          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1241            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1242          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1243          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1244      }      }
1245      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1170  String LSCPServer::SetMIDIInputType(Stri Line 1253  String LSCPServer::SetMIDIInputType(Stri
1253      LSCPResultSet result;      LSCPResultSet result;
1254      try {      try {
1255          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1256          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1257          // Driver type name aliasing...          // Driver type name aliasing...
1258          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1259          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1260          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1261          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1190  String LSCPServer::SetMIDIInputType(Stri Line 1273  String LSCPServer::SetMIDIInputType(Stri
1273              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1274              // Make it with at least one initial port.              // Make it with at least one initial port.
1275              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1276              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1277          }          }
1278          // Must have a device...          // Must have a device...
1279          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1213  String LSCPServer::SetMIDIInput(uint MID Line 1296  String LSCPServer::SetMIDIInput(uint MID
1296      LSCPResultSet result;      LSCPResultSet result;
1297      try {      try {
1298          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1299          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1300          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1301            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1302          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1303          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);  
1304      }      }
1305      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1306           result.Error(e);           result.Error(e);
# Line 1229  String LSCPServer::SetMIDIInput(uint MID Line 1312  String LSCPServer::SetMIDIInput(uint MID
1312   * 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
1313   * particular sampler channel.   * particular sampler channel.
1314   */   */
1315  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1316      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1317      LSCPResultSet result;      LSCPResultSet result;
1318      try {      try {
1319          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1320          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1321          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1322          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
1323          pEngine->Volume(Volume);          pEngine->Volume(dVolume);
1324      }      }
1325      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1326           result.Error(e);           result.Error(e);
# Line 1253  String LSCPServer::ResetChannel(uint uiS Line 1336  String LSCPServer::ResetChannel(uint uiS
1336      LSCPResultSet result;      LSCPResultSet result;
1337      try {      try {
1338          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1339          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1340          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1341          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
1342          pEngine->Reset();          pEngine->Reset();
1343      }      }
1344      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1265  String LSCPServer::ResetChannel(uint uiS Line 1348  String LSCPServer::ResetChannel(uint uiS
1348  }  }
1349    
1350  /**  /**
1351     * Will be called by the parser to reset the whole sampler.
1352     */
1353    String LSCPServer::ResetSampler() {
1354        dmsg(2,("LSCPServer: ResetSampler()\n"));
1355        pSampler->Reset();
1356        LSCPResultSet result;
1357        return result.Produce();
1358    }
1359    
1360    /**
1361   * 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
1362   * server for receiving event messages.   * server for receiving event messages.
1363   */   */
# Line 1290  String LSCPServer::UnsubscribeNotificati Line 1383  String LSCPServer::UnsubscribeNotificati
1383      return result.Produce();      return result.Produce();
1384  }  }
1385    
1386    /**
1387     * Will be called by the parser to enable or disable echo mode; if echo
1388     * mode is enabled, all commands from the client will (immediately) be
1389     * echoed back to the client.
1390     */
1391    String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) {
1392        dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value));
1393        LSCPResultSet result;
1394        try {
1395            if      (boolean_value == 0) pSession->bVerbose = false;
1396            else if (boolean_value == 1) pSession->bVerbose = true;
1397            else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");
1398        }
1399        catch (LinuxSamplerException e) {
1400             result.Error(e);
1401        }
1402        return result.Produce();
1403    }
1404    
1405  // Instrument loader constructor.  // Instrument loader constructor.
1406  LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)

Legend:
Removed from v.209  
changed lines
  Added in v.374

  ViewVC Help
Powered by ViewVC