/[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 620 by schoenebeck, Wed Jun 8 23:16:13 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 "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
37  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
38    
# Line 50  std::map< LSCPEvent::event_t, std::list< Line 58  std::map< LSCPEvent::event_t, std::list<
58  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex = Mutex();
59  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex = Mutex();
60  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
61    Mutex LSCPServer::RTNotifyMutex = Mutex();
62    
63  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
64      this->pSampler = pSampler;      this->pSampler = pSampler;
65      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
66      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
67      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
68      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
69      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
71        hSocket = -1;
72    }
73    
74    LSCPServer::~LSCPServer() {
75        if (hSocket >= 0) close(hSocket);
76  }  }
77    
78  /**  /**
# Line 76  int LSCPServer::WaitUntilInitialized(lon Line 90  int LSCPServer::WaitUntilInitialized(lon
90  }  }
91    
92  int LSCPServer::Main() {  int LSCPServer::Main() {
93      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
94      if (hSocket < 0) {      if (hSocket < 0) {
95          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
96          //return -1;          //return -1;
# Line 88  int LSCPServer::Main() { Line 102  int LSCPServer::Main() {
102      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
103    
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 147  int LSCPServer::Main() { Line 170  int LSCPServer::Main() {
170                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
171                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
172                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
173                                  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
174                                    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 173  int LSCPServer::Main() { Line 198  int LSCPServer::Main() {
198          }          }
199          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
200      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
201  }  }
202    
203  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 216  void LSCPServer::CloseConnection( std::v
216          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
217          close(socket);          close(socket);
218          NotifyMutex.Unlock();          NotifyMutex.Unlock();
219          //yylex_destroy((*iter).pScanner);  }
220    
221    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
222            int subs = 0;
223            SubscriptionMutex.Lock();
224            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
225                            iter != events.end(); iter++)
226            {
227                    subs += eventSubscriptions.count(*iter);
228            }
229            SubscriptionMutex.Unlock();
230            return subs;
231  }  }
232    
233  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
# Line 392  String LSCPServer::DestroyAudioOutputDev Line 426  String LSCPServer::DestroyAudioOutputDev
426      LSCPResultSet result;      LSCPResultSet result;
427      try {      try {
428          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
429          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) + ".");
430          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
431          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
432      }      }
# Line 407  String LSCPServer::DestroyMidiInputDevic Line 441  String LSCPServer::DestroyMidiInputDevic
441      LSCPResultSet result;      LSCPResultSet result;
442      try {      try {
443          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
444            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
445          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
446          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
447      }      }
448      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 425  String LSCPServer::LoadInstrument(String Line 459  String LSCPServer::LoadInstrument(String
459      LSCPResultSet result;      LSCPResultSet result;
460      try {      try {
461          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
462          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
463          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
464          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
465          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
466              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
467          if (bBackground) {          if (bBackground) {
468              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
469              pLoadInstrument->StartThread();          }
470            else {
471                // tell the engine channel which instrument to load
472                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
473                // actually start to load the instrument (blocks until completed)
474                pEngineChannel->LoadInstrument();
475          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
476      }      }
477      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
478           result.Error(e);           result.Error(e);
# Line 443  String LSCPServer::LoadInstrument(String Line 481  String LSCPServer::LoadInstrument(String
481  }  }
482    
483  /**  /**
484   * 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
485     * sampler channel.
486   */   */
487  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
488      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));
489      LSCPResultSet result;      LSCPResultSet result;
490      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
491          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
492          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
493          pSamplerChannel->LoadEngine(type);          LockRTNotify();
494            pSamplerChannel->SetEngineType(EngineName);
495            UnlockRTNotify();
496      }      }
497      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
498           result.Error(e);           result.Error(e);
# Line 505  String LSCPServer::AddChannel() { Line 543  String LSCPServer::AddChannel() {
543  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
544      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
545      LSCPResultSet result;      LSCPResultSet result;
546        LockRTNotify();
547      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
548        UnlockRTNotify();
549      return result.Produce();      return result.Produce();
550  }  }
551    
552  /**  /**
553   * 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.
554   */   */
555  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
556      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
557      LSCPResultSet result("GigEngine");      LSCPResultSet result("1");
558      return result.Produce();      return result.Produce();
559  }  }
560    
561  /**  /**
562   * Will be called by the parser to get descriptions for a particular engine.   * Will be called by the parser to get a list of all available engines.
563     */
564    String LSCPServer::ListAvailableEngines() {
565        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
566        LSCPResultSet result("\'GIG\'");
567        return result.Produce();
568    }
569    
570    /**
571     * Will be called by the parser to get descriptions for a particular
572     * sampler engine.
573   */   */
574  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
575      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
576      LSCPResultSet result;      LSCPResultSet result;
577      try {      try {
578          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
579              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
580              result.Add(pEngine->Description());          result.Add("VERSION",     pEngine->Version());
581              result.Add(pEngine->Version());          delete pEngine;
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
582      }      }
583      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
584           result.Error(e);           result.Error(e);
# Line 548  String LSCPServer::GetChannelInfo(uint u Line 595  String LSCPServer::GetChannelInfo(uint u
595      LSCPResultSet result;      LSCPResultSet result;
596      try {      try {
597          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
598          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
599          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
600    
601          //Defaults values          //Defaults values
602          String EngineName = "NONE";          String EngineName = "NONE";
603          float Volume = 0;          float Volume = 0.0f;
604          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
605            String InstrumentName = "NONE";
606          int InstrumentIndex = -1;          int InstrumentIndex = -1;
607          int InstrumentStatus = -1;          int InstrumentStatus = -1;
608            int AudioOutputChannels = 0;
609            String AudioRouting;
610    
611          if (pEngine) {          if (pEngineChannel) {
612              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
613              Volume = pEngine->Volume();              AudioOutputChannels = pEngineChannel->Channels();
614              InstrumentStatus = pEngine->InstrumentStatus();              Volume              = pEngineChannel->Volume();
615              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
616              if (InstrumentIndex != -1)              InstrumentIndex     = pEngineChannel->InstrumentIndex();
617                  InstrumentFileName = pEngine->InstrumentFileName();              if (InstrumentIndex != -1) {
618                    InstrumentFileName = pEngineChannel->InstrumentFileName();
619                    InstrumentName     = pEngineChannel->InstrumentName();
620                }
621                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
622                    if (AudioRouting != "") AudioRouting += ",";
623                    AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
624                }
625          }          }
626    
627          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 572  String LSCPServer::GetChannelInfo(uint u Line 629  String LSCPServer::GetChannelInfo(uint u
629    
630          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
631          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
632          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
633          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
634    
635          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
636          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
637          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
638            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
639    
640          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
641          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
642            result.Add("INSTRUMENT_NAME", InstrumentName);
643          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
644      }      }
645      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 598  String LSCPServer::GetVoiceCount(uint ui Line 657  String LSCPServer::GetVoiceCount(uint ui
657      LSCPResultSet result;      LSCPResultSet result;
658      try {      try {
659          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
660          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
661          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
662          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
663          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
664            result.Add(pEngineChannel->GetEngine()->VoiceCount());
665      }      }
666      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
667           result.Error(e);           result.Error(e);
# Line 618  String LSCPServer::GetStreamCount(uint u Line 678  String LSCPServer::GetStreamCount(uint u
678      LSCPResultSet result;      LSCPResultSet result;
679      try {      try {
680          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
681          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
682          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
683          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
684          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
685            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
686      }      }
687      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
688           result.Error(e);           result.Error(e);
# Line 638  String LSCPServer::GetBufferFill(fill_re Line 699  String LSCPServer::GetBufferFill(fill_re
699      LSCPResultSet result;      LSCPResultSet result;
700      try {      try {
701          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
702          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
703          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
704          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
705          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
706              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
707          else {          else {
708              switch (ResponseType) {              switch (ResponseType) {
709                  case fill_response_bytes:                  case fill_response_bytes:
710                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
711                      break;                      break;
712                  case fill_response_percentage:                  case fill_response_percentage:
713                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
714                      break;                      break;
715                  default:                  default:
716                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
717              }              }
# Line 666  String LSCPServer::GetAvailableAudioOutp Line 727  String LSCPServer::GetAvailableAudioOutp
727      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
728      LSCPResultSet result;      LSCPResultSet result;
729      try {      try {
730            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
731            result.Add(n);
732        }
733        catch (LinuxSamplerException e) {
734            result.Error(e);
735        }
736        return result.Produce();
737    }
738    
739    String LSCPServer::ListAvailableAudioOutputDrivers() {
740        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
741        LSCPResultSet result;
742        try {
743          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
744          result.Add(s);          result.Add(s);
745      }      }
# Line 679  String LSCPServer::GetAvailableMidiInput Line 753  String LSCPServer::GetAvailableMidiInput
753      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
754      LSCPResultSet result;      LSCPResultSet result;
755      try {      try {
756            int n = MidiInputDeviceFactory::AvailableDrivers().size();
757            result.Add(n);
758        }
759        catch (LinuxSamplerException e) {
760            result.Error(e);
761        }
762        return result.Produce();
763    }
764    
765    String LSCPServer::ListAvailableMidiInputDrivers() {
766        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
767        LSCPResultSet result;
768        try {
769          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
770          result.Add(s);          result.Add(s);
771      }      }
# Line 737  String LSCPServer::GetAudioOutputDriverI Line 824  String LSCPServer::GetAudioOutputDriverI
824  }  }
825    
826  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
827      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()));
828      LSCPResultSet result;      LSCPResultSet result;
829      try {      try {
830          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 746  String LSCPServer::GetMidiInputDriverPar Line 833  String LSCPServer::GetMidiInputDriverPar
833          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
834          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
835          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
836          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
837          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
838          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
839          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
840          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
841            if (oDepends)       result.Add("DEPENDS",       *oDepends);
842            if (oDefault)       result.Add("DEFAULT",       *oDefault);
843            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
844            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
845            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
846      }      }
847      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
848          result.Error(e);          result.Error(e);
# Line 759  String LSCPServer::GetMidiInputDriverPar Line 851  String LSCPServer::GetMidiInputDriverPar
851  }  }
852    
853  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
854      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()));
855      LSCPResultSet result;      LSCPResultSet result;
856      try {      try {
857          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 768  String LSCPServer::GetAudioOutputDriverP Line 860  String LSCPServer::GetAudioOutputDriverP
860          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
861          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
862          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
863          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
864          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
865          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
866          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
867          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
868            if (oDepends)       result.Add("DEPENDS",       *oDepends);
869            if (oDefault)       result.Add("DEFAULT",       *oDefault);
870            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
871            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
872            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
873      }      }
874      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
875          result.Error(e);          result.Error(e);
# Line 849  String LSCPServer::GetAudioOutputDeviceI Line 946  String LSCPServer::GetAudioOutputDeviceI
946      LSCPResultSet result;      LSCPResultSet result;
947      try {      try {
948          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
949          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) + ".");
950          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
951          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
952          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
953          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
954          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 869  String LSCPServer::GetMidiInputDeviceInf Line 966  String LSCPServer::GetMidiInputDeviceInf
966      LSCPResultSet result;      LSCPResultSet result;
967      try {      try {
968          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
969            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
970          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
971          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
972          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
973          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
974          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 887  String LSCPServer::GetMidiInputPortInfo( Line 984  String LSCPServer::GetMidiInputPortInfo(
984      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
985      LSCPResultSet result;      LSCPResultSet result;
986      try {      try {
987            // get MIDI input device
988          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
989            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
990          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
991          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
992          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
993          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
994          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
995          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
996            // return the values of all MIDI port parameters
997            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
998            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
999          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
1000              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1001          }          }
# Line 910  String LSCPServer::GetAudioOutputChannel Line 1012  String LSCPServer::GetAudioOutputChannel
1012      try {      try {
1013          // get audio output device          // get audio output device
1014          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1015          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) + ".");
1016          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1017    
1018          // get audio channel          // get audio channel
1019          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1020          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) + ".");
1021    
1022          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1023          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 934  String LSCPServer::GetMidiInputPortParam Line 1036  String LSCPServer::GetMidiInputPortParam
1036      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()));
1037      LSCPResultSet result;      LSCPResultSet result;
1038      try {      try {
1039          // get audio output device          // get MIDI input device
1040          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1041          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) + ".");
1042          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1043    
1044          // get midi port          // get midi port
1045          MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1046          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) + ".");
1047    
1048          // get desired port parameter          // get desired port parameter
1049          std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1050          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 + "'.");
1051          DeviceCreationParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1052    
1053          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
1054          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
1055          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1056          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1057          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1058          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1059          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1060          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1061      }      }
1062      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1063          result.Error(e);          result.Error(e);
# Line 969  String LSCPServer::GetAudioOutputChannel Line 1071  String LSCPServer::GetAudioOutputChannel
1071      try {      try {
1072          // get audio output device          // get audio output device
1073          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1074          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) + ".");
1075          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1076    
1077          // get audio channel          // get audio channel
1078          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1079          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) + ".");
1080    
1081          // get desired audio channel parameter          // get desired audio channel parameter
1082          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1083          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 + "'.");
1084          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1085    
1086          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 986  String LSCPServer::GetAudioOutputChannel Line 1088  String LSCPServer::GetAudioOutputChannel
1088          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1089          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1090          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1091          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1092          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1093          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1094      }      }
1095      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1096          result.Error(e);          result.Error(e);
# Line 1002  String LSCPServer::SetAudioOutputChannel Line 1104  String LSCPServer::SetAudioOutputChannel
1104      try {      try {
1105          // get audio output device          // get audio output device
1106          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1107          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) + ".");
1108          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1109    
1110          // get audio channel          // get audio channel
1111          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1112          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) + ".");
1113    
1114          // get desired audio channel parameter          // get desired audio channel parameter
1115          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1116          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 + "'.");
1117          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1118    
1119          // set new channel parameter value          // set new channel parameter value
# Line 1028  String LSCPServer::SetAudioOutputDeviceP Line 1130  String LSCPServer::SetAudioOutputDeviceP
1130      LSCPResultSet result;      LSCPResultSet result;
1131      try {      try {
1132          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1133          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) + ".");
1134          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1135          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1136          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 + "'");
1137          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1138      }      }
1139      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1045  String LSCPServer::SetMidiInputDevicePar Line 1147  String LSCPServer::SetMidiInputDevicePar
1147      LSCPResultSet result;      LSCPResultSet result;
1148      try {      try {
1149          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1150          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) + ".");
1151          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1152          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1153          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 + "'");
1154          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1155      }      }
1156      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1061  String LSCPServer::SetMidiInputPortParam Line 1163  String LSCPServer::SetMidiInputPortParam
1163      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()));
1164      LSCPResultSet result;      LSCPResultSet result;
1165      try {      try {
1166            // get MIDI input device
1167          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1168            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1169          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1170          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1171          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1172          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1173          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1174          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1175            // set port parameter value
1176            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1177            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1178          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1179      }      }
1180      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1082  String LSCPServer::SetMidiInputPortParam Line 1189  String LSCPServer::SetMidiInputPortParam
1189   */   */
1190  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1191      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));
1192      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1193        try {
1194            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1195            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1196            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1197            if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1198            if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1199            pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1200        }
1201        catch (LinuxSamplerException e) {
1202             result.Error(e);
1203        }
1204        return result.Produce();
1205  }  }
1206    
1207  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1090  String LSCPServer::SetAudioOutputDevice( Line 1209  String LSCPServer::SetAudioOutputDevice(
1209      LSCPResultSet result;      LSCPResultSet result;
1210      try {      try {
1211          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1212          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1213          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1214            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1215          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1216          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1217      }      }
1218      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1107  String LSCPServer::SetAudioOutputType(St Line 1226  String LSCPServer::SetAudioOutputType(St
1226      LSCPResultSet result;      LSCPResultSet result;
1227      try {      try {
1228          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1229          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1230          // Driver type name aliasing...          // Driver type name aliasing...
1231          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1232          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1233          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1234          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1235          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1144  String LSCPServer::SetMIDIInputPort(uint Line 1263  String LSCPServer::SetMIDIInputPort(uint
1263      LSCPResultSet result;      LSCPResultSet result;
1264      try {      try {
1265          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1266          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1267          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1268      }      }
1269      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1158  String LSCPServer::SetMIDIInputChannel(u Line 1277  String LSCPServer::SetMIDIInputChannel(u
1277      LSCPResultSet result;      LSCPResultSet result;
1278      try {      try {
1279          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1280          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1281          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1282      }      }
1283      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1284           result.Error(e);           result.Error(e);
# Line 1172  String LSCPServer::SetMIDIInputDevice(ui Line 1291  String LSCPServer::SetMIDIInputDevice(ui
1291      LSCPResultSet result;      LSCPResultSet result;
1292      try {      try {
1293          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1294          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1295          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1296            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1297          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1298          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1299      }      }
1300      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1189  String LSCPServer::SetMIDIInputType(Stri Line 1308  String LSCPServer::SetMIDIInputType(Stri
1308      LSCPResultSet result;      LSCPResultSet result;
1309      try {      try {
1310          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1311          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1312          // Driver type name aliasing...          // Driver type name aliasing...
1313          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1314          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1315          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1316          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1209  String LSCPServer::SetMIDIInputType(Stri Line 1328  String LSCPServer::SetMIDIInputType(Stri
1328              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1329              // Make it with at least one initial port.              // Make it with at least one initial port.
1330              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1331              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1332          }          }
1333          // Must have a device...          // Must have a device...
1334          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1232  String LSCPServer::SetMIDIInput(uint MID Line 1351  String LSCPServer::SetMIDIInput(uint MID
1351      LSCPResultSet result;      LSCPResultSet result;
1352      try {      try {
1353          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1354          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1355          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1356            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1357          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1358          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);  
1359      }      }
1360      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1361           result.Error(e);           result.Error(e);
# Line 1248  String LSCPServer::SetMIDIInput(uint MID Line 1367  String LSCPServer::SetMIDIInput(uint MID
1367   * 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
1368   * particular sampler channel.   * particular sampler channel.
1369   */   */
1370  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1371      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1372      LSCPResultSet result;      LSCPResultSet result;
1373      try {      try {
1374          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1375          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1376          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1377          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1378          pEngine->Volume(Volume);          pEngineChannel->Volume(dVolume);
1379      }      }
1380      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1381           result.Error(e);           result.Error(e);
# Line 1272  String LSCPServer::ResetChannel(uint uiS Line 1391  String LSCPServer::ResetChannel(uint uiS
1391      LSCPResultSet result;      LSCPResultSet result;
1392      try {      try {
1393          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1394          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1395          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1396          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1397          pEngine->Reset();          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
1398            pEngineChannel->GetEngine()->Reset();
1399      }      }
1400      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1401           result.Error(e);           result.Error(e);
# Line 1284  String LSCPServer::ResetChannel(uint uiS Line 1404  String LSCPServer::ResetChannel(uint uiS
1404  }  }
1405    
1406  /**  /**
1407     * Will be called by the parser to reset the whole sampler.
1408     */
1409    String LSCPServer::ResetSampler() {
1410        dmsg(2,("LSCPServer: ResetSampler()\n"));
1411        pSampler->Reset();
1412        LSCPResultSet result;
1413        return result.Produce();
1414    }
1415    
1416    /**
1417     * Will be called by the parser to return general informations about this
1418     * sampler.
1419     */
1420    String LSCPServer::GetServerInfo() {
1421        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1422        LSCPResultSet result;
1423        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1424        result.Add("VERSION", VERSION);
1425        result.Add("PROTOCOL_VERSION", "1.0");
1426        return result.Produce();
1427    }
1428    
1429    /**
1430   * 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
1431   * server for receiving event messages.   * server for receiving event messages.
1432   */   */
# Line 1309  String LSCPServer::UnsubscribeNotificati Line 1452  String LSCPServer::UnsubscribeNotificati
1452      return result.Produce();      return result.Produce();
1453  }  }
1454    
1455    static int select_callback(void * lscpResultSet, int argc,
1456                            char **argv, char **azColName)
1457    {
1458        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1459        resultSet->Add(argc, argv);
1460        return 0;
1461    }
1462    
1463    String LSCPServer::QueryDatabase(String query) {
1464        LSCPResultSet result;
1465    #if HAVE_SQLITE3
1466        char* zErrMsg = NULL;
1467        sqlite3 *db;
1468        String selectStr = "SELECT " + query;
1469    
1470        int rc = sqlite3_open("linuxsampler.db", &db);
1471        if (rc == SQLITE_OK)
1472        {
1473                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1474        }
1475        if ( rc != SQLITE_OK )
1476        {
1477                result.Error(String(zErrMsg), rc);
1478        }
1479        sqlite3_close(db);
1480    #else
1481        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1482    #endif
1483        return result.Produce();
1484    }
1485    
1486  /**  /**
1487   * 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
1488   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1327  String LSCPServer::SetEcho(yyparse_param Line 1501  String LSCPServer::SetEcho(yyparse_param
1501      }      }
1502      return result.Produce();      return result.Produce();
1503  }  }
   
 // 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.620

  ViewVC Help
Powered by ViewVC