/[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 68 by senkov, Sat May 8 19:03:17 2004 UTC revision 155 by senkov, Mon Jun 28 04:30:11 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    #include "../mididriver/MidiInputDeviceFactory.h"
29    
30  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
31      this->pSampler = pSampler;      this->pSampler = pSampler;
# Line 89  void LSCPServer::AnswerClient(String Ret Line 92  void LSCPServer::AnswerClient(String Ret
92  }  }
93    
94  /**  /**
95     * Find a created audio output device index.
96     */
97    int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice )
98    {
99        // Search for the created device to get its index
100        std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
101        std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
102        for (; iter != devices.end(); iter++) {
103            if (iter->second == pDevice)
104                return iter->first;
105        }
106        // Not found.
107        return -1;
108    }
109    
110    /**
111     * Find a created midi input device index.
112     */
113    int LSCPServer::GetMidiInputDeviceIndex ( MidiInputDevice *pDevice )
114    {
115        // Search for the created device to get its index
116        std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
117        std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
118        for (; iter != devices.end(); iter++) {
119            if (iter->second == pDevice)
120                return iter->first;
121        }
122        // Not found.
123        return -1;
124    }
125    
126    String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) {
127        dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));
128        LSCPResultSet result;
129        try {
130            AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
131            // search for the created device to get its index
132            int index = GetAudioOutputDeviceIndex(pDevice);
133            if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");
134            result = index; // success
135        }
136        catch (LinuxSamplerException e) {
137            result.Error(e);
138        }
139        return result.Produce();
140    }
141    
142    String LSCPServer::CreateMidiInputDevice(String Driver, std::map<String,String> Parameters) {
143        dmsg(2,("LSCPServer: CreateMidiInputDevice(Driver=%s)\n", Driver.c_str()));
144        LSCPResultSet result;
145        try {
146            MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
147            // search for the created device to get its index
148            int index = GetMidiInputDeviceIndex(pDevice);
149            if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device.");
150            result = index; // success
151        }
152        catch (LinuxSamplerException e) {
153            result.Error(e);
154        }
155        return result.Produce();
156    }
157    
158    String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) {
159        dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex));
160        LSCPResultSet result;
161        try {
162            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
163            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
164            AudioOutputDevice* pDevice = devices[DeviceIndex];
165            pSampler->DestroyAudioOutputDevice(pDevice);
166        }
167        catch (LinuxSamplerException e) {
168            result.Error(e);
169        }
170        return result.Produce();
171    }
172    
173    String LSCPServer::DestroyMidiInputDevice(uint DeviceIndex) {
174        dmsg(2,("LSCPServer: DestroyMidiInputDevice(DeviceIndex=%d)\n", DeviceIndex));
175        LSCPResultSet result;
176        try {
177            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
178            MidiInputDevice* pDevice = devices[DeviceIndex];
179            if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
180            pSampler->DestroyMidiInputDevice(pDevice);
181        }
182        catch (LinuxSamplerException e) {
183            result.Error(e);
184        }
185        return result.Produce();
186    }
187    
188    /**
189   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
190   */   */
191  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) {  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) {
192      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));
193      result_t result;      LSCPResultSet result;
194      try {      try {
195          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
196          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
197          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
198          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
199          pEngine->LoadInstrument(Filename.c_str(), uiInstrument);          if (pSamplerChannel->GetAudioOutputDevice() == NULL)
200          result.type = result_type_success;              throw LinuxSamplerException("No audio output device on channel");
201            if (bBackground) {
202                LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
203                pLoadInstrument->StartThread();
204            }
205            else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
206      }      }
207      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
208           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
209      }      }
210      return ConvertResult(result);      return result.Produce();
211  }  }
212    
213  /**  /**
# Line 116  String LSCPServer::LoadInstrument(String Line 215  String LSCPServer::LoadInstrument(String
215   */   */
216  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {
217      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));
218      result_t result;      LSCPResultSet result;
219      try {      try {
220          Engine::type_t type;          Engine::type_t type;
221          if (EngineName == "gig") type = Engine::type_gig;          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
222          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
223          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
224          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
225          pSamplerChannel->LoadEngine(type);          pSamplerChannel->LoadEngine(type);
         result.type = result_type_success;  
226      }      }
227      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
228           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
229      }      }
230      return ConvertResult(result);      return result.Produce();
231  }  }
232    
233  /**  /**
# Line 140  String LSCPServer::LoadEngine(String Eng Line 235  String LSCPServer::LoadEngine(String Eng
235   */   */
236  String LSCPServer::GetChannels() {  String LSCPServer::GetChannels() {
237      dmsg(2,("LSCPServer: GetChannels()\n"));      dmsg(2,("LSCPServer: GetChannels()\n"));
238      return ToString(pSampler->SamplerChannels()) + "\r\n";      LSCPResultSet result;
239        result.Add(pSampler->SamplerChannels());
240        return result.Produce();
241  }  }
242    
243  /**  /**
# Line 149  String LSCPServer::GetChannels() { Line 246  String LSCPServer::GetChannels() {
246  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
247      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
248      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
249      return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n";      LSCPResultSet result(pSamplerChannel->Index());
250        return result.Produce();
251  }  }
252    
253  /**  /**
# Line 157  String LSCPServer::AddChannel() { Line 255  String LSCPServer::AddChannel() {
255   */   */
256  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
257      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
258        LSCPResultSet result;
259      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
260      return "OK\r\n";      return result.Produce();
261  }  }
262    
263  /**  /**
# Line 166  String LSCPServer::RemoveChannel(uint ui Line 265  String LSCPServer::RemoveChannel(uint ui
265   */   */
266  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
267      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
268      return "gig\r\n";      LSCPResultSet result("GigEngine");
269        return result.Produce();
270  }  }
271    
272  /**  /**
# Line 174  String LSCPServer::GetAvailableEngines() Line 274  String LSCPServer::GetAvailableEngines()
274   */   */
275  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
276      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
277      result_t result;      LSCPResultSet result;
278      try {      try {
279          if (EngineName == "gig") {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
280              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
281              String info = pEngine->Description() + "\r\n";              result.Add(pEngine->Description());
282                result.Add(pEngine->Version());
283              delete pEngine;              delete pEngine;
             return info; // success  
284          }          }
285          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
286      }      }
287      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
288           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
289      }      }
290      return ConvertResult(result);      return result.Produce();
291  }  }
292    
293  /**  /**
# Line 199  String LSCPServer::GetEngineInfo(String Line 296  String LSCPServer::GetEngineInfo(String
296   */   */
297  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {
298      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));
299      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
300        try {
301            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
302            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
303            Engine* pEngine = pSamplerChannel->GetEngine();
304    
305            //Defaults values
306            String EngineName = "NONE";
307            float Volume = 0;
308            String InstrumentFileName = "NONE";
309            int InstrumentIndex = -1;
310            int InstrumentStatus = -1;
311    
312            if (pEngine) {
313                EngineName =  pEngine->EngineName();
314                Volume = pEngine->Volume();
315                InstrumentStatus = pEngine->InstrumentStatus();
316                InstrumentIndex = pEngine->InstrumentIndex();
317                if (InstrumentIndex != -1)
318                    InstrumentFileName = pEngine->InstrumentFileName();
319            }
320    
321            result.Add("ENGINE_NAME", EngineName);
322            result.Add("VOLUME", Volume);
323    
324            //Some not-so-hardcoded stuff to make GUI look good
325            result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
326            result.Add("AUDIO_OUTPUT_CHANNELS", "2");
327            result.Add("AUDIO_OUTPUT_ROUTING", "0,1");
328    
329            result.Add("INSTRUMENT_FILE", InstrumentFileName);
330            result.Add("INSTRUMENT_NR", InstrumentIndex);
331            result.Add("INSTRUMENT_STATUS", InstrumentStatus);
332    
333            MidiInputDevice *pDevice = pSamplerChannel->GetMidiInputDevice();
334            if (pDevice) {
335                    result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pDevice));
336                    MidiInputDevice::MidiInputPort *pPort = pSamplerChannel->GetMidiInputPort();
337                    if (pPort) {
338                            result.Add("MIDI_INPUT_PORT", (int)pPort->GetPortNumber());
339                            result.Add("MIDI_INPUT_CHANNEL", (int)pSamplerChannel->GetMidiInputChannel());
340                    }
341    
342            }
343        }
344        catch (LinuxSamplerException e) {
345             result.Error(e);
346        }
347        return result.Produce();
348  }  }
349    
350  /**  /**
# Line 208  String LSCPServer::GetChannelInfo(uint u Line 353  String LSCPServer::GetChannelInfo(uint u
353   */   */
354  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {
355      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
356      result_t result;      LSCPResultSet result;
357      try {      try {
358          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
359          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
360          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
361          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
362          return ToString(pEngine->VoiceCount()) + "\r\n"; // success          result.Add(pEngine->VoiceCount());
363      }      }
364      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
365           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
366      }      }
367      return ConvertResult(result);      return result.Produce();
368  }  }
369    
370  /**  /**
# Line 231  String LSCPServer::GetVoiceCount(uint ui Line 373  String LSCPServer::GetVoiceCount(uint ui
373   */   */
374  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {
375      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
376      result_t result;      LSCPResultSet result;
377      try {      try {
378          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
379          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
380          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
381          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
382          return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success          result.Add(pEngine->DiskStreamCount());
383      }      }
384      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
385           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
386      }      }
387      return ConvertResult(result);      return result.Produce();
388  }  }
389    
390  /**  /**
# Line 254  String LSCPServer::GetStreamCount(uint u Line 393  String LSCPServer::GetStreamCount(uint u
393   */   */
394  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {
395      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
396      result_t result;      LSCPResultSet result;
397      try {      try {
398          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
399          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
400          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
401          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
402          if (!pEngine->DiskStreamSupported()) return "NA\r\n";          if (!pEngine->DiskStreamSupported())
403          switch (ResponseType) {              result.Add("NA");
404              case fill_response_bytes:          else {
405                  return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success              switch (ResponseType) {
406              case fill_response_percentage:                  case fill_response_bytes:
407                  return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success                      result.Add(pEngine->DiskStreamBufferFillBytes());
408              default:                      break;
409                  throw LinuxSamplerException("Unknown fill response type");                  case fill_response_percentage:
410                        result.Add(pEngine->DiskStreamBufferFillPercentage());
411                        break;
412                    default:
413                        throw LinuxSamplerException("Unknown fill response type");
414                }
415            }
416        }
417        catch (LinuxSamplerException e) {
418             result.Error(e);
419        }
420        return result.Produce();
421    }
422    
423    String LSCPServer::GetAvailableAudioOutputDrivers() {
424        dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
425        LSCPResultSet result;
426        try {
427            String s = AudioOutputDeviceFactory::AvailableDriversAsString();
428            result.Add(s);
429        }
430        catch (LinuxSamplerException e) {
431            result.Error(e);
432        }
433        return result.Produce();
434    }
435    
436    String LSCPServer::GetAvailableMidiInputDrivers() {
437        dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
438        LSCPResultSet result;
439        try {
440            String s = MidiInputDeviceFactory::AvailableDriversAsString();
441            result.Add(s);
442        }
443        catch (LinuxSamplerException e) {
444            result.Error(e);
445        }
446        return result.Produce();
447    }
448    
449    String LSCPServer::GetMidiInputDriverInfo(String Driver) {
450        dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str()));
451        LSCPResultSet result;
452        try {
453            result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver));
454            result.Add("VERSION",     MidiInputDeviceFactory::GetDriverVersion(Driver));
455    
456            std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver);
457            if (parameters.size()) { // if there are parameters defined for this driver
458                String s;
459                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
460                for (;iter != parameters.end(); iter++) {
461                    if (s != "") s += ",";
462                    s += iter->first;
463                }
464                result.Add("PARAMETERS", s);
465          }          }
466      }      }
467      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
468           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
469      }      }
470      return ConvertResult(result);      return result.Produce();
471  }  }
472    
473  /**  String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
474   * Will be called by the parser to change the audio output type on a      dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
475   * particular sampler channel.      LSCPResultSet result;
476   */      try {
477  String LSCPServer::SetAudioOutputType(AudioOutputDevice::type_t AudioOutputType, uint uiSamplerChannel) {          result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver));
478      dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel));          result.Add("VERSION",     AudioOutputDeviceFactory::GetDriverVersion(Driver));
479      result_t result;  
480            std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver);
481            if (parameters.size()) { // if there are parameters defined for this driver
482                String s;
483                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
484                for (;iter != parameters.end(); iter++) {
485                    if (s != "") s += ",";
486                    s += iter->first;
487                }
488                result.Add("PARAMETERS", s);
489            }
490        }
491        catch (LinuxSamplerException e) {
492            result.Error(e);
493        }
494        return result.Produce();
495    }
496    
497    String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
498        dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
499        LSCPResultSet result;
500      try {      try {
501          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
502          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          result.Add("TYPE",         pParameter->Type());
503          pSamplerChannel->SetAudioOutputDevice(AudioOutputType);          result.Add("DESCRIPTION",  pParameter->Description());
504          result.type = result_type_success;          result.Add("MANDATORY",    pParameter->Mandatory());
505            result.Add("FIX",          pParameter->Fix());
506            result.Add("MULTIPLICITY", pParameter->Multiplicity());
507            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
508            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
509            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
510            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
511            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
512        }
513        catch (LinuxSamplerException e) {
514            result.Error(e);
515        }
516        return result.Produce();
517    }
518    
519    String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
520        dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
521        LSCPResultSet result;
522        try {
523            DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
524            result.Add("TYPE",         pParameter->Type());
525            result.Add("DESCRIPTION",  pParameter->Description());
526            result.Add("MANDATORY",    pParameter->Mandatory());
527            result.Add("FIX",          pParameter->Fix());
528            result.Add("MULTIPLICITY", pParameter->Multiplicity());
529            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
530            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
531            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
532            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
533            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
534        }
535        catch (LinuxSamplerException e) {
536            result.Error(e);
537        }
538        return result.Produce();
539    }
540    
541    String LSCPServer::GetAudioOutputDeviceCount() {
542        dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n"));
543        LSCPResultSet result;
544        try {
545            uint count = pSampler->AudioOutputDevices();
546            result.Add(count); // success
547        }
548        catch (LinuxSamplerException e) {
549            result.Error(e);
550        }
551        return result.Produce();
552    }
553    
554    String LSCPServer::GetMidiInputDeviceCount() {
555        dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n"));
556        LSCPResultSet result;
557        try {
558            uint count = pSampler->MidiInputDevices();
559            result.Add(count); // success
560      }      }
561      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
562           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
563      }      }
564      return ConvertResult(result);      return result.Produce();
565    }
566    
567    String LSCPServer::GetAudioOutputDevices() {
568        dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
569        LSCPResultSet result;
570        try {
571            String s;
572            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
573            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
574            for (; iter != devices.end(); iter++) {
575                if (s != "") s += ",";
576                s += ToString(iter->first);
577            }
578            result.Add(s);
579        }
580        catch (LinuxSamplerException e) {
581            result.Error(e);
582        }
583        return result.Produce();
584    }
585    
586    String LSCPServer::GetMidiInputDevices() {
587        dmsg(2,("LSCPServer: GetMidiInputDevices()\n"));
588        LSCPResultSet result;
589        try {
590            String s;
591            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
592            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
593            for (; iter != devices.end(); iter++) {
594                if (s != "") s += ",";
595                s += ToString(iter->first);
596            }
597            result.Add(s);
598        }
599        catch (LinuxSamplerException e) {
600            result.Error(e);
601        }
602        return result.Produce();
603    }
604    
605    String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
606        dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
607        LSCPResultSet result;
608        try {
609            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
610            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
611            AudioOutputDevice* pDevice = devices[DeviceIndex];
612            result.Add("driver", pDevice->Driver());
613            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
614            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
615            for (; iter != parameters.end(); iter++) {
616                result.Add(iter->first, iter->second->Value());
617            }
618        }
619        catch (LinuxSamplerException e) {
620            result.Error(e);
621        }
622        return result.Produce();
623    }
624    
625    String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) {
626        dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
627        LSCPResultSet result;
628        try {
629            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
630            MidiInputDevice* pDevice = devices[DeviceIndex];
631            if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");
632            result.Add("driver", pDevice->Driver());
633            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
634            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
635            for (; iter != parameters.end(); iter++) {
636                result.Add(iter->first, iter->second->Value());
637            }
638        }
639        catch (LinuxSamplerException e) {
640            result.Error(e);
641        }
642        return result.Produce();
643    }
644    String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) {
645        dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
646        LSCPResultSet result;
647        try {
648            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
649            MidiInputDevice* pDevice = devices[DeviceIndex];
650            if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");
651            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
652            if (!pMidiInputPort) throw LinuxSamplerException("There is no midi input port with index " + ToString(PortIndex) + ".");
653            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
654            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
655            for (; iter != parameters.end(); iter++) {
656                result.Add(iter->first, iter->second->Value());
657            }
658        }
659        catch (LinuxSamplerException e) {
660            result.Error(e);
661        }
662        return result.Produce();
663    }
664    
665    String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
666        dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
667        LSCPResultSet result;
668        try {
669            // get audio output device
670            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
671            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
672            AudioOutputDevice* pDevice = devices[DeviceId];
673    
674            // get audio channel
675            AudioChannel* pChannel = pDevice->Channel(ChannelId);
676            if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");
677    
678            // return the values of all audio channel parameters
679            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
680            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
681            for (; iter != parameters.end(); iter++) {
682                result.Add(iter->first, iter->second->Value());
683            }
684        }
685        catch (LinuxSamplerException e) {
686            result.Error(e);
687        }
688        return result.Produce();
689    }
690    
691    String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
692        dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
693        LSCPResultSet result;
694        try {
695            // get audio output device
696            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
697            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
698            AudioOutputDevice* pDevice = devices[DeviceId];
699    
700            // get audio channel
701            AudioChannel* pChannel = pDevice->Channel(ChannelId);
702            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
703    
704            // get desired audio channel parameter
705            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
706            if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
707            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
708    
709            // return all fields of this audio channel parameter
710            result.Add("TYPE",         pParameter->Type());
711            result.Add("DESCRIPTION",  pParameter->Description());
712            result.Add("FIX",          pParameter->Fix());
713            result.Add("MULTIPLICITY", pParameter->Multiplicity());
714            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
715            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
716            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
717        }
718        catch (LinuxSamplerException e) {
719            result.Error(e);
720        }
721        return result.Produce();
722    }
723    
724    String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) {
725        dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str()));
726        LSCPResultSet result;
727        try {
728            // get audio output device
729            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
730            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
731            AudioOutputDevice* pDevice = devices[DeviceId];
732    
733            // get audio channel
734            AudioChannel* pChannel = pDevice->Channel(ChannelId);
735            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
736    
737            // get desired audio channel parameter
738            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
739            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
740            DeviceRuntimeParameter* pParameter = parameters[ParamKey];
741    
742            // set new channel parameter value
743            pParameter->SetValue(ParamVal);
744        }
745        catch (LinuxSamplerException e) {
746            result.Error(e);
747        }
748        return result.Produce();
749    }
750    
751    String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
752        dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
753        LSCPResultSet result;
754        try {
755            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
756            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
757            AudioOutputDevice* pDevice = devices[DeviceIndex];
758            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
759            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
760            parameters[ParamKey]->SetValue(ParamVal);
761        }
762        catch (LinuxSamplerException e) {
763            result.Error(e);
764        }
765        return result.Produce();
766    }
767    
768    String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
769        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
770        LSCPResultSet result;
771        try {
772            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
773            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");
774            MidiInputDevice* pDevice = devices[DeviceIndex];
775            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
776            if (!parameters[ParamKey]) throw LinuxSamplerException("Midi input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
777            parameters[ParamKey]->SetValue(ParamVal);
778        }
779        catch (LinuxSamplerException e) {
780            result.Error(e);
781        }
782        return result.Produce();
783    }
784    
785    String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) {
786        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
787        LSCPResultSet result;
788        try {
789            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
790            MidiInputDevice* pDevice = devices[DeviceIndex];
791            if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");
792            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
793            if (!pMidiInputPort) throw LinuxSamplerException("There is no midi input port with index " + ToString(PortIndex) + ".");
794            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
795            if (!parameters[ParamKey]) throw LinuxSamplerException("Midi input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
796            parameters[ParamKey]->SetValue(ParamVal);
797        }
798        catch (LinuxSamplerException e) {
799            result.Error(e);
800        }
801        return result.Produce();
802  }  }
803    
804  /**  /**
805   * 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
806   * playback on a particular sampler channel.   * playback on a particular sampler channel.
807   */   */
808  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
809      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));
810      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?
811    }
812    
813    String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
814        dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
815        LSCPResultSet result;
816        try {
817            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
818            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
819            // Driver type name aliasing...
820            if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";
821            if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";        
822            // Check if there's one audio output device already created
823            // for the intended audio driver type (AudioOutputDriver)...
824            AudioOutputDevice *pDevice = NULL;
825            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
826            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
827            for (; iter != devices.end(); iter++) {
828                if ((iter->second)->Driver() == AudioOutputDriver) {
829                    pDevice = iter->second;
830                    break;
831                }
832            }
833            // If it doesn't exist, create a new one with default parameters...
834            if (pDevice == NULL) {
835                std::map<String,String> params;
836                pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
837            }
838            // Must have a device...
839            if (pDevice == NULL)
840                throw LinuxSamplerException("Internal error: could not create audio output device.");
841            // Set it as the current channel device...
842            pSamplerChannel->SetAudioOutputDevice(pDevice);
843        }
844        catch (LinuxSamplerException e) {
845             result.Error(e);
846        }
847        return result.Produce();
848  }  }
849    
850  String LSCPServer::SetMIDIInputType(MidiInputDevice::type_t MidiInputType, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
851      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));
852      result_t result;      LSCPResultSet result;
853      try {      try {
854    #if 1
855            throw LinuxSamplerException("Command deprecated");
856    #else
857          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
858          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
859            // 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)
860            if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";
861            if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");
862            MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;
863          pSamplerChannel->SetMidiInputDevice(MidiInputType);          pSamplerChannel->SetMidiInputDevice(MidiInputType);
864          result.type = result_type_success;  #endif
865      }      }
866      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
867           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
868      }      }
869      return ConvertResult(result);      return result.Produce();
870  }  }
871    
872  /**  /**
873   * 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 device, port and channel on which
874   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
875   */   */
876  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInput(uint MIDIDevice, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {
877      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInput(MIDIDevice=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDevice, MIDIPort, MIDIChannel, uiSamplerChannel));
878      result_t result;      LSCPResultSet result;
879      try {      try {
880          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
881          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
882          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
883          pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());          MidiInputDevice* pDevice = devices[MIDIDevice];
884          result.type = result_type_success;          if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(MIDIDevice));
885            pSamplerChannel->SetMidiInputPort(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
886      }      }
887      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
888           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
889      }      }
890      return ConvertResult(result);      return result.Produce();
891  }  }
892    
893  /**  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
894   * Will be called by the parser to change the MIDI input channel on which the      LSCPResultSet result;
  * engine of a particular sampler channel should listen to.  
  */  
 String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));  
     result_t result;  
