/[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 360 by senkov, Mon Feb 7 00:19:30 2005 UTC revision 660 by schoenebeck, Fri Jun 17 19:49:30 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 52  Mutex LSCPServer::NotifyBufferMutex = Mu Line 61  Mutex LSCPServer::NotifyBufferMutex = Mu
61  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
62  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
63    
64  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
65      this->pSampler = pSampler;      this->pSampler = pSampler;
66      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
67      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
68      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
69      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
71      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
72        hSocket = -1;
73    }
74    
75    LSCPServer::~LSCPServer() {
76        if (hSocket >= 0) close(hSocket);
77  }  }
78    
79  /**  /**
# Line 77  int LSCPServer::WaitUntilInitialized(lon Line 91  int LSCPServer::WaitUntilInitialized(lon
91  }  }
92    
93  int LSCPServer::Main() {  int LSCPServer::Main() {
94      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
95      if (hSocket < 0) {      if (hSocket < 0) {
96          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
97          //return -1;          //return -1;
# Line 160  int LSCPServer::Main() { Line 174  int LSCPServer::Main() {
174                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
175                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
176                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
177                                    dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
178                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
179                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
180                                  }                                  }
# Line 176  int LSCPServer::Main() { Line 191  int LSCPServer::Main() {
191                  }                  }
192          }          }
193    
194            // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
195            {
196                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
197                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
198                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
199                for (; itEngineChannel != itEnd; ++itEngineChannel) {
200                    if ((*itEngineChannel)->StatusChanged()) {
201                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
202                    }
203                }
204            }
205    
206          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
207          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
208          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 445  String LSCPServer::LoadInstrument(String Line 472  String LSCPServer::LoadInstrument(String
472      LSCPResultSet result;      LSCPResultSet result;
473      try {      try {
474          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
475          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
476          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
477          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
478          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
479              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
480          if (bBackground) {          if (bBackground) {
481              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
482              pLoadInstrument->StartThread();          }
483            else {
484                // tell the engine channel which instrument to load
485                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
486                // actually start to load the instrument (blocks until completed)
487                pEngineChannel->LoadInstrument();
488          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
489      }      }
490      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
491           result.Error(e);           result.Error(e);
# Line 463  String LSCPServer::LoadInstrument(String Line 494  String LSCPServer::LoadInstrument(String
494  }  }
495    
496  /**  /**
497   * 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
498     * sampler channel.
499   */   */
500  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
501      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));
502      LSCPResultSet result;      LSCPResultSet result;
503      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
504          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
505          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
506          LockRTNotify();          LockRTNotify();
507          pSamplerChannel->LoadEngine(type);          pSamplerChannel->SetEngineType(EngineName);
508          UnlockRTNotify();          UnlockRTNotify();
509      }      }
510      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 534  String LSCPServer::RemoveChannel(uint ui Line 563  String LSCPServer::RemoveChannel(uint ui
563  }  }
564    
565  /**  /**
566   * 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.
567   */   */
568  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
569      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
570      LSCPResultSet result("GigEngine");      LSCPResultSet result("1");
571        return result.Produce();
572    }
573    
574    /**
575     * Will be called by the parser to get a list of all available engines.
576     */
577    String LSCPServer::ListAvailableEngines() {
578        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
579        LSCPResultSet result("\'GIG\'");
580      return result.Produce();      return result.Produce();
581  }  }
582    
583  /**  /**
584   * 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
585     * sampler engine.
586   */   */
587  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
588      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
589      LSCPResultSet result;      LSCPResultSet result;
590      try {      try {
591          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
592              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
593              result.Add("DESCRIPTION", pEngine->Description());          result.Add("VERSION",     pEngine->Version());
594              result.Add("VERSION",     pEngine->Version());          EngineFactory::Destroy(pEngine);
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
595      }      }
596      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
597           result.Error(e);           result.Error(e);
# Line 572  String LSCPServer::GetChannelInfo(uint u Line 608  String LSCPServer::GetChannelInfo(uint u
608      LSCPResultSet result;      LSCPResultSet result;
609      try {      try {
610          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
611          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
612          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
613    
614          //Defaults values          //Defaults values
615          String EngineName = "NONE";          String EngineName = "NONE";
616          float Volume = 0.0f;          float Volume = 0.0f;
617          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
618            String InstrumentName = "NONE";
619          int InstrumentIndex = -1;          int InstrumentIndex = -1;
620          int InstrumentStatus = -1;          int InstrumentStatus = -1;
621          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
622          String AudioRouting;          String AudioRouting;
623    
624          if (pEngine) {          if (pEngineChannel) {
625              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
626              AudioOutputChannels = pEngine->Channels();              AudioOutputChannels = pEngineChannel->Channels();
627              Volume = pEngine->Volume();              Volume              = pEngineChannel->Volume();
628              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
629              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex     = pEngineChannel->InstrumentIndex();
630              if (InstrumentIndex != -1)              if (InstrumentIndex != -1) {
631                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngineChannel->InstrumentFileName();
632              for (int chan = 0; chan < pEngine->Channels(); chan++) {                  InstrumentName     = pEngineChannel->InstrumentName();
633                }
634                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
635                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
636                  AudioRouting += ToString(pEngine->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
637              }              }
638          }          }
639    
# Line 613  String LSCPServer::GetChannelInfo(uint u Line 652  String LSCPServer::GetChannelInfo(uint u
652    
653          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
654          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
655            result.Add("INSTRUMENT_NAME", InstrumentName);
656          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
657      }      }
658      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 630  String LSCPServer::GetVoiceCount(uint ui Line 670  String LSCPServer::GetVoiceCount(uint ui
670      LSCPResultSet result;      LSCPResultSet result;
671      try {      try {
672          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
673          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
674          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
675          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
676          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
677            result.Add(pEngineChannel->GetEngine()->VoiceCount());
678      }      }
679      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
680           result.Error(e);           result.Error(e);
# Line 650  String LSCPServer::GetStreamCount(uint u Line 691  String LSCPServer::GetStreamCount(uint u
691      LSCPResultSet result;      LSCPResultSet result;
692      try {      try {
693          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
694          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
695          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
696          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
697          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
698            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
699      }      }
700      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
701           result.Error(e);           result.Error(e);
# Line 670  String LSCPServer::GetBufferFill(fill_re Line 712  String LSCPServer::GetBufferFill(fill_re
712      LSCPResultSet result;      LSCPResultSet result;
713      try {      try {
714          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
715          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
716          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
717          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
718          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
719              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
720          else {          else {
721              switch (ResponseType) {              switch (ResponseType) {
722                  case fill_response_bytes:                  case fill_response_bytes:
723                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
724                      break;                      break;
725                  case fill_response_percentage:                  case fill_response_percentage:
726                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
727                      break;                      break;
728                  default:                  default:
729                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
730              }              }
# Line 698  String LSCPServer::GetAvailableAudioOutp Line 740  String LSCPServer::GetAvailableAudioOutp
740      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
741      LSCPResultSet result;      LSCPResultSet result;
742      try {      try {
743            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
744            result.Add(n);
745        }
746        catch (LinuxSamplerException e) {
747            result.Error(e);
748        }
749        return result.Produce();
750    }
751    
752    String LSCPServer::ListAvailableAudioOutputDrivers() {
753        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
754        LSCPResultSet result;
755        try {
756          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
757          result.Add(s);          result.Add(s);
758      }      }
# Line 711  String LSCPServer::GetAvailableMidiInput Line 766  String LSCPServer::GetAvailableMidiInput
766      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
767      LSCPResultSet result;      LSCPResultSet result;
768      try {      try {
769            int n = MidiInputDeviceFactory::AvailableDrivers().size();
770            result.Add(n);
771        }
772        catch (LinuxSamplerException e) {
773            result.Error(e);
774        }
775        return result.Produce();
776    }
777    
778    String LSCPServer::ListAvailableMidiInputDrivers() {
779        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
780        LSCPResultSet result;
781        try {
782          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
783          result.Add(s);          result.Add(s);
784      }      }
# Line 962  String LSCPServer::GetAudioOutputChannel Line 1030  String LSCPServer::GetAudioOutputChannel
1030    
1031          // get audio channel          // get audio channel
1032          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1033          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) + ".");
1034    
1035          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1036          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1021  String LSCPServer::GetAudioOutputChannel Line 1089  String LSCPServer::GetAudioOutputChannel
1089    
1090          // get audio channel          // get audio channel
1091          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1092          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) + ".");
1093    
1094          // get desired audio channel parameter          // get desired audio channel parameter
1095          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1054  String LSCPServer::SetAudioOutputChannel Line 1122  String LSCPServer::SetAudioOutputChannel
1122    
1123          // get audio channel          // get audio channel
1124          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1125          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) + ".");
1126    
1127          // get desired audio channel parameter          // get desired audio channel parameter
1128          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1137  String LSCPServer::SetAudioOutputChannel Line 1205  String LSCPServer::SetAudioOutputChannel
1205      LSCPResultSet result;      LSCPResultSet result;
1206      try {      try {
1207          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1208          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1209          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1210          if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));          if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1211          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1212          if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel));          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
         pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);  
