/[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 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 135 by senkov, Sun Jun 20 16:01:50 2004 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck         *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
8   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# 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 88  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    String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) {
94        dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));
95        LSCPResultSet result;
96        try {
97            AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
98            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
99            // search for the created device to get its index
100            int index = -1;
101            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
102            for (; iter != devices.end(); iter++) {
103                if (iter->second == pDevice) {
104                    index = iter->first;
105                    break;
106                }
107            }
108            if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");
109            result = index; // success
110        }
111        catch (LinuxSamplerException e) {
112            result.Error(e);
113        }
114        return result.Produce();
115    }
116    
117    String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) {
118        dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex));
119        LSCPResultSet result;
120        try {
121            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
122            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
123            AudioOutputDevice* pDevice = devices[DeviceIndex];
124            pSampler->DestroyAudioOutputDevice(pDevice);
125        }
126        catch (LinuxSamplerException e) {
127            result.Error(e);
128        }
129        return result.Produce();
130    }
131    
132  /**  /**
133   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
134   */   */
135  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) {  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) {
136      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));
137      result_t result;      LSCPResultSet result;
138      try {      try {
139          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
140          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
141          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
142          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
143          pEngine->LoadInstrument(Filename.c_str(), uiInstrument);          LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
144          result.type = result_type_success;          pLoadInstrument->StartThread();
145      }      }
146      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
147           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
148      }      }
149      return ConvertResult(result);      return result.Produce();
150  }  }
151    
152  /**  /**
# Line 116  String LSCPServer::LoadInstrument(String Line 154  String LSCPServer::LoadInstrument(String
154   */   */
155  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {
156      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));
157      result_t result;      LSCPResultSet result;
158      try {      try {
159          engine_type_t type;          Engine::type_t type;
160          if (EngineName == "gig") type = engine_type_gig;          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
161          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
162          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
163          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
164          pSamplerChannel->LoadEngine(type);          pSamplerChannel->LoadEngine(type);
         result.type = result_type_success;  
165      }      }
166      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
167           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
168      }      }
169      return ConvertResult(result);      return result.Produce();
170  }  }
171    
172  /**  /**
# Line 140  String LSCPServer::LoadEngine(String Eng Line 174  String LSCPServer::LoadEngine(String Eng
174   */   */
175  String LSCPServer::GetChannels() {  String LSCPServer::GetChannels() {
176      dmsg(2,("LSCPServer: GetChannels()\n"));      dmsg(2,("LSCPServer: GetChannels()\n"));
177      return ToString(pSampler->SamplerChannels()) + "\r\n";      LSCPResultSet result;
178        result.Add(pSampler->SamplerChannels());
179        return result.Produce();
180  }  }
181    
182  /**  /**
# Line 149  String LSCPServer::GetChannels() { Line 185  String LSCPServer::GetChannels() {
185  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
186      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
187      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
188      return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n";      LSCPResultSet result(pSamplerChannel->Index());
189        return result.Produce();
190  }  }
191    
192  /**  /**
# Line 157  String LSCPServer::AddChannel() { Line 194  String LSCPServer::AddChannel() {
194   */   */
195  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
196      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
197        LSCPResultSet result;
198      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
199      return "OK\r\n";      return result.Produce();
200  }  }
201    
202  /**  /**
# Line 166  String LSCPServer::RemoveChannel(uint ui Line 204  String LSCPServer::RemoveChannel(uint ui
204   */   */
205  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
206      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
207      return "gig\r\n";      LSCPResultSet result("GigEngine");
208        return result.Produce();
209  }  }
210    
211  /**  /**
# Line 174  String LSCPServer::GetAvailableEngines() Line 213  String LSCPServer::GetAvailableEngines()
213   */   */
214  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
215      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
216      result_t result;      LSCPResultSet result;
217      try {      try {
218          if (EngineName == "gig") {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
219              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
220              String info = pEngine->Description() + "\r\n";              result.Add(pEngine->Description());
221                result.Add(pEngine->Version());
222              delete pEngine;              delete pEngine;
             return info; // success  
223          }          }
224          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
225      }      }
226      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
227           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
228      }      }
229      return ConvertResult(result);      return result.Produce();
230  }  }
231    
232  /**  /**
# Line 199  String LSCPServer::GetEngineInfo(String Line 235  String LSCPServer::GetEngineInfo(String
235   */   */
236  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {
237      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));
238      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
239        try {
240            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
241            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
242            Engine* pEngine = pSamplerChannel->GetEngine();
243    
244            //Defaults values
245            String EngineName = "NONE";
246            float Volume = 0;
247            String InstrumentFileName = "NONE";
248            int InstrumentIndex = -1;
249            int InstrumentStatus = -1;
250    
251            if (pEngine) {
252                EngineName =  pEngine->EngineName();
253                Volume = pEngine->Volume();
254                InstrumentStatus = pEngine->InstrumentStatus();
255                InstrumentIndex = pEngine->InstrumentIndex();
256                if (InstrumentIndex != -1)
257                    InstrumentFileName = pEngine->InstrumentFileName();
258            }
259    
260            result.Add("ENGINE_NAME", EngineName);
261            result.Add("VOLUME", Volume);
262    
263            //Some hardcoded stuff for now to make GUI look good
264            result.Add("AUDIO_OUTPUT_DEVICE", "0");
265            result.Add("AUDIO_OUTPUT_CHANNELS", "2");
266            result.Add("AUDIO_OUTPUT_ROUTING", "0,1");
267    
268            result.Add("INSTRUMENT_FILE", InstrumentFileName);
269            result.Add("INSTRUMENT_NR", InstrumentIndex);
270            result.Add("INSTRUMENT_STATUS", InstrumentStatus);
271    
272            //Some more hardcoded stuff for now to make GUI look good
273            result.Add("MIDI_INPUT_DEVICE", "0");
274            result.Add("MIDI_INPUT_PORT", "0");
275            result.Add("MIDI_INPUT_CHANNEL", "1");
276        }
277        catch (LinuxSamplerException e) {
278             result.Error(e);
279        }
280        return result.Produce();
281  }  }
282    
283  /**  /**
# Line 208  String LSCPServer::GetChannelInfo(uint u Line 286  String LSCPServer::GetChannelInfo(uint u
286   */   */
287  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {
288      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
289      result_t result;      LSCPResultSet result;
290      try {      try {
291          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
292          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
293          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
294          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
295          return ToString(pEngine->VoiceCount()) + "\r\n"; // success          result.Add(pEngine->VoiceCount());
296      }      }
297      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
298           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
299      }      }
300      return ConvertResult(result);      return result.Produce();
301  }  }
302    
303  /**  /**
# Line 231  String LSCPServer::GetVoiceCount(uint ui Line 306  String LSCPServer::GetVoiceCount(uint ui
306   */   */
307  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {
308      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
309      result_t result;      LSCPResultSet result;
310      try {      try {
311          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
312          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
313          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
314          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
315          return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success          result.Add(pEngine->DiskStreamCount());
316      }      }
317      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
318           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
319      }      }
320      return ConvertResult(result);      return result.Produce();
321  }  }
322    
323  /**  /**
# Line 254  String LSCPServer::GetStreamCount(uint u Line 326  String LSCPServer::GetStreamCount(uint u
326   */   */
327  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {
328      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
329      result_t result;      LSCPResultSet result;
330      try {      try {
331          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
332          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
333          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
334          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
335          if (!pEngine->DiskStreamSupported()) return "NA\r\n";          if (!pEngine->DiskStreamSupported())
336          switch (ResponseType) {              result.Add("NA");
337              case fill_response_bytes:          else {
338                  return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success              switch (ResponseType) {
339              case fill_response_percentage:                  case fill_response_bytes:
340                  return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success                      result.Add(pEngine->DiskStreamBufferFillBytes());
341              default:                      break;
342                  throw LinuxSamplerException("Unknown fill response type");                  case fill_response_percentage:
343                        result.Add(pEngine->DiskStreamBufferFillPercentage());
344                        break;
345                    default:
346                        throw LinuxSamplerException("Unknown fill response type");
347                }
348            }
349        }
350        catch (LinuxSamplerException e) {
351             result.Error(e);
352        }
353        return result.Produce();
354    }
355    
356    String LSCPServer::GetAvailableAudioOutputDrivers() {
357        dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
358        LSCPResultSet result;
359        try {
360            String s = AudioOutputDeviceFactory::AvailableDriversAsString();
361            result.Add(s);
362        }
363        catch (LinuxSamplerException e) {
364            result.Error(e);
365        }
366        return result.Produce();
367    }
368    
369    String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
370        dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
371        LSCPResultSet result;
372        try {
373            result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver));
374            result.Add("VERSION",     AudioOutputDeviceFactory::GetDriverVersion(Driver));
375    
376            std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver);
377            if (parameters.size()) { // if there are parameters defined for this driver
378                String s;
379                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
380                for (;iter != parameters.end(); iter++) {
381                    if (s != "") s += ",";
382                    s += iter->first;
383                }
384                result.Add("PARAMETERS", s);
385          }          }
386      }      }
387      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
388           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
389      }      }
390      return ConvertResult(result);      return result.Produce();
391  }  }
392    
393  /**  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
394   * 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()));
395   * particular sampler channel.      LSCPResultSet result;
  */  
 String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel));  
     result_t result;  
