/[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 123 by schoenebeck, Mon Jun 14 19:33:16 2004 UTC revision 143 by capela, Wed Jun 23 18:54:08 2004 UTC
# Line 90  void LSCPServer::AnswerClient(String Ret Line 90  void LSCPServer::AnswerClient(String Ret
90      send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0);      send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0);
91  }  }
92    
93    /**
94     * Find a created audio output device index.
95     */
96    int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice )
97    {
98        // Search for the created device to get its index
99        std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
100        std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
101        for (; iter != devices.end(); iter++) {
102            if (iter->second == pDevice)
103                return iter->first;
104        }
105        // Not found.
106        return -1;
107    }
108    
109  String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) {  String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) {
110      dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));      dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));
111      LSCPResultSet result;      LSCPResultSet result;
112      try {      try {
113          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
         std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();  
114          // search for the created device to get its index          // search for the created device to get its index
115          int index = -1;          int index = GetAudioOutputDeviceIndex(pDevice);
         std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();  
         for (; iter != devices.end(); iter++) {  
             if (iter->second == pDevice) {  
                 index = iter->first;  
                 break;  
             }  
         }  
116          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");
117          result = index; // success          result = index; // success
118      }      }
# Line 132  String LSCPServer::DestroyAudioOutputDev Line 140  String LSCPServer::DestroyAudioOutputDev
140  /**  /**
141   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
142   */   */
143  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) {  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) {
144      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel));      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel));
145      LSCPResultSet result;      LSCPResultSet result;
146      try {      try {
# Line 140  String LSCPServer::LoadInstrument(String Line 148  String LSCPServer::LoadInstrument(String
148          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
149          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
150          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
151          pEngine->LoadInstrument(Filename.c_str(), uiInstrument);          if (pSamplerChannel->GetAudioOutputDevice() == NULL)
152                throw LinuxSamplerException("No audio output device on channel");
153            if (bBackground) {
154                LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
155                pLoadInstrument->StartThread();
156            }
157            else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
158      }      }
159      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
160           result.Error(e);           result.Error(e);
# Line 244  String LSCPServer::GetChannelInfo(uint u Line 258  String LSCPServer::GetChannelInfo(uint u
258          String EngineName = "NONE";          String EngineName = "NONE";
259          float Volume = 0;          float Volume = 0;
260          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
261          int InstrumentIndex = 0;          int InstrumentIndex = -1;
262            int InstrumentStatus = -1;
263    
264          if (pEngine) {          if (pEngine) {
265              EngineName =  pEngine->EngineName();              EngineName =  pEngine->EngineName();
266              Volume = pEngine->Volume();              Volume = pEngine->Volume();
267              int iIdx = pEngine->InstrumentIndex();              InstrumentStatus = pEngine->InstrumentStatus();
268              if (iIdx != -1) {              InstrumentIndex = pEngine->InstrumentIndex();
269                if (InstrumentIndex != -1)
270                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
                 InstrumentIndex = iIdx;  
             }  
271          }          }
272    
273          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
274          result.Add("VOLUME", Volume);          result.Add("VOLUME", Volume);
275    
276          //Some hardcoded stuff for now to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
277          result.Add("AUDIO_OUTPUT_DEVICE", "0");          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
278          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", "2");
279          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");
280    
281          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
282          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
283            result.Add("INSTRUMENT_STATUS", InstrumentStatus);
284    
285          //Some more hardcoded stuff for now to make GUI look good          //Some more hardcoded stuff for now to make GUI look good
286          result.Add("MIDI_INPUT_DEVICE", "0");          result.Add("MIDI_INPUT_DEVICE", "0");
# Line 330  String LSCPServer::GetBufferFill(fill_re Line 345  String LSCPServer::GetBufferFill(fill_re
345          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
346          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
347          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
348          if (!pEngine->DiskStreamSupported()) return "NA\r\n"; //FIXME: Update resultset class to support "NA"          if (!pEngine->DiskStreamSupported())
349          switch (ResponseType) {              result.Add("NA");
350              case fill_response_bytes:          else {
351                  result.Add(pEngine->DiskStreamBufferFillBytes());              switch (ResponseType) {
352                  break;                  case fill_response_bytes:
353              case fill_response_percentage:                      result.Add(pEngine->DiskStreamBufferFillBytes());
354                  result.Add(pEngine->DiskStreamBufferFillPercentage());                      break;
355                  break;                  case fill_response_percentage:
356              default:                      result.Add(pEngine->DiskStreamBufferFillPercentage());
357                  throw LinuxSamplerException("Unknown fill response type");                      break;
358          }                  default:
359                        throw LinuxSamplerException("Unknown fill response type");
360                }
361            }
362      }      }
363      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
364           result.Error(e);           result.Error(e);
# Line 412  String LSCPServer::GetAudioOutputDeviceC Line 430  String LSCPServer::GetAudioOutputDeviceC
430      LSCPResultSet result;      LSCPResultSet result;
431      try {      try {
432          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
433          result = count; // success          result.Add(count); // success
434      }      }
435      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
436          result.Error(e);          result.Error(e);
# Line 446  String LSCPServer::GetAudioOutputDeviceI Line 464  String LSCPServer::GetAudioOutputDeviceI
464          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
465          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
466          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
467            result.Add("driver", pDevice->Driver());
468          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
469          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
470          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 570  String LSCPServer::SetAudioOutputChannel Line 589  String LSCPServer::SetAudioOutputChannel
589      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?
590  }  }
591    
592    String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
593        dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
594        LSCPResultSet result;
595        try {
596            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
597            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
598            // Driver type name aliasing...
599            if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";
600            if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";        
601            // Check if there's one audio output device already created
602            // for the intended audio driver type (AudioOutputDriver)...
603            AudioOutputDevice *pDevice = NULL;
604            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
605            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
606            for (; iter != devices.end(); iter++) {
607                if ((iter->second)->Driver() == AudioOutputDriver) {
608                    pDevice = iter->second;
609                    break;
610                }
611            }
612            // If it doesn't exist, create a new one with default parameters...
613            if (pDevice == NULL) {
614                std::map<String,String> params;
615                pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
616            }
617            // Must have a device...
618            if (pDevice == NULL)
619                throw LinuxSamplerException("Internal error: could not create audio output device.");
620            // Set it as the current channel device...
621            pSamplerChannel->SetAudioOutputDevice(pDevice);
622        }
623        catch (LinuxSamplerException e) {
624             result.Error(e);
625        }
626        return result.Produce();
627    }
628    
629    
630  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
631      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));
632      LSCPResultSet result;      LSCPResultSet result;
# Line 577  String LSCPServer::SetMIDIInputType(Stri Line 634  String LSCPServer::SetMIDIInputType(Stri
634          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
635          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
636          // FIXME: workaround until MIDI driver configuration is implemented (using a Factory class for the MIDI input drivers then, like its already done for audio output drivers)          // FIXME: workaround until MIDI driver configuration is implemented (using a Factory class for the MIDI input drivers then, like its already done for audio output drivers)
637          if (MidiInputDriver != "ALSA") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";
638            if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");
639          MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;          MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;
640          pSamplerChannel->SetMidiInputDevice(MidiInputType);          pSamplerChannel->SetMidiInputDevice(MidiInputType);
641      }      }
# Line 626  String LSCPServer::SetMIDIInputChannel(u Line 684  String LSCPServer::SetMIDIInputChannel(u
684      return result.Produce();      return result.Produce();
685  }  }
686    
687  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
688      LSCPResultSet result;      LSCPResultSet result;
689      try {      try {
690          throw LinuxSamplerException("Command not yet implemented");          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
691            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
692            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
693            if (!devices[AudioDeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
694            AudioOutputDevice* pDevice = devices[AudioDeviceId];
695            pSamplerChannel->SetAudioOutputDevice(pDevice);
696      }      }
697      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
698           result.Error(e);           result.Error(e);
# Line 680  String LSCPServer::ResetChannel(uint uiS Line 743  String LSCPServer::ResetChannel(uint uiS
743   * 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
744   * server for receiving event messages.   * server for receiving event messages.
745   */   */
746  String LSCPServer::SubscribeNotification(uint UDPPort) {  String LSCPServer::SubscribeNotification(event_t Event) {
747      dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event));
748      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
749  }  }
750    
# Line 689  String LSCPServer::SubscribeNotification Line 752  String LSCPServer::SubscribeNotification
752   * Will be called by the parser to unsubscribe a client on the server   * Will be called by the parser to unsubscribe a client on the server
753   * for not receiving further event messages.   * for not receiving further event messages.
754   */   */
755  String LSCPServer::UnsubscribeNotification(String SessionID) {  String LSCPServer::UnsubscribeNotification(event_t Event) {
756      dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event));
757      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
758  }  }
759    
760    
761    // Instrument loader constructor.
762    LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)
763        : Thread(false, 0, -4)
764    {
765        this->pEngine = pEngine;
766        this->Filename = Filename;
767        this->uiInstrument = uiInstrument;
768    }
769    
770    // Instrument loader process.
771    int LSCPLoadInstrument::Main()
772    {
773        try {
774            pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
775        }
776    
777        catch (LinuxSamplerException e) {
778            e.PrintMessage();
779        }
780    
781        // Always re-enable the engine.
782        pEngine->Enable();
783    
784        // FIXME: Shoot ourselves on the foot?
785        delete this;
786    }

Legend:
Removed from v.123  
changed lines
  Added in v.143

  ViewVC Help
Powered by ViewVC