895      try {      try {
896          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
897          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
898          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
899          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();          AudioOutputDevice* pDevice = devices[AudioDeviceId];
900          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) uiSamplerChannel);          if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
901            pSamplerChannel->SetAudioOutputDevice(pDevice);
         result.type = result_type_success;  
902      }      }
903      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
904           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
905      }      }
906      return ConvertResult(result);      return result.Produce();
907  }  }
908    
909  /**  /**
# Line 382  String LSCPServer::SetMIDIInputChannel(u Line 912  String LSCPServer::SetMIDIInputChannel(u
912   */   */
913  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {
914      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));
915      result_t result;      LSCPResultSet result;
916      try {      try {
917          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
918          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
919          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
920          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
921          pEngine->Volume(Volume);          pEngine->Volume(Volume);
         result.type = result_type_success;  
922      }      }
923      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
924           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
925      }      }
926      return ConvertResult(result);      return result.Produce();
927  }  }
928    
929  /**  /**
# Line 405  String LSCPServer::SetVolume(double Volu Line 931  String LSCPServer::SetVolume(double Volu
931   */   */
932  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
933      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
934      result_t result;      LSCPResultSet result;
935      try {      try {
936          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
937          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
938          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
939          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
940          pEngine->Reset();          pEngine->Reset();
         result.type = result_type_success;  
941      }      }
942      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
943           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
944      }      }
945      return ConvertResult(result);      return result.Produce();
946  }  }
947    
948  /**  /**
949   * 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
950   * server for receiving event messages.   * server for receiving event messages.
951   */   */
952  String LSCPServer::SubscribeNotification(uint UDPPort) {  String LSCPServer::SubscribeNotification(event_t Event) {
953      dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event));
954      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
955  }  }
956    
# Line 436  String LSCPServer::SubscribeNotification Line 958  String LSCPServer::SubscribeNotification
958   * 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
959   * for not receiving further event messages.   * for not receiving further event messages.
960   */   */
961  String LSCPServer::UnsubscribeNotification(String SessionID) {  String LSCPServer::UnsubscribeNotification(event_t Event) {
962      dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event));
963      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
964  }  }
965    
966    
967    // Instrument loader constructor.
968    LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)
969        : Thread(false, 0, -4)
970    {
971        this->pEngine = pEngine;
972        this->Filename = Filename;
973        this->uiInstrument = uiInstrument;
974    }
975    
976    // Instrument loader process.
977    int LSCPLoadInstrument::Main()
978    {
979        try {
980            pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
981        }
982    
983        catch (LinuxSamplerException e) {
984            e.PrintMessage();
985        }
986    
987        // Always re-enable the engine.
988        pEngine->Enable();
989    
990        // FIXME: Shoot ourselves on the foot?
991        delete this;
992    }

Legend:
Removed from v.68  
changed lines
  Added in v.155

  ViewVC Help
Powered by ViewVC