/[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 223 by schoenebeck, Sat Aug 21 11:43:53 2004 UTC revision 227 by schoenebeck, Thu Aug 26 22:05:44 2004 UTC
# Line 88  int LSCPServer::Main() { Line 88  int LSCPServer::Main() {
88      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
89    
90      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
91          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";
92          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
93          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
94          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
95                        std::cerr << "gave up!" << std::endl;
96                        close(hSocket);
97                        //return -1;
98                        exit(EXIT_FAILURE);
99                    }
100                    else sleep(1); // sleep 1s
101                }
102                else break; // success
103            }
104      }      }
105    
106      listen(hSocket, 1);      listen(hSocket, 1);
# Line 525  String LSCPServer::GetEngineInfo(String Line 534  String LSCPServer::GetEngineInfo(String
534      try {      try {
535          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
536              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
537              result.Add(pEngine->Description());              result.Add("DESCRIPTION", pEngine->Description());
538              result.Add(pEngine->Version());              result.Add("VERSION",     pEngine->Version());
539              delete pEngine;              delete pEngine;
540          }          }
541          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
# Line 551  String LSCPServer::GetChannelInfo(uint u Line 560  String LSCPServer::GetChannelInfo(uint u
560    
561          //Defaults values          //Defaults values
562          String EngineName = "NONE";          String EngineName = "NONE";
563          float Volume = 0;          float Volume = 0.0f;
564          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
565          int InstrumentIndex = -1;          int InstrumentIndex = -1;
566          int InstrumentStatus = -1;          int InstrumentStatus = -1;
567            int AudioOutputChannels = 0;
568            String AudioRouting;
569    
570          if (pEngine) {          if (pEngine) {
571              EngineName =  pEngine->EngineName();              EngineName =  pEngine->EngineName();
572                AudioOutputChannels = pEngine->Channels();
573              Volume = pEngine->Volume();              Volume = pEngine->Volume();
574              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus = pEngine->InstrumentStatus();
575              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex = pEngine->InstrumentIndex();
576              if (InstrumentIndex != -1)              if (InstrumentIndex != -1)
577                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
578                for (int chan = 0; chan < pEngine->Channels(); chan++) {
579                    if (AudioRouting != "") AudioRouting += ",";
580                    AudioRouting += ToString(pEngine->OutputChannel(chan));
581                }
582          }          }
583    
584          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 570  String LSCPServer::GetChannelInfo(uint u Line 586  String LSCPServer::GetChannelInfo(uint u
586    
587          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
588          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
589          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
590          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
591    
592          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
593          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
594          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel()) result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
595            else                                        result.Add("MIDI_INPUT_CHANNEL", "ALL");
596    
597          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
598          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
# Line 735  String LSCPServer::GetAudioOutputDriverI Line 752  String LSCPServer::GetAudioOutputDriverI
752  }  }
753    
754  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
755      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));
756      LSCPResultSet result;      LSCPResultSet result;
757      try {      try {
758          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 744  String LSCPServer::GetMidiInputDriverPar Line 761  String LSCPServer::GetMidiInputDriverPar
761          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
762          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
763          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
764          if (pParameter->Depends())       result.Add("DEPENDS",       *pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
765          if (pParameter->Default())       result.Add("DEFAULT",       *pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
766          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
767          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
768          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
769            if (oDepends)       result.Add("DEPENDS",       *oDepends);
770            if (oDefault)       result.Add("DEFAULT",       *oDefault);
771            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
772            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
773            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
774      }      }
775      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
776          result.Error(e);          result.Error(e);
# Line 757  String LSCPServer::GetMidiInputDriverPar Line 779  String LSCPServer::GetMidiInputDriverPar
779  }  }
780    
781  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
782      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));
783      LSCPResultSet result;      LSCPResultSet result;
784      try {      try {
785          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 766  String LSCPServer::GetAudioOutputDriverP Line 788  String LSCPServer::GetAudioOutputDriverP
788          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
789          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
790          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
791          if (pParameter->Depends())       result.Add("DEPENDS",       *pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
792          if (pParameter->Default())       result.Add("DEFAULT",       *pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
793          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
794          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
795          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
796            if (oDepends)       result.Add("DEPENDS",       *oDepends);
797            if (oDefault)       result.Add("DEFAULT",       *oDefault);
798            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
799            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
800            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
801      }      }
802      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
803          result.Error(e);          result.Error(e);
# Line 1090  String LSCPServer::SetMidiInputPortParam Line 1117  String LSCPServer::SetMidiInputPortParam
1117   */   */
1118  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1119      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));
1120      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1121        try {
1122            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1123            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1124            Engine* pEngine = pSamplerChannel->GetEngine();
1125            if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));
1126            pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1127        }
1128        catch (LinuxSamplerException e) {
1129             result.Error(e);
1130        }
1131        return result.Produce();
1132  }  }
1133    
1134  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1117  String LSCPServer::SetAudioOutputType(St Line 1155  String LSCPServer::SetAudioOutputType(St
1155          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1156          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1157          // Driver type name aliasing...          // Driver type name aliasing...
1158          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1159          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1160          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1161          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1162          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1199  String LSCPServer::SetMIDIInputType(Stri Line 1237  String LSCPServer::SetMIDIInputType(Stri
1237          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1238          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1239          // Driver type name aliasing...          // Driver type name aliasing...
1240          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1241          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1242          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1243          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1256  String LSCPServer::SetMIDIInput(uint MID Line 1294  String LSCPServer::SetMIDIInput(uint MID
1294   * Will be called by the parser to change the global volume factor on a   * Will be called by the parser to change the global volume factor on a
1295   * particular sampler channel.   * particular sampler channel.
1296   */   */
1297  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1298      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1299      LSCPResultSet result;      LSCPResultSet result;
1300      try {      try {
1301          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1302          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
1303          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1304          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
1305          pEngine->Volume(Volume);          pEngine->Volume(dVolume);
1306      }      }
1307      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1308           result.Error(e);           result.Error(e);

Legend:
Removed from v.223  
changed lines
  Added in v.227

  ViewVC Help
Powered by ViewVC