1213      }      }
1214      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1215           result.Error(e);           result.Error(e);
# Line 1155  String LSCPServer::SetAudioOutputDevice( Line 1222  String LSCPServer::SetAudioOutputDevice(
1222      LSCPResultSet result;      LSCPResultSet result;
1223      try {      try {
1224          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1225          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1226          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1227          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1228          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
# Line 1172  String LSCPServer::SetAudioOutputType(St Line 1239  String LSCPServer::SetAudioOutputType(St
1239      LSCPResultSet result;      LSCPResultSet result;
1240      try {      try {
1241          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1242          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1243          // Driver type name aliasing...          // Driver type name aliasing...
1244          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1245          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1209  String LSCPServer::SetMIDIInputPort(uint Line 1276  String LSCPServer::SetMIDIInputPort(uint
1276      LSCPResultSet result;      LSCPResultSet result;
1277      try {      try {
1278          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1279          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1280          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1281      }      }
1282      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1223  String LSCPServer::SetMIDIInputChannel(u Line 1290  String LSCPServer::SetMIDIInputChannel(u
1290      LSCPResultSet result;      LSCPResultSet result;
1291      try {      try {
1292          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1293          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1294          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1295      }      }
1296      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1237  String LSCPServer::SetMIDIInputDevice(ui Line 1304  String LSCPServer::SetMIDIInputDevice(ui
1304      LSCPResultSet result;      LSCPResultSet result;
1305      try {      try {
1306          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1307          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1308          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1309          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1310          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
# Line 1254  String LSCPServer::SetMIDIInputType(Stri Line 1321  String LSCPServer::SetMIDIInputType(Stri
1321      LSCPResultSet result;      LSCPResultSet result;
1322      try {      try {
1323          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1324          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1325          // Driver type name aliasing...          // Driver type name aliasing...
1326          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1327          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1297  String LSCPServer::SetMIDIInput(uint MID Line 1364  String LSCPServer::SetMIDIInput(uint MID
1364      LSCPResultSet result;      LSCPResultSet result;
1365      try {      try {
1366          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1367          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1368          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1369          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1370          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
# Line 1318  String LSCPServer::SetVolume(double dVol Line 1385  String LSCPServer::SetVolume(double dVol
1385      LSCPResultSet result;      LSCPResultSet result;
1386      try {      try {
1387          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1388          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1389          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1390          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1391          pEngine->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1392      }      }
1393      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1394           result.Error(e);           result.Error(e);
# Line 1337  String LSCPServer::ResetChannel(uint uiS Line 1404  String LSCPServer::ResetChannel(uint uiS
1404      LSCPResultSet result;      LSCPResultSet result;
1405      try {      try {
1406          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1407          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1408          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1409          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1410          pEngine->Reset();          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
1411            pEngineChannel->GetEngine()->Reset();
1412      }      }
1413      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1414           result.Error(e);           result.Error(e);
# Line 1359  String LSCPServer::ResetSampler() { Line 1427  String LSCPServer::ResetSampler() {
1427  }  }
1428    
1429  /**  /**
1430     * Will be called by the parser to return general informations about this
1431     * sampler.
1432     */
1433    String LSCPServer::GetServerInfo() {
1434        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1435        LSCPResultSet result;
1436        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1437        result.Add("VERSION", VERSION);
1438        result.Add("PROTOCOL_VERSION", "1.0");
1439        return result.Produce();
1440    }
1441    
1442    /**
1443   * 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
1444   * server for receiving event messages.   * server for receiving event messages.
1445   */   */
# Line 1384  String LSCPServer::UnsubscribeNotificati Line 1465  String LSCPServer::UnsubscribeNotificati
1465      return result.Produce();      return result.Produce();
1466  }  }
1467    
1468    static int select_callback(void * lscpResultSet, int argc,
1469                            char **argv, char **azColName)
1470    {
1471        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1472        resultSet->Add(argc, argv);
1473        return 0;
1474    }
1475    
1476    String LSCPServer::QueryDatabase(String query) {
1477        LSCPResultSet result;
1478    #if HAVE_SQLITE3
1479        char* zErrMsg = NULL;
1480        sqlite3 *db;
1481        String selectStr = "SELECT " + query;
1482    
1483        int rc = sqlite3_open("linuxsampler.db", &db);
1484        if (rc == SQLITE_OK)
1485        {
1486                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1487        }
1488        if ( rc != SQLITE_OK )
1489        {
1490                result.Error(String(zErrMsg), rc);
1491        }
1492        sqlite3_close(db);
1493    #else
1494        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1495    #endif
1496        return result.Produce();
1497    }
1498    
1499  /**  /**
1500   * 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
1501   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1402  String LSCPServer::SetEcho(yyparse_param Line 1514  String LSCPServer::SetEcho(yyparse_param
1514      }      }
1515      return result.Produce();      return result.Produce();
1516  }  }
   
 // 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.360  
changed lines
  Added in v.660

  ViewVC Help
Powered by ViewVC