1 |
capela |
107 |
// device.c |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
|
|
liblscp - LinuxSampler Control Protocol API |
5 |
|
|
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public |
9 |
|
|
License as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
|
12 |
|
|
This library is distributed in the hope that it will be useful, |
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
|
|
Lesser General Public License for more details. |
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU Lesser General Public |
18 |
|
|
License along with this library; if not, write to the Free Software |
19 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
|
21 |
|
|
*****************************************************************************/ |
22 |
|
|
|
23 |
|
|
#include "common.h" |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
// Local prototypes. |
27 |
|
|
|
28 |
|
|
static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery); |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
//------------------------------------------------------------------------- |
32 |
|
|
// Local funtions. |
33 |
|
|
|
34 |
|
|
// Common driver type query command. |
35 |
|
|
static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery ) |
36 |
|
|
{ |
37 |
|
|
const char *pszResult; |
38 |
|
|
const char *pszSeps = ":"; |
39 |
|
|
const char *pszCrlf = "\r\n"; |
40 |
|
|
char *pszToken; |
41 |
|
|
char *pch; |
42 |
|
|
|
43 |
capela |
132 |
// Lock this section up. |
44 |
|
|
lscp_mutex_lock(pClient->mutex); |
45 |
|
|
|
46 |
capela |
107 |
lscp_driver_info_reset(pDriverInfo); |
47 |
capela |
132 |
if (lscp_client_call(pClient, pszQuery) == LSCP_OK) { |
48 |
|
|
pszResult = lscp_client_get_result(pClient); |
49 |
|
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
50 |
|
|
while (pszToken) { |
51 |
|
|
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
52 |
|
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
53 |
|
|
if (pszToken) |
54 |
|
|
pDriverInfo->description = lscp_unquote(&pszToken, 1); |
55 |
|
|
} |
56 |
|
|
else if (strcasecmp(pszToken, "VERSION") == 0) { |
57 |
|
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
58 |
|
|
if (pszToken) |
59 |
|
|
pDriverInfo->version = lscp_unquote(&pszToken, 1); |
60 |
|
|
} |
61 |
|
|
else if (strcasecmp(pszToken, "PARAMETERS") == 0) { |
62 |
|
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
63 |
|
|
if (pszToken) |
64 |
|
|
pDriverInfo->parameters = lscp_szsplit_create(pszToken, ","); |
65 |
|
|
} |
66 |
|
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
67 |
capela |
107 |
} |
68 |
|
|
} |
69 |
capela |
132 |
|
70 |
|
|
// Unlock this section down. |
71 |
|
|
lscp_mutex_unlock(pClient->mutex); |
72 |
capela |
107 |
|
73 |
|
|
return pDriverInfo; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
//------------------------------------------------------------------------- |
78 |
|
|
// Audio driver control functions. |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Getting all available audio output drivers. |
82 |
|
|
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
83 |
|
|
* |
84 |
|
|
* @param pClient Pointer to client instance structure. |
85 |
|
|
* |
86 |
|
|
* @returns A NULL terminated array of audio output driver type |
87 |
|
|
* name strings, or NULL in case of failure. |
88 |
|
|
*/ |
89 |
|
|
const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient ) |
90 |
|
|
{ |
91 |
|
|
const char *pszSeps = ","; |
92 |
|
|
|
93 |
capela |
132 |
// Lock this section up. |
94 |
|
|
lscp_mutex_lock(pClient->mutex); |
95 |
|
|
|
96 |
capela |
107 |
if (pClient->audio_drivers) { |
97 |
|
|
lscp_szsplit_destroy(pClient->audio_drivers); |
98 |
|
|
pClient->audio_drivers = NULL; |
99 |
|
|
} |
100 |
|
|
|
101 |
capela |
132 |
if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
102 |
capela |
107 |
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
103 |
|
|
|
104 |
capela |
132 |
// Unlock this section down. |
105 |
|
|
lscp_mutex_unlock(pClient->mutex); |
106 |
|
|
|
107 |
capela |
107 |
return (const char **) pClient->audio_drivers; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
/** |
112 |
|
|
* Getting informations about a specific audio output driver. |
113 |
|
|
* GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
114 |
|
|
* |
115 |
|
|
* @param pClient Pointer to client instance structure. |
116 |
|
|
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
117 |
|
|
* |
118 |
|
|
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
119 |
|
|
* the given audio driver information, or NULL in case of failure. |
120 |
|
|
*/ |
121 |
|
|
lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver ) |
122 |
|
|
{ |
123 |
|
|
char szQuery[LSCP_BUFSIZ]; |
124 |
|
|
|
125 |
|
|
if (pszAudioDriver == NULL) |
126 |
|
|
return NULL; |
127 |
|
|
|
128 |
|
|
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver); |
129 |
|
|
return _lscp_driver_info_query(pClient, &(pClient->audio_info), szQuery); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
|
133 |
|
|
/** |
134 |
|
|
* Getting informations about specific audio output driver parameter. |
135 |
|
|
* GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>] |
136 |
|
|
* |
137 |
|
|
* @param pClient Pointer to client instance structure. |
138 |
|
|
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
139 |
|
|
* @param pszParam Audio driver parameter name. |
140 |
|
|
* @param pDepList Pointer to specific dependencies parameter list. |
141 |
|
|
* |
142 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
143 |
|
|
* the given audio driver parameter information, or NULL in case of failure. |
144 |
|
|
*/ |
145 |
|
|
lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList ) |
146 |
|
|
{ |
147 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
148 |
|
|
|
149 |
|
|
if (pClient == NULL) |
150 |
|
|
return NULL; |
151 |
|
|
if (pszAudioDriver == NULL) |
152 |
|
|
return NULL; |
153 |
|
|
if (pszParam == NULL) |
154 |
|
|
return NULL; |
155 |
|
|
if (pDepList == NULL) |
156 |
|
|
return NULL; |
157 |
|
|
|
158 |
|
|
return pParamInfo; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
|
162 |
|
|
//------------------------------------------------------------------------- |
163 |
|
|
// Audio device control functions. |
164 |
|
|
|
165 |
|
|
/** |
166 |
|
|
* Creating an audio output device. |
167 |
|
|
* CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
168 |
|
|
* |
169 |
|
|
* @param pClient Pointer to client instance structure. |
170 |
|
|
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
171 |
|
|
* @param pParams Pointer to specific parameter list. |
172 |
|
|
* |
173 |
|
|
* @returns The new audio device number identifier on success, |
174 |
|
|
* or -1 in case of failure. |
175 |
|
|
*/ |
176 |
|
|
int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams ) |
177 |
|
|
{ |
178 |
|
|
int iAudioDevice = -1; |
179 |
|
|
|
180 |
|
|
if (pClient == NULL) |
181 |
|
|
return -1; |
182 |
|
|
if (pszAudioDriver == NULL) |
183 |
|
|
return -1; |
184 |
|
|
if (pParams == NULL) |
185 |
|
|
return -1; |
186 |
|
|
|
187 |
|
|
return iAudioDevice; |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
|
191 |
|
|
/** |
192 |
|
|
* Destroying an audio output device. |
193 |
|
|
* DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
194 |
|
|
* |
195 |
|
|
* @param pClient Pointer to client instance structure. |
196 |
|
|
* @param iAudioDevice Audio device number identifier. |
197 |
|
|
* |
198 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
199 |
|
|
*/ |
200 |
|
|
lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice ) |
201 |
|
|
{ |
202 |
|
|
lscp_status_t ret = LSCP_FAILED; |
203 |
|
|
|
204 |
|
|
if (pClient == NULL) |
205 |
|
|
return ret; |
206 |
|
|
if (iAudioDevice < 0) |
207 |
|
|
return ret; |
208 |
|
|
|
209 |
|
|
return ret; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
|
213 |
|
|
/** |
214 |
capela |
125 |
* Getting all created audio output device count. |
215 |
capela |
107 |
* GET AUDIO_OUTPUT_DEVICES |
216 |
|
|
* |
217 |
|
|
* @param pClient Pointer to client instance structure. |
218 |
|
|
* |
219 |
capela |
125 |
* @returns The current total number of audio devices on success, |
220 |
|
|
* -1 otherwise. |
221 |
|
|
*/ |
222 |
|
|
int lscp_get_audio_devices ( lscp_client_t *pClient ) |
223 |
|
|
{ |
224 |
|
|
int iAudioDevices = -1; |
225 |
capela |
132 |
|
226 |
|
|
// Lock this section up. |
227 |
|
|
lscp_mutex_lock(pClient->mutex); |
228 |
|
|
|
229 |
|
|
if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
230 |
capela |
125 |
iAudioDevices = atoi(lscp_client_get_result(pClient)); |
231 |
capela |
132 |
|
232 |
|
|
// Unlock this section down. |
233 |
|
|
lscp_mutex_unlock(pClient->mutex); |
234 |
|
|
|
235 |
capela |
125 |
return iAudioDevices; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
|
239 |
|
|
/** |
240 |
|
|
* Getting all created audio output device list. |
241 |
|
|
* LIST AUDIO_OUTPUT_DEVICES |
242 |
|
|
* |
243 |
|
|
* @param pClient Pointer to client instance structure. |
244 |
|
|
* |
245 |
capela |
107 |
* @returns An array of audio device number identifiers, |
246 |
|
|
* terminated with -1 on success, or NULL in case of failure. |
247 |
|
|
*/ |
248 |
capela |
125 |
int *lscp_list_audio_devices ( lscp_client_t *pClient ) |
249 |
capela |
107 |
{ |
250 |
capela |
125 |
const char *pszSeps = ","; |
251 |
capela |
107 |
|
252 |
|
|
if (pClient == NULL) |
253 |
|
|
return NULL; |
254 |
|
|
|
255 |
capela |
132 |
// Lock this section up. |
256 |
|
|
lscp_mutex_lock(pClient->mutex); |
257 |
|
|
|
258 |
capela |
125 |
if (pClient->audio_devices) { |
259 |
|
|
lscp_isplit_destroy(pClient->audio_devices); |
260 |
|
|
pClient->audio_devices = NULL; |
261 |
|
|
} |
262 |
|
|
|
263 |
capela |
132 |
if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
264 |
capela |
125 |
pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
265 |
|
|
|
266 |
capela |
132 |
// Unlock this section down. |
267 |
|
|
lscp_mutex_unlock(pClient->mutex); |
268 |
|
|
|
269 |
capela |
125 |
return pClient->audio_devices; |
270 |
capela |
107 |
} |
271 |
|
|
|
272 |
|
|
|
273 |
|
|
/** |
274 |
|
|
* Getting current settings of an audio output device. |
275 |
|
|
* GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
276 |
|
|
* |
277 |
|
|
* @param pClient Pointer to client instance structure. |
278 |
|
|
* @param iAudioDevice Audio device number identifier. |
279 |
|
|
* |
280 |
|
|
* @returns A pointer to a @ref lscp_device_info_t structure, with |
281 |
|
|
* the given audio device information, or NULL in case of failure. |
282 |
|
|
*/ |
283 |
|
|
lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice ) |
284 |
|
|
{ |
285 |
|
|
lscp_device_info_t *pDeviceInfo = NULL; |
286 |
|
|
|
287 |
|
|
if (pClient == NULL) |
288 |
|
|
return NULL; |
289 |
|
|
if (iAudioDevice < 0) |
290 |
|
|
return NULL; |
291 |
|
|
|
292 |
|
|
return pDeviceInfo; |
293 |
|
|
} |
294 |
|
|
|
295 |
|
|
|
296 |
|
|
/** |
297 |
|
|
* Changing settings of audio output devices. |
298 |
|
|
* SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param> <value> |
299 |
|
|
* |
300 |
|
|
* @param pClient Pointer to client instance structure. |
301 |
|
|
* @param iAudioDevice Audio device number identifier. |
302 |
|
|
* @param pParam Pointer to a key-valued audio device parameter. |
303 |
|
|
* |
304 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
305 |
|
|
*/ |
306 |
|
|
lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam ) |
307 |
|
|
{ |
308 |
|
|
lscp_status_t ret = LSCP_FAILED; |
309 |
|
|
|
310 |
|
|
if (pClient == NULL) |
311 |
|
|
return ret; |
312 |
|
|
if (iAudioDevice < 0) |
313 |
|
|
return ret; |
314 |
|
|
if (pParam == NULL) |
315 |
|
|
return ret; |
316 |
|
|
|
317 |
|
|
return ret; |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
|
321 |
|
|
/** |
322 |
|
|
* Getting informations about an audio channel. |
323 |
|
|
* GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
324 |
|
|
* |
325 |
|
|
* @param pClient Pointer to client instance structure. |
326 |
|
|
* @param iAudioDevice Audio device number identifier. |
327 |
|
|
* @param iAudioChannel Audio channel number. |
328 |
|
|
* |
329 |
|
|
* @returns A pointer to a @ref lscp_device_channel_info_t structure, |
330 |
|
|
* with the given audio channel information, or NULL in case of failure. |
331 |
|
|
*/ |
332 |
|
|
lscp_device_channel_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel ) |
333 |
|
|
{ |
334 |
|
|
lscp_device_channel_info_t *pDevChannelInfo = NULL; |
335 |
|
|
|
336 |
|
|
if (pClient == NULL) |
337 |
|
|
return NULL; |
338 |
|
|
if (iAudioDevice < 0) |
339 |
|
|
return NULL; |
340 |
|
|
if (iAudioChannel < 0) |
341 |
|
|
return NULL; |
342 |
|
|
|
343 |
|
|
return pDevChannelInfo; |
344 |
|
|
} |
345 |
|
|
|
346 |
|
|
|
347 |
|
|
/** |
348 |
|
|
* Getting informations about specific audio channel parameter. |
349 |
|
|
* GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
350 |
|
|
* |
351 |
|
|
* @param pClient Pointer to client instance structure. |
352 |
|
|
* @param iAudioDevice Audio device number identifier. |
353 |
|
|
* @param iAudioChannel Audio channel number. |
354 |
|
|
* @param pszParam Audio channel parameter name. |
355 |
|
|
* |
356 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
357 |
|
|
* the given audio channel parameter information, or NULL in case of failure. |
358 |
|
|
*/ |
359 |
|
|
lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam ) |
360 |
|
|
{ |
361 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
362 |
|
|
|
363 |
|
|
if (pClient == NULL) |
364 |
|
|
return NULL; |
365 |
|
|
if (iAudioDevice < 0) |
366 |
|
|
return NULL; |
367 |
|
|
if (iAudioChannel < 0) |
368 |
|
|
return NULL; |
369 |
|
|
if (pszParam == NULL) |
370 |
|
|
return NULL; |
371 |
|
|
|
372 |
|
|
return pParamInfo; |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
|
376 |
|
|
/** |
377 |
|
|
* Changing settings of audio output channels. |
378 |
|
|
* SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value> |
379 |
|
|
* |
380 |
|
|
* @param pClient Pointer to client instance structure. |
381 |
|
|
* @param iAudioDevice Audio device number identifier. |
382 |
|
|
* @param iAudioChannel Audio channel number. |
383 |
|
|
* @param pParam Pointer to a key-valued audio channel parameter. |
384 |
|
|
* |
385 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
386 |
|
|
*/ |
387 |
|
|
lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam ) |
388 |
|
|
{ |
389 |
|
|
lscp_status_t ret = LSCP_FAILED; |
390 |
|
|
|
391 |
|
|
if (pClient == NULL) |
392 |
|
|
return ret; |
393 |
|
|
if (iAudioDevice < 0) |
394 |
|
|
return ret; |
395 |
|
|
if (iAudioChannel < 0) |
396 |
|
|
return ret; |
397 |
|
|
if (pParam == NULL) |
398 |
|
|
return ret; |
399 |
|
|
|
400 |
|
|
return ret; |
401 |
|
|
} |
402 |
|
|
|
403 |
|
|
|
404 |
|
|
//------------------------------------------------------------------------- |
405 |
|
|
// MIDI driver control functions. |
406 |
|
|
|
407 |
|
|
/** |
408 |
|
|
* Getting all available MIDI input drivers. |
409 |
|
|
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
410 |
|
|
* |
411 |
|
|
* @param pClient Pointer to client instance structure. |
412 |
|
|
* |
413 |
|
|
* @returns A NULL terminated array of MIDI input driver type |
414 |
|
|
* name strings, or NULL in case of failure. |
415 |
|
|
*/ |
416 |
|
|
const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
417 |
|
|
{ |
418 |
|
|
const char *pszSeps = ","; |
419 |
|
|
|
420 |
capela |
132 |
// Lock this section up. |
421 |
|
|
lscp_mutex_lock(pClient->mutex); |
422 |
|
|
|
423 |
capela |
107 |
if (pClient->midi_drivers) { |
424 |
|
|
lscp_szsplit_destroy(pClient->midi_drivers); |
425 |
|
|
pClient->midi_drivers = NULL; |
426 |
|
|
} |
427 |
|
|
|
428 |
capela |
132 |
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
429 |
capela |
107 |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
430 |
|
|
|
431 |
capela |
132 |
// Unlock this section up. |
432 |
|
|
lscp_mutex_unlock(pClient->mutex); |
433 |
|
|
|
434 |
capela |
107 |
return (const char **) pClient->midi_drivers; |
435 |
|
|
} |
436 |
|
|
|
437 |
|
|
|
438 |
|
|
/** |
439 |
|
|
* Getting informations about a specific MIDI input driver. |
440 |
|
|
* GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
441 |
|
|
* |
442 |
|
|
* @param pClient Pointer to client instance structure. |
443 |
|
|
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
444 |
|
|
* |
445 |
|
|
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
446 |
|
|
* the given MIDI driver information, or NULL in case of failure. |
447 |
|
|
*/ |
448 |
|
|
lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver ) |
449 |
|
|
{ |
450 |
|
|
char szQuery[LSCP_BUFSIZ]; |
451 |
|
|
|
452 |
|
|
if (pszMidiDriver == NULL) |
453 |
|
|
return NULL; |
454 |
|
|
|
455 |
|
|
sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver); |
456 |
|
|
return _lscp_driver_info_query(pClient, &(pClient->midi_info), szQuery); |
457 |
|
|
} |
458 |
|
|
|
459 |
|
|
|
460 |
|
|
/** |
461 |
|
|
* Getting informations about specific MIDI input driver parameter. |
462 |
|
|
* GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>] |
463 |
|
|
* |
464 |
|
|
* @param pClient Pointer to client instance structure. |
465 |
|
|
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
466 |
|
|
* @param pszParam MIDI driver parameter name. |
467 |
|
|
* @param pDepList Pointer to specific dependencies parameter list. |
468 |
|
|
* |
469 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
470 |
|
|
* the given MIDI driver parameter information, or NULL in case of failure. |
471 |
|
|
* |
472 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
473 |
|
|
*/ |
474 |
|
|
lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList ) |
475 |
|
|
{ |
476 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
477 |
|
|
|
478 |
|
|
if (pClient == NULL) |
479 |
|
|
return NULL; |
480 |
|
|
if (pszMidiDriver == NULL) |
481 |
|
|
return NULL; |
482 |
|
|
if (pszParam == NULL) |
483 |
|
|
return NULL; |
484 |
|
|
if (pDepList == NULL) |
485 |
|
|
return NULL; |
486 |
|
|
|
487 |
|
|
return pParamInfo; |
488 |
|
|
} |
489 |
|
|
|
490 |
|
|
|
491 |
|
|
//------------------------------------------------------------------------- |
492 |
|
|
// MIDI device control functions. |
493 |
|
|
|
494 |
|
|
/** |
495 |
|
|
* Creating a MIDI input device. |
496 |
|
|
* CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
497 |
|
|
* |
498 |
|
|
* @param pClient Pointer to client instance structure. |
499 |
|
|
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
500 |
|
|
* @param pParams Pointer to specific parameter list. |
501 |
|
|
* |
502 |
|
|
* @returns The new audio device number identifier on success, |
503 |
|
|
* or -1 in case of failure. |
504 |
|
|
*/ |
505 |
|
|
int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams ) |
506 |
|
|
{ |
507 |
|
|
int iMidiDevice = -1; |
508 |
|
|
|
509 |
|
|
if (pClient == NULL) |
510 |
|
|
return -1; |
511 |
|
|
if (pszMidiDriver == NULL) |
512 |
|
|
return -1; |
513 |
|
|
if (pParams == NULL) |
514 |
|
|
return -1; |
515 |
|
|
|
516 |
|
|
return iMidiDevice; |
517 |
|
|
} |
518 |
|
|
|
519 |
|
|
|
520 |
|
|
/** |
521 |
|
|
* Destroying a MIDI input device. |
522 |
|
|
* DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
523 |
|
|
* |
524 |
|
|
* @param pClient Pointer to client instance structure. |
525 |
|
|
* @param iMidiDevice MIDI device number identifier. |
526 |
|
|
* |
527 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
528 |
|
|
*/ |
529 |
|
|
lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice ) |
530 |
|
|
{ |
531 |
|
|
lscp_status_t ret = LSCP_FAILED; |
532 |
|
|
|
533 |
|
|
if (pClient == NULL) |
534 |
|
|
return ret; |
535 |
|
|
if (iMidiDevice < 0) |
536 |
|
|
return ret; |
537 |
|
|
|
538 |
|
|
return ret; |
539 |
|
|
} |
540 |
|
|
|
541 |
|
|
|
542 |
|
|
/** |
543 |
capela |
125 |
* Getting all created MIDI intput device count. |
544 |
capela |
107 |
* GET MIDI_INPUT_DEVICES |
545 |
|
|
* |
546 |
|
|
* @param pClient Pointer to client instance structure. |
547 |
|
|
* |
548 |
capela |
125 |
* @returns The current total number of MIDI devices on success, |
549 |
|
|
* -1 otherwise. |
550 |
|
|
*/ |
551 |
|
|
int lscp_get_midi_devices ( lscp_client_t *pClient ) |
552 |
|
|
{ |
553 |
|
|
int iMidiDevices = -1; |
554 |
capela |
132 |
|
555 |
|
|
// Lock this section up. |
556 |
|
|
lscp_mutex_lock(pClient->mutex); |
557 |
|
|
|
558 |
|
|
if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
559 |
capela |
125 |
iMidiDevices = atoi(lscp_client_get_result(pClient)); |
560 |
capela |
132 |
|
561 |
|
|
// Unlock this section down. |
562 |
|
|
lscp_mutex_unlock(pClient->mutex); |
563 |
|
|
|
564 |
capela |
125 |
return iMidiDevices; |
565 |
|
|
} |
566 |
|
|
|
567 |
|
|
|
568 |
|
|
/** |
569 |
|
|
* Getting all created MIDI intput device list. |
570 |
|
|
* LIST MIDI_INPUT_DEVICES |
571 |
|
|
* |
572 |
|
|
* @param pClient Pointer to client instance structure. |
573 |
|
|
* |
574 |
capela |
107 |
* @returns An array of MIDI device number identifiers, |
575 |
|
|
* terminated with -1 on success, or NULL in case of failure. |
576 |
|
|
*/ |
577 |
capela |
125 |
int *lscp_list_midi_devices ( lscp_client_t *pClient ) |
578 |
capela |
107 |
{ |
579 |
capela |
125 |
const char *pszSeps = ","; |
580 |
capela |
107 |
|
581 |
|
|
if (pClient == NULL) |
582 |
|
|
return NULL; |
583 |
|
|
|
584 |
capela |
132 |
// Lock this section up. |
585 |
|
|
lscp_mutex_lock(pClient->mutex); |
586 |
|
|
|
587 |
capela |
125 |
if (pClient->midi_devices) { |
588 |
|
|
lscp_isplit_destroy(pClient->midi_devices); |
589 |
|
|
pClient->midi_devices = NULL; |
590 |
|
|
} |
591 |
|
|
|
592 |
capela |
132 |
if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
593 |
capela |
125 |
pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
594 |
|
|
|
595 |
capela |
132 |
// Unlock this section down. |
596 |
|
|
lscp_mutex_unlock(pClient->mutex); |
597 |
|
|
|
598 |
capela |
125 |
return pClient->midi_devices; |
599 |
capela |
107 |
} |
600 |
|
|
|
601 |
|
|
|
602 |
|
|
/** |
603 |
|
|
* Getting current settings of a MIDI input device. |
604 |
|
|
* GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
605 |
|
|
* |
606 |
|
|
* @param pClient Pointer to client instance structure. |
607 |
|
|
* @param iMidiDevice MIDI device number identifier. |
608 |
|
|
* |
609 |
|
|
* @returns A pointer to a @ref lscp_device_info_t structure, with |
610 |
|
|
* the given MIDI device information, or NULL in case of failure. |
611 |
|
|
*/ |
612 |
|
|
lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice ) |
613 |
|
|
{ |
614 |
|
|
lscp_device_info_t *pDeviceInfo = NULL; |
615 |
|
|
|
616 |
|
|
if (pClient == NULL) |
617 |
|
|
return NULL; |
618 |
|
|
if (iMidiDevice < 0) |
619 |
|
|
return NULL; |
620 |
|
|
|
621 |
|
|
return pDeviceInfo; |
622 |
|
|
} |
623 |
|
|
|
624 |
|
|
|
625 |
|
|
/** |
626 |
|
|
* Changing settings of MIDI input devices. |
627 |
|
|
* SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param> <value> |
628 |
|
|
* |
629 |
|
|
* @param pClient Pointer to client instance structure. |
630 |
|
|
* @param iMidiDevice MIDI device number identifier. |
631 |
|
|
* @param pParam Pointer to a key-valued MIDI device parameter. |
632 |
|
|
* |
633 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
634 |
|
|
*/ |
635 |
|
|
lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam ) |
636 |
|
|
{ |
637 |
|
|
lscp_status_t ret = LSCP_FAILED; |
638 |
|
|
|
639 |
|
|
if (pClient == NULL) |
640 |
|
|
return ret; |
641 |
|
|
if (iMidiDevice < 0) |
642 |
|
|
return ret; |
643 |
|
|
if (pParam == NULL) |
644 |
|
|
return ret; |
645 |
|
|
|
646 |
|
|
return ret; |
647 |
|
|
} |
648 |
|
|
|
649 |
|
|
|
650 |
|
|
/** |
651 |
|
|
* Getting informations about a MIDI port. |
652 |
|
|
* GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
653 |
|
|
* |
654 |
|
|
* @param pClient Pointer to client instance structure. |
655 |
|
|
* @param iMidiDevice MIDI device number identifier. |
656 |
|
|
* @param iMidiPort MIDI port number. |
657 |
|
|
* |
658 |
|
|
* @returns A pointer to a @ref lscp_device_channel_info_t structure, |
659 |
|
|
* with the given MIDI port information, or NULL in case of failure. |
660 |
|
|
*/ |
661 |
|
|
lscp_device_channel_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort ) |
662 |
|
|
{ |
663 |
|
|
lscp_device_channel_info_t *pDevChannelInfo = NULL; |
664 |
|
|
|
665 |
|
|
if (pClient == NULL) |
666 |
|
|
return NULL; |
667 |
|
|
if (iMidiDevice < 0) |
668 |
|
|
return NULL; |
669 |
|
|
if (iMidiPort < 0) |
670 |
|
|
return NULL; |
671 |
|
|
|
672 |
|
|
return pDevChannelInfo; |
673 |
|
|
} |
674 |
|
|
|
675 |
|
|
|
676 |
|
|
/** |
677 |
|
|
* Getting informations about specific MIDI port parameter. |
678 |
|
|
* GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
679 |
|
|
* |
680 |
|
|
* @param pClient Pointer to client instance structure. |
681 |
|
|
* @param iMidiDevice MIDI device number identifier. |
682 |
|
|
* @param iMidiPort MIDI port number. |
683 |
|
|
* @param pszParam MIDI port parameter name. |
684 |
|
|
* |
685 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
686 |
|
|
* the given MIDI port parameter information, or NULL in case of failure. |
687 |
|
|
*/ |
688 |
|
|
lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam ) |
689 |
|
|
{ |
690 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
691 |
|
|
|
692 |
|
|
if (pClient == NULL) |
693 |
|
|
return NULL; |
694 |
|
|
if (iMidiDevice < 0) |
695 |
|
|
return NULL; |
696 |
|
|
if (iMidiPort < 0) |
697 |
|
|
return NULL; |
698 |
|
|
if (pszParam == NULL) |
699 |
|
|
return NULL; |
700 |
|
|
|
701 |
|
|
return pParamInfo; |
702 |
|
|
} |
703 |
|
|
|
704 |
|
|
|
705 |
|
|
/** |
706 |
|
|
* Changing settings of MIDI input ports. |
707 |
|
|
* SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value> |
708 |
|
|
* |
709 |
|
|
* @param pClient Pointer to client instance structure. |
710 |
|
|
* @param iMidiDevice MIDI device number identifier. |
711 |
|
|
* @param iMidiPort MIDI port number. |
712 |
|
|
* @param pParam Pointer to a key-valued MIDI port parameter. |
713 |
|
|
* |
714 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
715 |
|
|
*/ |
716 |
|
|
lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam ) |
717 |
|
|
{ |
718 |
|
|
lscp_status_t ret = LSCP_FAILED; |
719 |
|
|
|
720 |
|
|
if (pClient == NULL) |
721 |
|
|
return ret; |
722 |
|
|
if (iMidiDevice < 0) |
723 |
|
|
return ret; |
724 |
|
|
if (iMidiPort < 0) |
725 |
|
|
return ret; |
726 |
|
|
if (pParam == NULL) |
727 |
|
|
return ret; |
728 |
|
|
|
729 |
|
|
return ret; |
730 |
|
|
} |
731 |
|
|
|
732 |
|
|
// end of device.c |
733 |
|
|
|