/[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 121 by senkov, Sat Jun 12 07:46:02 2004 UTC revision 159 by capela, Tue Jun 29 21:11:50 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("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
330            result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
331            result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
332    
333          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
334          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
335                    result.Add("INSTRUMENT_STATUS", InstrumentStatus);
         //Some more hardcoded stuff for now to make GUI look good  
         result.Add("MIDI_INPUT_DEVICE", "0");  
         result.Add("MIDI_INPUT_PORT", "0");  
         result.Add("MIDI_INPUT_CHANNEL", "1");  
336      }      }
337      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
338           result.Error(e);           result.Error(e);
# Line 289  String LSCPServer::GetBufferFill(fill_re Line 392  String LSCPServer::GetBufferFill(fill_re
392          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
393          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
394          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
395          if (!pEngine->DiskStreamSupported()) return "NA\r\n"; //FIXME: Update resultset class to support "NA"          if (!pEngine->DiskStreamSupported())
396          switch (ResponseType) {              result.Add("NA");
397              case fill_response_bytes:          else {
398                  result.Add(pEngine->DiskStreamBufferFillBytes());              switch (ResponseType) {
399                  break;                  case fill_response_bytes:
400              case fill_response_percentage:                      result.Add(pEngine->DiskStreamBufferFillBytes());
401                  result.Add(pEngine->DiskStreamBufferFillPercentage());                      break;
402                  break;                  case fill_response_percentage:
403              default:                      result.Add(pEngine->DiskStreamBufferFillPercentage());
404                  throw LinuxSamplerException("Unknown fill response type");                      break;
405          }                  default:
406                        throw LinuxSamplerException("Unknown fill response type");
407                }
408            }
409      }      }
410      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
411           result.Error(e);           result.Error(e);
# Line 307  String LSCPServer::GetBufferFill(fill_re Line 413  String LSCPServer::GetBufferFill(fill_re
413      return result.Produce();      return result.Produce();
414  }  }
415    
416  /**  String LSCPServer::GetAvailableAudioOutputDrivers() {
417   * 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));  
418      LSCPResultSet result;      LSCPResultSet result;
419      try {      try {
420          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
421          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          result.Add(s);
         pSamplerChannel->SetAudioOutputDevice(AudioOutputType);  
422      }      }
423      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
424           result.Error(e);          result.Error(e);
425        }
426        return result.Produce();
427    }
428    
429    String LSCPServer::GetAvailableMidiInputDrivers() {
430        dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
431        LSCPResultSet result;
432        try {
433            String s = MidiInputDeviceFactory::AvailableDriversAsString();
434            result.Add(s);
435        }
436        catch (LinuxSamplerException e) {
437            result.Error(e);
438        }
439        return result.Produce();
440    }
441    
442    String LSCPServer::GetMidiInputDriverInfo(String Driver) {
443        dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str()));
444        LSCPResultSet result;
445        try {
446            result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver));
447            result.Add("VERSION",     MidiInputDeviceFactory::GetDriverVersion(Driver));
448    
449            std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver);
450            if (parameters.size()) { // if there are parameters defined for this driver
451                String s;
452                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
453                for (;iter != parameters.end(); iter++) {
454                    if (s != "") s += ",";
455                    s += iter->first;
456                }
457                result.Add("PARAMETERS", s);
458            }
459        }
460        catch (LinuxSamplerException e) {
461            result.Error(e);
462        }
463        return result.Produce();
464    }
465    
466    String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
467        dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
468        LSCPResultSet result;
469        try {
470            result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver));
471            result.Add("VERSION",     AudioOutputDeviceFactory::GetDriverVersion(Driver));
472    
473            std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver);
474            if (parameters.size()) { // if there are parameters defined for this driver
475                String s;
476                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
477                for (;iter != parameters.end(); iter++) {
478                    if (s != "") s += ",";
479                    s += iter->first;
480                }
481                result.Add("PARAMETERS", s);
482            }
483        }
484        catch (LinuxSamplerException e) {
485            result.Error(e);
486        }
487        return result.Produce();
488    }
489    
490    String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
491        dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
492        LSCPResultSet result;
493        try {
494            DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
495            result.Add("TYPE",         pParameter->Type());
496            result.Add("DESCRIPTION",  pParameter->Description());
497            result.Add("MANDATORY",    pParameter->Mandatory());
498            result.Add("FIX",          pParameter->Fix());
499            result.Add("MULTIPLICITY", pParameter->Multiplicity());
500            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
501            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
502            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
503            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
504            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
505        }
506        catch (LinuxSamplerException e) {
507            result.Error(e);
508        }
509        return result.Produce();
510    }
511    
512    String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
513        dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
514        LSCPResultSet result;
515        try {
516            DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
517            result.Add("TYPE",         pParameter->Type());
518            result.Add("DESCRIPTION",  pParameter->Description());
519            result.Add("MANDATORY",    pParameter->Mandatory());
520            result.Add("FIX",          pParameter->Fix());
521            result.Add("MULTIPLICITY", pParameter->Multiplicity());
522            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
523            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
524            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
525            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
526            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
527        }
528        catch (LinuxSamplerException e) {
529            result.Error(e);
530        }
531        return result.Produce();
532    }
533    
534    String LSCPServer::GetAudioOutputDeviceCount() {
535        dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n"));
536        LSCPResultSet result;
537        try {
538            uint count = pSampler->AudioOutputDevices();
539            result.Add(count); // success
540        }
541        catch (LinuxSamplerException e) {
542            result.Error(e);
543        }
544        return result.Produce();
545    }
546    
547    String LSCPServer::GetMidiInputDeviceCount() {
548        dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n"));
549        LSCPResultSet result;
550        try {
551            uint count = pSampler->MidiInputDevices();
552            result.Add(count); // success
553        }
554        catch (LinuxSamplerException e) {
555            result.Error(e);
556        }
557        return result.Produce();
558    }
559    
560    String LSCPServer::GetAudioOutputDevices() {
561        dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
562        LSCPResultSet result;
563        try {
564            String s;
565            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
566            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
567            for (; iter != devices.end(); iter++) {
568                if (s != "") s += ",";
569                s += ToString(iter->first);
570            }
571            result.Add(s);
572        }
573        catch (LinuxSamplerException e) {
574            result.Error(e);
575        }
576        return result.Produce();
577    }
578    
579    String LSCPServer::GetMidiInputDevices() {
580        dmsg(2,("LSCPServer: GetMidiInputDevices()\n"));
581        LSCPResultSet result;
582        try {
583            String s;
584            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
585            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
586            for (; iter != devices.end(); iter++) {
587                if (s != "") s += ",";
588                s += ToString(iter->first);
589            }
590            result.Add(s);
591        }
592        catch (LinuxSamplerException e) {
593            result.Error(e);
594        }
595        return result.Produce();
596    }
597    
598    String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
599        dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
600        LSCPResultSet result;
601        try {
602            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
603            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
604            AudioOutputDevice* pDevice = devices[DeviceIndex];
605            result.Add("driver", pDevice->Driver());
606            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
607            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
608            for (; iter != parameters.end(); iter++) {
609                result.Add(iter->first, iter->second->Value());
610            }
611        }
612        catch (LinuxSamplerException e) {
613            result.Error(e);
614        }
615        return result.Produce();
616    }
617    
618    String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) {
619        dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
620        LSCPResultSet result;
621        try {
622            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
623            MidiInputDevice* pDevice = devices[DeviceIndex];
624            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
625            result.Add("driver", pDevice->Driver());
626            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
627            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
628            for (; iter != parameters.end(); iter++) {
629                result.Add(iter->first, iter->second->Value());
630            }
631        }
632        catch (LinuxSamplerException e) {
633            result.Error(e);
634        }
635        return result.Produce();
636    }
637    String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) {
638        dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
639        LSCPResultSet result;
640        try {
641            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
642            MidiInputDevice* pDevice = devices[DeviceIndex];
643            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
644            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
645            if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
646            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
647            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
648            for (; iter != parameters.end(); iter++) {
649                result.Add(iter->first, iter->second->Value());
650            }
651        }
652        catch (LinuxSamplerException e) {
653            result.Error(e);
654        }
655        return result.Produce();
656    }
657    
658    String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
659        dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
660        LSCPResultSet result;
661        try {
662            // get audio output device
663            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
664            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
665            AudioOutputDevice* pDevice = devices[DeviceId];
666    
667            // get audio channel
668            AudioChannel* pChannel = pDevice->Channel(ChannelId);
669            if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");
670    
671            // return the values of all audio channel parameters
672            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
673            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
674            for (; iter != parameters.end(); iter++) {
675                result.Add(iter->first, iter->second->Value());
676            }
677        }
678        catch (LinuxSamplerException e) {
679            result.Error(e);
680        }
681        return result.Produce();
682    }
683    
684    String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
685        dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
686        LSCPResultSet result;
687        try {
688            // get audio output device
689            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
690            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
691            AudioOutputDevice* pDevice = devices[DeviceId];
692    
693            // get audio channel
694            AudioChannel* pChannel = pDevice->Channel(ChannelId);
695            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
696    
697            // get desired audio channel parameter
698            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
699            if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
700            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
701    
702            // return all fields of this audio channel parameter
703            result.Add("TYPE",         pParameter->Type());
704            result.Add("DESCRIPTION",  pParameter->Description());
705            result.Add("FIX",          pParameter->Fix());
706            result.Add("MULTIPLICITY", pParameter->Multiplicity());
707            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
708            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
709            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
710        }
711        catch (LinuxSamplerException e) {
712            result.Error(e);
713        }
714        return result.Produce();
715    }
716    
717    String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) {
718        dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str()));
719        LSCPResultSet result;
720        try {
721            // get audio output device
722            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
723            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
724            AudioOutputDevice* pDevice = devices[DeviceId];
725    
726            // get audio channel
727            AudioChannel* pChannel = pDevice->Channel(ChannelId);
728            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
729    
730            // get desired audio channel parameter
731            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
732            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
733            DeviceRuntimeParameter* pParameter = parameters[ParamKey];
734    
735            // set new channel parameter value
736            pParameter->SetValue(ParamVal);
737        }
738        catch (LinuxSamplerException e) {
739            result.Error(e);
740        }
741        return result.Produce();
742    }
743    
744    String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
745        dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
746        LSCPResultSet result;
747        try {
748            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
749            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
750            AudioOutputDevice* pDevice = devices[DeviceIndex];
751            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
752            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
753            parameters[ParamKey]->SetValue(ParamVal);
754        }
755        catch (LinuxSamplerException e) {
756            result.Error(e);
757        }
758        return result.Produce();
759    }
760    
761    String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
762        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
763        LSCPResultSet result;
764        try {
765            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
766            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
767            MidiInputDevice* pDevice = devices[DeviceIndex];
768            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
769            if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
770            parameters[ParamKey]->SetValue(ParamVal);
771        }
772        catch (LinuxSamplerException e) {
773            result.Error(e);
774        }
775        return result.Produce();
776    }
777    
778    String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) {
779        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
780        LSCPResultSet result;
781        try {
782            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
783            MidiInputDevice* pDevice = devices[DeviceIndex];
784            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
785            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
786            if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
787            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
788            if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
789            parameters[ParamKey]->SetValue(ParamVal);
790        }
791        catch (LinuxSamplerException e) {
792            result.Error(e);
793      }      }
794      return result.Produce();      return result.Produce();
795  }  }
# Line 329  String LSCPServer::SetAudioOutputType(Au Line 798  String LSCPServer::SetAudioOutputType(Au
798   * 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
799   * playback on a particular sampler channel.   * playback on a particular sampler channel.
800   */   */
801  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
802      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));
803      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?
804  }  }
805    
806  String LSCPServer::SetMIDIInputType(MidiInputDevice::type_t MidiInputType, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
807      dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
808      LSCPResultSet result;      LSCPResultSet result;
809      try {      try {
810          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
811          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
812          pSamplerChannel->SetMidiInputDevice(MidiInputType);          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
813            AudioOutputDevice* pDevice = devices[AudioDeviceId];
814            if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
815            pSamplerChannel->SetAudioOutputDevice(pDevice);
816      }      }
817      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
818           result.Error(e);           result.Error(e);
# Line 348  String LSCPServer::SetMIDIInputType(Midi Line 820  String LSCPServer::SetMIDIInputType(Midi
820      return result.Produce();      return result.Produce();
821  }  }
822    
823  /**  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
824   * Will be called by the parser to change the MIDI input port on which the      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.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));  
825      LSCPResultSet result;      LSCPResultSet result;
826      try {      try {
827          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
828          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
829          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          // Driver type name aliasing...
830          pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";
831            if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";        
832            // Check if there's one audio output device already created
833            // for the intended audio driver type (AudioOutputDriver)...
834            AudioOutputDevice *pDevice = NULL;
835            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
836            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
837            for (; iter != devices.end(); iter++) {
838                if ((iter->second)->Driver() == AudioOutputDriver) {
839                    pDevice = iter->second;
840                    break;
841                }
842            }
843            // If it doesn't exist, create a new one with default parameters...
844            if (pDevice == NULL) {
845                std::map<String,String> params;
846                pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
847            }
848            // Must have a device...
849            if (pDevice == NULL)
850                throw LinuxSamplerException("Internal error: could not create audio output device.");
851            // Set it as the current channel device...
852            pSamplerChannel->SetAudioOutputDevice(pDevice);
853        }
854        catch (LinuxSamplerException e) {
855             result.Error(e);
856        }
857        return result.Produce();
858    }
859    
860    String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) {
861        dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel));
862        LSCPResultSet result;
863        try {
864            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
865            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
866            pSamplerChannel->SetMidiInputPort(MIDIPort);
867        }
868        catch (LinuxSamplerException e) {
869             result.Error(e);
870        }
871        return result.Produce();
872    }
873    
874    String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
875        dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel));
876        LSCPResultSet result;
877        try {
878            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
879            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
880            pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
881        }
882        catch (LinuxSamplerException e) {
883             result.Error(e);
884        }
885        return result.Produce();
886    }
887    
888    String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) {
889        dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,uiSamplerChannel));
890        LSCPResultSet result;
891        try {
892            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
893            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
894            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
895            MidiInputDevice* pDevice = devices[MIDIDeviceId];
896            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
897            pSamplerChannel->SetMidiInputDevice(pDevice);
898        }
899        catch (LinuxSamplerException e) {
900             result.Error(e);
901        }
902        return result.Produce();
903    }
904    
905    String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
906        dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));
907        LSCPResultSet result;
908        try {
909            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
910            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
911            // Driver type name aliasing...
912            if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";
913            // Check if there's one MIDI input device already created
914            // for the intended MIDI driver type (MidiInputDriver)...
915            MidiInputDevice *pDevice = NULL;
916            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
917            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
918            for (; iter != devices.end(); iter++) {
919                if ((iter->second)->Driver() == MidiInputDriver) {
920                    pDevice = iter->second;
921                    break;
922                }
923            }
924            // If it doesn't exist, create a new one with default parameters...
925            if (pDevice == NULL) {
926                std::map<String,String> params;
927                pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
928                // Make it with at least one initial port.
929                std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
930                parameters["ports"]->SetValue("1");
931            }
932            // Must have a device...
933            if (pDevice == NULL)
934                throw LinuxSamplerException("Internal error: could not create MIDI input device.");
935            // Set it as the current channel device...
936            pSamplerChannel->SetMidiInputDevice(pDevice);
937      }      }
938      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
939           result.Error(e);           result.Error(e);
# Line 368  String LSCPServer::SetMIDIInputPort(Stri Line 942  String LSCPServer::SetMIDIInputPort(Stri
942  }  }
943    
944  /**  /**
945   * 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
946   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
947   */   */
948  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {
949      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel));
950      LSCPResultSet result;      LSCPResultSet result;
951      try {      try {
952          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
953          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
954          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
955          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();          MidiInputDevice* pDevice = devices[MIDIDeviceId];
956          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel);          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
957            pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
958      }      }
959      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
960           result.Error(e);           result.Error(e);
# Line 430  String LSCPServer::ResetChannel(uint uiS Line 1005  String LSCPServer::ResetChannel(uint uiS
1005   * 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
1006   * server for receiving event messages.   * server for receiving event messages.
1007   */   */
1008  String LSCPServer::SubscribeNotification(uint UDPPort) {  String LSCPServer::SubscribeNotification(event_t Event) {
1009      dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%d)\n", Event));
1010      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
1011  }  }
1012    
# Line 439  String LSCPServer::SubscribeNotification Line 1014  String LSCPServer::SubscribeNotification
1014   * 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
1015   * for not receiving further event messages.   * for not receiving further event messages.
1016   */   */
1017  String LSCPServer::UnsubscribeNotification(String SessionID) {  String LSCPServer::UnsubscribeNotification(event_t Event) {
1018      dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%d)\n", Event));
1019      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
1020  }  }
1021    
1022    
1023    // Instrument loader constructor.
1024    LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)
1025        : Thread(false, 0, -4)
1026    {
1027        this->pEngine = pEngine;
1028        this->Filename = Filename;
1029        this->uiInstrument = uiInstrument;
1030    }
1031    
1032    // Instrument loader process.
1033    int LSCPLoadInstrument::Main()
1034    {
1035        try {
1036            pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
1037        }
1038    
1039        catch (LinuxSamplerException e) {
1040            e.PrintMessage();
1041        }
1042    
1043        // Always re-enable the engine.
1044        pEngine->Enable();
1045    
1046        // FIXME: Shoot ourselves on the foot?
1047        delete this;
1048    }

Legend:
Removed from v.121  
changed lines
  Added in v.159

  ViewVC Help
Powered by ViewVC