/[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 563 by schoenebeck, Sun May 22 20:43:32 2005 UTC revision 667 by senkov, Sun Jun 19 21:22:34 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_channel_count, "CHANNEL_COUNT");      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");
# 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 578  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 660  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 680  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 700  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 1391  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            if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
1410          pEngineChannel->GetEngine()->Reset();          pEngineChannel->GetEngine()->Reset();
1411      }      }
1412      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1417  String LSCPServer::GetServerInfo() { Line 1433  String LSCPServer::GetServerInfo() {
1433      dmsg(2,("LSCPServer: GetServerInfo()\n"));      dmsg(2,("LSCPServer: GetServerInfo()\n"));
1434      LSCPResultSet result;      LSCPResultSet result;
1435      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1436      result.Add("VERSION", VERSION);          result.Add("VERSION", VERSION);
1437        result.Add("PROTOCOL_VERSION", "1.0");
1438      return result.Produce();      return result.Produce();
1439  }  }
1440    

Legend:
Removed from v.563  
changed lines
  Added in v.667

  ViewVC Help
Powered by ViewVC