/[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 64 by schoenebeck, Thu May 6 20:06:20 2004 UTC revision 143 by capela, Wed Jun 23 18:54:08 2004 UTC
# Line 21  Line 21 
21   ***************************************************************************/   ***************************************************************************/
22    
23  #include "lscpserver.h"  #include "lscpserver.h"
24    #include "lscpresultset.h"
25    
26  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
27    #include "../audiodriver/AudioOutputDeviceFactory.h"
28    
29  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
30      this->pSampler = pSampler;      this->pSampler = pSampler;
# Line 89  void LSCPServer::AnswerClient(String Ret Line 91  void LSCPServer::AnswerClient(String Ret
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) {
110        dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));
111        LSCPResultSet result;
112        try {
113            AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
114            // search for the created device to get its index
115            int index = GetAudioOutputDeviceIndex(pDevice);
116            if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");
117            result = index; // success
118        }
119        catch (LinuxSamplerException e) {
120            result.Error(e);
121        }
122        return result.Produce();
123    }
124    
125    String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) {
126        dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex));
127        LSCPResultSet result;
128        try {
129            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
130            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
131            AudioOutputDevice* pDevice = devices[DeviceIndex];
132            pSampler->DestroyAudioOutputDevice(pDevice);
133        }
134        catch (LinuxSamplerException e) {
135            result.Error(e);
136        }
137        return result.Produce();
138    }
139    
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      result_t result;      LSCPResultSet result;
146      try {      try {
147          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
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          result.type = result_type_success;              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           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
161      }      }
162      return ConvertResult(result);      return result.Produce();
163  }  }
164    
165  /**  /**
# Line 116  String LSCPServer::LoadInstrument(String Line 167  String LSCPServer::LoadInstrument(String
167   */   */
168  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {
169      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));
170      result_t result;      LSCPResultSet result;
171      try {      try {
172          Engine::type_t type;          Engine::type_t type;
173          if (EngineName == "gig") type = Engine::type_gig;          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
174          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
175          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
176          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
177          pSamplerChannel->LoadEngine(type);          pSamplerChannel->LoadEngine(type);
         result.type = result_type_success;  
178      }      }
179      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
180           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
181      }      }
182      return ConvertResult(result);      return result.Produce();
183  }  }
184    
185  /**  /**
# Line 140  String LSCPServer::LoadEngine(String Eng Line 187  String LSCPServer::LoadEngine(String Eng
187   */   */
188  String LSCPServer::GetChannels() {  String LSCPServer::GetChannels() {
189      dmsg(2,("LSCPServer: GetChannels()\n"));      dmsg(2,("LSCPServer: GetChannels()\n"));
190      return ToString(pSampler->SamplerChannels()) + "\r\n";      LSCPResultSet result;
191        result.Add(pSampler->SamplerChannels());
192        return result.Produce();
193  }  }
194    
195  /**  /**
# Line 149  String LSCPServer::GetChannels() { Line 198  String LSCPServer::GetChannels() {
198  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
199      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
200      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
201      return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n";      LSCPResultSet result(pSamplerChannel->Index());
202        return result.Produce();
203  }  }
204    
205  /**  /**
# Line 157  String LSCPServer::AddChannel() { Line 207  String LSCPServer::AddChannel() {
207   */   */
208  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
209      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
210        LSCPResultSet result;
211      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
212      return "OK\r\n";      return result.Produce();
213  }  }
214    
215  /**  /**
# Line 166  String LSCPServer::RemoveChannel(uint ui Line 217  String LSCPServer::RemoveChannel(uint ui
217   */   */
218  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
219      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
220      return "gig\r\n";      LSCPResultSet result("GigEngine");
221        return result.Produce();
222  }  }
223    
224  /**  /**
# Line 174  String LSCPServer::GetAvailableEngines() Line 226  String LSCPServer::GetAvailableEngines()
226   */   */
227  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
228      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
229      result_t result;      LSCPResultSet result;
230      try {      try {
231          if (EngineName == "gig") {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
232              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
233              String info = pEngine->Description() + "\r\n";              result.Add(pEngine->Description());
234                result.Add(pEngine->Version());
235              delete pEngine;              delete pEngine;
             return info; // success  
236          }          }
237          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
238      }      }
239      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
240           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
241      }      }
242      return ConvertResult(result);      return result.Produce();
243  }  }
244    
245  /**  /**
# Line 199  String LSCPServer::GetEngineInfo(String Line 248  String LSCPServer::GetEngineInfo(String
248   */   */
249  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {
250      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));
251      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
252        try {
253            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
254            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
255            Engine* pEngine = pSamplerChannel->GetEngine();
256    
257            //Defaults values
258            String EngineName = "NONE";
259            float Volume = 0;
260            String InstrumentFileName = "NONE";
261            int InstrumentIndex = -1;
262            int InstrumentStatus = -1;
263    
264            if (pEngine) {
265                EngineName =  pEngine->EngineName();
266                Volume = pEngine->Volume();
267                InstrumentStatus = pEngine->InstrumentStatus();
268                InstrumentIndex = pEngine->InstrumentIndex();
269                if (InstrumentIndex != -1)
270                    InstrumentFileName = pEngine->InstrumentFileName();
271            }
272    
273            result.Add("ENGINE_NAME", EngineName);
274            result.Add("VOLUME", Volume);
275    
276            //Some not-so-hardcoded stuff to make GUI look good
277            result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
278            result.Add("AUDIO_OUTPUT_CHANNELS", "2");
279            result.Add("AUDIO_OUTPUT_ROUTING", "0,1");
280    
281            result.Add("INSTRUMENT_FILE", InstrumentFileName);
282            result.Add("INSTRUMENT_NR", InstrumentIndex);
283            result.Add("INSTRUMENT_STATUS", InstrumentStatus);
284    
285            //Some more hardcoded stuff for now to make GUI look good
286            result.Add("MIDI_INPUT_DEVICE", "0");
287            result.Add("MIDI_INPUT_PORT", "0");
288            result.Add("MIDI_INPUT_CHANNEL", "1");
289        }
290        catch (LinuxSamplerException e) {
291             result.Error(e);
292        }
293        return result.Produce();
294  }  }
295    
296  /**  /**
# Line 208  String LSCPServer::GetChannelInfo(uint u Line 299  String LSCPServer::GetChannelInfo(uint u
299   */   */
300  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {
301      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
302      result_t result;      LSCPResultSet result;
303      try {      try {
304          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
305          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
306          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
307          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
308          return ToString(pEngine->VoiceCount()) + "\r\n"; // success          result.Add(pEngine->VoiceCount());
309      }      }
310      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
311           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
312      }      }
313      return ConvertResult(result);      return result.Produce();
314  }  }
315    
316  /**  /**
# Line 231  String LSCPServer::GetVoiceCount(uint ui Line 319  String LSCPServer::GetVoiceCount(uint ui
319   */   */
320  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {
321      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
322      result_t result;      LSCPResultSet result;
323      try {      try {
324          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
325          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
326          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
327          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
328          return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success          result.Add(pEngine->DiskStreamCount());
329      }      }
330      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
331           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
332      }      }
333      return ConvertResult(result);      return result.Produce();
334  }  }
335    
336  /**  /**
# Line 254  String LSCPServer::GetStreamCount(uint u Line 339  String LSCPServer::GetStreamCount(uint u
339   */   */
340  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {
341      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
342      result_t result;      LSCPResultSet result;
343      try {      try {
344          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
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";          if (!pEngine->DiskStreamSupported())
349          switch (ResponseType) {              result.Add("NA");
350              case fill_response_bytes:          else {
351                  return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success              switch (ResponseType) {
352              case fill_response_percentage:                  case fill_response_bytes:
353                  return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success                      result.Add(pEngine->DiskStreamBufferFillBytes());
354              default:                      break;
355                  throw LinuxSamplerException("Unknown fill response type");                  case fill_response_percentage:
356                        result.Add(pEngine->DiskStreamBufferFillPercentage());
357                        break;
358                    default:
359                        throw LinuxSamplerException("Unknown fill response type");
360                }
361            }
362        }
363        catch (LinuxSamplerException e) {
364             result.Error(e);
365        }
366        return result.Produce();
367    }
368    
369    String LSCPServer::GetAvailableAudioOutputDrivers() {
370        dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
371        LSCPResultSet result;
372        try {
373            String s = AudioOutputDeviceFactory::AvailableDriversAsString();
374            result.Add(s);
375        }
376        catch (LinuxSamplerException e) {
377            result.Error(e);
378        }
379        return result.Produce();
380    }
381    
382    String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
383        dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
384        LSCPResultSet result;
385        try {
386            result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver));
387            result.Add("VERSION",     AudioOutputDeviceFactory::GetDriverVersion(Driver));
388    
389            std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver);
390            if (parameters.size()) { // if there are parameters defined for this driver
391                String s;
392                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
393                for (;iter != parameters.end(); iter++) {
394                    if (s != "") s += ",";
395                    s += iter->first;
396                }
397                result.Add("PARAMETERS", s);
398          }          }
399      }      }
400      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
401           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
402      }      }
403      return ConvertResult(result);      return result.Produce();
404  }  }
405    
406  /**  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
407   * Will be called by the parser to change the audio output type on a      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
408   * particular sampler channel.      LSCPResultSet result;
  */  
 String LSCPServer::SetAudioOutputType(AudioOutputDevice::type_t AudioOutputType, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel));  
     result_t result;  
