2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
liblscp - LinuxSampler Control Protocol API |
liblscp - LinuxSampler Control Protocol API |
5 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This library is free software; you can redistribute it and/or |
This library is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU Lesser General Public |
modify it under the terms of the GNU Lesser General Public |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
Lesser General Public License for more details. |
Lesser General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU Lesser General Public |
You should have received a copy of the GNU General Public License along |
18 |
License along with this library; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
55 |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
56 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
57 |
if (pszToken) |
if (pszToken) |
58 |
pDriverInfo->description = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pDriverInfo->description), &pszToken); |
59 |
} |
} |
60 |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
61 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
62 |
if (pszToken) |
if (pszToken) |
63 |
pDriverInfo->version = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pDriverInfo->version), &pszToken); |
64 |
} |
} |
65 |
else if (strcasecmp(pszToken, "PARAMETERS") == 0) { |
else if (strcasecmp(pszToken, "PARAMETERS") == 0) { |
66 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
67 |
if (pszToken) |
if (pszToken) { |
68 |
|
if (pDriverInfo->parameters) |
69 |
|
lscp_szsplit_destroy(pDriverInfo->parameters); |
70 |
pDriverInfo->parameters = lscp_szsplit_create(pszToken, ","); |
pDriverInfo->parameters = lscp_szsplit_create(pszToken, ","); |
71 |
|
} |
72 |
} |
} |
73 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
74 |
} |
} |
75 |
} |
} |
76 |
|
else pDriverInfo = NULL; |
77 |
|
|
78 |
// Unlock this section down. |
// Unlock this section down. |
79 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
103 |
if (strcasecmp(pszToken, "DRIVER") == 0) { |
if (strcasecmp(pszToken, "DRIVER") == 0) { |
104 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
105 |
if (pszToken) |
if (pszToken) |
106 |
pDeviceInfo->driver = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pDeviceInfo->driver), &pszToken); |
107 |
} |
} |
108 |
else { |
else { |
109 |
pszKey = pszToken; |
pszKey = pszToken; |
114 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
115 |
} |
} |
116 |
} |
} |
117 |
|
else pDeviceInfo = NULL; |
118 |
|
|
119 |
// Unlock this section down. |
// Unlock this section down. |
120 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
144 |
if (strcasecmp(pszToken, "NAME") == 0) { |
if (strcasecmp(pszToken, "NAME") == 0) { |
145 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
146 |
if (pszToken) |
if (pszToken) |
147 |
pDevicePortInfo->name = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pDevicePortInfo->name), &pszToken); |
148 |
} |
} |
149 |
else { |
else { |
150 |
pszKey = pszToken; |
pszKey = pszToken; |
155 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
156 |
} |
} |
157 |
} |
} |
158 |
|
else pDevicePortInfo = NULL; |
159 |
|
|
160 |
// Unlock this section down. |
// Unlock this section down. |
161 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
199 |
else if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
else if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
200 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
201 |
if (pszToken) |
if (pszToken) |
202 |
pParamInfo->description = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pParamInfo->description), &pszToken); |
203 |
} |
} |
204 |
else if (strcasecmp(pszToken, "MANDATORY") == 0) { |
else if (strcasecmp(pszToken, "MANDATORY") == 0) { |
205 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
218 |
} |
} |
219 |
else if (strcasecmp(pszToken, "DEPENDS") == 0) { |
else if (strcasecmp(pszToken, "DEPENDS") == 0) { |
220 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
221 |
if (pszToken) |
if (pszToken) { |
222 |
|
if (pParamInfo->depends) |
223 |
|
lscp_szsplit_destroy(pParamInfo->depends); |
224 |
pParamInfo->depends = lscp_szsplit_create(pszToken, ","); |
pParamInfo->depends = lscp_szsplit_create(pszToken, ","); |
225 |
|
} |
226 |
} |
} |
227 |
else if (strcasecmp(pszToken, "DEFAULT") == 0) { |
else if (strcasecmp(pszToken, "DEFAULT") == 0) { |
228 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
229 |
if (pszToken) |
if (pszToken) |
230 |
pParamInfo->defaultv = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pParamInfo->defaultv), &pszToken); |
231 |
} |
} |
232 |
else if (strcasecmp(pszToken, "RANGE_MIN") == 0) { |
else if (strcasecmp(pszToken, "RANGE_MIN") == 0) { |
233 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
234 |
if (pszToken) |
if (pszToken) |
235 |
pParamInfo->range_min = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pParamInfo->range_min), &pszToken); |
236 |
} |
} |
237 |
else if (strcasecmp(pszToken, "RANGE_MAX") == 0) { |
else if (strcasecmp(pszToken, "RANGE_MAX") == 0) { |
238 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
239 |
if (pszToken) |
if (pszToken) |
240 |
pParamInfo->range_max = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pParamInfo->range_max), &pszToken); |
241 |
} |
} |
242 |
else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) { |
else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) { |
243 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
244 |
if (pszToken) |
if (pszToken) { |
245 |
|
if (pParamInfo->possibilities) |
246 |
|
lscp_szsplit_destroy(pParamInfo->possibilities); |
247 |
pParamInfo->possibilities = lscp_szsplit_create(pszToken, ","); |
pParamInfo->possibilities = lscp_szsplit_create(pszToken, ","); |
248 |
|
} |
249 |
} |
} |
250 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
251 |
} |
} |
252 |
} |
} |
253 |
|
else pParamInfo = NULL; |
254 |
|
|
255 |
// Unlock this section down. |
// Unlock this section down. |
256 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
263 |
// Audio driver control functions. |
// Audio driver control functions. |
264 |
|
|
265 |
/** |
/** |
266 |
* Getting all available audio output drivers. |
* Getting all available audio output driver count. |
267 |
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
* GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
268 |
* |
* |
269 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
270 |
* |
* |
271 |
|
* @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 |
|
int iAudioDrivers = -1; |
277 |
|
|
278 |
|
// Lock this section up. |
279 |
|
lscp_mutex_lock(pClient->mutex); |
280 |
|
|
281 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
282 |
|
iAudioDrivers = atoi(lscp_client_get_result(pClient)); |
283 |
|
|
284 |
|
// Unlock this section down. |
285 |
|
lscp_mutex_unlock(pClient->mutex); |
286 |
|
|
287 |
|
return iAudioDrivers; |
288 |
|
} |
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 |
* @returns A NULL terminated array of audio output driver type |
* @returns A NULL terminated array of audio output driver type |
298 |
* name strings, or NULL in case of failure. |
* name strings, or NULL in case of failure. |
299 |
*/ |
*/ |
300 |
const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient ) |
const char ** lscp_list_available_audio_drivers ( lscp_client_t *pClient ) |
301 |
{ |
{ |
302 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
303 |
|
|
309 |
pClient->audio_drivers = NULL; |
pClient->audio_drivers = NULL; |
310 |
} |
} |
311 |
|
|
312 |
if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK) |
313 |
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
314 |
|
|
315 |
// Unlock this section down. |
// Unlock this section down. |
537 |
if (pParam == NULL) |
if (pParam == NULL) |
538 |
return LSCP_FAILED; |
return LSCP_FAILED; |
539 |
|
|
540 |
sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d", iAudioDevice); |
sprintf(szQuery, "SET AUDIO_OUTPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iAudioDevice, pParam->key, pParam->value); |
|
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
|
541 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
542 |
} |
} |
543 |
|
|
623 |
if (pParam == NULL) |
if (pParam == NULL) |
624 |
return LSCP_FAILED; |
return LSCP_FAILED; |
625 |
|
|
626 |
sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d", iAudioDevice, iAudioChannel); |
sprintf(szQuery, "SET AUDIO_OUTPUT_CHANNEL_PARAMETER %d %d %s='%s'\r\n", iAudioDevice, iAudioChannel, pParam->key, pParam->value); |
|
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
|
627 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
628 |
} |
} |
629 |
|
|
632 |
// MIDI driver control functions. |
// MIDI driver control functions. |
633 |
|
|
634 |
/** |
/** |
635 |
* Getting all available MIDI input drivers. |
* Getting all available MIDI input driver count. |
636 |
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
* GET AVAILABLE_MIDI_INPUT_DRIVERS |
637 |
* |
* |
638 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
639 |
* |
* |
640 |
|
* @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 |
|
int iMidiDrivers = -1; |
646 |
|
|
647 |
|
// Lock this section up. |
648 |
|
lscp_mutex_lock(pClient->mutex); |
649 |
|
|
650 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
651 |
|
iMidiDrivers = atoi(lscp_client_get_result(pClient)); |
652 |
|
|
653 |
|
// Unlock this section up. |
654 |
|
lscp_mutex_unlock(pClient->mutex); |
655 |
|
|
656 |
|
return iMidiDrivers; |
657 |
|
} |
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 |
* @returns A NULL terminated array of MIDI input driver type |
* @returns A NULL terminated array of MIDI input driver type |
667 |
* name strings, or NULL in case of failure. |
* name strings, or NULL in case of failure. |
668 |
*/ |
*/ |
669 |
const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient ) |
const char** lscp_list_available_midi_drivers ( lscp_client_t *pClient ) |
670 |
{ |
{ |
671 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
672 |
|
|
678 |
pClient->midi_drivers = NULL; |
pClient->midi_drivers = NULL; |
679 |
} |
} |
680 |
|
|
681 |
if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK) |
682 |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
683 |
|
|
684 |
// Unlock this section up. |
// Unlock this section up. |
908 |
if (pParam == NULL) |
if (pParam == NULL) |
909 |
return LSCP_FAILED; |
return LSCP_FAILED; |
910 |
|
|
911 |
sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d", iMidiDevice); |
sprintf(szQuery, "SET MIDI_INPUT_DEVICE_PARAMETER %d %s='%s'\r\n", iMidiDevice, pParam->key, pParam->value); |
|
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
|
912 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
913 |
} |
} |
914 |
|
|
994 |
if (pParam == NULL) |
if (pParam == NULL) |
995 |
return LSCP_FAILED; |
return LSCP_FAILED; |
996 |
|
|
997 |
sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d", iMidiDevice, iMidiPort); |
sprintf(szQuery, "SET MIDI_INPUT_PORT_PARAMETER %d %d %s='%s'\r\n", iMidiDevice, iMidiPort, pParam->key, pParam->value); |
|
lscp_param_concat(szQuery, sizeof(szQuery), pParam); |
|
998 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
999 |
} |
} |
1000 |
|
|
1001 |
|
|
1002 |
|
//------------------------------------------------------------------------- |
1003 |
|
// Generic parameter list functions. |
1004 |
|
|
1005 |
|
const char *lscp_get_param_value ( lscp_param_t *pParams, const char *pszParam ) |
1006 |
|
{ |
1007 |
|
int i; |
1008 |
|
|
1009 |
|
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 |
|
} |
1015 |
|
|
1016 |
|
|
1017 |
// end of device.c |
// end of device.c |
1018 |
|
|