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

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

  ViewVC Help
Powered by ViewVC