/[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 211 by schoenebeck, Sun Jul 25 23:27:41 2004 UTC revision 385 by schoenebeck, Thu Feb 17 02:53:45 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
10   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# Line 50  std::map< LSCPEvent::event_t, std::list< Line 51  std::map< LSCPEvent::event_t, std::list<
51  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex = Mutex();
52  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex = Mutex();
53  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
54    Mutex LSCPServer::RTNotifyMutex = Mutex();
55    
56  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
57      this->pSampler = pSampler;      this->pSampler = pSampler;
# Line 88  int LSCPServer::Main() { Line 90  int LSCPServer::Main() {
90      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
91    
92      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
93          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...";
94          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
95          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
96          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
97                        std::cerr << "gave up!" << std::endl;
98                        close(hSocket);
99                        //return -1;
100                        exit(EXIT_FAILURE);
101                    }
102                    else sleep(1); // sleep 1s
103                }
104                else break; // success
105            }
106      }      }
107    
108      listen(hSocket, 1);      listen(hSocket, 1);
# Line 147  int LSCPServer::Main() { Line 158  int LSCPServer::Main() {
158                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
159                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
160                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
161                                  yylex_init(&((*iter).pScanner)); //FIXME: should me moved out of this loop and initialized only when a new session is created                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
162                                    restart(NULL, dummy); // restart the 'scanner'
163                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
164                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
165                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
# Line 173  int LSCPServer::Main() { Line 185  int LSCPServer::Main() {
185          }          }
186          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
187      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
188  }  }
189    
190  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
# Line 193  void LSCPServer::CloseConnection( std::v Line 203  void LSCPServer::CloseConnection( std::v
203          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
204          close(socket);          close(socket);
205          NotifyMutex.Unlock();          NotifyMutex.Unlock();
206          //yylex_destroy((*iter).pScanner);  }
207    
208    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
209            int subs = 0;
210            SubscriptionMutex.Lock();
211            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
212                            iter != events.end(); iter++)
213            {
214                    subs += eventSubscriptions.count(*iter);
215            }
216            SubscriptionMutex.Unlock();
217            return subs;
218  }  }
219    
220  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
# Line 392  String LSCPServer::DestroyAudioOutputDev Line 413  String LSCPServer::DestroyAudioOutputDev
413      LSCPResultSet result;      LSCPResultSet result;
414      try {      try {
415          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
416          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) + ".");
417          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
418          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
419      }      }
# Line 407  String LSCPServer::DestroyMidiInputDevic Line 428  String LSCPServer::DestroyMidiInputDevic
428      LSCPResultSet result;      LSCPResultSet result;
429      try {      try {
430          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
431            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
432          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
433          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
434      }      }
435      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 425  String LSCPServer::LoadInstrument(String Line 446  String LSCPServer::LoadInstrument(String
446      LSCPResultSet result;      LSCPResultSet result;
447      try {      try {
448          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
449          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
450          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
451          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
452          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
453              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
454          if (bBackground) {          if (bBackground) {
455              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine);
             pLoadInstrument->StartThread();  
456          }          }
457          else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);          else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
458      }      }
# Line 453  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 505  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 527  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 548  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            String InstrumentName = "NONE";
583          int InstrumentIndex = -1;          int InstrumentIndex = -1;
584          int InstrumentStatus = -1;          int InstrumentStatus = -1;
585            int AudioOutputChannels = 0;
586            String AudioRouting;
587    
588          if (pEngine) {          if (pEngine) {
589              EngineName =  pEngine->EngineName();              EngineName =  pEngine->EngineName();
590                AudioOutputChannels = pEngine->Channels();
591              Volume = pEngine->Volume();              Volume = pEngine->Volume();
592              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus = pEngine->InstrumentStatus();
593              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex = pEngine->InstrumentIndex();
594              if (InstrumentIndex != -1)              if (InstrumentIndex != -1)
595                {
596                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
597                    InstrumentName = pEngine->InstrumentName();
598                }
599                for (int chan = 0; chan < pEngine->Channels(); chan++) {
600                    if (AudioRouting != "") AudioRouting += ",";
601                    AudioRouting += ToString(pEngine->OutputChannel(chan));
602                }
603          }          }
604    
605          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 572  String LSCPServer::GetChannelInfo(uint u Line 607  String LSCPServer::GetChannelInfo(uint u
607    
608          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
609          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
610          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
611          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
612    
613          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
614          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
615          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
616            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
617    
618          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
619          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
620            result.Add("INSTRUMENT_NAME", InstrumentName);
621          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
622      }      }
623      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 598  String LSCPServer::GetVoiceCount(uint ui Line 635  String LSCPServer::GetVoiceCount(uint ui
635      LSCPResultSet result;      LSCPResultSet result;
636      try {      try {
637          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
638          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
639          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
640          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
641          result.Add(pEngine->VoiceCount());          result.Add(pEngine->VoiceCount());
642      }      }
643      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 618  String LSCPServer::GetStreamCount(uint u Line 655  String LSCPServer::GetStreamCount(uint u
655      LSCPResultSet result;      LSCPResultSet result;
656      try {      try {
657          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
658          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
659          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
660          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
661          result.Add(pEngine->DiskStreamCount());          result.Add(pEngine->DiskStreamCount());
662      }      }
663      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 638  String LSCPServer::GetBufferFill(fill_re Line 675  String LSCPServer::GetBufferFill(fill_re
675      LSCPResultSet result;      LSCPResultSet result;
676      try {      try {
677          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
678          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
679          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
680          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
681          if (!pEngine->DiskStreamSupported())          if (!pEngine->DiskStreamSupported())
682              result.Add("NA");              result.Add("NA");
683          else {          else {
# Line 737  String LSCPServer::GetAudioOutputDriverI Line 774  String LSCPServer::GetAudioOutputDriverI
774  }  }
775    
776  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
777      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()));
778      LSCPResultSet result;      LSCPResultSet result;
779      try {      try {
780          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 746  String LSCPServer::GetMidiInputDriverPar Line 783  String LSCPServer::GetMidiInputDriverPar
783          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
784          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
785          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
786          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
787          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
788          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
789          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
790          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
791            if (oDepends)       result.Add("DEPENDS",       *oDepends);
792            if (oDefault)       result.Add("DEFAULT",       *oDefault);
793            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
794            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
795            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
796      }      }
797      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
798          result.Error(e);          result.Error(e);
# Line 759  String LSCPServer::GetMidiInputDriverPar Line 801  String LSCPServer::GetMidiInputDriverPar
801  }  }
802    
803  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
804      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()));
805      LSCPResultSet result;      LSCPResultSet result;
806      try {      try {
807          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 768  String LSCPServer::GetAudioOutputDriverP Line 810  String LSCPServer::GetAudioOutputDriverP
810          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
811          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
812          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
813          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
814          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
815          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
816          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
817          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
818            if (oDepends)       result.Add("DEPENDS",       *oDepends);
819            if (oDefault)       result.Add("DEFAULT",       *oDefault);
820            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
821            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
822            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
823      }      }
824      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
825          result.Error(e);          result.Error(e);
# Line 849  String LSCPServer::GetAudioOutputDeviceI Line 896  String LSCPServer::GetAudioOutputDeviceI
896      LSCPResultSet result;      LSCPResultSet result;
897      try {      try {
898          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
899          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) + ".");
900          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
901          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
902          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
903          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
904          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 869  String LSCPServer::GetMidiInputDeviceInf Line 916  String LSCPServer::GetMidiInputDeviceInf
916      LSCPResultSet result;      LSCPResultSet result;
917      try {      try {
918          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
919            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
920          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
921          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
922          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
923          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
924          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 887  String LSCPServer::GetMidiInputPortInfo( Line 934  String LSCPServer::GetMidiInputPortInfo(
934      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
935      LSCPResultSet result;      LSCPResultSet result;
936      try {      try {
937            // get MIDI input device
938          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
939            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
940          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
941          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
942          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
943          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
944          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
945          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
946            // return the values of all MIDI port parameters
947            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
948            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
949          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
950              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
951          }          }
# Line 910  String LSCPServer::GetAudioOutputChannel Line 962  String LSCPServer::GetAudioOutputChannel
962      try {      try {
963          // get audio output device          // get audio output device
964          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
965          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) + ".");
966          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
967    
968          // get audio channel          // get audio channel
969          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
970          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) + ".");
971    
972          // return the values of all audio channel parameters          // return the values of all audio channel parameters
973          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 934  String LSCPServer::GetMidiInputPortParam Line 986  String LSCPServer::GetMidiInputPortParam
986      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()));
987      LSCPResultSet result;      LSCPResultSet result;
988      try {      try {
989          // get audio output device          // get MIDI input device
990          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
991          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) + ".");
992          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
993    
994          // get midi port          // get midi port
995          MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
996          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) + ".");
997    
998          // get desired port parameter          // get desired port parameter
999          std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1000          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 + "'.");
1001          DeviceCreationParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1002    
1003          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
1004          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
1005          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1006          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1007          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1008          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1009          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1010          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1011      }      }
1012      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1013          result.Error(e);          result.Error(e);
# Line 969  String LSCPServer::GetAudioOutputChannel Line 1021  String LSCPServer::GetAudioOutputChannel
1021      try {      try {
1022          // get audio output device          // get audio output device
1023          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1024          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) + ".");
1025          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1026    
1027          // get audio channel          // get audio channel
1028          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1029          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) + ".");
1030    
1031          // get desired audio channel parameter          // get desired audio channel parameter
1032          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1033          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 + "'.");
1034          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1035    
1036          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 986  String LSCPServer::GetAudioOutputChannel Line 1038  String LSCPServer::GetAudioOutputChannel
1038          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1039          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1040          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1041          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1042          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1043          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1044      }      }
1045      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1046          result.Error(e);          result.Error(e);
# Line 1002  String LSCPServer::SetAudioOutputChannel Line 1054  String LSCPServer::SetAudioOutputChannel
1054      try {      try {
1055          // get audio output device          // get audio output device
1056          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1057          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) + ".");
1058          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1059    
1060          // get audio channel          // get audio channel
1061          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1062          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) + ".");
1063    
1064          // get desired audio channel parameter          // get desired audio channel parameter
1065          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1066          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 + "'.");
1067          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1068    
1069          // set new channel parameter value          // set new channel parameter value
# Line 1028  String LSCPServer::SetAudioOutputDeviceP Line 1080  String LSCPServer::SetAudioOutputDeviceP
1080      LSCPResultSet result;      LSCPResultSet result;
1081      try {      try {
1082          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1083          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) + ".");
1084          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1085          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1086          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 + "'");
1087          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1088      }      }
1089      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1045  String LSCPServer::SetMidiInputDevicePar Line 1097  String LSCPServer::SetMidiInputDevicePar
1097      LSCPResultSet result;      LSCPResultSet result;
1098      try {      try {
1099          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1100          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) + ".");
1101          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1102          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1103          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 + "'");
1104          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1105      }      }
1106      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1061  String LSCPServer::SetMidiInputPortParam Line 1113  String LSCPServer::SetMidiInputPortParam
1113      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()));
1114      LSCPResultSet result;      LSCPResultSet result;
1115      try {      try {
1116            // get MIDI input device
1117          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1118            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1119          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1120          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1121          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1122          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1123          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1124          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1125            // set port parameter value
1126            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1127            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1128          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1129      }      }
1130      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1082  String LSCPServer::SetMidiInputPortParam Line 1139  String LSCPServer::SetMidiInputPortParam
1139   */   */
1140  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1141      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));
1142      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1143        try {
1144            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1145            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1146            Engine* pEngine = pSamplerChannel->GetEngine();
1147            if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));
1148            if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1149            pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1150        }
1151        catch (LinuxSamplerException e) {
1152             result.Error(e);
1153        }
1154        return result.Produce();
1155  }  }
1156    
1157  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1090  String LSCPServer::SetAudioOutputDevice( Line 1159  String LSCPServer::SetAudioOutputDevice(
1159      LSCPResultSet result;      LSCPResultSet result;
1160      try {      try {
1161          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1162          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1163          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1164            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1165          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1166          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1167      }      }
1168      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1107  String LSCPServer::SetAudioOutputType(St Line 1176  String LSCPServer::SetAudioOutputType(St
1176      LSCPResultSet result;      LSCPResultSet result;
1177      try {      try {
1178          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1179          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1180          // Driver type name aliasing...          // Driver type name aliasing...
1181          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1182          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1183          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1184          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1185          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1144  String LSCPServer::SetMIDIInputPort(uint Line 1213  String LSCPServer::SetMIDIInputPort(uint
1213      LSCPResultSet result;      LSCPResultSet result;
1214      try {      try {
1215          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1216          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1217          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1218      }      }
1219      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1158  String LSCPServer::SetMIDIInputChannel(u Line 1227  String LSCPServer::SetMIDIInputChannel(u
1227      LSCPResultSet result;      LSCPResultSet result;
1228      try {      try {
1229          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1230          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1231          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1232      }      }
1233      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1234           result.Error(e);           result.Error(e);
# Line 1172  String LSCPServer::SetMIDIInputDevice(ui Line 1241  String LSCPServer::SetMIDIInputDevice(ui
1241      LSCPResultSet result;      LSCPResultSet result;
1242      try {      try {
1243          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1244          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1245          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1246            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1247          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1248          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1249      }      }
1250      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1189  String LSCPServer::SetMIDIInputType(Stri Line 1258  String LSCPServer::SetMIDIInputType(Stri
1258      LSCPResultSet result;      LSCPResultSet result;
1259      try {      try {
1260          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1261          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1262          // Driver type name aliasing...          // Driver type name aliasing...
1263          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1264          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1265          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1266          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1209  String LSCPServer::SetMIDIInputType(Stri Line 1278  String LSCPServer::SetMIDIInputType(Stri
1278              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1279              // Make it with at least one initial port.              // Make it with at least one initial port.
1280              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1281              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1282          }          }
1283          // Must have a device...          // Must have a device...
1284          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1232  String LSCPServer::SetMIDIInput(uint MID Line 1301  String LSCPServer::SetMIDIInput(uint MID
1301      LSCPResultSet result;      LSCPResultSet result;
1302      try {      try {
1303          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1304          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1305          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1306            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1307          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1308          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);  
1309      }      }
1310      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1311           result.Error(e);           result.Error(e);
# Line 1248  String LSCPServer::SetMIDIInput(uint MID Line 1317  String LSCPServer::SetMIDIInput(uint MID
1317   * 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
1318   * particular sampler channel.   * particular sampler channel.
1319   */   */
1320  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1321      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1322      LSCPResultSet result;      LSCPResultSet result;
1323      try {      try {
1324          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1325          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1326          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1327          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
1328          pEngine->Volume(Volume);          pEngine->Volume(dVolume);
1329      }      }
1330      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1331           result.Error(e);           result.Error(e);
# Line 1272  String LSCPServer::ResetChannel(uint uiS Line 1341  String LSCPServer::ResetChannel(uint uiS
1341      LSCPResultSet result;      LSCPResultSet result;
1342      try {      try {
1343          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1344          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1345          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1346          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
1347          pEngine->Reset();          pEngine->Reset();
1348      }      }
1349      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1284  String LSCPServer::ResetChannel(uint uiS Line 1353  String LSCPServer::ResetChannel(uint uiS
1353  }  }
1354    
1355  /**  /**
1356     * Will be called by the parser to reset the whole sampler.
1357     */
1358    String LSCPServer::ResetSampler() {
1359        dmsg(2,("LSCPServer: ResetSampler()\n"));
1360        pSampler->Reset();
1361        LSCPResultSet result;
1362        return result.Produce();
1363    }
1364    
1365    /**
1366   * 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
1367   * server for receiving event messages.   * server for receiving event messages.
1368   */   */
# Line 1327  String LSCPServer::SetEcho(yyparse_param Line 1406  String LSCPServer::SetEcho(yyparse_param
1406      }      }
1407      return result.Produce();      return result.Produce();
1408  }  }
   
 // Instrument loader constructor.  
 LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  
     : Thread(false, 0, -4)  
 {  
     this->pEngine = pEngine;  
     this->Filename = Filename;  
     this->uiInstrument = uiInstrument;  
 }  
   
 // Instrument loader process.  
 int LSCPLoadInstrument::Main()  
 {  
     try {  
         pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
     }  
   
     catch (LinuxSamplerException e) {  
         e.PrintMessage();  
     }  
   
     // Always re-enable the engine.  
     pEngine->Enable();  
   
     // FIXME: Shoot ourselves on the foot?  
     delete this;  
 }  

Legend:
Removed from v.211  
changed lines
  Added in v.385

  ViewVC Help
Powered by ViewVC