/[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 401 by schoenebeck, Tue Feb 22 14:09:26 2005 UTC revision 475 by schoenebeck, Thu Mar 17 23:56:56 2005 UTC
# Line 26  Line 26 
26  #include "lscpevent.h"  #include "lscpevent.h"
27  //#include "../common/global.h"  //#include "../common/global.h"
28    
29    #include <fcntl.h>
30    
31  #if HAVE_SQLITE3  #if HAVE_SQLITE3
32  # include "sqlite3.h"  # include "sqlite3.h"
33  #endif  #endif
34    
35  #include "../engines/gig/Engine.h"  #include "../engines/EngineFactory.h"
36  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
37  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
38    
# Line 66  LSCPServer::LSCPServer(Sampler* pSampler Line 68  LSCPServer::LSCPServer(Sampler* pSampler
68      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
69      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
71        hSocket = -1;
72    }
73    
74    LSCPServer::~LSCPServer() {
75        if (hSocket >= 0) close(hSocket);
76  }  }
77    
78  /**  /**
# Line 83  int LSCPServer::WaitUntilInitialized(lon Line 90  int LSCPServer::WaitUntilInitialized(lon
90  }  }
91    
92  int LSCPServer::Main() {  int LSCPServer::Main() {
93      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
94      if (hSocket < 0) {      if (hSocket < 0) {
95          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
96          //return -1;          //return -1;
# Line 166  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 452  String LSCPServer::LoadInstrument(String Line 460  String LSCPServer::LoadInstrument(String
460      try {      try {
461          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
462          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
463          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
464          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
465          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
466              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
467          if (bBackground) {          if (bBackground) {
468              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
469          }          }
470          else {          else {
471              // tell the engine which instrument to load              // tell the engine channel which instrument to load
472              pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument);              pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
473              // actually start to load the instrument (blocks until completed)              // actually start to load the instrument (blocks until completed)
474              pEngine->LoadInstrument();              pEngineChannel->LoadInstrument();
475          }          }
476      }      }
477      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 473  String LSCPServer::LoadInstrument(String Line 481  String LSCPServer::LoadInstrument(String
481  }  }
482    
483  /**  /**
484   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to assign a sampler engine type to a
485     * sampler channel.
486   */   */
487  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
488      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
489      LSCPResultSet result;      LSCPResultSet result;
490      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
491          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
492          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
493          LockRTNotify();          LockRTNotify();
494          pSamplerChannel->LoadEngine(type);          pSamplerChannel->SetEngineType(EngineName);
495          UnlockRTNotify();          UnlockRTNotify();
496      }      }
497      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 553  String LSCPServer::GetAvailableEngines() Line 559  String LSCPServer::GetAvailableEngines()
559  }  }
560    
561  /**  /**
562   * Will be called by the parser to get descriptions for a particular engine.   * Will be called by the parser to get descriptions for a particular
563     * sampler engine.
564   */   */
565  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
566      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
567      LSCPResultSet result;      LSCPResultSet result;
568      try {      try {
569          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
570              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
571              result.Add("DESCRIPTION", pEngine->Description());          result.Add("VERSION",     pEngine->Version());
572              result.Add("VERSION",     pEngine->Version());          delete pEngine;
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
573      }      }
574      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
575           result.Error(e);           result.Error(e);
# Line 583  String LSCPServer::GetChannelInfo(uint u Line 587  String LSCPServer::GetChannelInfo(uint u
587      try {      try {
588          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
589          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
590          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
591    
592          //Defaults values          //Defaults values
593          String EngineName = "NONE";          String EngineName = "NONE";
# Line 595  String LSCPServer::GetChannelInfo(uint u Line 599  String LSCPServer::GetChannelInfo(uint u
599          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
600          String AudioRouting;          String AudioRouting;
601    
602          if (pEngine) {          if (pEngineChannel) {
603              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
604              AudioOutputChannels = pEngine->Channels();              AudioOutputChannels = pEngineChannel->Channels();
605              Volume = pEngine->Volume();              Volume              = pEngineChannel->Volume();
606              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
607              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex     = pEngineChannel->InstrumentIndex();
608              if (InstrumentIndex != -1)              if (InstrumentIndex != -1) {
609              {                  InstrumentFileName = pEngineChannel->InstrumentFileName();
610                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentName     = pEngineChannel->InstrumentName();
611                  InstrumentName = pEngine->InstrumentName();              }
612              }              for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
             for (int chan = 0; chan < pEngine->Channels(); chan++) {  
613                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
614                  AudioRouting += ToString(pEngine->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
615              }              }
616          }          }
617    
# Line 646  String LSCPServer::GetVoiceCount(uint ui Line 649  String LSCPServer::GetVoiceCount(uint ui
649      try {      try {
650          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
651          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
652          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
653          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
654          result.Add(pEngine->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
655      }      }
656      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
657           result.Error(e);           result.Error(e);
# Line 666  String LSCPServer::GetStreamCount(uint u Line 669  String LSCPServer::GetStreamCount(uint u
669      try {      try {
670          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
671          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
672          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
673          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
674          result.Add(pEngine->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
675      }      }
676      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
677           result.Error(e);           result.Error(e);
# Line 686  String LSCPServer::GetBufferFill(fill_re Line 689  String LSCPServer::GetBufferFill(fill_re
689      try {      try {
690          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
691          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
692          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
693          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
694          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
             result.Add("NA");  
695          else {          else {
696              switch (ResponseType) {              switch (ResponseType) {
697                  case fill_response_bytes:                  case fill_response_bytes:
698                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
699                      break;                      break;
700                  case fill_response_percentage:                  case fill_response_percentage:
701                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
702                      break;                      break;
703                  default:                  default:
704                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
705              }              }
# Line 1153  String LSCPServer::SetAudioOutputChannel Line 1155  String LSCPServer::SetAudioOutputChannel
1155      try {      try {
1156          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1157          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1158          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1159          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));
1160          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));
1161          pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1162      }      }
1163      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1164           result.Error(e);           result.Error(e);
# Line 1333  String LSCPServer::SetVolume(double dVol Line 1335  String LSCPServer::SetVolume(double dVol
1335      try {      try {
1336          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1337          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1338          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1339          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1340          pEngine->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1341      }      }
1342      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1343           result.Error(e);           result.Error(e);
# Line 1352  String LSCPServer::ResetChannel(uint uiS Line 1354  String LSCPServer::ResetChannel(uint uiS
1354      try {      try {
1355          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1356          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1357          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1358          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1359          pEngine->Reset();          pEngineChannel->GetEngine()->Reset();
1360      }      }
1361      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1362           result.Error(e);           result.Error(e);

Legend:
Removed from v.401  
changed lines
  Added in v.475

  ViewVC Help
Powered by ViewVC