/[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 219 by schoenebeck, Tue Aug 17 20:35:04 2004 UTC revision 667 by senkov, Sun Jun 19 21:22:34 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 23  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
27    //#include "../common/global.h"
28    
29  #include "../engines/gig/Engine.h"  #include <fcntl.h>
30    
31    #if HAVE_SQLITE3
32    # include "sqlite3.h"
33    #endif
34    
35    #include "../engines/EngineFactory.h"
36    #include "../engines/EngineChannelFactory.h"
37  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
38  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
39    
# Line 50  std::map< LSCPEvent::event_t, std::list< Line 59  std::map< LSCPEvent::event_t, std::list<
59  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex = Mutex();
60  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex = Mutex();
61  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
62    Mutex LSCPServer::RTNotifyMutex = Mutex();
63    
64  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) {
65        SocketAddress.sin_family      = AF_INET;
66        SocketAddress.sin_addr.s_addr = addr;
67        SocketAddress.sin_port        = port;
68      this->pSampler = pSampler;      this->pSampler = pSampler;
69      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
71      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
72      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
75        hSocket = -1;
76    }
77    
78    LSCPServer::~LSCPServer() {
79        if (hSocket >= 0) close(hSocket);
80  }  }
81    
82  /**  /**
# Line 76  int LSCPServer::WaitUntilInitialized(lon Line 94  int LSCPServer::WaitUntilInitialized(lon
94  }  }
95    
96  int LSCPServer::Main() {  int LSCPServer::Main() {
97      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
98      if (hSocket < 0) {      if (hSocket < 0) {
99          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
100          //return -1;          //return -1;
101          exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
102      }      }
103    
     SocketAddress.sin_family      = AF_INET;  
     SocketAddress.sin_port        = htons(LSCP_PORT);  
     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);  
   
104      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
105          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...";
106          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
107          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
108          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
109                        std::cerr << "gave up!" << std::endl;
110                        close(hSocket);
111                        //return -1;
112                        exit(EXIT_FAILURE);
113                    }
114                    else sleep(1); // sleep 1s
115                }
116                else break; // success
117            }
118      }      }
119    
120      listen(hSocket, 1);      listen(hSocket, 1);
# Line 150  int LSCPServer::Main() { Line 173  int LSCPServer::Main() {
173                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
174                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
175                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
176                                    dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
177                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
178                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
179                                  }                                  }
# Line 166  int LSCPServer::Main() { Line 190  int LSCPServer::Main() {
190                  }                  }
191          }          }
192    
193            // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
194            {
195                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
196                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
197                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
198                for (; itEngineChannel != itEnd; ++itEngineChannel) {
199                    if ((*itEngineChannel)->StatusChanged()) {
200                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
201                    }
202                }
203            }
204    
205          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
206          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
207          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
# Line 194  void LSCPServer::CloseConnection( std::v Line 230  void LSCPServer::CloseConnection( std::v
230          NotifyMutex.Unlock();          NotifyMutex.Unlock();
231  }  }
232    
233    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
234            int subs = 0;
235            SubscriptionMutex.Lock();
236            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
237                            iter != events.end(); iter++)
238            {
239                    subs += eventSubscriptions.count(*iter);
240            }
241            SubscriptionMutex.Unlock();
242            return subs;
243    }
244    
245  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
246          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
247          if (eventSubscriptions.count(event.GetType()) == 0) {          if (eventSubscriptions.count(event.GetType()) == 0) {
# Line 390  String LSCPServer::DestroyAudioOutputDev Line 438  String LSCPServer::DestroyAudioOutputDev
438      LSCPResultSet result;      LSCPResultSet result;
439      try {      try {
440          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
441          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) + ".");
442          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
443          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
444      }      }
# Line 405  String LSCPServer::DestroyMidiInputDevic Line 453  String LSCPServer::DestroyMidiInputDevic
453      LSCPResultSet result;      LSCPResultSet result;
454      try {      try {
455          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
456            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
457          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
458          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
459      }      }
460      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 423  String LSCPServer::LoadInstrument(String Line 471  String LSCPServer::LoadInstrument(String
471      LSCPResultSet result;      LSCPResultSet result;
472      try {      try {
473          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
474          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
475          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
476          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
477          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
478              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
479          if (bBackground) {          if (bBackground) {
480              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
481              pLoadInstrument->StartThread();          }
482            else {
483                // tell the engine channel which instrument to load
484                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
485                // actually start to load the instrument (blocks until completed)
486                pEngineChannel->LoadInstrument();
487          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
488      }      }
489      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
490           result.Error(e);           result.Error(e);
# Line 441  String LSCPServer::LoadInstrument(String Line 493  String LSCPServer::LoadInstrument(String
493  }  }
494    
495  /**  /**
496   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to assign a sampler engine type to a
497     * sampler channel.
498   */   */
499  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
500      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
501      LSCPResultSet result;      LSCPResultSet result;
502      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
503          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
504          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
505          pSamplerChannel->LoadEngine(type);          LockRTNotify();
506            pSamplerChannel->SetEngineType(EngineName);
507            UnlockRTNotify();
508      }      }
509      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
510           result.Error(e);           result.Error(e);
# Line 503  String LSCPServer::AddChannel() { Line 555  String LSCPServer::AddChannel() {
555  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
556      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
557      LSCPResultSet result;      LSCPResultSet result;
558        LockRTNotify();
559      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
560        UnlockRTNotify();
561      return result.Produce();      return result.Produce();
562  }  }
563    
564  /**  /**
565   * Will be called by the parser to get all available engines.   * Will be called by the parser to get the amount of all available engines.
566   */   */
567  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
568      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
569      LSCPResultSet result("GigEngine");      LSCPResultSet result("1");
570        return result.Produce();
571    }
572    
573    /**
574     * Will be called by the parser to get a list of all available engines.
575     */
576    String LSCPServer::ListAvailableEngines() {
577        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
578        LSCPResultSet result("\'GIG\'");
579      return result.Produce();      return result.Produce();
580  }  }
581    
582  /**  /**
583   * Will be called by the parser to get descriptions for a particular engine.   * Will be called by the parser to get descriptions for a particular
584     * sampler engine.
585   */   */
586  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
587      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
588      LSCPResultSet result;      LSCPResultSet result;
589      try {      try {
590          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
591              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
592              result.Add(pEngine->Description());          result.Add("VERSION",     pEngine->Version());
593              result.Add(pEngine->Version());          EngineFactory::Destroy(pEngine);
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
594      }      }
595      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
596           result.Error(e);           result.Error(e);
# Line 546  String LSCPServer::GetChannelInfo(uint u Line 607  String LSCPServer::GetChannelInfo(uint u
607      LSCPResultSet result;      LSCPResultSet result;
608      try {      try {
609          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
610          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
611          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
612    
613          //Defaults values          //Defaults values
614          String EngineName = "NONE";          String EngineName = "NONE";
615          float Volume = 0;          float Volume = 0.0f;
616          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
617            String InstrumentName = "NONE";
618          int InstrumentIndex = -1;          int InstrumentIndex = -1;
619          int InstrumentStatus = -1;          int InstrumentStatus = -1;
620            int AudioOutputChannels = 0;
621            String AudioRouting;
622    
623          if (pEngine) {          if (pEngineChannel) {
624              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
625              Volume = pEngine->Volume();              AudioOutputChannels = pEngineChannel->Channels();
626              InstrumentStatus = pEngine->InstrumentStatus();              Volume              = pEngineChannel->Volume();
627              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
628              if (InstrumentIndex != -1)              InstrumentIndex     = pEngineChannel->InstrumentIndex();
629                  InstrumentFileName = pEngine->InstrumentFileName();              if (InstrumentIndex != -1) {
630                    InstrumentFileName = pEngineChannel->InstrumentFileName();
631                    InstrumentName     = pEngineChannel->InstrumentName();
632                }
633                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
634                    if (AudioRouting != "") AudioRouting += ",";
635                    AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
636                }
637          }          }
638    
639          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 570  String LSCPServer::GetChannelInfo(uint u Line 641  String LSCPServer::GetChannelInfo(uint u
641    
642          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
643          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
644          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
645          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
646    
647          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
648          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
649          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
650            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
651    
652          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
653          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
654            result.Add("INSTRUMENT_NAME", InstrumentName);
655          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
656      }      }
657      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 596  String LSCPServer::GetVoiceCount(uint ui Line 669  String LSCPServer::GetVoiceCount(uint ui
669      LSCPResultSet result;      LSCPResultSet result;
670      try {      try {
671          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
672          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
673          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
674          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
675          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
676            result.Add(pEngineChannel->GetEngine()->VoiceCount());
677      }      }
678      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
679           result.Error(e);           result.Error(e);
# Line 616  String LSCPServer::GetStreamCount(uint u Line 690  String LSCPServer::GetStreamCount(uint u
690      LSCPResultSet result;      LSCPResultSet result;
691      try {      try {
692          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
693          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
694          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
695          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
696          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
697            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
698      }      }
699      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
700           result.Error(e);           result.Error(e);
# Line 636  String LSCPServer::GetBufferFill(fill_re Line 711  String LSCPServer::GetBufferFill(fill_re
711      LSCPResultSet result;      LSCPResultSet result;
712      try {      try {
713          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
714          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
715          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
716          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
717          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
718              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
719          else {          else {
720              switch (ResponseType) {              switch (ResponseType) {
721                  case fill_response_bytes:                  case fill_response_bytes:
722                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
723                      break;                      break;
724                  case fill_response_percentage:                  case fill_response_percentage:
725                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
726                      break;                      break;
727                  default:                  default:
728                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
729              }              }
# Line 664  String LSCPServer::GetAvailableAudioOutp Line 739  String LSCPServer::GetAvailableAudioOutp
739      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
740      LSCPResultSet result;      LSCPResultSet result;
741      try {      try {
742            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
743            result.Add(n);
744        }
745        catch (LinuxSamplerException e) {
746            result.Error(e);
747        }
748        return result.Produce();
749    }
750    
751    String LSCPServer::ListAvailableAudioOutputDrivers() {
752        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
753        LSCPResultSet result;
754        try {
755          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
756          result.Add(s);          result.Add(s);
757      }      }
# Line 677  String LSCPServer::GetAvailableMidiInput Line 765  String LSCPServer::GetAvailableMidiInput
765      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
766      LSCPResultSet result;      LSCPResultSet result;
767      try {      try {
768            int n = MidiInputDeviceFactory::AvailableDrivers().size();
769            result.Add(n);
770        }
771        catch (LinuxSamplerException e) {
772            result.Error(e);
773        }
774        return result.Produce();
775    }
776    
777    String LSCPServer::ListAvailableMidiInputDrivers() {
778        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
779        LSCPResultSet result;
780        try {
781          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
782          result.Add(s);          result.Add(s);
783      }      }
# Line 735  String LSCPServer::GetAudioOutputDriverI Line 836  String LSCPServer::GetAudioOutputDriverI
836  }  }
837    
838  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
839      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()));
840      LSCPResultSet result;      LSCPResultSet result;
841      try {      try {
842          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
843          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
844          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
845          result.Add("MANDATORY",    (pParameter->Mandatory())    ? "true" : "false");          result.Add("MANDATORY",    pParameter->Mandatory());
846          result.Add("FIX",          (pParameter->Fix())          ? "true" : "false");          result.Add("FIX",          pParameter->Fix());
847          result.Add("MULTIPLICITY", (pParameter->Multiplicity()) ? "true" : "false");          result.Add("MULTIPLICITY", pParameter->Multiplicity());
848          if (pParameter->Depends())       result.Add("DEPENDS",       *pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
849          if (pParameter->Default())       result.Add("DEFAULT",       *pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
850          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
851          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
852          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
853            if (oDepends)       result.Add("DEPENDS",       *oDepends);
854            if (oDefault)       result.Add("DEFAULT",       *oDefault);
855            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
856            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
857            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
858      }      }
859      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
860          result.Error(e);          result.Error(e);
# Line 757  String LSCPServer::GetMidiInputDriverPar Line 863  String LSCPServer::GetMidiInputDriverPar
863  }  }
864    
865  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
866      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()));
867      LSCPResultSet result;      LSCPResultSet result;
868      try {      try {
869          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
870          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
871          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
872          result.Add("MANDATORY",    (pParameter->Mandatory())    ? "true" : "false");          result.Add("MANDATORY",    pParameter->Mandatory());
873          result.Add("FIX",          (pParameter->Fix())          ? "true" : "false");          result.Add("FIX",          pParameter->Fix());
874          result.Add("MULTIPLICITY", (pParameter->Multiplicity()) ? "true" : "false");          result.Add("MULTIPLICITY", pParameter->Multiplicity());
875          if (pParameter->Depends())       result.Add("DEPENDS",       *pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
876          if (pParameter->Default())       result.Add("DEFAULT",       *pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
877          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
878          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
879          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
880            if (oDepends)       result.Add("DEPENDS",       *oDepends);
881            if (oDefault)       result.Add("DEFAULT",       *oDefault);
882            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
883            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
884            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
885      }      }
886      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
887          result.Error(e);          result.Error(e);
# Line 847  String LSCPServer::GetAudioOutputDeviceI Line 958  String LSCPServer::GetAudioOutputDeviceI
958      LSCPResultSet result;      LSCPResultSet result;
959      try {      try {
960          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
961          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) + ".");
962          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
963          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
964          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
965          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
966          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 867  String LSCPServer::GetMidiInputDeviceInf Line 978  String LSCPServer::GetMidiInputDeviceInf
978      LSCPResultSet result;      LSCPResultSet result;
979      try {      try {
980          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
981            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
982          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
983          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
984          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
985          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
986          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 885  String LSCPServer::GetMidiInputPortInfo( Line 996  String LSCPServer::GetMidiInputPortInfo(
996      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
997      LSCPResultSet result;      LSCPResultSet result;
998      try {      try {
999            // get MIDI input device
1000          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1001            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1002          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1003          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1004          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1005          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1006          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1007          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
1008            // return the values of all MIDI port parameters
1009            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1010            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
1011          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
1012              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1013          }          }
# Line 908  String LSCPServer::GetAudioOutputChannel Line 1024  String LSCPServer::GetAudioOutputChannel
1024      try {      try {
1025          // get audio output device          // get audio output device
1026          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1027          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) + ".");
1028          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1029    
1030          // get audio channel          // get audio channel
1031          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1032          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) + ".");
1033    
1034          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1035          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 932  String LSCPServer::GetMidiInputPortParam Line 1048  String LSCPServer::GetMidiInputPortParam
1048      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()));
1049      LSCPResultSet result;      LSCPResultSet result;
1050      try {      try {
1051          // get audio output device          // get MIDI input device
1052          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1053          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) + ".");
1054          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1055    
1056          // get midi port          // get midi port
1057          MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1058          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) + ".");
1059    
1060          // get desired port parameter          // get desired port parameter
1061          std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1062          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 + "'.");
1063          DeviceCreationParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1064    
1065          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
1066          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
1067          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1068          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1069          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1070          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1071          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1072          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1073      }      }
1074      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1075          result.Error(e);          result.Error(e);
# Line 967  String LSCPServer::GetAudioOutputChannel Line 1083  String LSCPServer::GetAudioOutputChannel
1083      try {      try {
1084          // get audio output device          // get audio output device
1085          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1086          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) + ".");
1087          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1088    
1089          // get audio channel          // get audio channel
1090          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1091          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) + ".");
1092    
1093          // get desired audio channel parameter          // get desired audio channel parameter
1094          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1095          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 + "'.");
1096          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1097    
1098          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 984  String LSCPServer::GetAudioOutputChannel Line 1100  String LSCPServer::GetAudioOutputChannel
1100          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1101          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1102          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1103          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1104          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1105          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1106      }      }
1107      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1108          result.Error(e);          result.Error(e);
# Line 1000  String LSCPServer::SetAudioOutputChannel Line 1116  String LSCPServer::SetAudioOutputChannel
1116      try {      try {
1117          // get audio output device          // get audio output device
1118          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1119          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) + ".");
1120          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1121    
1122          // get audio channel          // get audio channel
1123          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1124          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) + ".");
1125    
1126          // get desired audio channel parameter          // get desired audio channel parameter
1127          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1128          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 + "'.");
1129          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1130    
1131          // set new channel parameter value          // set new channel parameter value
# Line 1026  String LSCPServer::SetAudioOutputDeviceP Line 1142  String LSCPServer::SetAudioOutputDeviceP
1142      LSCPResultSet result;      LSCPResultSet result;
1143      try {      try {
1144          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1145          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) + ".");
1146          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1147          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1148          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 + "'");
1149          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1150      }      }
1151      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1043  String LSCPServer::SetMidiInputDevicePar Line 1159  String LSCPServer::SetMidiInputDevicePar
1159      LSCPResultSet result;      LSCPResultSet result;
1160      try {      try {
1161          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1162          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) + ".");
1163          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1164          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1165          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 + "'");
1166          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1167      }      }
1168      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1059  String LSCPServer::SetMidiInputPortParam Line 1175  String LSCPServer::SetMidiInputPortParam
1175      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()));
1176      LSCPResultSet result;      LSCPResultSet result;
1177      try {      try {
1178            // get MIDI input device
1179          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1180            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1181          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1182          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1183          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1184          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1185          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1186          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1187            // set port parameter value
1188            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1189            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1190          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1191      }      }
1192      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1080  String LSCPServer::SetMidiInputPortParam Line 1201  String LSCPServer::SetMidiInputPortParam
1201   */   */
1202  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1203      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));
1204      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1205        try {
1206            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1207            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1208            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1209            if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1210            if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1211            pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1212        }
1213        catch (LinuxSamplerException e) {
1214             result.Error(e);
1215        }
1216        return result.Produce();
1217  }  }
1218    
1219  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1088  String LSCPServer::SetAudioOutputDevice( Line 1221  String LSCPServer::SetAudioOutputDevice(
1221      LSCPResultSet result;      LSCPResultSet result;
1222      try {      try {
1223          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1224          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1225          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1226            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1227          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1228          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1229      }      }
1230      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1105  String LSCPServer::SetAudioOutputType(St Line 1238  String LSCPServer::SetAudioOutputType(St
1238      LSCPResultSet result;      LSCPResultSet result;
1239      try {      try {
1240          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1241          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1242          // Driver type name aliasing...          // Driver type name aliasing...
1243          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1244          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1245          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1246          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1247          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1142  String LSCPServer::SetMIDIInputPort(uint Line 1275  String LSCPServer::SetMIDIInputPort(uint
1275      LSCPResultSet result;      LSCPResultSet result;
1276      try {      try {
1277          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1278          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1279          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1280      }      }
1281      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1156  String LSCPServer::SetMIDIInputChannel(u Line 1289  String LSCPServer::SetMIDIInputChannel(u
1289      LSCPResultSet result;      LSCPResultSet result;
1290      try {      try {
1291          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1292          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1293          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1294      }      }
1295      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1296           result.Error(e);           result.Error(e);
# Line 1170  String LSCPServer::SetMIDIInputDevice(ui Line 1303  String LSCPServer::SetMIDIInputDevice(ui
1303      LSCPResultSet result;      LSCPResultSet result;
1304      try {      try {
1305          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1306          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1307          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1308            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1309          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1310          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1311      }      }
1312      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1187  String LSCPServer::SetMIDIInputType(Stri Line 1320  String LSCPServer::SetMIDIInputType(Stri
1320      LSCPResultSet result;      LSCPResultSet result;
1321      try {      try {
1322          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1323          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1324          // Driver type name aliasing...          // Driver type name aliasing...
1325          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1326          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1327          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1328          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1207  String LSCPServer::SetMIDIInputType(Stri Line 1340  String LSCPServer::SetMIDIInputType(Stri
1340              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1341              // Make it with at least one initial port.              // Make it with at least one initial port.
1342              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1343              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1344          }          }
1345          // Must have a device...          // Must have a device...
1346          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1230  String LSCPServer::SetMIDIInput(uint MID Line 1363  String LSCPServer::SetMIDIInput(uint MID
1363      LSCPResultSet result;      LSCPResultSet result;
1364      try {      try {
1365          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1366          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1367          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1368            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1369          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1370          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);  
1371      }      }
1372      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1373           result.Error(e);           result.Error(e);
# Line 1246  String LSCPServer::SetMIDIInput(uint MID Line 1379  String LSCPServer::SetMIDIInput(uint MID
1379   * 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
1380   * particular sampler channel.   * particular sampler channel.
1381   */   */
1382  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1383      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1384      LSCPResultSet result;      LSCPResultSet result;
1385      try {      try {
1386          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1387          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1388          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1389          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1390          pEngine->Volume(Volume);          pEngineChannel->Volume(dVolume);
1391      }      }
1392      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1393           result.Error(e);           result.Error(e);
# Line 1270  String LSCPServer::ResetChannel(uint uiS Line 1403  String LSCPServer::ResetChannel(uint uiS
1403      LSCPResultSet result;      LSCPResultSet result;
1404      try {      try {
1405          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1406          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1407          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1408          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1409          pEngine->Reset();          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
1410            pEngineChannel->GetEngine()->Reset();
1411      }      }
1412      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1413           result.Error(e);           result.Error(e);
# Line 1292  String LSCPServer::ResetSampler() { Line 1426  String LSCPServer::ResetSampler() {
1426  }  }
1427    
1428  /**  /**
1429     * Will be called by the parser to return general informations about this
1430     * sampler.
1431     */
1432    String LSCPServer::GetServerInfo() {
1433        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1434        LSCPResultSet result;
1435        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1436        result.Add("VERSION", VERSION);
1437        result.Add("PROTOCOL_VERSION", "1.0");
1438        return result.Produce();
1439    }
1440    
1441    /**
1442   * 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
1443   * server for receiving event messages.   * server for receiving event messages.
1444   */   */
# Line 1317  String LSCPServer::UnsubscribeNotificati Line 1464  String LSCPServer::UnsubscribeNotificati
1464      return result.Produce();      return result.Produce();
1465  }  }
1466    
1467    static int select_callback(void * lscpResultSet, int argc,
1468                            char **argv, char **azColName)
1469    {
1470        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1471        resultSet->Add(argc, argv);
1472        return 0;
1473    }
1474    
1475    String LSCPServer::QueryDatabase(String query) {
1476        LSCPResultSet result;
1477    #if HAVE_SQLITE3
1478        char* zErrMsg = NULL;
1479        sqlite3 *db;
1480        String selectStr = "SELECT " + query;
1481    
1482        int rc = sqlite3_open("linuxsampler.db", &db);
1483        if (rc == SQLITE_OK)
1484        {
1485                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1486        }
1487        if ( rc != SQLITE_OK )
1488        {
1489                result.Error(String(zErrMsg), rc);
1490        }
1491        sqlite3_close(db);
1492    #else
1493        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1494    #endif
1495        return result.Produce();
1496    }
1497    
1498  /**  /**
1499   * Will be called by the parser to enable or disable echo mode; if echo   * Will be called by the parser to enable or disable echo mode; if echo
1500   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1335  String LSCPServer::SetEcho(yyparse_param Line 1513  String LSCPServer::SetEcho(yyparse_param
1513      }      }
1514      return result.Produce();      return result.Produce();
1515  }  }
   
 // 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.219  
changed lines
  Added in v.667

  ViewVC Help
Powered by ViewVC