/[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 35 by schoenebeck, Fri Mar 5 13:46:15 2004 UTC revision 159 by capela, Tue Jun 29 21:11:50 2004 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck         *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
8   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 21  Line 21 
21   ***************************************************************************/   ***************************************************************************/
22    
23  #include "lscpserver.h"  #include "lscpserver.h"
24    #include "lscpresultset.h"
25    
26  LSCPServer::LSCPServer(AudioThread* pEngine) : Thread(false, 0, -4) {  #include "../engines/gig/Engine.h"
27      this->pEngine = pEngine;  #include "../audiodriver/AudioOutputDeviceFactory.h"
28    #include "../mididriver/MidiInputDeviceFactory.h"
29    
30    LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
31        this->pSampler = pSampler;
32  }  }
33    
34  int LSCPServer::Main() {  int LSCPServer::Main() {
35      hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
36      if (hSocket < 0) {      if (hSocket < 0) {
37          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
38          return -1;          //return -1;
39            exit(EXIT_FAILURE);
40      }      }
41    
42      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
# Line 40  int LSCPServer::Main() { Line 46  int LSCPServer::Main() {
46      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
47          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;
48          close(hSocket);          close(hSocket);
49          return -1;          //return -1;
50            exit(EXIT_FAILURE);
51      }      }
52    
53      listen(hSocket, 1);      listen(hSocket, 1);
# Line 54  int LSCPServer::Main() { Line 61  int LSCPServer::Main() {
61          if (hSession < 0) {          if (hSession < 0) {
62              std::cerr << "LSCPServer: Client connection failed." << std::endl;              std::cerr << "LSCPServer: Client connection failed." << std::endl;
63              close(hSocket);              close(hSocket);
64              return -1;              //return -1;
65                exit(EXIT_FAILURE);
66          }          }
67    
68          dmsg(1,("LSCPServer: Client connection established.\n"));          dmsg(1,("LSCPServer: Client connection established.\n"));
# Line 84  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 Instrument, uint SamplerChannel) {  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(), Instrument, SamplerChannel));      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel));
193      result_t res = pEngine->LoadInstrument(Filename.c_str(), Instrument);      LSCPResultSet result;
194      return ConvertResult(res);      try {
195            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
196            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
197            Engine* pEngine = pSamplerChannel->GetEngine();
198            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) {
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) {
208             result.Error(e);
209        }
210        return result.Produce();
211  }  }
212    
213  /**  /**
214   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to load and deploy an engine.
215   */   */
216  String LSCPServer::LoadEngine(String EngineName, uint SamplerChannel) {  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {
217      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), SamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
218      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
219        try {
220            Engine::type_t type;
221            if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
222            else throw LinuxSamplerException("Unknown engine type");
223            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
224            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
225            pSamplerChannel->LoadEngine(type);
226        }
227        catch (LinuxSamplerException e) {
228             result.Error(e);
229        }
230        return result.Produce();
231  }  }
232    
233  /**  /**
# Line 105  String LSCPServer::LoadEngine(String Eng Line 235  String LSCPServer::LoadEngine(String Eng
235   */   */
236  String LSCPServer::GetChannels() {  String LSCPServer::GetChannels() {
237      dmsg(2,("LSCPServer: GetChannels()\n"));      dmsg(2,("LSCPServer: GetChannels()\n"));
238      return "1\r\n";      LSCPResultSet result;
239        result.Add(pSampler->SamplerChannels());
240        return result.Produce();
241  }  }
242    
243  /**  /**
# Line 113  String LSCPServer::GetChannels() { Line 245  String LSCPServer::GetChannels() {
245   */   */
246  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
247      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
248      return "ERR:0:Not implemented yet.\r\n";      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
249        LSCPResultSet result(pSamplerChannel->Index());
250        return result.Produce();
251  }  }
252    
253  /**  /**
254   * Will be called by the parser to remove a sampler channel.   * Will be called by the parser to remove a sampler channel.
255   */   */
256  String LSCPServer::RemoveChannel(uint SamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
257      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
258      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
259        pSampler->RemoveSamplerChannel(uiSamplerChannel);
260        return result.Produce();
261  }  }
262    
263  /**  /**
# Line 129  String LSCPServer::RemoveChannel(uint Sa Line 265  String LSCPServer::RemoveChannel(uint Sa
265   */   */
266  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
267      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
268      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result("GigEngine");
269        return result.Produce();
270  }  }
271    
272  /**  /**
# Line 137  String LSCPServer::GetAvailableEngines() Line 274  String LSCPServer::GetAvailableEngines()
274   */   */
275  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
276      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
277      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
278        try {
279            if ((EngineName == "GigEngine") || (EngineName == "gig")) {
280                Engine* pEngine = new LinuxSampler::gig::Engine;
281                result.Add(pEngine->Description());
282                result.Add(pEngine->Version());
283                delete pEngine;
284            }
285            else throw LinuxSamplerException("Unknown engine type");
286        }
287        catch (LinuxSamplerException e) {
288             result.Error(e);
289        }
290        return result.Produce();
291  }  }
292    
293  /**  /**
294   * Will be called by the parser to get informations about a particular   * Will be called by the parser to get informations about a particular
295   * sampler channel.   * sampler channel.
296   */   */
297  String LSCPServer::GetChannelInfo(uint SamplerChannel) {  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {
298      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));
299      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
300        try {
301            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
302            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
303            Engine* pEngine = pSamplerChannel->GetEngine();
304    
305            //Defaults values
306            String EngineName = "NONE";
307            float Volume = 0;
308            String InstrumentFileName = "NONE";
309            int InstrumentIndex = -1;
310            int InstrumentStatus = -1;
311    
312            if (pEngine) {
313                EngineName =  pEngine->EngineName();
314                Volume = pEngine->Volume();
315                InstrumentStatus = pEngine->InstrumentStatus();
316                InstrumentIndex = pEngine->InstrumentIndex();
317                if (InstrumentIndex != -1)
318                    InstrumentFileName = pEngine->InstrumentFileName();
319            }
320    
321            result.Add("ENGINE_NAME", EngineName);
322            result.Add("VOLUME", Volume);
323    
324            //Some not-so-hardcoded stuff to make GUI look good
325            result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
326            result.Add("AUDIO_OUTPUT_CHANNELS", "2");
327            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);
334            result.Add("INSTRUMENT_NR", InstrumentIndex);
335            result.Add("INSTRUMENT_STATUS", InstrumentStatus);
336        }
337        catch (LinuxSamplerException e) {
338             result.Error(e);
339        }
340        return result.Produce();
341  }  }
342    
343  /**  /**
344   * Will be called by the parser to get the amount of active voices on a   * Will be called by the parser to get the amount of active voices on a
345   * particular sampler channel.   * particular sampler channel.
346   */   */
347  String LSCPServer::GetVoiceCount(uint SamplerChannel) {  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {
348      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
349      return ToString(pEngine->ActiveVoiceCount) + "\r\n";      LSCPResultSet result;
350        try {
351            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
352            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
353            Engine* pEngine = pSamplerChannel->GetEngine();
354            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
355            result.Add(pEngine->VoiceCount());
356        }
357        catch (LinuxSamplerException e) {
358             result.Error(e);
359        }
360        return result.Produce();
361  }  }
362    
363  /**  /**
364   * Will be called by the parser to get the amount of active disk streams on a   * Will be called by the parser to get the amount of active disk streams on a
365   * particular sampler channel.   * particular sampler channel.
366   */   */
367  String LSCPServer::GetStreamCount(uint SamplerChannel) {  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {
368      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
369      return ToString(pEngine->pDiskThread->ActiveStreamCount) + "\r\n";      LSCPResultSet result;
370        try {
371            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
372            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
373            Engine* pEngine = pSamplerChannel->GetEngine();
374            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
375            result.Add(pEngine->DiskStreamCount());
376        }
377        catch (LinuxSamplerException e) {
378             result.Error(e);
379        }
380        return result.Produce();
381  }  }
382    
383  /**  /**
384   * Will be called by the parser to get the buffer fill states of all disk   * Will be called by the parser to get the buffer fill states of all disk
385   * streams on a particular sampler channel.   * streams on a particular sampler channel.
386   */   */
387  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint SamplerChannel) {  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {
388      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, SamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
389      return (ResponseType == fill_response_bytes) ? pEngine->pDiskThread->GetBufferFillBytes() + "\r\n"      LSCPResultSet result;
390                                                   : pEngine->pDiskThread->GetBufferFillPercentage() + "\r\n";      try {
391            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
392            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
393            Engine* pEngine = pSamplerChannel->GetEngine();
394            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
395            if (!pEngine->DiskStreamSupported())
396                result.Add("NA");
397            else {
398                switch (ResponseType) {
399                    case fill_response_bytes:
400                        result.Add(pEngine->DiskStreamBufferFillBytes());
401                        break;
402                    case fill_response_percentage:
403                        result.Add(pEngine->DiskStreamBufferFillPercentage());
404                        break;
405                    default:
406                        throw LinuxSamplerException("Unknown fill response type");
407                }
408            }
409        }
410        catch (LinuxSamplerException e) {
411             result.Error(e);
412        }
413        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"));
418   * particular sampler channel.      LSCPResultSet result;
419   */      try {
420  String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint SamplerChannel) {          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
421      dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, SamplerChannel));          result.Add(s);
422      return "ERR:0:Not implemented yet.\r\n";      }
423        catch (LinuxSamplerException e) {
424            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();
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.
800   */   */
801  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint SamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
802      dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, SamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));
803      return "ERR:0:Not implemented yet.\r\n";      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   * Will be called by the parser to change the MIDI input port on which the      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
808   * engine of a particular sampler channel should listen to.      LSCPResultSet result;
809   */      try {
810  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint Samplerchannel) {          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
811      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), Samplerchannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
812      return "ERR:0:Not implemented yet.\r\n";          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) {
824        dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
825        LSCPResultSet result;
826        try {
827            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
828            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
829            // Driver type name aliasing...
830            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) {
939             result.Error(e);
940        }
941        return result.Produce();
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 SamplerChannel) {  String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {
949      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, SamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel));
950      return "ERR:0:Not implemented yet.\r\n";      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) {
960             result.Error(e);
961        }
962        return result.Produce();
963  }  }
964    
965  /**  /**
966   * Will be called by the parser to change the global volume factor on a   * Will be called by the parser to change the global volume factor on a
967   * particular sampler channel.   * particular sampler channel.
968   */   */
969  String LSCPServer::SetVolume(double Volume, uint SamplerChannel) {  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {
970      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, SamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));
971      pEngine->Volume = Volume;      LSCPResultSet result;
972      return "OK\r\n";      try {
973            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
974            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
975            Engine* pEngine = pSamplerChannel->GetEngine();
976            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
977            pEngine->Volume(Volume);
978        }
979        catch (LinuxSamplerException e) {
980             result.Error(e);
981        }
982        return result.Produce();
983  }  }
984    
985  /**  /**
986   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
987   */   */
988  String LSCPServer::ResetChannel(uint SamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
989      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
990      pEngine->Reset();      LSCPResultSet result;
991      return "OK\r\n";      try {
992            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
993            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
994            Engine* pEngine = pSamplerChannel->GetEngine();
995            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
996            pEngine->Reset();
997        }
998        catch (LinuxSamplerException e) {
999             result.Error(e);
1000        }
1001        return result.Produce();
1002  }  }
1003    
1004  /**  /**
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 245  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.35  
changed lines
  Added in v.159

  ViewVC Help
Powered by ViewVC