21 |
***************************************************************************/ |
***************************************************************************/ |
22 |
|
|
23 |
#include "lscpserver.h" |
#include "lscpserver.h" |
24 |
|
#include "lscpresultset.h" |
25 |
|
|
26 |
#include "../engines/gig/Engine.h" |
#include "../engines/gig/Engine.h" |
27 |
|
#include "../audiodriver/AudioOutputDeviceFactory.h" |
28 |
|
|
29 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
30 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
90 |
send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
91 |
} |
} |
92 |
|
|
93 |
|
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
94 |
|
dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str())); |
95 |
|
LSCPResultSet result; |
96 |
|
try { |
97 |
|
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
98 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
99 |
|
// search for the created device to get its index |
100 |
|
int index = -1; |
101 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
102 |
|
for (; iter != devices.end(); iter++) { |
103 |
|
if (iter->second == pDevice) { |
104 |
|
index = iter->first; |
105 |
|
break; |
106 |
|
} |
107 |
|
} |
108 |
|
if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); |
109 |
|
result = index; // success |
110 |
|
} |
111 |
|
catch (LinuxSamplerException e) { |
112 |
|
result.Error(e); |
113 |
|
} |
114 |
|
return result.Produce(); |
115 |
|
} |
116 |
|
|
117 |
|
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
118 |
|
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
119 |
|
LSCPResultSet result; |
120 |
|
try { |
121 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
122 |
|
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
123 |
|
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
124 |
|
pSampler->DestroyAudioOutputDevice(pDevice); |
125 |
|
} |
126 |
|
catch (LinuxSamplerException e) { |
127 |
|
result.Error(e); |
128 |
|
} |
129 |
|
return result.Produce(); |
130 |
|
} |
131 |
|
|
132 |
/** |
/** |
133 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
134 |
*/ |
*/ |
135 |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { |
136 |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
137 |
result_t result; |
LSCPResultSet result; |
138 |
try { |
try { |
139 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
140 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
141 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
142 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
143 |
pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
result.type = result_type_success; |
|
144 |
} |
} |
145 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
146 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
147 |
} |
} |
148 |
return ConvertResult(result); |
return result.Produce(); |
149 |
} |
} |
150 |
|
|
151 |
/** |
/** |
153 |
*/ |
*/ |
154 |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
155 |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
156 |
result_t result; |
LSCPResultSet result; |
157 |
try { |
try { |
158 |
engine_type_t type; |
Engine::type_t type; |
159 |
if (EngineName == "gig") type = engine_type_gig; |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
160 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
161 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
162 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
163 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->LoadEngine(type); |
|
result.type = result_type_success; |
|
164 |
} |
} |
165 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
166 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
167 |
} |
} |
168 |
return ConvertResult(result); |
return result.Produce(); |
169 |
} |
} |
170 |
|
|
171 |
/** |
/** |
173 |
*/ |
*/ |
174 |
String LSCPServer::GetChannels() { |
String LSCPServer::GetChannels() { |
175 |
dmsg(2,("LSCPServer: GetChannels()\n")); |
dmsg(2,("LSCPServer: GetChannels()\n")); |
176 |
return ToString(pSampler->SamplerChannels()) + "\r\n"; |
LSCPResultSet result; |
177 |
|
result.Add(pSampler->SamplerChannels()); |
178 |
|
return result.Produce(); |
179 |
} |
} |
180 |
|
|
181 |
/** |
/** |
184 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
185 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
186 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
187 |
return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n"; |
LSCPResultSet result(pSamplerChannel->Index()); |
188 |
|
return result.Produce(); |
189 |
} |
} |
190 |
|
|
191 |
/** |
/** |
193 |
*/ |
*/ |
194 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
195 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
196 |
|
LSCPResultSet result; |
197 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
198 |
return "OK\r\n"; |
return result.Produce(); |
199 |
} |
} |
200 |
|
|
201 |
/** |
/** |
203 |
*/ |
*/ |
204 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
205 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
206 |
return "gig\r\n"; |
LSCPResultSet result("GigEngine"); |
207 |
|
return result.Produce(); |
208 |
} |
} |
209 |
|
|
210 |
/** |
/** |
212 |
*/ |
*/ |
213 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
214 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
215 |
result_t result; |
LSCPResultSet result; |
216 |
try { |
try { |
217 |
if (EngineName == "gig") { |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
218 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
Engine* pEngine = new LinuxSampler::gig::Engine; |
219 |
String info = pEngine->Description() + "\r\n"; |
result.Add(pEngine->Description()); |
220 |
|
result.Add(pEngine->Version()); |
221 |
delete pEngine; |
delete pEngine; |
|
return info; // success |
|
222 |
} |
} |
223 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
224 |
} |
} |
225 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
226 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
227 |
} |
} |
228 |
return ConvertResult(result); |
return result.Produce(); |
229 |
} |
} |
230 |
|
|
231 |
/** |
/** |
234 |
*/ |
*/ |
235 |
String LSCPServer::GetChannelInfo(uint uiSamplerChannel) { |
String LSCPServer::GetChannelInfo(uint uiSamplerChannel) { |
236 |
dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel)); |
237 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
238 |
|
try { |
239 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
240 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
241 |
|
Engine* pEngine = pSamplerChannel->GetEngine(); |
242 |
|
|
243 |
|
//Defaults values |
244 |
|
String EngineName = "NONE"; |
245 |
|
float Volume = 0; |
246 |
|
String InstrumentFileName = "NONE"; |
247 |
|
int InstrumentIndex = 0; |
248 |
|
|
249 |
|
if (pEngine) { |
250 |
|
EngineName = pEngine->EngineName(); |
251 |
|
Volume = pEngine->Volume(); |
252 |
|
int iIdx = pEngine->InstrumentIndex(); |
253 |
|
if (iIdx != -1) { |
254 |
|
InstrumentFileName = pEngine->InstrumentFileName(); |
255 |
|
InstrumentIndex = iIdx; |
256 |
|
} |
257 |
|
} |
258 |
|
|
259 |
|
result.Add("ENGINE_NAME", EngineName); |
260 |
|
result.Add("VOLUME", Volume); |
261 |
|
|
262 |
|
//Some hardcoded stuff for now to make GUI look good |
263 |
|
result.Add("AUDIO_OUTPUT_DEVICE", "0"); |
264 |
|
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
265 |
|
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
266 |
|
|
267 |
|
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
268 |
|
result.Add("INSTRUMENT_NR", InstrumentIndex); |
269 |
|
|
270 |
|
//Some more hardcoded stuff for now to make GUI look good |
271 |
|
result.Add("MIDI_INPUT_DEVICE", "0"); |
272 |
|
result.Add("MIDI_INPUT_PORT", "0"); |
273 |
|
result.Add("MIDI_INPUT_CHANNEL", "1"); |
274 |
|
} |
275 |
|
catch (LinuxSamplerException e) { |
276 |
|
result.Error(e); |
277 |
|
} |
278 |
|
return result.Produce(); |
279 |
} |
} |
280 |
|
|
281 |
/** |
/** |
284 |
*/ |
*/ |
285 |
String LSCPServer::GetVoiceCount(uint uiSamplerChannel) { |
String LSCPServer::GetVoiceCount(uint uiSamplerChannel) { |
286 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
287 |
result_t result; |
LSCPResultSet result; |
288 |
try { |
try { |
289 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
290 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
291 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
292 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
293 |
return ToString(pEngine->VoiceCount()) + "\r\n"; // success |
result.Add(pEngine->VoiceCount()); |
294 |
} |
} |
295 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
296 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
297 |
} |
} |
298 |
return ConvertResult(result); |
return result.Produce(); |
299 |
} |
} |
300 |
|
|
301 |
/** |
/** |
304 |
*/ |
*/ |
305 |
String LSCPServer::GetStreamCount(uint uiSamplerChannel) { |
String LSCPServer::GetStreamCount(uint uiSamplerChannel) { |
306 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
307 |
result_t result; |
LSCPResultSet result; |
308 |
try { |
try { |
309 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
310 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
311 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
312 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
313 |
return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success |
result.Add(pEngine->DiskStreamCount()); |
314 |
} |
} |
315 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
316 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
317 |
} |
} |
318 |
return ConvertResult(result); |
return result.Produce(); |
319 |
} |
} |
320 |
|
|
321 |
/** |
/** |
324 |
*/ |
*/ |
325 |
String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) { |
String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) { |
326 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
327 |
result_t result; |
LSCPResultSet result; |
328 |
try { |
try { |
329 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
330 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
331 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
332 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
333 |
if (!pEngine->DiskStreamSupported()) return "NA\r\n"; |
if (!pEngine->DiskStreamSupported()) |
334 |
switch (ResponseType) { |
result.Add("NA"); |
335 |
case fill_response_bytes: |
else { |
336 |
return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success |
switch (ResponseType) { |
337 |
case fill_response_percentage: |
case fill_response_bytes: |
338 |
return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success |
result.Add(pEngine->DiskStreamBufferFillBytes()); |
339 |
default: |
break; |
340 |
throw LinuxSamplerException("Unknown fill response type"); |
case fill_response_percentage: |
341 |
|
result.Add(pEngine->DiskStreamBufferFillPercentage()); |
342 |
|
break; |
343 |
|
default: |
344 |
|
throw LinuxSamplerException("Unknown fill response type"); |
345 |
|
} |
346 |
|
} |
347 |
|
} |
348 |
|
catch (LinuxSamplerException e) { |
349 |
|
result.Error(e); |
350 |
|
} |
351 |
|
return result.Produce(); |
352 |
|
} |
353 |
|
|
354 |
|
String LSCPServer::GetAvailableAudioOutputDrivers() { |
355 |
|
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
356 |
|
LSCPResultSet result; |
357 |
|
try { |
358 |
|
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
359 |
|
result.Add(s); |
360 |
|
} |
361 |
|
catch (LinuxSamplerException e) { |
362 |
|
result.Error(e); |
363 |
|
} |
364 |
|
return result.Produce(); |
365 |
|
} |
366 |
|
|
367 |
|
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
368 |
|
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
369 |
|
LSCPResultSet result; |
370 |
|
try { |
371 |
|
result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver)); |
372 |
|
result.Add("VERSION", AudioOutputDeviceFactory::GetDriverVersion(Driver)); |
373 |
|
|
374 |
|
std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver); |
375 |
|
if (parameters.size()) { // if there are parameters defined for this driver |
376 |
|
String s; |
377 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
378 |
|
for (;iter != parameters.end(); iter++) { |
379 |
|
if (s != "") s += ","; |
380 |
|
s += iter->first; |
381 |
|
} |
382 |
|
result.Add("PARAMETERS", s); |
383 |
} |
} |
384 |
} |
} |
385 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
386 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
387 |
} |
} |
388 |
return ConvertResult(result); |
return result.Produce(); |
389 |
} |
} |
390 |
|
|
391 |
/** |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
392 |
* Will be called by the parser to change the audio output type on a |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
393 |
* particular sampler channel. |
LSCPResultSet result; |
|
*/ |
|
|
String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint uiSamplerChannel) { |
|
|
dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel)); |
|
|
result_t result; |
|
394 |
try { |
try { |
395 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
396 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
result.Add("TYPE", pParameter->Type()); |
397 |
pSamplerChannel->SetAudioOutputDevice(AudioOutputType); |
result.Add("DESCRIPTION", pParameter->Description()); |
398 |
result.type = result_type_success; |
result.Add("MANDATORY", pParameter->Mandatory()); |
399 |
|
result.Add("FIX", pParameter->Fix()); |
400 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
401 |
|
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
402 |
|
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
403 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
404 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
405 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
406 |
|
} |
407 |
|
catch (LinuxSamplerException e) { |
408 |
|
result.Error(e); |
409 |
|
} |
410 |
|
return result.Produce(); |
411 |
|
} |
412 |
|
|
413 |
|
String LSCPServer::GetAudioOutputDeviceCount() { |
414 |
|
dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n")); |
415 |
|
LSCPResultSet result; |
416 |
|
try { |
417 |
|
uint count = pSampler->AudioOutputDevices(); |
418 |
|
result = count; // success |
419 |
|
} |
420 |
|
catch (LinuxSamplerException e) { |
421 |
|
result.Error(e); |
422 |
|
} |
423 |
|
return result.Produce(); |
424 |
|
} |
425 |
|
|
426 |
|
String LSCPServer::GetAudioOutputDevices() { |
427 |
|
dmsg(2,("LSCPServer: GetAudioOutputDevices()\n")); |
428 |
|
LSCPResultSet result; |
429 |
|
try { |
430 |
|
String s; |
431 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
432 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
433 |
|
for (; iter != devices.end(); iter++) { |
434 |
|
if (s != "") s += ","; |
435 |
|
s += ToString(iter->first); |
436 |
|
} |
437 |
|
result.Add(s); |
438 |
} |
} |
439 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
440 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
441 |
} |
} |
442 |
return ConvertResult(result); |
return result.Produce(); |
443 |
|
} |
444 |
|
|
445 |
|
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
446 |
|
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
447 |
|
LSCPResultSet result; |
448 |
|
try { |
449 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
450 |
|
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
451 |
|
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
452 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
453 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
454 |
|
for (; iter != parameters.end(); iter++) { |
455 |
|
result.Add(iter->first, iter->second->Value()); |
456 |
|
} |
457 |
|
} |
458 |
|
catch (LinuxSamplerException e) { |
459 |
|
result.Error(e); |
460 |
|
} |
461 |
|
return result.Produce(); |
462 |
|
} |
463 |
|
|
464 |
|
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
465 |
|
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
466 |
|
LSCPResultSet result; |
467 |
|
try { |
468 |
|
// get audio output device |
469 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
470 |
|
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
471 |
|
AudioOutputDevice* pDevice = devices[DeviceId]; |
472 |
|
|
473 |
|
// get audio channel |
474 |
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
475 |
|
if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + "."); |
476 |
|
|
477 |
|
// return the values of all audio channel parameters |
478 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
479 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
480 |
|
for (; iter != parameters.end(); iter++) { |
481 |
|
result.Add(iter->first, iter->second->Value()); |
482 |
|
} |
483 |
|
} |
484 |
|
catch (LinuxSamplerException e) { |
485 |
|
result.Error(e); |
486 |
|
} |
487 |
|
return result.Produce(); |
488 |
|
} |
489 |
|
|
490 |
|
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
491 |
|
dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str())); |
492 |
|
LSCPResultSet result; |
493 |
|
try { |
494 |
|
// get audio output device |
495 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
496 |
|
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
497 |
|
AudioOutputDevice* pDevice = devices[DeviceId]; |
498 |
|
|
499 |
|
// get audio channel |
500 |
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
501 |
|
if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); |
502 |
|
|
503 |
|
// get desired audio channel parameter |
504 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
505 |
|
if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); |
506 |
|
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
507 |
|
|
508 |
|
// return all fields of this audio channel parameter |
509 |
|
result.Add("TYPE", pParameter->Type()); |
510 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
511 |
|
result.Add("FIX", pParameter->Fix()); |
512 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
513 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
514 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
515 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
516 |
|
} |
517 |
|
catch (LinuxSamplerException e) { |
518 |
|
result.Error(e); |
519 |
|
} |
520 |
|
return result.Produce(); |
521 |
|
} |
522 |
|
|
523 |
|
String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) { |
524 |
|
dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str())); |
525 |
|
LSCPResultSet result; |
526 |
|
try { |
527 |
|
// get audio output device |
528 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
529 |
|
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
530 |
|
AudioOutputDevice* pDevice = devices[DeviceId]; |
531 |
|
|
532 |
|
// get audio channel |
533 |
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
534 |
|
if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); |
535 |
|
|
536 |
|
// get desired audio channel parameter |
537 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
538 |
|
if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); |
539 |
|
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
540 |
|
|
541 |
|
// set new channel parameter value |
542 |
|
pParameter->SetValue(ParamVal); |
543 |
|
} |
544 |
|
catch (LinuxSamplerException e) { |
545 |
|
result.Error(e); |
546 |
|
} |
547 |
|
return result.Produce(); |
548 |
|
} |
549 |
|
|
550 |
|
String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
551 |
|
dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
552 |
|
LSCPResultSet result; |
553 |
|
try { |
554 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
555 |
|
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
556 |
|
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
557 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
558 |
|
if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
559 |
|
parameters[ParamKey]->SetValue(ParamVal); |
560 |
|
} |
561 |
|
catch (LinuxSamplerException e) { |
562 |
|
result.Error(e); |
563 |
|
} |
564 |
|
return result.Produce(); |
565 |
} |
} |
566 |
|
|
567 |
/** |
/** |
568 |
* 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 |
569 |
* playback on a particular sampler channel. |
* playback on a particular sampler channel. |
570 |
*/ |
*/ |
571 |
String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
572 |
dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
573 |
return "ERR:0:Not implemented yet.\r\n"; |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
574 |
} |
} |
575 |
|
|
576 |
String LSCPServer::SetMIDIInputType(midi_input_type_t MidiInputType, uint uiSamplerChannel) { |
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
577 |
dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
578 |
result_t result; |
LSCPResultSet result; |
579 |
try { |
try { |
580 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
581 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
582 |
|
// 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) |
583 |
|
if (MidiInputDriver != "ALSA") throw LinuxSamplerException("Unknown MIDI input driver '" + MidiInputDriver + "'."); |
584 |
|
MidiInputDevice::type_t MidiInputType = MidiInputDevice::type_alsa; |
585 |
pSamplerChannel->SetMidiInputDevice(MidiInputType); |
pSamplerChannel->SetMidiInputDevice(MidiInputType); |
|
result.type = result_type_success; |
|
586 |
} |
} |
587 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
588 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
589 |
} |
} |
590 |
return ConvertResult(result); |
return result.Produce(); |
591 |
} |
} |
592 |
|
|
593 |
/** |
/** |
594 |
* Will be called by the parser to change the MIDI input port on which the |
* Will be called by the parser to change the MIDI input port on which the |
595 |
* engine of a particular sampler channel should listen to. |
* engine of a particular sampler channel should listen to. |
596 |
*/ |
*/ |
597 |
String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel) { |
String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) { |
598 |
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerchannel)); |
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel)); |
599 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
600 |
|
try { |
601 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
602 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
603 |
|
if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); |
604 |
|
pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str()); |
605 |
|
} |
606 |
|
catch (LinuxSamplerException e) { |
607 |
|
result.Error(e); |
608 |
|
} |
609 |
|
return result.Produce(); |
610 |
} |
} |
611 |
|
|
612 |
/** |
/** |
615 |
*/ |
*/ |
616 |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
617 |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel)); |
618 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
619 |
|
try { |
620 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
621 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
622 |
|
if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet"); |
623 |
|
MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type(); |
624 |
|
pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel); |
625 |
|
} |
626 |
|
catch (LinuxSamplerException e) { |
627 |
|
result.Error(e); |
628 |
|
} |
629 |
|
return result.Produce(); |
630 |
|
} |
631 |
|
|
632 |
|
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel) { |
633 |
|
LSCPResultSet result; |
634 |
|
try { |
635 |
|
throw LinuxSamplerException("Command not yet implemented"); |
636 |
|
} |
637 |
|
catch (LinuxSamplerException e) { |
638 |
|
result.Error(e); |
639 |
|
} |
640 |
|
return result.Produce(); |
641 |
} |
} |
642 |
|
|
643 |
/** |
/** |
646 |
*/ |
*/ |
647 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
648 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
649 |
result_t result; |
LSCPResultSet result; |
650 |
try { |
try { |
651 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
652 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
653 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
654 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
655 |
pEngine->Volume(Volume); |
pEngine->Volume(Volume); |
|
result.type = result_type_success; |
|
656 |
} |
} |
657 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
658 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
659 |
} |
} |
660 |
return ConvertResult(result); |
return result.Produce(); |
661 |
} |
} |
662 |
|
|
663 |
/** |
/** |
665 |
*/ |
*/ |
666 |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
667 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
668 |
result_t result; |
LSCPResultSet result; |
669 |
try { |
try { |
670 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
671 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
672 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
673 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
674 |
pEngine->Reset(); |
pEngine->Reset(); |
|
result.type = result_type_success; |
|
675 |
} |
} |
676 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
677 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
678 |
} |
} |
679 |
return ConvertResult(result); |
return result.Produce(); |
680 |
} |
} |
681 |
|
|
682 |
/** |
/** |