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

Legend:
Removed from v.64  
changed lines
  Added in v.137

  ViewVC Help
Powered by ViewVC