/[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 120 by senkov, Sat Jun 12 07:29:37 2004 UTC revision 155 by senkov, Mon Jun 28 04:30:11 2004 UTC
# Line 24  Line 24 
24  #include "lscpresultset.h"  #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 90  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      LSCPResultSet result;      LSCPResultSet result;
194      try {      try {
# Line 100  String LSCPServer::LoadInstrument(String Line 196  String LSCPServer::LoadInstrument(String
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                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           result.Error(e);           result.Error(e);
# Line 177  String LSCPServer::GetEngineInfo(String Line 279  String LSCPServer::GetEngineInfo(String
279          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
280              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
281              result.Add(pEngine->Description());              result.Add(pEngine->Description());
282                result.Add(pEngine->Version());
283              delete pEngine;              delete pEngine;
284          }          }
285          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
# Line 198  String LSCPServer::GetChannelInfo(uint u Line 301  String LSCPServer::GetChannelInfo(uint u
301          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
302          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
303          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
304            
305          //Defaults values          //Defaults values
306          String EngineName = "NONE";          String EngineName = "NONE";
307          float Volume = 0;          float Volume = 0;
308          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
309          int InstrumentIndex = 0;          int InstrumentIndex = -1;
310                    int InstrumentStatus = -1;
311    
312          if (pEngine) {          if (pEngine) {
313              EngineName =  pEngine->EngineName();              EngineName =  pEngine->EngineName();
314              Volume = pEngine->Volume();              Volume = pEngine->Volume();
315              int iIdx = pEngine->InstrumentIndex();              InstrumentStatus = pEngine->InstrumentStatus();
316              if (iIdx != -1) {              InstrumentIndex = pEngine->InstrumentIndex();
317                if (InstrumentIndex != -1)
318                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
                 InstrumentIndex = iIdx;  
             }  
319          }          }
320    
321          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
322          result.Add("VOLUME", Volume);          result.Add("VOLUME", Volume);
323    
324          //Some hardcoded stuff for now to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
325          result.Add("AUDIO_OUTPUT_DEVICE", "0");          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
326          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", "2");
327          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");
328    
329          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
330          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
331                    result.Add("INSTRUMENT_STATUS", InstrumentStatus);
332          //Some more hardcoded stuff for now to make GUI look good  
333          result.Add("MIDI_INPUT_DEVICE", "0");          MidiInputDevice *pDevice = pSamplerChannel->GetMidiInputDevice();
334          result.Add("MIDI_INPUT_PORT", "0");          if (pDevice) {
335          result.Add("MIDI_INPUT_CHANNEL", "1");                  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) {      catch (LinuxSamplerException e) {
345           result.Error(e);           result.Error(e);
# Line 289  String LSCPServer::GetBufferFill(fill_re Line 399  String LSCPServer::GetBufferFill(fill_re
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"; //FIXME: Update resultset class to support "NA"          if (!pEngine->DiskStreamSupported())
403          switch (ResponseType) {              result.Add("NA");
404              case fill_response_bytes:          else {
405                  result.Add(pEngine->DiskStreamBufferFillBytes());              switch (ResponseType) {
406              case fill_response_percentage:                  case fill_response_bytes:
407                  result.Add(pEngine->DiskStreamBufferFillPercentage());                      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) {      catch (LinuxSamplerException e) {
418           result.Error(e);           result.Error(e);
# Line 305  String LSCPServer::GetBufferFill(fill_re Line 420  String LSCPServer::GetBufferFill(fill_re
420      return result.Produce();      return result.Produce();
421  }  }
422    
423  /**  String LSCPServer::GetAvailableAudioOutputDrivers() {
424   * Will be called by the parser to change the audio output type on a      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
  * particular sampler channel.  
  */  
 String LSCPServer::SetAudioOutputType(AudioOutputDevice::type_t AudioOutputType, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel));  
425      LSCPResultSet result;      LSCPResultSet result;
426      try {      try {
427          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
428          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          result.Add(s);
         pSamplerChannel->SetAudioOutputDevice(AudioOutputType);  
429      }      }
430      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
431           result.Error(e);          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) {
468            result.Error(e);
469        }
470        return result.Produce();
471    }
472    
473    String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
474        dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
475        LSCPResultSet result;
476        try {
477            result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver));
478            result.Add("VERSION",     AudioOutputDeviceFactory::GetDriverVersion(Driver));
479    
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 {
501            DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
502            result.Add("TYPE",         pParameter->Type());
503            result.Add("DESCRIPTION",  pParameter->Description());
504            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) {
562            result.Error(e);
563        }
564        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();      return result.Produce();
802  }  }
# Line 327  String LSCPServer::SetAudioOutputType(Au Line 805  String LSCPServer::SetAudioOutputType(Au
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"; //FIXME: Add support for this in resultset class?      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?
811  }  }
812    
813  String LSCPServer::SetMIDIInputType(MidiInputDevice::type_t MidiInputType, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
814      dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
815      LSCPResultSet result;      LSCPResultSet result;
816      try {      try {
817          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
818          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
819          pSamplerChannel->SetMidiInputDevice(MidiInputType);          // 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) {      catch (LinuxSamplerException e) {
845           result.Error(e);           result.Error(e);
# Line 346  String LSCPServer::SetMIDIInputType(Midi Line 847  String LSCPServer::SetMIDIInputType(Midi
847      return result.Produce();      return result.Produce();
848  }  }
849    
850  /**  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
851   * Will be called by the parser to change the MIDI input port on which the      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));
  * engine of a particular sampler channel should listen to.  
  */  
 String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel));  
852      LSCPResultSet 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          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          // 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          pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());          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);
864    #endif
865      }      }
866      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
867           result.Error(e);           result.Error(e);
# Line 366  String LSCPServer::SetMIDIInputPort(Stri Line 870  String LSCPServer::SetMIDIInputPort(Stri
870  }  }
871    
872  /**  /**
873   * Will be called by the parser to change the MIDI input channel 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::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInput(uint MIDIDevice, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {
877      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInput(MIDIDevice=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDevice, MIDIPort, MIDIChannel, uiSamplerChannel));
878      LSCPResultSet 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          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();          MidiInputDevice* pDevice = devices[MIDIDevice];
884          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel);          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) {
888             result.Error(e);
889        }
890        return result.Produce();
891    }
892    
893    String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
894        LSCPResultSet result;
895        try {
896            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
897            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
898            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
899            AudioOutputDevice* pDevice = devices[AudioDeviceId];
900            if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
901            pSamplerChannel->SetAudioOutputDevice(pDevice);
902      }      }
903      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
904           result.Error(e);           result.Error(e);
# Line 428  String LSCPServer::ResetChannel(uint uiS Line 949  String LSCPServer::ResetChannel(uint uiS
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 437  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.120  
changed lines
  Added in v.155

  ViewVC Help
Powered by ViewVC