409      try {      try {
410          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
411          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          result.Add("TYPE",         pParameter->Type());
412          pSamplerChannel->SetAudioOutputDevice(AudioOutputType);          result.Add("DESCRIPTION",  pParameter->Description());
413          result.type = result_type_success;          result.Add("MANDATORY",    pParameter->Mandatory());
414            result.Add("FIX",          pParameter->Fix());
415            result.Add("MULTIPLICITY", pParameter->Multiplicity());
416            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
417            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
418            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
419            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
420            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
421        }
422        catch (LinuxSamplerException e) {
423            result.Error(e);
424        }
425        return result.Produce();
426    }
427    
428    String LSCPServer::GetAudioOutputDeviceCount() {
429        dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n"));
430        LSCPResultSet result;
431        try {
432            uint count = pSampler->AudioOutputDevices();
433            result.Add(count); // success
434        }
435        catch (LinuxSamplerException e) {
436            result.Error(e);
437        }
438        return result.Produce();
439    }
440    
441    String LSCPServer::GetAudioOutputDevices() {
442        dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
443        LSCPResultSet result;
444        try {
445            String s;
446            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
447            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
448            for (; iter != devices.end(); iter++) {
449                if (s != "") s += ",";
450                s += ToString(iter->first);
451            }
452            result.Add(s);
453        }
454        catch (LinuxSamplerException e) {
455            result.Error(e);
456        }
457        return result.Produce();
458    }
459    
460    String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
461        dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
462        LSCPResultSet result;
463        try {
464            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
465            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
466            AudioOutputDevice* pDevice = devices[DeviceIndex];
467            result.Add("driver", pDevice->Driver());
468            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
469            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
470            for (; iter != parameters.end(); iter++) {
471                result.Add(iter->first, iter->second->Value());
472            }
473        }
474        catch (LinuxSamplerException e) {
475            result.Error(e);
476        }
477        return result.Produce();
478    }
479    
480    String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
481        dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
482        LSCPResultSet result;
483        try {
484            // get audio output device
485            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
486            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
487            AudioOutputDevice* pDevice = devices[DeviceId];
488    
489            // get audio channel
490            AudioChannel* pChannel = pDevice->Channel(ChannelId);
491            if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");
492    
493            // return the values of all audio channel parameters
494            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
495            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
496            for (; iter != parameters.end(); iter++) {
497                result.Add(iter->first, iter->second->Value());
498            }
499        }
500        catch (LinuxSamplerException e) {
501            result.Error(e);
502        }
503        return result.Produce();
504    }
505    
506    String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
507        dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
508        LSCPResultSet result;
509        try {
510            // get audio output device
511            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
512            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
513            AudioOutputDevice* pDevice = devices[DeviceId];
514    
515            // get audio channel
516            AudioChannel* pChannel = pDevice->Channel(ChannelId);
517            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
518    
519            // get desired audio channel parameter
520            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
521            if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
522            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
523    
524            // return all fields of this audio channel parameter
525            result.Add("TYPE",         pParameter->Type());
526            result.Add("DESCRIPTION",  pParameter->Description());
527            result.Add("FIX",          pParameter->Fix());
528            result.Add("MULTIPLICITY", pParameter->Multiplicity());
529            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
530            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
531            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
532        }
533        catch (LinuxSamplerException e) {
534            result.Error(e);
535        }
536        return result.Produce();
537    }
538    
539    String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) {
540        dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str()));
541        LSCPResultSet result;
542        try {
543            // get audio output device
544            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
545            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
546            AudioOutputDevice* pDevice = devices[DeviceId];
547    
548            // get audio channel
549            AudioChannel* pChannel = pDevice->Channel(ChannelId);
550            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
551    
552            // get desired audio channel parameter
553            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
554            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
555            DeviceRuntimeParameter* pParameter = parameters[ParamKey];
556    
557            // set new channel parameter value
558            pParameter->SetValue(ParamVal);
559      }      }
560      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
561           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
562      }      }
563      return ConvertResult(result);      return result.Produce();
564    }
565    
566    String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
567        dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
568        LSCPResultSet result;
569        try {
570            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
571            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
572            AudioOutputDevice* pDevice = devices[DeviceIndex];
573            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
574            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
575            parameters[ParamKey]->SetValue(ParamVal);
576        }
577        catch (LinuxSamplerException e) {
578            result.Error(e);
579        }
580        return result.Produce();
581  }  }
582    
583  /**  /**
584   * Will be called by the parser to change the audio output channel for   * Will be called by the parser to change the audio output channel for
585   * playback on a particular sampler channel.   * playback on a particular sampler channel.
586   */   */
587  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
588      dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));
589      return "ERR:0:Not implemented yet.\r\n";      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  String LSCPServer::SetMIDIInputType(MidiInputDevice::type_t MidiInputType, uint uiSamplerChannel) {  
630      dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel));  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
631      result_t result;      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));
632        LSCPResultSet result;
633      try {      try {
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)
637            if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";
638            if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");
639            MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;
640          pSamplerChannel->SetMidiInputDevice(MidiInputType);          pSamplerChannel->SetMidiInputDevice(MidiInputType);
         result.type = result_type_success;  
641      }      }
642      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
643           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
644      }      }
645      return ConvertResult(result);      return result.Produce();
646  }  }
647    
648  /**  /**
649   * Will be called by the parser to change the MIDI input port on which the   * Will be called by the parser to change the MIDI input port on which the
650   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
651   */   */
652  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel) {  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) {
653      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerchannel));      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel));
654      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
655        try {
656            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
657            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
658            if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");
659            pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());
660        }
661        catch (LinuxSamplerException e) {
662             result.Error(e);
663        }
664        return result.Produce();
665  }  }
666    
667  /**  /**
# Line 343  String LSCPServer::SetMIDIInputPort(Stri Line 670  String LSCPServer::SetMIDIInputPort(Stri
670   */   */
671  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
672      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));
673      result_t result;      LSCPResultSet result;
674      try {      try {
675          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
676          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
677          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");
678          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();
679          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) uiSamplerChannel);          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel);
680        }
681        catch (LinuxSamplerException e) {
682             result.Error(e);
683        }
684        return result.Produce();
685    }
686    
687          result.type = result_type_success;  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
688        LSCPResultSet result;
689        try {
690            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           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
699      }      }
700      return ConvertResult(result);      return result.Produce();
701  }  }
702    
703  /**  /**
# Line 368  String LSCPServer::SetMIDIInputChannel(u Line 706  String LSCPServer::SetMIDIInputChannel(u
706   */   */
707  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {
708      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));
709      result_t result;      LSCPResultSet result;
710      try {      try {
711          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
712          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
713          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
714          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
715          pEngine->Volume(Volume);          pEngine->Volume(Volume);
         result.type = result_type_success;  
716      }      }
717      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
718           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
719      }      }
720      return ConvertResult(result);      return result.Produce();
721  }  }
722    
723  /**  /**
# Line 391  String LSCPServer::SetVolume(double Volu Line 725  String LSCPServer::SetVolume(double Volu
725   */   */
726  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
727      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
728      result_t result;      LSCPResultSet result;
729      try {      try {
730          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
731          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
732          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
733          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
734          pEngine->Reset();          pEngine->Reset();
         result.type = result_type_success;  
735      }      }
736      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
737           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
738      }      }
739      return ConvertResult(result);      return result.Produce();
740  }  }
741    
742  /**  /**
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 422  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.64  
changed lines
  Added in v.143

  ViewVC Help
Powered by ViewVC