/[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 475 by schoenebeck, Thu Mar 17 23:56:56 2005 UTC revision 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC
# Line 33  Line 33 
33  #endif  #endif
34    
35  #include "../engines/EngineFactory.h"  #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 60  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;      hSocket = -1;
76  }  }
# Line 97  int LSCPServer::Main() { Line 101  int LSCPServer::Main() {
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 190  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 550  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    
# Line 569  String LSCPServer::GetEngineInfo(String Line 590  String LSCPServer::GetEngineInfo(String
590          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
591          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", pEngine->Description());
592          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
593          delete pEngine;          EngineFactory::Destroy(pEngine);
594      }      }
595      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
596           result.Error(e);           result.Error(e);
# Line 625  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 651  String LSCPServer::GetVoiceCount(uint ui Line 672  String LSCPServer::GetVoiceCount(uint ui
672          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
673          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
674          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
675            if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
676          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
677      }      }
678      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 671  String LSCPServer::GetStreamCount(uint u Line 693  String LSCPServer::GetStreamCount(uint u
693          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
694          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
695          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
696            if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
697          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
698      }      }
699      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 691  String LSCPServer::GetBufferFill(fill_re Line 714  String LSCPServer::GetBufferFill(fill_re
714          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
715          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
716          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
717            if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
718          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
719          else {          else {
720              switch (ResponseType) {              switch (ResponseType) {
# Line 715  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 728  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 1240  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 1317  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 1356  String LSCPServer::ResetChannel(uint uiS Line 1406  String LSCPServer::ResetChannel(uint uiS
1406          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1407          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1408          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1409          pEngineChannel->GetEngine()->Reset();          pEngineChannel->Reset();
1410      }      }
1411      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1412           result.Error(e);           result.Error(e);
# Line 1374  String LSCPServer::ResetSampler() { Line 1424  String LSCPServer::ResetSampler() {
1424      return result.Produce();      return result.Produce();
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.

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

  ViewVC Help
Powered by ViewVC