/[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 138 by senkov, Sun Jun 20 23:18:24 2004 UTC revision 155 by senkov, Mon Jun 28 04:30:11 2004 UTC
# Line 25  Line 25 
25    
26  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
27  #include "../audiodriver/AudioOutputDeviceFactory.h"  #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 91  void LSCPServer::AnswerClient(String Ret
91      send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0);      send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0);
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) {  String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) {
127      dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));      dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));
128      LSCPResultSet result;      LSCPResultSet result;
129      try {      try {
130          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
         std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();  
131          // search for the created device to get its index          // search for the created device to get its index
132          int index = -1;          int index = GetAudioOutputDeviceIndex(pDevice);
         std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();  
         for (; iter != devices.end(); iter++) {  
             if (iter->second == pDevice) {  
                 index = iter->first;  
                 break;  
             }  
         }  
133          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");
134          result = index; // success          result = index; // success
135      }      }
# Line 114  String LSCPServer::CreateAudioOutputDevi Line 139  String LSCPServer::CreateAudioOutputDevi
139      return result.Produce();      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) {  String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) {
159      dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex));      dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex));
160      LSCPResultSet result;      LSCPResultSet result;
# Line 129  String LSCPServer::DestroyAudioOutputDev Line 170  String LSCPServer::DestroyAudioOutputDev
170      return result.Produce();      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   */   */
# Line 140  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            if (pSamplerChannel->GetAudioOutputDevice() == NULL)
200                throw LinuxSamplerException("No audio output device on channel");
201          if (bBackground) {          if (bBackground) {
202              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
203              pLoadInstrument->StartThread();              pLoadInstrument->StartThread();
# Line 263  String LSCPServer::GetChannelInfo(uint u Line 321  String LSCPServer::GetChannelInfo(uint u
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    
# Line 272  String LSCPServer::GetChannelInfo(uint u Line 330  String LSCPServer::GetChannelInfo(uint u
330          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
331          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
332    
333          //Some more hardcoded stuff for now to make GUI look good          MidiInputDevice *pDevice = pSamplerChannel->GetMidiInputDevice();
334          result.Add("MIDI_INPUT_DEVICE", "0");          if (pDevice) {
335          result.Add("MIDI_INPUT_PORT", "0");                  result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pDevice));
336          result.Add("MIDI_INPUT_CHANNEL", "1");                  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 369  String LSCPServer::GetAvailableAudioOutp Line 433  String LSCPServer::GetAvailableAudioOutp
433      return result.Produce();      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) {  String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
474      dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
475      LSCPResultSet result;      LSCPResultSet result;
# Line 393  String LSCPServer::GetAudioOutputDriverI Line 494  String LSCPServer::GetAudioOutputDriverI
494      return result.Produce();      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) {  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()));      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
521      LSCPResultSet result;      LSCPResultSet result;
# Line 428  String LSCPServer::GetAudioOutputDeviceC Line 551  String LSCPServer::GetAudioOutputDeviceC
551      return result.Produce();      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() {  String LSCPServer::GetAudioOutputDevices() {
568      dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));      dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
569      LSCPResultSet result;      LSCPResultSet result;
# Line 447  String LSCPServer::GetAudioOutputDevices Line 583  String LSCPServer::GetAudioOutputDevices
583      return result.Produce();      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) {  String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
606      dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));      dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
607      LSCPResultSet result;      LSCPResultSet result;
# Line 454  String LSCPServer::GetAudioOutputDeviceI Line 609  String LSCPServer::GetAudioOutputDeviceI
609          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
610          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
611          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
612            result.Add("driver", pDevice->Driver());
613          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
614          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
615          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 466  String LSCPServer::GetAudioOutputDeviceI Line 622  String LSCPServer::GetAudioOutputDeviceI
622      return result.Produce();      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) {  String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
666      dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));      dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
667      LSCPResultSet result;      LSCPResultSet result;
# Line 569  String LSCPServer::SetAudioOutputDeviceP Line 765  String LSCPServer::SetAudioOutputDeviceP
765      return result.Produce();      return result.Produce();
766  }  }
767    
768    String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
769        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
770        LSCPResultSet result;
771        try {
772            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
773            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");
774            MidiInputDevice* pDevice = devices[DeviceIndex];
775            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
776            if (!parameters[ParamKey]) throw LinuxSamplerException("Midi input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
777            parameters[ParamKey]->SetValue(ParamVal);
778        }
779        catch (LinuxSamplerException e) {
780            result.Error(e);
781        }
782        return result.Produce();
783    }
784    
785    String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) {
786        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
787        LSCPResultSet result;
788        try {
789            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
790            MidiInputDevice* pDevice = devices[DeviceIndex];
791            if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");
792            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
793            if (!pMidiInputPort) throw LinuxSamplerException("There is no midi input port with index " + ToString(PortIndex) + ".");
794            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
795            if (!parameters[ParamKey]) throw LinuxSamplerException("Midi input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
796            parameters[ParamKey]->SetValue(ParamVal);
797        }
798        catch (LinuxSamplerException e) {
799            result.Error(e);
800        }
801        return result.Produce();
802    }
803    
804  /**  /**
805   * Will be called by the parser to change the audio output channel for   * Will be called by the parser to change the audio output channel for
806   * playback on a particular sampler channel.   * playback on a particular sampler channel.
# Line 578  String LSCPServer::SetAudioOutputChannel Line 810  String LSCPServer::SetAudioOutputChannel
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(String MidiInputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
814      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),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          // 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)          // Driver type name aliasing...
820          if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";
821          MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";        
822          pSamplerChannel->SetMidiInputDevice(MidiInputType);          // 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 595  String LSCPServer::SetMIDIInputType(Stri Line 847  String LSCPServer::SetMIDIInputType(Stri
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 615  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) {      catch (LinuxSamplerException e) {
888           result.Error(e);           result.Error(e);
# Line 634  String LSCPServer::SetMIDIInputChannel(u Line 890  String LSCPServer::SetMIDIInputChannel(u
890      return result.Produce();      return result.Produce();
891  }  }
892    
893  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
894      LSCPResultSet result;      LSCPResultSet result;
895      try {      try {
896          throw LinuxSamplerException("Command not yet implemented");          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);

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

  ViewVC Help
Powered by ViewVC