/[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 155 by senkov, Mon Jun 28 04:30:11 2004 UTC revision 159 by capela, Tue Jun 29 21:11:50 2004 UTC
# Line 326  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);
   
         MidiInputDevice *pDevice = pSamplerChannel->GetMidiInputDevice();  
         if (pDevice) {  
                 result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pDevice));  
                 MidiInputDevice::MidiInputPort *pPort = pSamplerChannel->GetMidiInputPort();  
                 if (pPort) {  
                         result.Add("MIDI_INPUT_PORT", (int)pPort->GetPortNumber());  
                         result.Add("MIDI_INPUT_CHANNEL", (int)pSamplerChannel->GetMidiInputChannel());  
                 }  
   
         }  
336      }      }
337      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
338           result.Error(e);           result.Error(e);
# Line 628  String LSCPServer::GetMidiInputDeviceInf Line 621  String LSCPServer::GetMidiInputDeviceInf
621      try {      try {
622          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
623          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
624          if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
625          result.Add("driver", pDevice->Driver());          result.Add("driver", pDevice->Driver());
626          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
627          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
# Line 647  String LSCPServer::GetMidiInputPortInfo( Line 640  String LSCPServer::GetMidiInputPortInfo(
640      try {      try {
641          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
642          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
643          if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
644          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
645          if (!pMidiInputPort) throw LinuxSamplerException("There is no midi input port with index " + ToString(PortIndex) + ".");          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
646          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
647          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
648          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 770  String LSCPServer::SetMidiInputDevicePar Line 763  String LSCPServer::SetMidiInputDevicePar
763      LSCPResultSet result;      LSCPResultSet result;
764      try {      try {
765          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
766          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
767          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
768          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          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 + "'");          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
770          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
771      }      }
772      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 788  String LSCPServer::SetMidiInputPortParam Line 781  String LSCPServer::SetMidiInputPortParam
781      try {      try {
782          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
783          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
784          if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceIndex) + ".");          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
785          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
786          if (!pMidiInputPort) throw LinuxSamplerException("There is no midi input port with index " + ToString(PortIndex) + ".");          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
787          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
788          if (!parameters[ParamKey]) throw LinuxSamplerException("Midi input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
789          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
790      }      }
791      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 810  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 847  String LSCPServer::SetAudioOutputType(St Line 857  String LSCPServer::SetAudioOutputType(St
857      return result.Produce();      return result.Produce();
858  }  }
859    
860  String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) {
861      dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel));
862      LSCPResultSet result;      LSCPResultSet result;
863      try {      try {
 #if 1  
         throw LinuxSamplerException("Command deprecated");  
 #else  
864          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
865          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
866          // 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->SetMidiInputPort(MIDIPort);
         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);  
 #endif  
867      }      }
868      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
869           result.Error(e);           result.Error(e);
# Line 869  String LSCPServer::SetMIDIInputType(Stri Line 871  String LSCPServer::SetMIDIInputType(Stri
871      return result.Produce();      return result.Produce();
872  }  }
873    
874  /**  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
875   * Will be called by the parser to change the MIDI input device, port and channel on which      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel));
  * engine of a particular sampler channel should listen to.  
  */  
 String LSCPServer::SetMIDIInput(uint MIDIDevice, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetMIDIInput(MIDIDevice=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDevice, MIDIPort, 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("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
880          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
         MidiInputDevice* pDevice = devices[MIDIDevice];  
         if (!pDevice) throw LinuxSamplerException("There is no midi input device with index " + ToString(MIDIDevice));  
         pSamplerChannel->SetMidiInputPort(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);  
881      }      }
882      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
883           result.Error(e);           result.Error(e);
# Line 890  String LSCPServer::SetMIDIInput(uint MID Line 885  String LSCPServer::SetMIDIInput(uint MID
885      return result.Produce();      return result.Produce();
886  }  }
887    
888  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) {
889        dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,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("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
894          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
895          AudioOutputDevice* pDevice = devices[AudioDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
896          if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
897          pSamplerChannel->SetAudioOutputDevice(pDevice);          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) {
939             result.Error(e);
940        }
941        return result.Produce();
942    }
943    
944    /**
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;
951        try {
952            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
953            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
954            std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
955            MidiInputDevice* pDevice = devices[MIDIDeviceId];
956            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);

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

  ViewVC Help
Powered by ViewVC