/[svn]/liblscp/trunk/src/device.c
ViewVC logotype

Annotation of /liblscp/trunk/src/device.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 952 - (hide annotations) (download)
Tue Nov 28 22:46:32 2006 UTC (17 years, 4 months ago) by capela
File MIME type: text/plain
File size: 31274 byte(s)
Code cleanup; preparations for 0.4.1 release (hopefully).

1 capela 107 // device.c
2     //
3     /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API
5 capela 869 Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 107
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 capela 921 You should have received a copy of the GNU General Public License along
18     with this program; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 capela 107
21     *****************************************************************************/
22    
23     #include "common.h"
24    
25    
26     // Local prototypes.
27    
28 capela 163 static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery);
29 capela 171 static lscp_device_info_t *_lscp_device_info_query (lscp_client_t *pClient, lscp_device_info_t *pDeviceInfo, char *pszQuery);
30     static lscp_param_info_t *_lscp_param_info_query (lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, int cchMaxQuery, lscp_param_t *pDepList);
31 capela 107
32 capela 171 static lscp_device_port_info_t *_lscp_device_port_info_query (lscp_client_t *pClient, lscp_device_port_info_t *pDevicePortInfo, char *pszQuery);
33 capela 107
34 capela 171
35 capela 107 //-------------------------------------------------------------------------
36     // Local funtions.
37    
38     // Common driver type query command.
39 capela 163 static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery )
40 capela 107 {
41 capela 952 const char *pszResult;
42     const char *pszSeps = ":";
43     const char *pszCrlf = "\r\n";
44     char *pszToken;
45     char *pch;
46 capela 107
47 capela 952 // Lock this section up.
48     lscp_mutex_lock(pClient->mutex);
49 capela 132
50 capela 952 lscp_driver_info_reset(pDriverInfo);
51     if (lscp_client_call(pClient, pszQuery, 1) == LSCP_OK) {
52     pszResult = lscp_client_get_result(pClient);
53     pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
54     while (pszToken) {
55     if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
56     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
57     if (pszToken)
58     lscp_unquote_dup(&(pDriverInfo->description), &pszToken);
59     }
60     else if (strcasecmp(pszToken, "VERSION") == 0) {
61     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
62     if (pszToken)
63     lscp_unquote_dup(&(pDriverInfo->version), &pszToken);
64     }
65     else if (strcasecmp(pszToken, "PARAMETERS") == 0) {
66     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
67     if (pszToken) {
68     if (pDriverInfo->parameters)
69     lscp_szsplit_destroy(pDriverInfo->parameters);
70     pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");
71     }
72     }
73     pszToken = lscp_strtok(NULL, pszSeps, &(pch));
74     }
75     }
76     else pDriverInfo = NULL;
77    
78     // Unlock this section down.
79     lscp_mutex_unlock(pClient->mutex);
80 capela 107
81 capela 952 return pDriverInfo;
82 capela 107 }
83    
84    
85 capela 171 // Common device info query command.
86     static lscp_device_info_t *_lscp_device_info_query ( lscp_client_t *pClient, lscp_device_info_t *pDeviceInfo, char *pszQuery )
87     {
88 capela 952 const char *pszResult;
89     const char *pszSeps = ":";
90     const char *pszCrlf = "\r\n";
91     char *pszToken;
92     char *pch;
93     char *pszKey;
94 capela 171
95 capela 952 // Lock this section up.
96     lscp_mutex_lock(pClient->mutex);
97 capela 171
98 capela 952 lscp_device_info_reset(pDeviceInfo);
99     if (lscp_client_call(pClient, pszQuery, 1) == LSCP_OK) {
100     pszResult = lscp_client_get_result(pClient);
101     pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
102     while (pszToken) {
103     if (strcasecmp(pszToken, "DRIVER") == 0) {
104     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
105     if (pszToken)
106     lscp_unquote_dup(&(pDeviceInfo->driver), &pszToken);
107     }
108     else {
109     pszKey = pszToken;
110     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
111     if (pszToken)
112     lscp_plist_append(&(pDeviceInfo->params), pszKey, lscp_unquote(&pszToken, 0));
113     }
114     pszToken = lscp_strtok(NULL, pszSeps, &(pch));
115     }
116     }
117     else pDeviceInfo = NULL;
118 capela 171
119 capela 952 // Unlock this section down.
120     lscp_mutex_unlock(pClient->mutex);
121 capela 171
122 capela 952 return pDeviceInfo;
123 capela 171 }
124    
125    
126     // Common device channel/port info query command.
127     static lscp_device_port_info_t *_lscp_device_port_info_query ( lscp_client_t *pClient, lscp_device_port_info_t *pDevicePortInfo, char *pszQuery )
128     {
129 capela 952 const char *pszResult;
130     const char *pszSeps = ":";
131     const char *pszCrlf = "\r\n";
132     char *pszToken;
133     char *pch;
134     char *pszKey;
135 capela 171
136 capela 952 // Lock this section up.
137     lscp_mutex_lock(pClient->mutex);
138 capela 171
139 capela 952 lscp_device_port_info_reset(pDevicePortInfo);
140     if (lscp_client_call(pClient, pszQuery, 1) == LSCP_OK) {
141     pszResult = lscp_client_get_result(pClient);
142     pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
143     while (pszToken) {
144     if (strcasecmp(pszToken, "NAME") == 0) {
145     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
146     if (pszToken)
147     lscp_unquote_dup(&(pDevicePortInfo->name), &pszToken);
148     }
149     else {
150     pszKey = pszToken;
151     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
152     if (pszToken)
153     lscp_plist_append(&(pDevicePortInfo->params), pszKey, lscp_unquote(&pszToken, 0));
154     }
155     pszToken = lscp_strtok(NULL, pszSeps, &(pch));
156     }
157     }
158     else pDevicePortInfo = NULL;
159 capela 171
160 capela 952 // Unlock this section down.
161     lscp_mutex_unlock(pClient->mutex);
162 capela 171
163 capela 952 return pDevicePortInfo;
164 capela 171 }
165    
166    
167 capela 163 // Common parameter info query command.
168 capela 171 static lscp_param_info_t *_lscp_param_info_query ( lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, int cchMaxQuery, lscp_param_t *pDepList )
169 capela 163 {
170 capela 952 const char *pszResult;
171     const char *pszSeps = ":";
172     const char *pszCrlf = "\r\n";
173     char *pszToken;
174     char *pch;
175 capela 163
176 capela 952 // Lock this section up.
177     lscp_mutex_lock(pClient->mutex);
178 capela 163
179 capela 952 lscp_param_info_reset(pParamInfo);
180     lscp_param_concat(pszQuery, cchMaxQuery, pDepList);
181     if (lscp_client_call(pClient, pszQuery, 1) == LSCP_OK) {
182     pszResult = lscp_client_get_result(pClient);
183     pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
184     while (pszToken) {
185     if (strcasecmp(pszToken, "TYPE") == 0) {
186     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
187     if (pszToken) {
188     pszToken = lscp_unquote(&pszToken, 0);
189     if (strcasecmp(pszToken, "BOOL") == 0)
190     pParamInfo->type = LSCP_TYPE_BOOL;
191     else if (strcasecmp(pszToken, "INT") == 0)
192     pParamInfo->type = LSCP_TYPE_INT;
193     else if (strcasecmp(pszToken, "FLOAT") == 0)
194     pParamInfo->type = LSCP_TYPE_FLOAT;
195     else if (strcasecmp(pszToken, "STRING") == 0)
196     pParamInfo->type = LSCP_TYPE_STRING;
197     }
198     }
199     else if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
200     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
201     if (pszToken)
202     lscp_unquote_dup(&(pParamInfo->description), &pszToken);
203     }
204     else if (strcasecmp(pszToken, "MANDATORY") == 0) {
205     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
206     if (pszToken)
207     pParamInfo->mandatory = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
208     }
209     else if (strcasecmp(pszToken, "FIX") == 0) {
210     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
211     if (pszToken)
212     pParamInfo->fix = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
213     }
214     else if (strcasecmp(pszToken, "MULTIPLICITY") == 0) {
215     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
216     if (pszToken)
217     pParamInfo->multiplicity = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
218     }
219     else if (strcasecmp(pszToken, "DEPENDS") == 0) {
220     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
221     if (pszToken) {
222     if (pParamInfo->depends)
223     lscp_szsplit_destroy(pParamInfo->depends);
224     pParamInfo->depends = lscp_szsplit_create(pszToken, ",");
225     }
226     }
227     else if (strcasecmp(pszToken, "DEFAULT") == 0) {
228     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
229     if (pszToken)
230     lscp_unquote_dup(&(pParamInfo->defaultv), &pszToken);
231     }
232     else if (strcasecmp(pszToken, "RANGE_MIN") == 0) {
233     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
234     if (pszToken)
235     lscp_unquote_dup(&(pParamInfo->range_min), &pszToken);
236     }
237     else if (strcasecmp(pszToken, "RANGE_MAX") == 0) {
238     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
239     if (pszToken)
240     lscp_unquote_dup(&(pParamInfo->range_max), &pszToken);
241     }
242     else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) {
243     pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
244     if (pszToken) {
245     if (pParamInfo->possibilities)
246     lscp_szsplit_destroy(pParamInfo->possibilities);
247     pParamInfo->possibilities = lscp_szsplit_create(pszToken, ",");
248     }
249     }
250     pszToken = lscp_strtok(NULL, pszSeps, &(pch));
251     }
252     }
253     else pParamInfo = NULL;
254 capela 163
255 capela 952 // Unlock this section down.
256     lscp_mutex_unlock(pClient->mutex);
257 capela 163
258 capela 952 return pParamInfo;
259 capela 163 }
260    
261    
262 capela 107 //-------------------------------------------------------------------------
263     // Audio driver control functions.
264    
265     /**
266 capela 523 * Getting all available audio output driver count.
267 capela 107 * GET AVAILABLE_AUDIO_OUTPUT_DRIVERS
268     *
269     * @param pClient Pointer to client instance structure.
270     *
271 capela 523 * @returns The current total number of audio output drivers on success,
272     * -1 otherwise.
273     */
274     int lscp_get_available_audio_drivers ( lscp_client_t *pClient )
275     {
276 capela 952 int iAudioDrivers = -1;
277 capela 523
278 capela 952 // Lock this section up.
279     lscp_mutex_lock(pClient->mutex);
280 capela 523
281 capela 952 if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n", 0) == LSCP_OK)
282     iAudioDrivers = atoi(lscp_client_get_result(pClient));
283 capela 523
284 capela 952 // Unlock this section down.
285     lscp_mutex_unlock(pClient->mutex);
286 capela 523
287 capela 952 return iAudioDrivers;
288 capela 523 }
289    
290    
291     /**
292     * Getting all available audio output drivers.
293     * LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS
294     *
295     * @param pClient Pointer to client instance structure.
296     *
297 capela 107 * @returns A NULL terminated array of audio output driver type
298     * name strings, or NULL in case of failure.
299     */
300 capela 523 const char ** lscp_list_available_audio_drivers ( lscp_client_t *pClient )
301 capela 107 {
302 capela 952 const char *pszSeps = ",";
303 capela 107
304 capela 952 // Lock this section up.
305     lscp_mutex_lock(pClient->mutex);
306 capela 132
307 capela 952 if (pClient->audio_drivers) {
308     lscp_szsplit_destroy(pClient->audio_drivers);
309     pClient->audio_drivers = NULL;
310     }
311 capela 107
312 capela 952 if (lscp_client_call(pClient, "LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n", 0) == LSCP_OK)
313     pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
314 capela 107
315 capela 952 // Unlock this section down.
316     lscp_mutex_unlock(pClient->mutex);
317 capela 132
318 capela 952 return (const char **) pClient->audio_drivers;
319 capela 107 }
320    
321    
322     /**
323     * Getting informations about a specific audio output driver.
324     * GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type>
325     *
326     * @param pClient Pointer to client instance structure.
327     * @param pszAudioDriver Audio driver type string (e.g. "ALSA").
328     *
329     * @returns A pointer to a @ref lscp_driver_info_t structure, with
330     * the given audio driver information, or NULL in case of failure.
331     */
332     lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver )
333     {
334 capela 952 char szQuery[LSCP_BUFSIZ];
335 capela 107
336 capela 952 if (pszAudioDriver == NULL)
337     return NULL;
338 capela 107
339 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);
340     return _lscp_driver_info_query(pClient, &(pClient->audio_driver_info), szQuery);
341 capela 107 }
342    
343    
344     /**
345     * Getting informations about specific audio output driver parameter.
346     * GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>]
347     *
348     * @param pClient Pointer to client instance structure.
349     * @param pszAudioDriver Audio driver type string (e.g. "ALSA").
350     * @param pszParam Audio driver parameter name.
351     * @param pDepList Pointer to specific dependencies parameter list.
352     *
353     * @returns A pointer to a @ref lscp_param_info_t structure, with
354     * the given audio driver parameter information, or NULL in case of failure.
355     */
356     lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList )
357     {
358 capela 952 char szQuery[LSCP_BUFSIZ];
359 capela 107
360 capela 952 if (pClient == NULL)
361     return NULL;
362     if (pszAudioDriver == NULL)
363     return NULL;
364     if (pszParam == NULL)
365     return NULL;
366 capela 107
367 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s", pszAudioDriver, pszParam);
368     return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, sizeof(szQuery), pDepList);
369 capela 107 }
370    
371    
372     //-------------------------------------------------------------------------
373     // Audio device control functions.
374    
375     /**
376     * Creating an audio output device.
377     * CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>]
378     *
379     * @param pClient Pointer to client instance structure.
380     * @param pszAudioDriver Audio driver type string (e.g. "ALSA").
381     * @param pParams Pointer to specific parameter list.
382     *
383     * @returns The new audio device number identifier on success,
384     * or -1 in case of failure.
385     */
386     int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams )
387     {
388 capela 952 char szQuery[LSCP_BUFSIZ];
389     int iAudioDevice = -1;
390 capela 107
391 capela 952 if (pClient == NULL)
392     return iAudioDevice;
393     if (pszAudioDriver == NULL)
394     return iAudioDevice;
395 capela 107
396 capela 952 // Lock this section up.
397     lscp_mutex_lock(pClient->mutex);
398 capela 171
399 capela 952 sprintf(szQuery, "CREATE AUDIO_OUTPUT_DEVICE %s", pszAudioDriver);
400     lscp_param_concat(szQuery, sizeof(szQuery), pParams);
401     if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
402     iAudioDevice = atoi(lscp_client_get_result(pClient));
403 capela 171
404 capela 952 // Unlock this section down.
405     lscp_mutex_unlock(pClient->mutex);
406 capela 171
407 capela 952 return iAudioDevice;
408 capela 107 }
409    
410    
411     /**
412     * Destroying an audio output device.
413     * DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id>
414     *
415     * @param pClient Pointer to client instance structure.
416     * @param iAudioDevice Audio device number identifier.
417     *
418     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
419     */
420     lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice )
421     {
422 capela 952 lscp_status_t ret = LSCP_FAILED;
423     char szQuery[LSCP_BUFSIZ];
424 capela 107
425 capela 952 if (pClient == NULL)
426     return ret;
427     if (iAudioDevice < 0)
428     return ret;
429 capela 107
430 capela 952 sprintf(szQuery, "DESTROY AUDIO_OUTPUT_DEVICE %d\r\n", iAudioDevice);
431     return lscp_client_query(pClient, szQuery);
432 capela 107 }
433    
434    
435     /**
436 capela 125 * Getting all created audio output device count.
437 capela 107 * GET AUDIO_OUTPUT_DEVICES
438     *
439     * @param pClient Pointer to client instance structure.
440     *
441 capela 125 * @returns The current total number of audio devices on success,
442     * -1 otherwise.
443     */
444     int lscp_get_audio_devices ( lscp_client_t *pClient )
445     {
446 capela 952 int iAudioDevices = -1;
447 capela 132
448 capela 952 // Lock this section up.
449     lscp_mutex_lock(pClient->mutex);
450 capela 132
451 capela 952 if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n", 0) == LSCP_OK)
452     iAudioDevices = atoi(lscp_client_get_result(pClient));
453 capela 132
454 capela 952 // Unlock this section down.
455     lscp_mutex_unlock(pClient->mutex);
456 capela 132
457 capela 952 return iAudioDevices;
458 capela 125 }
459    
460    
461     /**
462     * Getting all created audio output device list.
463     * LIST AUDIO_OUTPUT_DEVICES
464     *
465     * @param pClient Pointer to client instance structure.
466     *
467 capela 107 * @returns An array of audio device number identifiers,
468     * terminated with -1 on success, or NULL in case of failure.
469     */
470 capela 125 int *lscp_list_audio_devices ( lscp_client_t *pClient )
471 capela 107 {
472 capela 952 const char *pszSeps = ",";
473 capela 107
474 capela 952 if (pClient == NULL)
475     return NULL;
476 capela 107
477 capela 952 // Lock this section up.
478     lscp_mutex_lock(pClient->mutex);
479 capela 132
480 capela 952 if (pClient->audio_devices) {
481     lscp_isplit_destroy(pClient->audio_devices);
482     pClient->audio_devices = NULL;
483     }
484 capela 125
485 capela 952 if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n", 0) == LSCP_OK)
486     pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
487 capela 125
488 capela 952 // Unlock this section down.
489     lscp_mutex_unlock(pClient->mutex);
490 capela 132
491 capela 952 return pClient->audio_devices;
492 capela 107 }
493    
494    
495     /**
496     * Getting current settings of an audio output device.
497     * GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id>
498     *
499     * @param pClient Pointer to client instance structure.
500     * @param iAudioDevice Audio device number identifier.
501     *
502     * @returns A pointer to a @ref lscp_device_info_t structure, with
503     * the given audio device information, or NULL in case of failure.
504     */
505     lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice )
506     {
507 capela 952 char szQuery[LSCP_BUFSIZ];
508 capela 107
509 capela 952 if (pClient == NULL)
510     return NULL;
511     if (iAudioDevice < 0)
512     return NULL;
513 capela 107
514 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_DEVICE INFO %d\r\n", iAudioDevice);
515     return _lscp_device_info_query(pClient, &(pClient->audio_device_info), szQuery);
516 capela 107 }
517    
518    
519     /**
520     * Changing settings of audio output devices.
521 capela 171 * SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param>=<value>
522 capela 107 *
523     * @param pClient Pointer to client instance structure.
524     * @param iAudioDevice Audio device number identifier.
525     * @param pParam Pointer to a key-valued audio device parameter.
526     *
527     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
528     */
529     lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam )
530     {
531 capela 952 char szQuery[LSCP_BUFSIZ];
532 capela 107
533 capela 952 if (pClient == NULL)
534     return LSCP_FAILED;
535     if (iAudioDevice < 0)
536     return LSCP_FAILED;
537     if (pParam == NULL)
538     return LSCP_FAILED;
539 capela 107
540 capela 952 sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iAudioDevice, pParam->key, pParam->value);
541     return lscp_client_query(pClient, szQuery);
542 capela 107 }
543    
544    
545     /**
546     * Getting informations about an audio channel.
547     * GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel>
548     *
549     * @param pClient Pointer to client instance structure.
550     * @param iAudioDevice Audio device number identifier.
551     * @param iAudioChannel Audio channel number.
552     *
553 capela 171 * @returns A pointer to a @ref lscp_device_port_info_t structure,
554 capela 107 * with the given audio channel information, or NULL in case of failure.
555     */
556 capela 171 lscp_device_port_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
557 capela 107 {
558 capela 952 char szQuery[LSCP_BUFSIZ];
559 capela 107
560 capela 952 if (pClient == NULL)
561     return NULL;
562     if (iAudioDevice < 0)
563     return NULL;
564     if (iAudioChannel < 0)
565     return NULL;
566 capela 107
567 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL INFO %d %d\r\n", iAudioDevice, iAudioChannel);
568     return _lscp_device_port_info_query(pClient, &(pClient->audio_channel_info), szQuery);
569 capela 107 }
570    
571    
572     /**
573     * Getting informations about specific audio channel parameter.
574     * GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param>
575     *
576     * @param pClient Pointer to client instance structure.
577     * @param iAudioDevice Audio device number identifier.
578     * @param iAudioChannel Audio channel number.
579     * @param pszParam Audio channel parameter name.
580     *
581     * @returns A pointer to a @ref lscp_param_info_t structure, with
582     * the given audio channel parameter information, or NULL in case of failure.
583     */
584     lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam )
585     {
586 capela 952 char szQuery[LSCP_BUFSIZ];
587 capela 107
588 capela 952 if (pClient == NULL)
589     return NULL;
590     if (iAudioDevice < 0)
591     return NULL;
592     if (iAudioChannel < 0)
593     return NULL;
594     if (pszParam == NULL)
595     return NULL;
596 capela 107
597 capela 952 sprintf(szQuery, "GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO %d %d %s", iAudioDevice, iAudioChannel, pszParam);
598     return _lscp_param_info_query(pClient, &(pClient->audio_channel_param_info), szQuery, sizeof(szQuery), NULL);
599 capela 107 }
600    
601    
602     /**
603     * Changing settings of audio output channels.
604     * SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value>
605     *
606     * @param pClient Pointer to client instance structure.
607     * @param iAudioDevice Audio device number identifier.
608     * @param iAudioChannel Audio channel number.
609     * @param pParam Pointer to a key-valued audio channel parameter.
610     *
611     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
612     */
613     lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam )
614     {
615 capela 952 char szQuery[LSCP_BUFSIZ];
616 capela 107
617 capela 952 if (pClient == NULL)
618     return LSCP_FAILED;
619     if (iAudioDevice < 0)
620     return LSCP_FAILED;
621     if (iAudioChannel < 0)
622     return LSCP_FAILED;
623     if (pParam == NULL)
624     return LSCP_FAILED;
625 capela 107
626 capela 952 sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d %s='%s'\r\n", iAudioDevice, iAudioChannel, pParam->key, pParam->value);
627     return lscp_client_query(pClient, szQuery);
628 capela 107 }
629    
630    
631     //-------------------------------------------------------------------------
632     // MIDI driver control functions.
633    
634     /**
635 capela 523 * Getting all available MIDI input driver count.
636 capela 107 * GET AVAILABLE_MIDI_INPUT_DRIVERS
637     *
638     * @param pClient Pointer to client instance structure.
639     *
640 capela 523 * @returns The current total number of MIDI input drivers on success,
641     * -1 otherwise.
642     */
643     int lscp_get_available_midi_drivers ( lscp_client_t *pClient )
644     {
645 capela 952 int iMidiDrivers = -1;
646 capela 523
647 capela 952 // Lock this section up.
648     lscp_mutex_lock(pClient->mutex);
649 capela 523
650 capela 952 if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n", 0) == LSCP_OK)
651     iMidiDrivers = atoi(lscp_client_get_result(pClient));
652 capela 523
653 capela 952 // Unlock this section up.
654     lscp_mutex_unlock(pClient->mutex);
655 capela 523
656 capela 952 return iMidiDrivers;
657 capela 523 }
658    
659    
660     /**
661     * Getting all available MIDI input drivers.
662     * LIST AVAILABLE_MIDI_INPUT_DRIVERS
663     *
664     * @param pClient Pointer to client instance structure.
665     *
666 capela 107 * @returns A NULL terminated array of MIDI input driver type
667     * name strings, or NULL in case of failure.
668     */
669 capela 523 const char** lscp_list_available_midi_drivers ( lscp_client_t *pClient )
670 capela 107 {
671 capela 952 const char *pszSeps = ",";
672 capela 107
673 capela 952 // Lock this section up.
674     lscp_mutex_lock(pClient->mutex);
675 capela 132
676 capela 952 if (pClient->midi_drivers) {
677     lscp_szsplit_destroy(pClient->midi_drivers);
678     pClient->midi_drivers = NULL;
679     }
680 capela 107
681 capela 952 if (lscp_client_call(pClient, "LIST AVAILABLE_MIDI_INPUT_DRIVERS\r\n", 0) == LSCP_OK)
682     pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
683 capela 107
684 capela 952 // Unlock this section up.
685     lscp_mutex_unlock(pClient->mutex);
686 capela 132
687 capela 952 return (const char **) pClient->midi_drivers;
688 capela 107 }
689    
690    
691     /**
692     * Getting informations about a specific MIDI input driver.
693     * GET MIDI_INPUT_DRIVER INFO <midi-input-type>
694     *
695     * @param pClient Pointer to client instance structure.
696     * @param pszMidiDriver MIDI driver type string (e.g. "ALSA").
697     *
698     * @returns A pointer to a @ref lscp_driver_info_t structure, with
699     * the given MIDI driver information, or NULL in case of failure.
700     */
701     lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver )
702     {
703 capela 952 char szQuery[LSCP_BUFSIZ];
704 capela 107
705 capela 952 if (pszMidiDriver == NULL)
706     return NULL;
707 capela 107
708 capela 952 sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);
709     return _lscp_driver_info_query(pClient, &(pClient->midi_driver_info), szQuery);
710 capela 107 }
711    
712    
713     /**
714     * Getting informations about specific MIDI input driver parameter.
715     * GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>]
716     *
717     * @param pClient Pointer to client instance structure.
718     * @param pszMidiDriver MIDI driver type string (e.g. "ALSA").
719     * @param pszParam MIDI driver parameter name.
720     * @param pDepList Pointer to specific dependencies parameter list.
721     *
722     * @returns A pointer to a @ref lscp_param_info_t structure, with
723     * the given MIDI driver parameter information, or NULL in case of failure.
724     *
725     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
726     */
727     lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList )
728     {
729 capela 952 char szQuery[LSCP_BUFSIZ];
730 capela 107
731 capela 952 if (pClient == NULL)
732     return NULL;
733     if (pszMidiDriver == NULL)
734     return NULL;
735     if (pszParam == NULL)
736     return NULL;
737 capela 107
738 capela 952 sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s", pszMidiDriver, pszParam);
739     return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, sizeof(szQuery), pDepList);
740 capela 107 }
741    
742    
743     //-------------------------------------------------------------------------
744     // MIDI device control functions.
745    
746     /**
747     * Creating a MIDI input device.
748     * CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>]
749     *
750     * @param pClient Pointer to client instance structure.
751     * @param pszMidiDriver MIDI driver type string (e.g. "ALSA").
752     * @param pParams Pointer to specific parameter list.
753     *
754     * @returns The new audio device number identifier on success,
755     * or -1 in case of failure.
756     */
757     int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams )
758     {
759 capela 952 char szQuery[LSCP_BUFSIZ];
760     int iMidiDevice = -1;
761 capela 107
762 capela 952 if (pClient == NULL)
763     return iMidiDevice;
764     if (pszMidiDriver == NULL)
765     return iMidiDevice;
766 capela 107
767 capela 952 // Lock this section up.
768     lscp_mutex_lock(pClient->mutex);
769 capela 171
770 capela 952 sprintf(szQuery, "CREATE MIDI_INPUT_DEVICE %s", pszMidiDriver);
771     lscp_param_concat(szQuery, sizeof(szQuery), pParams);
772     if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK)
773     iMidiDevice = atoi(lscp_client_get_result(pClient));
774 capela 171
775 capela 952 // Unlock this section down.
776     lscp_mutex_unlock(pClient->mutex);
777 capela 171
778 capela 952 return iMidiDevice;
779 capela 107 }
780    
781    
782     /**
783     * Destroying a MIDI input device.
784     * DESTROY MIDI_INPUT_DEVICE <midi-device-id>
785     *
786     * @param pClient Pointer to client instance structure.
787     * @param iMidiDevice MIDI device number identifier.
788     *
789     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
790     */
791     lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice )
792     {
793 capela 952 lscp_status_t ret = LSCP_FAILED;
794     char szQuery[LSCP_BUFSIZ];
795 capela 107
796 capela 952 if (pClient == NULL)
797     return ret;
798     if (iMidiDevice < 0)
799     return ret;
800 capela 107
801 capela 952 sprintf(szQuery, "DESTROY MIDI_INPUT_DEVICE %d\r\n", iMidiDevice);
802     return lscp_client_query(pClient, szQuery);
803 capela 107 }
804    
805    
806     /**
807 capela 125 * Getting all created MIDI intput device count.
808 capela 107 * GET MIDI_INPUT_DEVICES
809     *
810     * @param pClient Pointer to client instance structure.
811     *
812 capela 125 * @returns The current total number of MIDI devices on success,
813     * -1 otherwise.
814     */
815     int lscp_get_midi_devices ( lscp_client_t *pClient )
816     {
817 capela 952 int iMidiDevices = -1;
818 capela 132
819 capela 952 // Lock this section up.
820     lscp_mutex_lock(pClient->mutex);
821 capela 132
822 capela 952 if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n", 0) == LSCP_OK)
823     iMidiDevices = atoi(lscp_client_get_result(pClient));
824    
825     // Unlock this section down.
826     lscp_mutex_unlock(pClient->mutex);
827 capela 132
828 capela 952 return iMidiDevices;
829 capela 125 }
830    
831    
832     /**
833     * Getting all created MIDI intput device list.
834     * LIST MIDI_INPUT_DEVICES
835     *
836     * @param pClient Pointer to client instance structure.
837     *
838 capela 107 * @returns An array of MIDI device number identifiers,
839     * terminated with -1 on success, or NULL in case of failure.
840     */
841 capela 125 int *lscp_list_midi_devices ( lscp_client_t *pClient )
842 capela 107 {
843 capela 952 const char *pszSeps = ",";
844 capela 107
845 capela 952 if (pClient == NULL)
846     return NULL;
847 capela 107
848 capela 952 // Lock this section up.
849     lscp_mutex_lock(pClient->mutex);
850 capela 132
851 capela 952 if (pClient->midi_devices) {
852     lscp_isplit_destroy(pClient->midi_devices);
853     pClient->midi_devices = NULL;
854     }
855 capela 125
856 capela 952 if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n", 0) == LSCP_OK)
857     pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
858 capela 125
859 capela 952 // Unlock this section down.
860     lscp_mutex_unlock(pClient->mutex);
861 capela 132
862 capela 952 return pClient->midi_devices;
863 capela 107 }
864    
865    
866     /**
867     * Getting current settings of a MIDI input device.
868     * GET MIDI_INPUT_DEVICE INFO <midi-device-id>
869     *
870     * @param pClient Pointer to client instance structure.
871     * @param iMidiDevice MIDI device number identifier.
872     *
873     * @returns A pointer to a @ref lscp_device_info_t structure, with
874     * the given MIDI device information, or NULL in case of failure.
875     */
876     lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice )
877     {
878 capela 952 char szQuery[LSCP_BUFSIZ];
879 capela 107
880 capela 952 if (pClient == NULL)
881     return NULL;
882     if (iMidiDevice < 0)
883     return NULL;
884 capela 107
885 capela 952 sprintf(szQuery, "GET MIDI_INPUT_DEVICE INFO %d\r\n", iMidiDevice);
886     return _lscp_device_info_query(pClient, &(pClient->midi_device_info), szQuery);
887 capela 107 }
888    
889    
890     /**
891     * Changing settings of MIDI input devices.
892 capela 171 * SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param>=<value>
893 capela 107 *
894     * @param pClient Pointer to client instance structure.
895     * @param iMidiDevice MIDI device number identifier.
896     * @param pParam Pointer to a key-valued MIDI device parameter.
897     *
898     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
899     */
900     lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam )
901     {
902 capela 952 char szQuery[LSCP_BUFSIZ];
903 capela 107
904 capela 952 if (pClient == NULL)
905     return LSCP_FAILED;
906     if (iMidiDevice < 0)
907     return LSCP_FAILED;
908     if (pParam == NULL)
909     return LSCP_FAILED;
910 capela 107
911 capela 952 sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iMidiDevice, pParam->key, pParam->value);
912     return lscp_client_query(pClient, szQuery);
913 capela 107 }
914    
915    
916     /**
917     * Getting informations about a MIDI port.
918     * GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port>
919     *
920     * @param pClient Pointer to client instance structure.
921     * @param iMidiDevice MIDI device number identifier.
922     * @param iMidiPort MIDI port number.
923     *
924 capela 171 * @returns A pointer to a @ref lscp_device_port_info_t structure,
925 capela 107 * with the given MIDI port information, or NULL in case of failure.
926     */
927 capela 171 lscp_device_port_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
928 capela 107 {
929 capela 952 char szQuery[LSCP_BUFSIZ];
930 capela 107
931 capela 952 if (pClient == NULL)
932     return NULL;
933     if (iMidiDevice < 0)
934     return NULL;
935     if (iMidiPort < 0)
936     return NULL;
937 capela 107
938 capela 952 sprintf(szQuery, "GET MIDI_INPUT_PORT INFO %d %d\r\n", iMidiDevice, iMidiPort);
939     return _lscp_device_port_info_query(pClient, &(pClient->midi_port_info), szQuery);
940 capela 107 }
941    
942    
943     /**
944     * Getting informations about specific MIDI port parameter.
945     * GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param>
946     *
947     * @param pClient Pointer to client instance structure.
948     * @param iMidiDevice MIDI device number identifier.
949     * @param iMidiPort MIDI port number.
950     * @param pszParam MIDI port parameter name.
951     *
952     * @returns A pointer to a @ref lscp_param_info_t structure, with
953     * the given MIDI port parameter information, or NULL in case of failure.
954     */
955     lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam )
956     {
957 capela 952 char szQuery[LSCP_BUFSIZ];
958 capela 107
959 capela 952 if (pClient == NULL)
960     return NULL;
961     if (iMidiDevice < 0)
962     return NULL;
963     if (iMidiPort < 0)
964     return NULL;
965     if (pszParam == NULL)
966     return NULL;
967 capela 107
968 capela 952 sprintf(szQuery, "GET MIDI_INPUT_PORT_PARAMETER INFO %d %d %s", iMidiDevice, iMidiPort, pszParam);
969     return _lscp_param_info_query(pClient, &(pClient->midi_port_param_info), szQuery, sizeof(szQuery), NULL);
970 capela 107 }
971    
972    
973     /**
974     * Changing settings of MIDI input ports.
975     * SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value>
976     *
977     * @param pClient Pointer to client instance structure.
978     * @param iMidiDevice MIDI device number identifier.
979     * @param iMidiPort MIDI port number.
980     * @param pParam Pointer to a key-valued MIDI port parameter.
981     *
982     * @returns LSCP_OK on success, LSCP_FAILED otherwise.
983     */
984     lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam )
985     {
986 capela 952 char szQuery[LSCP_BUFSIZ];
987 capela 107
988 capela 952 if (pClient == NULL)
989     return LSCP_FAILED;
990     if (iMidiDevice < 0)
991     return LSCP_FAILED;
992     if (iMidiPort < 0)
993     return LSCP_FAILED;
994     if (pParam == NULL)
995     return LSCP_FAILED;
996 capela 107
997 capela 952 sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d %s='%s'\r\n", iMidiDevice, iMidiPort, pParam->key, pParam->value);
998     return lscp_client_query(pClient, szQuery);
999 capela 107 }
1000    
1001 capela 189
1002     //-------------------------------------------------------------------------
1003     // Generic parameter list functions.
1004    
1005     const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam )
1006     {
1007 capela 952 int i;
1008 capela 449
1009 capela 952 for (i = 0; pParams && pParams[i].key; i++) {
1010     if (strcasecmp(pParams[i].key, pszParam) == 0)
1011     return (const char *) pParams[i].value;
1012     }
1013     return NULL;
1014 capela 189 }
1015    
1016    
1017 capela 107 // end of device.c
1018    

  ViewVC Help
Powered by ViewVC