396      try {      try {
397          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
398          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          result.Add("TYPE",         pParameter->Type());
399          pSamplerChannel->SetAudioOutputDevice(AudioOutputType);          result.Add("DESCRIPTION",  pParameter->Description());
400          result.type = result_type_success;          result.Add("MANDATORY",    pParameter->Mandatory());
401            result.Add("FIX",          pParameter->Fix());
402            result.Add("MULTIPLICITY", pParameter->Multiplicity());
403            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
404            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
405            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
406            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
407            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
408        }
409        catch (LinuxSamplerException e) {
410            result.Error(e);
411        }
412        return result.Produce();
413    }
414    
415    String LSCPServer::GetAudioOutputDeviceCount() {
416        dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n"));
417        LSCPResultSet result;
418        try {
419            uint count = pSampler->AudioOutputDevices();
420            result = count; // success
421        }
422        catch (LinuxSamplerException e) {
423            result.Error(e);
424        }
425        return result.Produce();
426    }
427    
428    String LSCPServer::GetAudioOutputDevices() {
429        dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
430        LSCPResultSet result;
431        try {
432            String s;
433            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
434            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
435            for (; iter != devices.end(); iter++) {
436                if (s != "") s += ",";
437                s += ToString(iter->first);
438            }
439            result.Add(s);
440        }
441        catch (LinuxSamplerException e) {
442            result.Error(e);
443        }
444        return result.Produce();
445    }
446    
447    String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
448        dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
449        LSCPResultSet result;
450        try {
451            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
452            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
453            AudioOutputDevice* pDevice = devices[DeviceIndex];
454            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
455            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
456            for (; iter != parameters.end(); iter++) {
457                result.Add(iter->first, iter->second->Value());
458            }
459      }      }
460      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
461           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
462      }      }
463      return ConvertResult(result);      return result.Produce();
464    }
465    
466    String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
467        dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
468        LSCPResultSet result;
469        try {
470            // get audio output device
471            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
472            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
473            AudioOutputDevice* pDevice = devices[DeviceId];
474    
475            // get audio channel
476            AudioChannel* pChannel = pDevice->Channel(ChannelId);
477            if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");
478    
479            // return the values of all audio channel parameters
480            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
481            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
482            for (; iter != parameters.end(); iter++) {
483                result.Add(iter->first, iter->second->Value());
484            }
485        }
486        catch (LinuxSamplerException e) {
487            result.Error(e);
488        }
489        return result.Produce();
490    }
491    
492    String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
493        dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
494        LSCPResultSet result;
495        try {
496            // get audio output device
497            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
498            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
499            AudioOutputDevice* pDevice = devices[DeviceId];
500    
501            // get audio channel
502            AudioChannel* pChannel = pDevice->Channel(ChannelId);
503            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
504    
505            // get desired audio channel parameter
506            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
507            if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
508            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
509    
510            // return all fields of this audio channel parameter
511            result.Add("TYPE",         pParameter->Type());
512            result.Add("DESCRIPTION",  pParameter->Description());
513            result.Add("FIX",          pParameter->Fix());
514            result.Add("MULTIPLICITY", pParameter->Multiplicity());
515            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
516            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
517            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
518        }
519        catch (LinuxSamplerException e) {
520            result.Error(e);
521        }
522        return result.Produce();
523    }
524    
525    String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) {
526        dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str()));
527        LSCPResultSet result;
528        try {
529            // get audio output device
530            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
531            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
532            AudioOutputDevice* pDevice = devices[DeviceId];
533    
534            // get audio channel
535            AudioChannel* pChannel = pDevice->Channel(ChannelId);
536            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
537    
538            // get desired audio channel parameter
539            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
540            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
541            DeviceRuntimeParameter* pParameter = parameters[ParamKey];
542    
543            // set new channel parameter value
544            pParameter->SetValue(ParamVal);
545        }
546        catch (LinuxSamplerException e) {
547            result.Error(e);
548        }
549        return result.Produce();
550    }
551    
552    String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
553        dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
554        LSCPResultSet result;
555        try {
556            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
557            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
558            AudioOutputDevice* pDevice = devices[DeviceIndex];
559            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
560            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
561            parameters[ParamKey]->SetValue(ParamVal);
562        }
563        catch (LinuxSamplerException e) {
564            result.Error(e);
565        }
566        return result.Produce();
567  }  }
568    
569  /**  /**
570   * 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
571   * playback on a particular sampler channel.   * playback on a particular sampler channel.
572   */   */
573  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
574      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));
575      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?
576  }  }
577    
578  String LSCPServer::SetMIDIInputType(midi_input_type_t MidiInputType, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
579      dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));
580      result_t result;      LSCPResultSet result;
581      try {      try {
582          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
583          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
584            // 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)
585            if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");
586            MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;
587          pSamplerChannel->SetMidiInputDevice(MidiInputType);          pSamplerChannel->SetMidiInputDevice(MidiInputType);
         result.type = result_type_success;  
588      }      }
589      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
590           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
591      }      }
592      return ConvertResult(result);      return result.Produce();
593  }  }
594    
595  /**  /**
596   * 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
597   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
598   */   */
599  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel) {  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) {
600      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));
601      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
602        try {
603            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
604            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
605            if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");
606            pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());
607        }
608        catch (LinuxSamplerException e) {
609             result.Error(e);
610        }
611        return result.Produce();
612  }  }
613    
614  /**  /**
# Line 343  String LSCPServer::SetMIDIInputPort(Stri Line 617  String LSCPServer::SetMIDIInputPort(Stri
617   */   */
618  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
619      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));
620      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
621        try {
622            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
623            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
624            if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");
625            MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();
626            pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel);
627        }
628        catch (LinuxSamplerException e) {
629             result.Error(e);
630        }
631        return result.Produce();
632    }
633    
634    String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) {
635        LSCPResultSet result;
636        try {
637            throw LinuxSamplerException("Command not yet implemented");
638        }
639        catch (LinuxSamplerException e) {
640             result.Error(e);
641        }
642        return result.Produce();
643  }  }
644    
645  /**  /**
# Line 352  String LSCPServer::SetMIDIInputChannel(u Line 648  String LSCPServer::SetMIDIInputChannel(u
648   */   */
649  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {
650      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));
651      result_t result;      LSCPResultSet result;
652      try {      try {
653          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
654          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
655          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
656          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
657          pEngine->Volume(Volume);          pEngine->Volume(Volume);
         result.type = result_type_success;  
658      }      }
659      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
660           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
661      }      }
662      return ConvertResult(result);      return result.Produce();
663  }  }
664    
665  /**  /**
# Line 375  String LSCPServer::SetVolume(double Volu Line 667  String LSCPServer::SetVolume(double Volu
667   */   */
668  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
669      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
670      result_t result;      LSCPResultSet result;
671      try {      try {
672          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
673          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
674          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
675          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
676          pEngine->Reset();          pEngine->Reset();
         result.type = result_type_success;  
677      }      }
678      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
679           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
680      }      }
681      return ConvertResult(result);      return result.Produce();
682  }  }
683    
684  /**  /**
685   * 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
686   * server for receiving event messages.   * server for receiving event messages.
687   */   */
688  String LSCPServer::SubscribeNotification(uint UDPPort) {  String LSCPServer::SubscribeNotification(event_t Event) {
689      dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event));
690      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
691  }  }
692    
# Line 406  String LSCPServer::SubscribeNotification Line 694  String LSCPServer::SubscribeNotification
694   * 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
695   * for not receiving further event messages.   * for not receiving further event messages.
696   */   */
697  String LSCPServer::UnsubscribeNotification(String SessionID) {  String LSCPServer::UnsubscribeNotification(event_t Event) {
698      dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event));
699      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
700  }  }
701    
702    
703    // Instrument loader constructor.
704    LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)
705        : Thread(false, 0, -4)
706    {
707        this->pEngine = pEngine;
708        this->Filename = Filename;
709        this->uiInstrument = uiInstrument;
710    }
711    
712    // Instrument loader process.
713    int LSCPLoadInstrument::Main()
714    {
715        try {
716            pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
717        }
718    
719        catch (LinuxSamplerException e) {
720            e.PrintMessage();
721        }
722    
723        // Always re-enable the engine.
724        pEngine->Enable();
725    
726        // FIXME: Shoot ourselves on the foot?
727        delete this;
728    }

Legend:
Removed from v.53  
changed lines
  Added in v.135

  ViewVC Help
Powered by ViewVC