/[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 392 by schoenebeck, Sat Feb 19 02:40:24 2005 UTC revision 707 by iliev, Thu Jul 21 08:38:15 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(true, 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++) {
208                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);                  send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
209                  bufferedNotifies.erase(iterNotify);                  bufferedNotifies.erase(iterNotify);
210          }          }
211          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
# Line 230  void LSCPServer::SendLSCPNotify( LSCPEve Line 255  void LSCPServer::SendLSCPNotify( LSCPEve
255          while (true) {          while (true) {
256                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
257                          for(;iter != end; iter++)                          for(;iter != end; iter++)
258                                  send(*iter, notify.c_str(), notify.size(), 0);                                  send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
259                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
260                          break;                          break;
261                  } else {                  } else {
# Line 339  void LSCPServer::AnswerClient(String Ret Line 364  void LSCPServer::AnswerClient(String Ret
364      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
365      if (currentSocket != -1) {      if (currentSocket != -1) {
366              NotifyMutex.Lock();              NotifyMutex.Lock();
367              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
368              NotifyMutex.Unlock();              NotifyMutex.Unlock();
369      }      }
370  }  }
# 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 {          else {
483              // tell the engine which instrument to load              // tell the engine channel which instrument to load
484              pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument);              pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
485              // actually start to load the instrument (blocks until completed)              // actually start to load the instrument (blocks until completed)
486              pEngine->LoadInstrument();              pEngineChannel->LoadInstrument();
487          }          }
488      }      }
489      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 468  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: SetEngineType(EngineName=%s,uiSamplerChannel=%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            if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
508          UnlockRTNotify();          UnlockRTNotify();
509      }      }
510      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 539  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 578  String LSCPServer::GetChannelInfo(uint u Line 609  String LSCPServer::GetChannelInfo(uint u
609      try {      try {
610          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
611          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          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";
# Line 589  String LSCPServer::GetChannelInfo(uint u Line 620  String LSCPServer::GetChannelInfo(uint u
620          int InstrumentStatus = -1;          int InstrumentStatus = -1;
621          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
622          String AudioRouting;          String AudioRouting;
623            int Mute = 0;
624            bool Solo = false;
625    
626          if (pEngine) {          if (pEngineChannel) {
627              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
628              AudioOutputChannels = pEngine->Channels();              AudioOutputChannels = pEngineChannel->Channels();
629              Volume = pEngine->Volume();              Volume              = pEngineChannel->Volume();
630              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
631              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex     = pEngineChannel->InstrumentIndex();
632              if (InstrumentIndex != -1)              if (InstrumentIndex != -1) {
633              {                  InstrumentFileName = pEngineChannel->InstrumentFileName();
634                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentName     = pEngineChannel->InstrumentName();
635                  InstrumentName = pEngine->InstrumentName();              }
636              }              for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
             for (int chan = 0; chan < pEngine->Channels(); chan++) {  
637                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
638                  AudioRouting += ToString(pEngine->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
639              }              }
640                Mute = pEngineChannel->GetMute();
641                Solo = pEngineChannel->GetSolo();
642          }          }
643    
644          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 617  String LSCPServer::GetChannelInfo(uint u Line 651  String LSCPServer::GetChannelInfo(uint u
651    
652          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
653          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
654          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");
655          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
656    
657          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
658          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
659          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", InstrumentName);
660          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
661            result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
662            result.Add("SOLO", Solo);
663      }      }
664      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
665           result.Error(e);           result.Error(e);
# Line 641  String LSCPServer::GetVoiceCount(uint ui Line 677  String LSCPServer::GetVoiceCount(uint ui
677      try {      try {
678          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
679          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
680          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
681          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
682          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
683            result.Add(pEngineChannel->GetEngine()->VoiceCount());
684      }      }
685      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
686           result.Error(e);           result.Error(e);
# Line 661  String LSCPServer::GetStreamCount(uint u Line 698  String LSCPServer::GetStreamCount(uint u
698      try {      try {
699          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
700          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
701          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
702          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
703          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
704            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
705      }      }
706      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
707           result.Error(e);           result.Error(e);
# Line 681  String LSCPServer::GetBufferFill(fill_re Line 719  String LSCPServer::GetBufferFill(fill_re
719      try {      try {
720          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
721          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
722          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
723          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
724          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
725              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
726          else {          else {
727              switch (ResponseType) {              switch (ResponseType) {
728                  case fill_response_bytes:                  case fill_response_bytes:
729                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
730                      break;                      break;
731                  case fill_response_percentage:                  case fill_response_percentage:
732                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
733                      break;                      break;
734                  default:                  default:
735                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
736              }              }
# Line 708  String LSCPServer::GetAvailableAudioOutp Line 746  String LSCPServer::GetAvailableAudioOutp
746      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
747      LSCPResultSet result;      LSCPResultSet result;
748      try {      try {
749            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
750            result.Add(n);
751        }
752        catch (LinuxSamplerException e) {
753            result.Error(e);
754        }
755        return result.Produce();
756    }
757    
758    String LSCPServer::ListAvailableAudioOutputDrivers() {
759        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
760        LSCPResultSet result;
761        try {
762          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
763          result.Add(s);          result.Add(s);
764      }      }
# Line 721  String LSCPServer::GetAvailableMidiInput Line 772  String LSCPServer::GetAvailableMidiInput
772      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
773      LSCPResultSet result;      LSCPResultSet result;
774      try {      try {
775            int n = MidiInputDeviceFactory::AvailableDrivers().size();
776            result.Add(n);
777        }
778        catch (LinuxSamplerException e) {
779            result.Error(e);
780        }
781        return result.Produce();
782    }
783    
784    String LSCPServer::ListAvailableMidiInputDrivers() {
785        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
786        LSCPResultSet result;
787        try {
788          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
789          result.Add(s);          result.Add(s);
790      }      }
# Line 1148  String LSCPServer::SetAudioOutputChannel Line 1212  String LSCPServer::SetAudioOutputChannel
1212      try {      try {
1213          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1214          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1215          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1216          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));
1217          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));
1218          pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1219      }      }
1220      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1221           result.Error(e);           result.Error(e);
# Line 1233  String LSCPServer::SetMIDIInputChannel(u Line 1297  String LSCPServer::SetMIDIInputChannel(u
1297      try {      try {
1298          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1299          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1300          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1301      }      }
1302      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1303           result.Error(e);           result.Error(e);
# Line 1310  String LSCPServer::SetMIDIInput(uint MID Line 1374  String LSCPServer::SetMIDIInput(uint MID
1374          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1375          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));
1376          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1377          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1378      }      }
1379      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1380           result.Error(e);           result.Error(e);
# Line 1328  String LSCPServer::SetVolume(double dVol Line 1392  String LSCPServer::SetVolume(double dVol
1392      try {      try {
1393          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1394          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          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 sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1397          pEngine->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1398      }      }
1399      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1400           result.Error(e);           result.Error(e);
# Line 1339  String LSCPServer::SetVolume(double dVol Line 1403  String LSCPServer::SetVolume(double dVol
1403  }  }
1404    
1405  /**  /**
1406     * Will be called by the parser to mute/unmute particular sampler channel.
1407     */
1408    String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) {
1409        dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1410        LSCPResultSet result;
1411        try {
1412            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1413            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1414    
1415            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1416            if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1417    
1418            if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1419            else pEngineChannel->SetMute(1);
1420        } catch (LinuxSamplerException e) {
1421            result.Error(e);
1422        }
1423        return result.Produce();
1424    }
1425    
1426    /**
1427     * Will be called by the parser to solo particular sampler channel.
1428     */
1429    String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) {
1430        dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1431        LSCPResultSet result;
1432        try {
1433            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1434            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1435    
1436            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1437            if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1438    
1439            bool oldSolo = pEngineChannel->GetSolo();
1440            bool hadSoloChannel = HasSoloChannel();
1441            
1442            pEngineChannel->SetSolo(bSolo);
1443            
1444            if(!oldSolo && bSolo) {
1445                if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1446                if(!hadSoloChannel) MuteNonSoloChannels();
1447            }
1448            
1449            if(oldSolo && !bSolo) {
1450                if(!HasSoloChannel()) UnmuteChannels();
1451                else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1452            }
1453        } catch (LinuxSamplerException e) {
1454            result.Error(e);
1455        }
1456        return result.Produce();
1457    }
1458    
1459    /**
1460     * Determines whether there is at least one solo channel in the channel list.
1461     *
1462     * @returns true if there is at least one solo channel in the channel list,
1463     * false otherwise.
1464     */
1465    bool LSCPServer::HasSoloChannel() {
1466        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1467        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1468        for (; iter != channels.end(); iter++) {
1469            EngineChannel* c = iter->second->GetEngineChannel();
1470            if(c && c->GetSolo()) return true;
1471        }
1472    
1473        return false;
1474    }
1475    
1476    /**
1477     * Mutes all unmuted non-solo channels. Notice that the channels are muted
1478     * with -1 which indicates that they are muted because of the presence
1479     * of a solo channel(s). Channels muted with -1 will be automatically unmuted
1480     * when there are no solo channels left.
1481     */
1482    void LSCPServer::MuteNonSoloChannels() {
1483        dmsg(2,("LSCPServer: MuteNonSoloChannels()\n"));
1484        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1485        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1486        for (; iter != channels.end(); iter++) {
1487            EngineChannel* c = iter->second->GetEngineChannel();
1488            if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1);
1489        }
1490    }
1491    
1492    /**
1493     * Unmutes all channels that are muted because of the presence
1494     * of a solo channel(s).
1495     */
1496    void  LSCPServer::UnmuteChannels() {
1497        dmsg(2,("LSCPServer: UnmuteChannels()\n"));
1498        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1499        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1500        for (; iter != channels.end(); iter++) {
1501            EngineChannel* c = iter->second->GetEngineChannel();
1502            if(c && c->GetMute() == -1) c->SetMute(0);
1503        }
1504    }
1505    
1506    /**
1507   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
1508   */   */
1509  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
# Line 1347  String LSCPServer::ResetChannel(uint uiS Line 1512  String LSCPServer::ResetChannel(uint uiS
1512      try {      try {
1513          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1514          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1515          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1516          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1517          pEngine->Reset();          pEngineChannel->Reset();
1518      }      }
1519      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1520           result.Error(e);           result.Error(e);
# Line 1368  String LSCPServer::ResetSampler() { Line 1533  String LSCPServer::ResetSampler() {
1533  }  }
1534    
1535  /**  /**
1536     * Will be called by the parser to return general informations about this
1537     * sampler.
1538     */
1539    String LSCPServer::GetServerInfo() {
1540        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1541        LSCPResultSet result;
1542        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1543        result.Add("VERSION", VERSION);
1544        result.Add("PROTOCOL_VERSION", "1.0");
1545        return result.Produce();
1546    }
1547    
1548    /**
1549   * 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
1550   * server for receiving event messages.   * server for receiving event messages.
1551   */   */
# Line 1393  String LSCPServer::UnsubscribeNotificati Line 1571  String LSCPServer::UnsubscribeNotificati
1571      return result.Produce();      return result.Produce();
1572  }  }
1573    
1574    static int select_callback(void * lscpResultSet, int argc,
1575                            char **argv, char **azColName)
1576    {
1577        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1578        resultSet->Add(argc, argv);
1579        return 0;
1580    }
1581    
1582    String LSCPServer::QueryDatabase(String query) {
1583        LSCPResultSet result;
1584    #if HAVE_SQLITE3
1585        char* zErrMsg = NULL;
1586        sqlite3 *db;
1587        String selectStr = "SELECT " + query;
1588    
1589        int rc = sqlite3_open("linuxsampler.db", &db);
1590        if (rc == SQLITE_OK)
1591        {
1592                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1593        }
1594        if ( rc != SQLITE_OK )
1595        {
1596                result.Error(String(zErrMsg), rc);
1597        }
1598        sqlite3_close(db);
1599    #else
1600        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1601    #endif
1602        return result.Produce();
1603    }
1604    
1605  /**  /**
1606   * 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
1607   * 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.392  
changed lines
  Added in v.707

  ViewVC Help
Powered by ViewVC