/[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 143 by capela, Wed Jun 23 18:54:08 2004 UTC revision 159 by capela, Tue Jun 29 21:11:50 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 106  int LSCPServer::GetAudioOutputDeviceInde Line 107  int LSCPServer::GetAudioOutputDeviceInde
107      return -1;      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;
# Line 122  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 137  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 278  String LSCPServer::GetChannelInfo(uint u Line 326  String LSCPServer::GetChannelInfo(uint u
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);          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 379  String LSCPServer::GetAvailableAudioOutp Line 426  String LSCPServer::GetAvailableAudioOutp
426      return result.Produce();      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) {  String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
467      dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
468      LSCPResultSet result;      LSCPResultSet result;
# Line 403  String LSCPServer::GetAudioOutputDriverI Line 487  String LSCPServer::GetAudioOutputDriverI
487      return result.Produce();      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) {  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()));      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
514      LSCPResultSet result;      LSCPResultSet result;
# Line 438  String LSCPServer::GetAudioOutputDeviceC Line 544  String LSCPServer::GetAudioOutputDeviceC
544      return result.Produce();      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() {  String LSCPServer::GetAudioOutputDevices() {
561      dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));      dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
562      LSCPResultSet result;      LSCPResultSet result;
# Line 457  String LSCPServer::GetAudioOutputDevices Line 576  String LSCPServer::GetAudioOutputDevices
576      return result.Produce();      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) {  String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
599      dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));      dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
600      LSCPResultSet result;      LSCPResultSet result;
# Line 477  String LSCPServer::GetAudioOutputDeviceI Line 615  String LSCPServer::GetAudioOutputDeviceI
615      return result.Produce();      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) {  String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
659      dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));      dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
660      LSCPResultSet result;      LSCPResultSet result;
# Line 580  String LSCPServer::SetAudioOutputDeviceP Line 758  String LSCPServer::SetAudioOutputDeviceP
758      return result.Produce();      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();
795    }
796    
797  /**  /**
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.
# Line 589  String LSCPServer::SetAudioOutputChannel Line 803  String LSCPServer::SetAudioOutputChannel
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::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
807        dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
808        LSCPResultSet result;
809        try {
810            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
811            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
812            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) {
818             result.Error(e);
819        }
820        return result.Produce();
821    }
822    
823  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
824      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
825      LSCPResultSet result;      LSCPResultSet result;
# Line 626  String LSCPServer::SetAudioOutputType(St Line 857  String LSCPServer::SetAudioOutputType(St
857      return result.Produce();      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::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
875      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel));
876      LSCPResultSet result;      LSCPResultSet result;
877      try {      try {
878          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
879          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
880          // 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)          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
         if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";  
         if (MidiInputDriver != "Alsa") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'.");  
         MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa;  
         pSamplerChannel->SetMidiInputDevice(MidiInputType);  
881      }      }
882      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
883           result.Error(e);           result.Error(e);
# Line 645  String LSCPServer::SetMIDIInputType(Stri Line 885  String LSCPServer::SetMIDIInputType(Stri
885      return result.Produce();      return result.Produce();
886  }  }
887    
888  /**  String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) {
889   * Will be called by the parser to change the MIDI input port on which the      dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,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));  
890      LSCPResultSet result;      LSCPResultSet result;
891      try {      try {
892          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
893          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
894          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
895          pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());          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) {      catch (LinuxSamplerException e) {
900           result.Error(e);           result.Error(e);
# Line 664  String LSCPServer::SetMIDIInputPort(Stri Line 902  String LSCPServer::SetMIDIInputPort(Stri
902      return result.Produce();      return result.Produce();
903  }  }
904    
905  /**  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
906   * Will be called by the parser to change the MIDI input channel 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::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));  
907      LSCPResultSet result;      LSCPResultSet result;
908      try {      try {
909          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
910          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
911          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          // Driver type name aliasing...
912          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";
913          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel);          // 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 684  String LSCPServer::SetMIDIInputChannel(u Line 941  String LSCPServer::SetMIDIInputChannel(u
941      return result.Produce();      return result.Produce();
942  }  }
943    
944  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  /**
945     * 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.
947     */
948    String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {
949        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("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
954          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
955          if (!devices[AudioDeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          MidiInputDevice* pDevice = devices[MIDIDeviceId];
956          AudioOutputDevice* pDevice = devices[AudioDeviceId];          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
957          pSamplerChannel->SetAudioOutputDevice(pDevice);          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);

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

  ViewVC Help
Powered by ViewVC