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 |
|
|
lscp_driver_info_reset(pDriverInfo); |
44 |
|
|
|
45 |
|
|
if (lscp_client_query(pClient, pszQuery) != LSCP_OK) |
46 |
|
|
return NULL; |
47 |
|
|
|
48 |
|
|
pszResult = lscp_client_get_result(pClient); |
49 |
capela |
114 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
50 |
capela |
107 |
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 |
|
|
} |
68 |
|
|
|
69 |
|
|
return pDriverInfo; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
//------------------------------------------------------------------------- |
74 |
|
|
// Audio driver control functions. |
75 |
|
|
|
76 |
|
|
/** |
77 |
|
|
* Getting all available audio output drivers. |
78 |
|
|
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
79 |
|
|
* |
80 |
|
|
* @param pClient Pointer to client instance structure. |
81 |
|
|
* |
82 |
|
|
* @returns A NULL terminated array of audio output driver type |
83 |
|
|
* name strings, or NULL in case of failure. |
84 |
|
|
*/ |
85 |
|
|
const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient ) |
86 |
|
|
{ |
87 |
|
|
const char *pszSeps = ","; |
88 |
|
|
|
89 |
|
|
if (pClient->audio_drivers) { |
90 |
|
|
lscp_szsplit_destroy(pClient->audio_drivers); |
91 |
|
|
pClient->audio_drivers = NULL; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
if (lscp_client_query(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
95 |
|
|
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
96 |
|
|
|
97 |
|
|
return (const char **) pClient->audio_drivers; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
/** |
102 |
|
|
* Getting informations about a specific audio output driver. |
103 |
|
|
* GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
104 |
|
|
* |
105 |
|
|
* @param pClient Pointer to client instance structure. |
106 |
|
|
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
107 |
|
|
* |
108 |
|
|
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
109 |
|
|
* the given audio driver information, or NULL in case of failure. |
110 |
|
|
*/ |
111 |
|
|
lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver ) |
112 |
|
|
{ |
113 |
|
|
char szQuery[LSCP_BUFSIZ]; |
114 |
|
|
|
115 |
|
|
if (pszAudioDriver == NULL) |
116 |
|
|
return NULL; |
117 |
|
|
|
118 |
|
|
sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver); |
119 |
|
|
return _lscp_driver_info_query(pClient, &(pClient->audio_info), szQuery); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
|
123 |
|
|
/** |
124 |
|
|
* Getting informations about specific audio output driver parameter. |
125 |
|
|
* GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>] |
126 |
|
|
* |
127 |
|
|
* @param pClient Pointer to client instance structure. |
128 |
|
|
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
129 |
|
|
* @param pszParam Audio driver parameter name. |
130 |
|
|
* @param pDepList Pointer to specific dependencies parameter list. |
131 |
|
|
* |
132 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
133 |
|
|
* the given audio driver parameter information, or NULL in case of failure. |
134 |
|
|
*/ |
135 |
|
|
lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList ) |
136 |
|
|
{ |
137 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
138 |
|
|
|
139 |
|
|
if (pClient == NULL) |
140 |
|
|
return NULL; |
141 |
|
|
if (pszAudioDriver == NULL) |
142 |
|
|
return NULL; |
143 |
|
|
if (pszParam == NULL) |
144 |
|
|
return NULL; |
145 |
|
|
if (pDepList == NULL) |
146 |
|
|
return NULL; |
147 |
|
|
|
148 |
|
|
return pParamInfo; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
//------------------------------------------------------------------------- |
153 |
|
|
// Audio device control functions. |
154 |
|
|
|
155 |
|
|
/** |
156 |
|
|
* Creating an audio output device. |
157 |
|
|
* CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
158 |
|
|
* |
159 |
|
|
* @param pClient Pointer to client instance structure. |
160 |
|
|
* @param pszAudioDriver Audio driver type string (e.g. "ALSA"). |
161 |
|
|
* @param pParams Pointer to specific parameter list. |
162 |
|
|
* |
163 |
|
|
* @returns The new audio device number identifier on success, |
164 |
|
|
* or -1 in case of failure. |
165 |
|
|
*/ |
166 |
|
|
int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams ) |
167 |
|
|
{ |
168 |
|
|
int iAudioDevice = -1; |
169 |
|
|
|
170 |
|
|
if (pClient == NULL) |
171 |
|
|
return -1; |
172 |
|
|
if (pszAudioDriver == NULL) |
173 |
|
|
return -1; |
174 |
|
|
if (pParams == NULL) |
175 |
|
|
return -1; |
176 |
|
|
|
177 |
|
|
return iAudioDevice; |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
/** |
182 |
|
|
* Destroying an audio output device. |
183 |
|
|
* DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
184 |
|
|
* |
185 |
|
|
* @param pClient Pointer to client instance structure. |
186 |
|
|
* @param iAudioDevice Audio device number identifier. |
187 |
|
|
* |
188 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
189 |
|
|
*/ |
190 |
|
|
lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice ) |
191 |
|
|
{ |
192 |
|
|
lscp_status_t ret = LSCP_FAILED; |
193 |
|
|
|
194 |
|
|
if (pClient == NULL) |
195 |
|
|
return ret; |
196 |
|
|
if (iAudioDevice < 0) |
197 |
|
|
return ret; |
198 |
|
|
|
199 |
|
|
return ret; |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
|
203 |
|
|
/** |
204 |
capela |
125 |
* Getting all created audio output device count. |
205 |
capela |
107 |
* GET AUDIO_OUTPUT_DEVICES |
206 |
|
|
* |
207 |
|
|
* @param pClient Pointer to client instance structure. |
208 |
|
|
* |
209 |
capela |
125 |
* @returns The current total number of audio devices on success, |
210 |
|
|
* -1 otherwise. |
211 |
|
|
*/ |
212 |
|
|
int lscp_get_audio_devices ( lscp_client_t *pClient ) |
213 |
|
|
{ |
214 |
|
|
int iAudioDevices = -1; |
215 |
|
|
if (lscp_client_query(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
216 |
|
|
iAudioDevices = atoi(lscp_client_get_result(pClient)); |
217 |
|
|
return iAudioDevices; |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
|
221 |
|
|
/** |
222 |
|
|
* Getting all created audio output device list. |
223 |
|
|
* LIST AUDIO_OUTPUT_DEVICES |
224 |
|
|
* |
225 |
|
|
* @param pClient Pointer to client instance structure. |
226 |
|
|
* |
227 |
capela |
107 |
* @returns An array of audio device number identifiers, |
228 |
|
|
* terminated with -1 on success, or NULL in case of failure. |
229 |
|
|
*/ |
230 |
capela |
125 |
int *lscp_list_audio_devices ( lscp_client_t *pClient ) |
231 |
capela |
107 |
{ |
232 |
capela |
125 |
const char *pszSeps = ","; |
233 |
capela |
107 |
|
234 |
|
|
if (pClient == NULL) |
235 |
|
|
return NULL; |
236 |
|
|
|
237 |
capela |
125 |
if (pClient->audio_devices) { |
238 |
|
|
lscp_isplit_destroy(pClient->audio_devices); |
239 |
|
|
pClient->audio_devices = NULL; |
240 |
|
|
} |
241 |
|
|
|
242 |
|
|
if (lscp_client_query(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK) |
243 |
|
|
pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
244 |
|
|
|
245 |
|
|
return pClient->audio_devices; |
246 |
capela |
107 |
} |
247 |
|
|
|
248 |
|
|
|
249 |
|
|
/** |
250 |
|
|
* Getting current settings of an audio output device. |
251 |
|
|
* GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
252 |
|
|
* |
253 |
|
|
* @param pClient Pointer to client instance structure. |
254 |
|
|
* @param iAudioDevice Audio device number identifier. |
255 |
|
|
* |
256 |
|
|
* @returns A pointer to a @ref lscp_device_info_t structure, with |
257 |
|
|
* the given audio device information, or NULL in case of failure. |
258 |
|
|
*/ |
259 |
|
|
lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice ) |
260 |
|
|
{ |
261 |
|
|
lscp_device_info_t *pDeviceInfo = NULL; |
262 |
|
|
|
263 |
|
|
if (pClient == NULL) |
264 |
|
|
return NULL; |
265 |
|
|
if (iAudioDevice < 0) |
266 |
|
|
return NULL; |
267 |
|
|
|
268 |
|
|
return pDeviceInfo; |
269 |
|
|
} |
270 |
|
|
|
271 |
|
|
|
272 |
|
|
/** |
273 |
|
|
* Changing settings of audio output devices. |
274 |
|
|
* SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param> <value> |
275 |
|
|
* |
276 |
|
|
* @param pClient Pointer to client instance structure. |
277 |
|
|
* @param iAudioDevice Audio device number identifier. |
278 |
|
|
* @param pParam Pointer to a key-valued audio device parameter. |
279 |
|
|
* |
280 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
281 |
|
|
*/ |
282 |
|
|
lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam ) |
283 |
|
|
{ |
284 |
|
|
lscp_status_t ret = LSCP_FAILED; |
285 |
|
|
|
286 |
|
|
if (pClient == NULL) |
287 |
|
|
return ret; |
288 |
|
|
if (iAudioDevice < 0) |
289 |
|
|
return ret; |
290 |
|
|
if (pParam == NULL) |
291 |
|
|
return ret; |
292 |
|
|
|
293 |
|
|
return ret; |
294 |
|
|
} |
295 |
|
|
|
296 |
|
|
|
297 |
|
|
/** |
298 |
|
|
* Getting informations about an audio channel. |
299 |
|
|
* GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
300 |
|
|
* |
301 |
|
|
* @param pClient Pointer to client instance structure. |
302 |
|
|
* @param iAudioDevice Audio device number identifier. |
303 |
|
|
* @param iAudioChannel Audio channel number. |
304 |
|
|
* |
305 |
|
|
* @returns A pointer to a @ref lscp_device_channel_info_t structure, |
306 |
|
|
* with the given audio channel information, or NULL in case of failure. |
307 |
|
|
*/ |
308 |
|
|
lscp_device_channel_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel ) |
309 |
|
|
{ |
310 |
|
|
lscp_device_channel_info_t *pDevChannelInfo = NULL; |
311 |
|
|
|
312 |
|
|
if (pClient == NULL) |
313 |
|
|
return NULL; |
314 |
|
|
if (iAudioDevice < 0) |
315 |
|
|
return NULL; |
316 |
|
|
if (iAudioChannel < 0) |
317 |
|
|
return NULL; |
318 |
|
|
|
319 |
|
|
return pDevChannelInfo; |
320 |
|
|
} |
321 |
|
|
|
322 |
|
|
|
323 |
|
|
/** |
324 |
|
|
* Getting informations about specific audio channel parameter. |
325 |
|
|
* GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
326 |
|
|
* |
327 |
|
|
* @param pClient Pointer to client instance structure. |
328 |
|
|
* @param iAudioDevice Audio device number identifier. |
329 |
|
|
* @param iAudioChannel Audio channel number. |
330 |
|
|
* @param pszParam Audio channel parameter name. |
331 |
|
|
* |
332 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
333 |
|
|
* the given audio channel parameter information, or NULL in case of failure. |
334 |
|
|
*/ |
335 |
|
|
lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam ) |
336 |
|
|
{ |
337 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
338 |
|
|
|
339 |
|
|
if (pClient == NULL) |
340 |
|
|
return NULL; |
341 |
|
|
if (iAudioDevice < 0) |
342 |
|
|
return NULL; |
343 |
|
|
if (iAudioChannel < 0) |
344 |
|
|
return NULL; |
345 |
|
|
if (pszParam == NULL) |
346 |
|
|
return NULL; |
347 |
|
|
|
348 |
|
|
return pParamInfo; |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
|
352 |
|
|
/** |
353 |
|
|
* Changing settings of audio output channels. |
354 |
|
|
* SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value> |
355 |
|
|
* |
356 |
|
|
* @param pClient Pointer to client instance structure. |
357 |
|
|
* @param iAudioDevice Audio device number identifier. |
358 |
|
|
* @param iAudioChannel Audio channel number. |
359 |
|
|
* @param pParam Pointer to a key-valued audio channel parameter. |
360 |
|
|
* |
361 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
362 |
|
|
*/ |
363 |
|
|
lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam ) |
364 |
|
|
{ |
365 |
|
|
lscp_status_t ret = LSCP_FAILED; |
366 |
|
|
|
367 |
|
|
if (pClient == NULL) |
368 |
|
|
return ret; |
369 |
|
|
if (iAudioDevice < 0) |
370 |
|
|
return ret; |
371 |
|
|
if (iAudioChannel < 0) |
372 |
|
|
return ret; |
373 |
|
|
if (pParam == NULL) |
374 |
|
|
return ret; |
375 |
|
|
|
376 |
|
|
return ret; |
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
|
380 |
|
|
//------------------------------------------------------------------------- |
381 |
|
|
// MIDI driver control functions. |
382 |
|
|
|
383 |
|
|
/** |
384 |
|
|
* Getting all available MIDI input drivers. |
385 |
|
|
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
386 |
|
|
* |
387 |
|
|
* @param pClient Pointer to client instance structure. |
388 |
|
|
* |
389 |
|
|
* @returns A NULL terminated array of MIDI input driver type |
390 |
|
|
* name strings, or NULL in case of failure. |
391 |
|
|
*/ |
392 |
|
|
const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
393 |
|
|
{ |
394 |
|
|
const char *pszSeps = ","; |
395 |
|
|
|
396 |
|
|
if (pClient->midi_drivers) { |
397 |
|
|
lscp_szsplit_destroy(pClient->midi_drivers); |
398 |
|
|
pClient->midi_drivers = NULL; |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
if (lscp_client_query(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
402 |
|
|
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
403 |
|
|
|
404 |
|
|
return (const char **) pClient->midi_drivers; |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
|
408 |
|
|
/** |
409 |
|
|
* Getting informations about a specific MIDI input driver. |
410 |
|
|
* GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
411 |
|
|
* |
412 |
|
|
* @param pClient Pointer to client instance structure. |
413 |
|
|
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
414 |
|
|
* |
415 |
|
|
* @returns A pointer to a @ref lscp_driver_info_t structure, with |
416 |
|
|
* the given MIDI driver information, or NULL in case of failure. |
417 |
|
|
*/ |
418 |
|
|
lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver ) |
419 |
|
|
{ |
420 |
|
|
char szQuery[LSCP_BUFSIZ]; |
421 |
|
|
|
422 |
|
|
if (pszMidiDriver == NULL) |
423 |
|
|
return NULL; |
424 |
|
|
|
425 |
|
|
sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver); |
426 |
|
|
return _lscp_driver_info_query(pClient, &(pClient->midi_info), szQuery); |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
|
430 |
|
|
/** |
431 |
|
|
* Getting informations about specific MIDI input driver parameter. |
432 |
|
|
* GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>] |
433 |
|
|
* |
434 |
|
|
* @param pClient Pointer to client instance structure. |
435 |
|
|
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
436 |
|
|
* @param pszParam MIDI driver parameter name. |
437 |
|
|
* @param pDepList Pointer to specific dependencies parameter list. |
438 |
|
|
* |
439 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
440 |
|
|
* the given MIDI driver parameter information, or NULL in case of failure. |
441 |
|
|
* |
442 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
443 |
|
|
*/ |
444 |
|
|
lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList ) |
445 |
|
|
{ |
446 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
447 |
|
|
|
448 |
|
|
if (pClient == NULL) |
449 |
|
|
return NULL; |
450 |
|
|
if (pszMidiDriver == NULL) |
451 |
|
|
return NULL; |
452 |
|
|
if (pszParam == NULL) |
453 |
|
|
return NULL; |
454 |
|
|
if (pDepList == NULL) |
455 |
|
|
return NULL; |
456 |
|
|
|
457 |
|
|
return pParamInfo; |
458 |
|
|
} |
459 |
|
|
|
460 |
|
|
|
461 |
|
|
//------------------------------------------------------------------------- |
462 |
|
|
// MIDI device control functions. |
463 |
|
|
|
464 |
|
|
/** |
465 |
|
|
* Creating a MIDI input device. |
466 |
|
|
* CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
467 |
|
|
* |
468 |
|
|
* @param pClient Pointer to client instance structure. |
469 |
|
|
* @param pszMidiDriver MIDI driver type string (e.g. "ALSA"). |
470 |
|
|
* @param pParams Pointer to specific parameter list. |
471 |
|
|
* |
472 |
|
|
* @returns The new audio device number identifier on success, |
473 |
|
|
* or -1 in case of failure. |
474 |
|
|
*/ |
475 |
|
|
int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams ) |
476 |
|
|
{ |
477 |
|
|
int iMidiDevice = -1; |
478 |
|
|
|
479 |
|
|
if (pClient == NULL) |
480 |
|
|
return -1; |
481 |
|
|
if (pszMidiDriver == NULL) |
482 |
|
|
return -1; |
483 |
|
|
if (pParams == NULL) |
484 |
|
|
return -1; |
485 |
|
|
|
486 |
|
|
return iMidiDevice; |
487 |
|
|
} |
488 |
|
|
|
489 |
|
|
|
490 |
|
|
/** |
491 |
|
|
* Destroying a MIDI input device. |
492 |
|
|
* DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
493 |
|
|
* |
494 |
|
|
* @param pClient Pointer to client instance structure. |
495 |
|
|
* @param iMidiDevice MIDI device number identifier. |
496 |
|
|
* |
497 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
498 |
|
|
*/ |
499 |
|
|
lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice ) |
500 |
|
|
{ |
501 |
|
|
lscp_status_t ret = LSCP_FAILED; |
502 |
|
|
|
503 |
|
|
if (pClient == NULL) |
504 |
|
|
return ret; |
505 |
|
|
if (iMidiDevice < 0) |
506 |
|
|
return ret; |
507 |
|
|
|
508 |
|
|
return ret; |
509 |
|
|
} |
510 |
|
|
|
511 |
|
|
|
512 |
|
|
/** |
513 |
capela |
125 |
* Getting all created MIDI intput device count. |
514 |
capela |
107 |
* GET MIDI_INPUT_DEVICES |
515 |
|
|
* |
516 |
|
|
* @param pClient Pointer to client instance structure. |
517 |
|
|
* |
518 |
capela |
125 |
* @returns The current total number of MIDI devices on success, |
519 |
|
|
* -1 otherwise. |
520 |
|
|
*/ |
521 |
|
|
int lscp_get_midi_devices ( lscp_client_t *pClient ) |
522 |
|
|
{ |
523 |
|
|
int iMidiDevices = -1; |
524 |
|
|
if (lscp_client_query(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
525 |
|
|
iMidiDevices = atoi(lscp_client_get_result(pClient)); |
526 |
|
|
return iMidiDevices; |
527 |
|
|
} |
528 |
|
|
|
529 |
|
|
|
530 |
|
|
/** |
531 |
|
|
* Getting all created MIDI intput device list. |
532 |
|
|
* LIST MIDI_INPUT_DEVICES |
533 |
|
|
* |
534 |
|
|
* @param pClient Pointer to client instance structure. |
535 |
|
|
* |
536 |
capela |
107 |
* @returns An array of MIDI device number identifiers, |
537 |
|
|
* terminated with -1 on success, or NULL in case of failure. |
538 |
|
|
*/ |
539 |
capela |
125 |
int *lscp_list_midi_devices ( lscp_client_t *pClient ) |
540 |
capela |
107 |
{ |
541 |
capela |
125 |
const char *pszSeps = ","; |
542 |
capela |
107 |
|
543 |
|
|
if (pClient == NULL) |
544 |
|
|
return NULL; |
545 |
|
|
|
546 |
capela |
125 |
if (pClient->midi_devices) { |
547 |
|
|
lscp_isplit_destroy(pClient->midi_devices); |
548 |
|
|
pClient->midi_devices = NULL; |
549 |
|
|
} |
550 |
|
|
|
551 |
|
|
if (lscp_client_query(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK) |
552 |
|
|
pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
553 |
|
|
|
554 |
|
|
return pClient->midi_devices; |
555 |
capela |
107 |
} |
556 |
|
|
|
557 |
|
|
|
558 |
|
|
/** |
559 |
|
|
* Getting current settings of a MIDI input device. |
560 |
|
|
* GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
561 |
|
|
* |
562 |
|
|
* @param pClient Pointer to client instance structure. |
563 |
|
|
* @param iMidiDevice MIDI device number identifier. |
564 |
|
|
* |
565 |
|
|
* @returns A pointer to a @ref lscp_device_info_t structure, with |
566 |
|
|
* the given MIDI device information, or NULL in case of failure. |
567 |
|
|
*/ |
568 |
|
|
lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice ) |
569 |
|
|
{ |
570 |
|
|
lscp_device_info_t *pDeviceInfo = NULL; |
571 |
|
|
|
572 |
|
|
if (pClient == NULL) |
573 |
|
|
return NULL; |
574 |
|
|
if (iMidiDevice < 0) |
575 |
|
|
return NULL; |
576 |
|
|
|
577 |
|
|
return pDeviceInfo; |
578 |
|
|
} |
579 |
|
|
|
580 |
|
|
|
581 |
|
|
/** |
582 |
|
|
* Changing settings of MIDI input devices. |
583 |
|
|
* SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param> <value> |
584 |
|
|
* |
585 |
|
|
* @param pClient Pointer to client instance structure. |
586 |
|
|
* @param iMidiDevice MIDI device number identifier. |
587 |
|
|
* @param pParam Pointer to a key-valued MIDI device parameter. |
588 |
|
|
* |
589 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
590 |
|
|
*/ |
591 |
|
|
lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam ) |
592 |
|
|
{ |
593 |
|
|
lscp_status_t ret = LSCP_FAILED; |
594 |
|
|
|
595 |
|
|
if (pClient == NULL) |
596 |
|
|
return ret; |
597 |
|
|
if (iMidiDevice < 0) |
598 |
|
|
return ret; |
599 |
|
|
if (pParam == NULL) |
600 |
|
|
return ret; |
601 |
|
|
|
602 |
|
|
return ret; |
603 |
|
|
} |
604 |
|
|
|
605 |
|
|
|
606 |
|
|
/** |
607 |
|
|
* Getting informations about a MIDI port. |
608 |
|
|
* GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
609 |
|
|
* |
610 |
|
|
* @param pClient Pointer to client instance structure. |
611 |
|
|
* @param iMidiDevice MIDI device number identifier. |
612 |
|
|
* @param iMidiPort MIDI port number. |
613 |
|
|
* |
614 |
|
|
* @returns A pointer to a @ref lscp_device_channel_info_t structure, |
615 |
|
|
* with the given MIDI port information, or NULL in case of failure. |
616 |
|
|
*/ |
617 |
|
|
lscp_device_channel_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort ) |
618 |
|
|
{ |
619 |
|
|
lscp_device_channel_info_t *pDevChannelInfo = NULL; |
620 |
|
|
|
621 |
|
|
if (pClient == NULL) |
622 |
|
|
return NULL; |
623 |
|
|
if (iMidiDevice < 0) |
624 |
|
|
return NULL; |
625 |
|
|
if (iMidiPort < 0) |
626 |
|
|
return NULL; |
627 |
|
|
|
628 |
|
|
return pDevChannelInfo; |
629 |
|
|
} |
630 |
|
|
|
631 |
|
|
|
632 |
|
|
/** |
633 |
|
|
* Getting informations about specific MIDI port parameter. |
634 |
|
|
* GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
635 |
|
|
* |
636 |
|
|
* @param pClient Pointer to client instance structure. |
637 |
|
|
* @param iMidiDevice MIDI device number identifier. |
638 |
|
|
* @param iMidiPort MIDI port number. |
639 |
|
|
* @param pszParam MIDI port parameter name. |
640 |
|
|
* |
641 |
|
|
* @returns A pointer to a @ref lscp_param_info_t structure, with |
642 |
|
|
* the given MIDI port parameter information, or NULL in case of failure. |
643 |
|
|
*/ |
644 |
|
|
lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam ) |
645 |
|
|
{ |
646 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
647 |
|
|
|
648 |
|
|
if (pClient == NULL) |
649 |
|
|
return NULL; |
650 |
|
|
if (iMidiDevice < 0) |
651 |
|
|
return NULL; |
652 |
|
|
if (iMidiPort < 0) |
653 |
|
|
return NULL; |
654 |
|
|
if (pszParam == NULL) |
655 |
|
|
return NULL; |
656 |
|
|
|
657 |
|
|
return pParamInfo; |
658 |
|
|
} |
659 |
|
|
|
660 |
|
|
|
661 |
|
|
/** |
662 |
|
|
* Changing settings of MIDI input ports. |
663 |
|
|
* SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value> |
664 |
|
|
* |
665 |
|
|
* @param pClient Pointer to client instance structure. |
666 |
|
|
* @param iMidiDevice MIDI device number identifier. |
667 |
|
|
* @param iMidiPort MIDI port number. |
668 |
|
|
* @param pParam Pointer to a key-valued MIDI port parameter. |
669 |
|
|
* |
670 |
|
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
671 |
|
|
*/ |
672 |
|
|
lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam ) |
673 |
|
|
{ |
674 |
|
|
lscp_status_t ret = LSCP_FAILED; |
675 |
|
|
|
676 |
|
|
if (pClient == NULL) |
677 |
|
|
return ret; |
678 |
|
|
if (iMidiDevice < 0) |
679 |
|
|
return ret; |
680 |
|
|
if (iMidiPort < 0) |
681 |
|
|
return ret; |
682 |
|
|
if (pParam == NULL) |
683 |
|
|
return ret; |
684 |
|
|
|
685 |
|
|
return ret; |
686 |
|
|
} |
687 |
|
|
|
688 |
|
|
// end of device.c |
689 |
|
|
|