/[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 385 by schoenebeck, Thu Feb 17 02:53:45 2005 UTC revision 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC
# Line 24  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 53  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, long int addr, short int port) : Thread(true, false, 0, -4) {
65        SocketAddress.sin_family      = AF_INET;
66        SocketAddress.sin_addr.s_addr = addr;
67        SocketAddress.sin_port        = port;
68      this->pSampler = pSampler;      this->pSampler = pSampler;
69      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
71      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
72      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
75        hSocket = -1;
76    }
77    
78    LSCPServer::~LSCPServer() {
79        if (hSocket >= 0) close(hSocket);
80  }  }
81    
82  /**  /**
# Line 78  int LSCPServer::WaitUntilInitialized(lon Line 94  int LSCPServer::WaitUntilInitialized(lon
94  }  }
95    
96  int LSCPServer::Main() {  int LSCPServer::Main() {
97      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
98      if (hSocket < 0) {      if (hSocket < 0) {
99          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
100          //return -1;          //return -1;
101          exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
102      }      }
103    
     SocketAddress.sin_family      = AF_INET;  
     SocketAddress.sin_port        = htons(LSCP_PORT);  
     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);  
   
104      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
105          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";
106          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
# Line 161  int LSCPServer::Main() { Line 173  int LSCPServer::Main() {
173                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
174                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
175                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
176                                    dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
177                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
178                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
179                                  }                                  }
# Line 177  int LSCPServer::Main() { Line 190  int LSCPServer::Main() {
190                  }                  }
191          }          }
192    
193            // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
194            {
195                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
196                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
197                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
198                for (; itEngineChannel != itEnd; ++itEngineChannel) {
199                    if ((*itEngineChannel)->StatusChanged()) {
200                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
201                    }
202                }
203            }
204    
205          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
206          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
207          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
# Line 447  String LSCPServer::LoadInstrument(String Line 472  String LSCPServer::LoadInstrument(String
472      try {      try {
473          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
474          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
475          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
476          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
477          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
478              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
479          if (bBackground) {          if (bBackground) {
480              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
481            }
482            else {
483                // tell the engine channel which instrument to load
484                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
485                // actually start to load the instrument (blocks until completed)
486                pEngineChannel->LoadInstrument();
487          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
488      }      }
489      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
490           result.Error(e);           result.Error(e);
# Line 463  String LSCPServer::LoadInstrument(String Line 493  String LSCPServer::LoadInstrument(String
493  }  }
494    
495  /**  /**
496   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to assign a sampler engine type to a
497     * sampler channel.
498   */   */
499  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
500      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
501      LSCPResultSet result;      LSCPResultSet result;
502      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
503          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
504          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
505          LockRTNotify();          LockRTNotify();
506          pSamplerChannel->LoadEngine(type);          pSamplerChannel->SetEngineType(EngineName);
507          UnlockRTNotify();          UnlockRTNotify();
508      }      }
509      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 534  String LSCPServer::RemoveChannel(uint ui Line 562  String LSCPServer::RemoveChannel(uint ui
562  }  }
563    
564  /**  /**
565   * Will be called by the parser to get all available engines.   * Will be called by the parser to get the amount of all available engines.
566   */   */
567  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
568      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
569      LSCPResultSet result("GigEngine");      LSCPResultSet result("1");
570        return result.Produce();
571    }
572    
573    /**
574     * Will be called by the parser to get a list of all available engines.
575     */
576    String LSCPServer::ListAvailableEngines() {
577        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
578        LSCPResultSet result("\'GIG\'");
579      return result.Produce();      return result.Produce();
580  }  }
581    
582  /**  /**
583   * Will be called by the parser to get descriptions for a particular engine.   * Will be called by the parser to get descriptions for a particular
584     * sampler engine.
585   */   */
586  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
587      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
588      LSCPResultSet result;      LSCPResultSet result;
589      try {      try {
590          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
591              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
592              result.Add("DESCRIPTION", pEngine->Description());          result.Add("VERSION",     pEngine->Version());
593              result.Add("VERSION",     pEngine->Version());          EngineFactory::Destroy(pEngine);
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
594      }      }
595      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
596           result.Error(e);           result.Error(e);
# Line 573  String LSCPServer::GetChannelInfo(uint u Line 608  String LSCPServer::GetChannelInfo(uint u
608      try {      try {
609          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
610          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
611          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
612    
613          //Defaults values          //Defaults values
614          String EngineName = "NONE";          String EngineName = "NONE";
# Line 585  String LSCPServer::GetChannelInfo(uint u Line 620  String LSCPServer::GetChannelInfo(uint u
620          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
621          String AudioRouting;          String AudioRouting;
622    
623          if (pEngine) {          if (pEngineChannel) {
624              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
625              AudioOutputChannels = pEngine->Channels();              AudioOutputChannels = pEngineChannel->Channels();
626              Volume = pEngine->Volume();              Volume              = pEngineChannel->Volume();
627              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
628              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex     = pEngineChannel->InstrumentIndex();
629              if (InstrumentIndex != -1)              if (InstrumentIndex != -1) {
630              {                  InstrumentFileName = pEngineChannel->InstrumentFileName();
631                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentName     = pEngineChannel->InstrumentName();
632                  InstrumentName = pEngine->InstrumentName();              }
633              }              for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
             for (int chan = 0; chan < pEngine->Channels(); chan++) {  
634                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
635                  AudioRouting += ToString(pEngine->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
636              }              }
637          }          }
638    
# Line 612  String LSCPServer::GetChannelInfo(uint u Line 646  String LSCPServer::GetChannelInfo(uint u
646    
647          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
648          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
649          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
650          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
651    
652          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
# Line 636  String LSCPServer::GetVoiceCount(uint ui Line 670  String LSCPServer::GetVoiceCount(uint ui
670      try {      try {
671          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
672          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
673          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
674          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
675          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
676            result.Add(pEngineChannel->GetEngine()->VoiceCount());
677      }      }
678      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
679           result.Error(e);           result.Error(e);
# Line 656  String LSCPServer::GetStreamCount(uint u Line 691  String LSCPServer::GetStreamCount(uint u
691      try {      try {
692          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
693          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
694          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
695          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
696          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
697            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
698      }      }
699      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
700           result.Error(e);           result.Error(e);
# Line 676  String LSCPServer::GetBufferFill(fill_re Line 712  String LSCPServer::GetBufferFill(fill_re
712      try {      try {
713          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
714          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
715          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
716          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
717          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
718              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
719          else {          else {
720              switch (ResponseType) {              switch (ResponseType) {
721                  case fill_response_bytes:                  case fill_response_bytes:
722                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
723                      break;                      break;
724                  case fill_response_percentage:                  case fill_response_percentage:
725                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
726                      break;                      break;
727                  default:                  default:
728                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
729              }              }
# Line 703  String LSCPServer::GetAvailableAudioOutp Line 739  String LSCPServer::GetAvailableAudioOutp
739      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
740      LSCPResultSet result;      LSCPResultSet result;
741      try {      try {
742            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
743            result.Add(n);
744        }
745        catch (LinuxSamplerException e) {
746            result.Error(e);
747        }
748        return result.Produce();
749    }
750    
751    String LSCPServer::ListAvailableAudioOutputDrivers() {
752        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
753        LSCPResultSet result;
754        try {
755          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
756          result.Add(s);          result.Add(s);
757      }      }
# Line 716  String LSCPServer::GetAvailableMidiInput Line 765  String LSCPServer::GetAvailableMidiInput
765      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
766      LSCPResultSet result;      LSCPResultSet result;
767      try {      try {
768            int n = MidiInputDeviceFactory::AvailableDrivers().size();
769            result.Add(n);
770        }
771        catch (LinuxSamplerException e) {
772            result.Error(e);
773        }
774        return result.Produce();
775    }
776    
777    String LSCPServer::ListAvailableMidiInputDrivers() {
778        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
779        LSCPResultSet result;
780        try {
781          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
782          result.Add(s);          result.Add(s);
783      }      }
# Line 1143  String LSCPServer::SetAudioOutputChannel Line 1205  String LSCPServer::SetAudioOutputChannel
1205      try {      try {
1206          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1207          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1208          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1209          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));
1210          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1211          pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1212      }      }
1213      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1214           result.Error(e);           result.Error(e);
# Line 1228  String LSCPServer::SetMIDIInputChannel(u Line 1290  String LSCPServer::SetMIDIInputChannel(u
1290      try {      try {
1291          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1292          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1293          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1294      }      }
1295      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1296           result.Error(e);           result.Error(e);
# Line 1305  String LSCPServer::SetMIDIInput(uint MID Line 1367  String LSCPServer::SetMIDIInput(uint MID
1367          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1368          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1369          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1370          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1371      }      }
1372      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1373           result.Error(e);           result.Error(e);
# Line 1323  String LSCPServer::SetVolume(double dVol Line 1385  String LSCPServer::SetVolume(double dVol
1385      try {      try {
1386          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1387          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1388          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1389          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1390          pEngine->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1391      }      }
1392      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1393           result.Error(e);           result.Error(e);
# Line 1342  String LSCPServer::ResetChannel(uint uiS Line 1404  String LSCPServer::ResetChannel(uint uiS
1404      try {      try {
1405          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1406          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1407          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1408          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1409          pEngine->Reset();          pEngineChannel->Reset();
1410      }      }
1411      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1412           result.Error(e);           result.Error(e);
# Line 1363  String LSCPServer::ResetSampler() { Line 1425  String LSCPServer::ResetSampler() {
1425  }  }
1426    
1427  /**  /**
1428     * Will be called by the parser to return general informations about this
1429     * sampler.
1430     */
1431    String LSCPServer::GetServerInfo() {
1432        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1433        LSCPResultSet result;
1434        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1435        result.Add("VERSION", VERSION);
1436        result.Add("PROTOCOL_VERSION", "1.0");
1437        return result.Produce();
1438    }
1439    
1440    /**
1441   * 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
1442   * server for receiving event messages.   * server for receiving event messages.
1443   */   */
# Line 1388  String LSCPServer::UnsubscribeNotificati Line 1463  String LSCPServer::UnsubscribeNotificati
1463      return result.Produce();      return result.Produce();
1464  }  }
1465    
1466    static int select_callback(void * lscpResultSet, int argc,
1467                            char **argv, char **azColName)
1468    {
1469        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1470        resultSet->Add(argc, argv);
1471        return 0;
1472    }
1473    
1474    String LSCPServer::QueryDatabase(String query) {
1475        LSCPResultSet result;
1476    #if HAVE_SQLITE3
1477        char* zErrMsg = NULL;
1478        sqlite3 *db;
1479        String selectStr = "SELECT " + query;
1480    
1481        int rc = sqlite3_open("linuxsampler.db", &db);
1482        if (rc == SQLITE_OK)
1483        {
1484                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1485        }
1486        if ( rc != SQLITE_OK )
1487        {
1488                result.Error(String(zErrMsg), rc);
1489        }
1490        sqlite3_close(db);
1491    #else
1492        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1493    #endif
1494        return result.Produce();
1495    }
1496    
1497  /**  /**
1498   * 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
1499   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be

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

  ViewVC Help
Powered by ViewVC