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 |
|
|
40 |
static void _lscp_client_evt_proc ( void *pvClient ) |
static void _lscp_client_evt_proc ( void *pvClient ) |
41 |
{ |
{ |
42 |
lscp_client_t *pClient = (lscp_client_t *) pvClient; |
lscp_client_t *pClient = (lscp_client_t *) pvClient; |
43 |
|
|
44 |
fd_set fds; // File descriptor list for select(). |
fd_set fds; // File descriptor list for select(). |
45 |
int fd, fdmax; // Maximum file descriptor number. |
int fd, fdmax; // Maximum file descriptor number. |
46 |
struct timeval tv; // For specifying a timeout value. |
struct timeval tv; // For specifying a timeout value. |
47 |
int iSelect; // Holds select return status. |
int iSelect; // Holds select return status. |
48 |
int iTimeout; |
int iTimeout; |
49 |
|
|
50 |
char achBuffer[LSCP_BUFSIZ]; |
char achBuffer[LSCP_BUFSIZ]; |
51 |
int cchBuffer; |
int cchBuffer; |
52 |
const char *pszSeps = ":\r\n"; |
const char *pszSeps = ":\r\n"; |
69 |
|
|
70 |
// Use the timeout (x10) select feature ... |
// Use the timeout (x10) select feature ... |
71 |
iTimeout = 10 * pClient->iTimeout; |
iTimeout = 10 * pClient->iTimeout; |
72 |
if (iTimeout > 1000) { |
if (iTimeout >= 1000) { |
73 |
tv.tv_sec = iTimeout / 1000; |
tv.tv_sec = iTimeout / 1000; |
74 |
iTimeout -= tv.tv_sec * 1000; |
iTimeout -= tv.tv_sec * 1000; |
75 |
} |
} |
111 |
} |
} |
112 |
} // Check if select has in error. |
} // Check if select has in error. |
113 |
else if (iSelect < 0) { |
else if (iSelect < 0) { |
114 |
lscp_socket_perror("_lscp_client_call: select"); |
lscp_socket_perror("_lscp_client_evt_proc: select"); |
115 |
pClient->evt.iState = 0; |
pClient->evt.iState = 0; |
116 |
} |
} |
117 |
|
|
118 |
// Finally, always signal the event. |
// Finally, always signal the event. |
119 |
lscp_cond_signal(pClient->cond); |
lscp_cond_signal(pClient->cond); |
120 |
} |
} |
164 |
closesocket(sock); |
closesocket(sock); |
165 |
return LSCP_FAILED; |
return LSCP_FAILED; |
166 |
} |
} |
167 |
|
|
168 |
// Set our socket agent struct... |
// Set our socket agent struct... |
169 |
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
170 |
|
|
171 |
// And finally the service thread... |
// And finally the service thread... |
172 |
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
173 |
} |
} |
198 |
|
|
199 |
// Wait on response. |
// Wait on response. |
200 |
lscp_cond_wait(pClient->cond, pClient->mutex); |
lscp_cond_wait(pClient->cond, pClient->mutex); |
201 |
|
|
202 |
// Update as naively as we can... |
// Update as naively as we can... |
203 |
if (iSubscribe) |
if (iSubscribe) |
204 |
pClient->events |= event; |
pClient->events |= event; |
337 |
lscp_device_port_info_init(&(pClient->midi_port_info)); |
lscp_device_port_info_init(&(pClient->midi_port_info)); |
338 |
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
339 |
lscp_param_info_init(&(pClient->midi_port_param_info)); |
lscp_param_info_init(&(pClient->midi_port_param_info)); |
340 |
|
lscp_server_info_init(&(pClient->server_info)); |
341 |
lscp_engine_info_init(&(pClient->engine_info)); |
lscp_engine_info_init(&(pClient->engine_info)); |
342 |
lscp_channel_info_init(&(pClient->channel_info)); |
lscp_channel_info_init(&(pClient->channel_info)); |
343 |
|
lscp_midi_instrument_info_init(&(pClient->midi_instrument_info)); |
344 |
// Initialize error stuff. |
// Initialize error stuff. |
345 |
pClient->pszResult = NULL; |
pClient->pszResult = NULL; |
346 |
pClient->iErrno = -1; |
pClient->iErrno = -1; |
349 |
pClient->iStreamCount = 0; |
pClient->iStreamCount = 0; |
350 |
// Default timeout value. |
// Default timeout value. |
351 |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
352 |
|
pClient->iTimeoutCount = 0; |
353 |
|
|
354 |
// Initialize the transaction mutex. |
// Initialize the transaction mutex. |
355 |
lscp_mutex_init(pClient->mutex); |
lscp_mutex_init(pClient->mutex); |
399 |
|
|
400 |
// Lock this section up. |
// Lock this section up. |
401 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
402 |
|
|
403 |
// Free up all cached members. |
// Free up all cached members. |
404 |
|
lscp_midi_instrument_info_free(&(pClient->midi_instrument_info)); |
405 |
lscp_channel_info_free(&(pClient->channel_info)); |
lscp_channel_info_free(&(pClient->channel_info)); |
406 |
lscp_engine_info_free(&(pClient->engine_info)); |
lscp_engine_info_free(&(pClient->engine_info)); |
407 |
|
lscp_server_info_free(&(pClient->server_info)); |
408 |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
409 |
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
410 |
lscp_device_port_info_free(&(pClient->midi_port_info)); |
lscp_device_port_info_free(&(pClient->midi_port_info)); |
505 |
lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery ) |
lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery ) |
506 |
{ |
{ |
507 |
lscp_status_t ret; |
lscp_status_t ret; |
508 |
|
|
509 |
// Lock this section up. |
// Lock this section up. |
510 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
511 |
|
|
512 |
// Just make the now guarded call. |
// Just make the now guarded call. |
513 |
ret = lscp_client_call(pClient, pszQuery); |
ret = lscp_client_call(pClient, pszQuery); |
514 |
|
|
515 |
// Unlock this section down. |
// Unlock this section down. |
516 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
517 |
|
|
518 |
return ret; |
return ret; |
519 |
} |
} |
520 |
|
|
558 |
|
|
559 |
/** |
/** |
560 |
* Register frontend for receiving event messages: |
* Register frontend for receiving event messages: |
561 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
562 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | CHANNEL_INFO | MISCELLANEOUS |
563 |
* |
* |
564 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
579 |
// If applicable, start the alternate connection... |
// If applicable, start the alternate connection... |
580 |
if (pClient->events == LSCP_EVENT_NONE) |
if (pClient->events == LSCP_EVENT_NONE) |
581 |
ret = _lscp_client_evt_connect(pClient); |
ret = _lscp_client_evt_connect(pClient); |
582 |
|
|
583 |
// Send the subscription commands. |
// Send the subscription commands. |
584 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
585 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT); |
586 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
587 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
588 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
603 |
|
|
604 |
/** |
/** |
605 |
* Deregister frontend from receiving UDP event messages anymore: |
* Deregister frontend from receiving UDP event messages anymore: |
606 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
607 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | CHANNEL_INFO | MISCELLANEOUS |
608 |
* |
* |
609 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
622 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
623 |
|
|
624 |
// Send the unsubscription commands. |
// Send the unsubscription commands. |
625 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
626 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT); |
627 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
628 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
629 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
774 |
|
|
775 |
if (pClient == NULL) |
if (pClient == NULL) |
776 |
return NULL; |
return NULL; |
777 |
|
|
778 |
// Lock this section up. |
// Lock this section up. |
779 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
780 |
|
|
811 |
|
|
812 |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
813 |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
814 |
|
|
815 |
// Unlock this section down. |
// Unlock this section down. |
816 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
817 |
|
|
841 |
|
|
842 |
|
|
843 |
/** |
/** |
844 |
* Getting all available engines: |
* Getting all available engines count: |
845 |
* GET AVAILABLE_ENGINES |
* GET AVAILABLE_ENGINES |
846 |
* |
* |
847 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
848 |
* |
* |
849 |
|
* @returns The current total number of sampler engines on success, |
850 |
|
* -1 otherwise. |
851 |
|
*/ |
852 |
|
int lscp_get_available_engines ( lscp_client_t *pClient ) |
853 |
|
{ |
854 |
|
int iAvailableEngines = -1; |
855 |
|
|
856 |
|
// Lock this section up. |
857 |
|
lscp_mutex_lock(pClient->mutex); |
858 |
|
|
859 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
860 |
|
iAvailableEngines = atoi(lscp_client_get_result(pClient)); |
861 |
|
|
862 |
|
// Unlock this section down. |
863 |
|
lscp_mutex_unlock(pClient->mutex); |
864 |
|
|
865 |
|
return iAvailableEngines; |
866 |
|
} |
867 |
|
|
868 |
|
|
869 |
|
/** |
870 |
|
* Getting all available engines: |
871 |
|
* LIST AVAILABLE_ENGINES |
872 |
|
* |
873 |
|
* @param pClient Pointer to client instance structure. |
874 |
|
* |
875 |
* @returns A NULL terminated array of engine name strings, |
* @returns A NULL terminated array of engine name strings, |
876 |
* or NULL in case of failure. |
* or NULL in case of failure. |
877 |
*/ |
*/ |
878 |
const char **lscp_get_available_engines ( lscp_client_t *pClient ) |
const char **lscp_list_available_engines ( lscp_client_t *pClient ) |
879 |
{ |
{ |
880 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
881 |
|
|
887 |
pClient->engines = NULL; |
pClient->engines = NULL; |
888 |
} |
} |
889 |
|
|
890 |
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK) |
891 |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
892 |
|
|
893 |
// Unlock this section down. |
// Unlock this section down. |
945 |
} |
} |
946 |
} |
} |
947 |
else pEngineInfo = NULL; |
else pEngineInfo = NULL; |
948 |
|
|
949 |
// Unlock this section down. |
// Unlock this section down. |
950 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
951 |
|
|
978 |
|
|
979 |
// Lock this section up. |
// Lock this section up. |
980 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
981 |
|
|
982 |
pChannelInfo = &(pClient->channel_info); |
pChannelInfo = &(pClient->channel_info); |
983 |
lscp_channel_info_reset(pChannelInfo); |
lscp_channel_info_reset(pChannelInfo); |
984 |
|
|
1020 |
if (pszToken) |
if (pszToken) |
1021 |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
1022 |
} |
} |
1023 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { |
1024 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1025 |
|
if (pszToken) |
1026 |
|
lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken); |
1027 |
|
} |
1028 |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
1029 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1030 |
if (pszToken) |
if (pszToken) |
1042 |
} |
} |
1043 |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
1044 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1045 |
if (pszToken) |
if (pszToken) { |
1046 |
pChannelInfo->midi_channel = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_ltrim(pszToken); |
1047 |
|
if (strcasecmp(pszToken, "ALL") == 0) |
1048 |
|
pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL; |
1049 |
|
else |
1050 |
|
pChannelInfo->midi_channel = atoi(pszToken); |
1051 |
|
} |
1052 |
} |
} |
1053 |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
1054 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1055 |
if (pszToken) |
if (pszToken) |
1056 |
pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
1057 |
} |
} |
1058 |
|
else if (strcasecmp(pszToken, "MUTE") == 0) { |
1059 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1060 |
|
if (pszToken) |
1061 |
|
pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
1062 |
|
} |
1063 |
|
else if (strcasecmp(pszToken, "SOLO") == 0) { |
1064 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1065 |
|
if (pszToken) |
1066 |
|
pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
1067 |
|
} |
1068 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1069 |
} |
} |
1070 |
} |
} |
1071 |
else pChannelInfo = NULL; |
else pChannelInfo = NULL; |
1072 |
|
|
1073 |
// Unlock this section up. |
// Unlock this section up. |
1074 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1075 |
|
|
1262 |
else while (iStream < pClient->iStreamCount) |
else while (iStream < pClient->iStreamCount) |
1263 |
pBufferFill[iStream++].stream_usage = 0; |
pBufferFill[iStream++].stream_usage = 0; |
1264 |
} |
} |
1265 |
|
|
1266 |
// Unlock this section down. |
// Unlock this section down. |
1267 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1268 |
|
|
1277 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1278 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1279 |
* @param pszAudioDriver Audio output driver type (e.g. "ALSA" or "JACK"). |
* @param pszAudioDriver Audio output driver type (e.g. "ALSA" or "JACK"). |
1280 |
|
* |
1281 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1282 |
*/ |
*/ |
1283 |
lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver ) |
lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver ) |
1284 |
{ |
{ |
1299 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1300 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1301 |
* @param iAudioDevice Audio output device number identifier. |
* @param iAudioDevice Audio output device number identifier. |
1302 |
|
* |
1303 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1304 |
*/ |
*/ |
1305 |
lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice ) |
lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice ) |
1306 |
{ |
{ |
1366 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1367 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1368 |
* @param iMidiDevice MIDI input device number identifier. |
* @param iMidiDevice MIDI input device number identifier. |
1369 |
|
* |
1370 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1371 |
*/ |
*/ |
1372 |
lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice ) |
lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice ) |
1373 |
{ |
{ |
1454 |
|
|
1455 |
|
|
1456 |
/** |
/** |
1457 |
|
* Muting a sampler channel: |
1458 |
|
* SET CHANNEL MUTE <sampler-channel> <mute> |
1459 |
|
* |
1460 |
|
* @param pClient Pointer to client instance structure. |
1461 |
|
* @param iSamplerChannel Sampler channel number. |
1462 |
|
* @param iMute Sampler channel mute state as a boolean value, |
1463 |
|
* either 1 (one) to mute the channel or 0 (zero) |
1464 |
|
* to unmute the channel. |
1465 |
|
* |
1466 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1467 |
|
*/ |
1468 |
|
lscp_status_t lscp_set_channel_mute ( lscp_client_t *pClient, int iSamplerChannel, int iMute ) |
1469 |
|
{ |
1470 |
|
char szQuery[LSCP_BUFSIZ]; |
1471 |
|
|
1472 |
|
if (iSamplerChannel < 0 || iMute < 0 || iMute > 1) |
1473 |
|
return LSCP_FAILED; |
1474 |
|
|
1475 |
|
sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute); |
1476 |
|
return lscp_client_query(pClient, szQuery); |
1477 |
|
} |
1478 |
|
|
1479 |
|
|
1480 |
|
/** |
1481 |
|
* Soloing a sampler channel: |
1482 |
|
* SET CHANNEL SOLO <sampler-channel> <solo> |
1483 |
|
* |
1484 |
|
* @param pClient Pointer to client instance structure. |
1485 |
|
* @param iSamplerChannel Sampler channel number. |
1486 |
|
* @param iSolo Sampler channel solo state as a boolean value, |
1487 |
|
* either 1 (one) to solo the channel or 0 (zero) |
1488 |
|
* to unsolo the channel. |
1489 |
|
* |
1490 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1491 |
|
*/ |
1492 |
|
lscp_status_t lscp_set_channel_solo ( lscp_client_t *pClient, int iSamplerChannel, int iSolo ) |
1493 |
|
{ |
1494 |
|
char szQuery[LSCP_BUFSIZ]; |
1495 |
|
|
1496 |
|
if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1) |
1497 |
|
return LSCP_FAILED; |
1498 |
|
|
1499 |
|
sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo); |
1500 |
|
return lscp_client_query(pClient, szQuery); |
1501 |
|
} |
1502 |
|
|
1503 |
|
|
1504 |
|
/** |
1505 |
* Resetting a sampler channel: |
* Resetting a sampler channel: |
1506 |
* RESET CHANNEL <sampler-channel> |
* RESET CHANNEL <sampler-channel> |
1507 |
* |
* |
1536 |
} |
} |
1537 |
|
|
1538 |
|
|
1539 |
|
/** |
1540 |
|
* Getting information about the server. |
1541 |
|
* GET SERVER INFO |
1542 |
|
* |
1543 |
|
* @param pClient Pointer to client instance structure. |
1544 |
|
* |
1545 |
|
* @returns A pointer to a @ref lscp_server_info_t structure, with all the |
1546 |
|
* information of the current connected server, or NULL in case of failure. |
1547 |
|
*/ |
1548 |
|
lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient ) |
1549 |
|
{ |
1550 |
|
lscp_server_info_t *pServerInfo; |
1551 |
|
const char *pszResult; |
1552 |
|
const char *pszSeps = ":"; |
1553 |
|
const char *pszCrlf = "\r\n"; |
1554 |
|
char *pszToken; |
1555 |
|
char *pch; |
1556 |
|
|
1557 |
|
// Lock this section up. |
1558 |
|
lscp_mutex_lock(pClient->mutex); |
1559 |
|
|
1560 |
|
pServerInfo = &(pClient->server_info); |
1561 |
|
lscp_server_info_reset(pServerInfo); |
1562 |
|
|
1563 |
|
if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) { |
1564 |
|
pszResult = lscp_client_get_result(pClient); |
1565 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1566 |
|
while (pszToken) { |
1567 |
|
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
1568 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1569 |
|
if (pszToken) |
1570 |
|
lscp_unquote_dup(&(pServerInfo->description), &pszToken); |
1571 |
|
} |
1572 |
|
else if (strcasecmp(pszToken, "VERSION") == 0) { |
1573 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1574 |
|
if (pszToken) |
1575 |
|
lscp_unquote_dup(&(pServerInfo->version), &pszToken); |
1576 |
|
} |
1577 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1578 |
|
} |
1579 |
|
} |
1580 |
|
else pServerInfo = NULL; |
1581 |
|
|
1582 |
|
// Unlock this section down. |
1583 |
|
lscp_mutex_unlock(pClient->mutex); |
1584 |
|
|
1585 |
|
return pServerInfo; |
1586 |
|
} |
1587 |
|
|
1588 |
|
|
1589 |
|
/** |
1590 |
|
* Current total number of active voices: |
1591 |
|
* GET TOTAL_VOICE_COUNT |
1592 |
|
* |
1593 |
|
* @param pClient Pointer to client instance structure. |
1594 |
|
* |
1595 |
|
* @returns The total number of voices currently active, |
1596 |
|
* -1 in case of failure. |
1597 |
|
*/ |
1598 |
|
int lscp_get_total_voice_count ( lscp_client_t *pClient ) |
1599 |
|
{ |
1600 |
|
int iVoiceCount = -1; |
1601 |
|
|
1602 |
|
// Lock this section up. |
1603 |
|
lscp_mutex_lock(pClient->mutex); |
1604 |
|
|
1605 |
|
if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT\r\n") == LSCP_OK) |
1606 |
|
iVoiceCount = atoi(lscp_client_get_result(pClient)); |
1607 |
|
|
1608 |
|
// Unlock this section down. |
1609 |
|
lscp_mutex_unlock(pClient->mutex); |
1610 |
|
|
1611 |
|
return iVoiceCount; |
1612 |
|
} |
1613 |
|
|
1614 |
|
|
1615 |
|
/** |
1616 |
|
* Maximum amount of active voices: |
1617 |
|
* GET TOTAL_VOICE_COUNT_MAX |
1618 |
|
* |
1619 |
|
* @param pClient Pointer to client instance structure. |
1620 |
|
* |
1621 |
|
* @returns The maximum amount of voices currently active, |
1622 |
|
* -1 in case of failure. |
1623 |
|
*/ |
1624 |
|
int lscp_get_total_voice_count_max ( lscp_client_t *pClient ) |
1625 |
|
{ |
1626 |
|
int iVoiceCount = -1; |
1627 |
|
|
1628 |
|
// Lock this section up. |
1629 |
|
lscp_mutex_lock(pClient->mutex); |
1630 |
|
|
1631 |
|
if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT_MAX\r\n") == LSCP_OK) |
1632 |
|
iVoiceCount = atoi(lscp_client_get_result(pClient)); |
1633 |
|
|
1634 |
|
// Unlock this section down. |
1635 |
|
lscp_mutex_unlock(pClient->mutex); |
1636 |
|
|
1637 |
|
return iVoiceCount; |
1638 |
|
} |
1639 |
|
|
1640 |
|
|
1641 |
|
/** |
1642 |
|
* Create or replace a MIDI instrumnet map entry: |
1643 |
|
* MAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
1644 |
|
* <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
1645 |
|
* |
1646 |
|
* @param pClient Pointer to client instance structure. |
1647 |
|
* @param pMidiInstr MIDI instrument bank and program parameter key. |
1648 |
|
* @param pszEngineName Engine name. |
1649 |
|
* @param pszFileName Instrument file name. |
1650 |
|
* @param iInstrIndex Instrument index number. |
1651 |
|
* @param fVolume Reflects the master volume of the instrument as |
1652 |
|
* a positive floating point number, where a value |
1653 |
|
* less than 1.0 for attenuation, and greater than |
1654 |
|
* 1.0 for amplification. |
1655 |
|
* @param load_mode Instrument load life-time strategy, either |
1656 |
|
* @ref LSCP_LOAD_DEFAULT, or |
1657 |
|
* @ref LSCP_LOAD_ON_DEMAND, or |
1658 |
|
* @ref LSCP_LOAD_ON_DEMAND_HOLD, or |
1659 |
|
* @ref LSCP_LOAD_PERSISTENT. |
1660 |
|
* @param pszName Instrument custom name for the map entry. |
1661 |
|
* |
1662 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1663 |
|
*/ |
1664 |
|
lscp_status_t lscp_map_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr, const char *pszEngineName, const char *pszFileName, int iInstrIndex, float fVolume, lscp_load_mode_t load_mode, const char *pszName ) |
1665 |
|
{ |
1666 |
|
char szQuery[LSCP_BUFSIZ]; |
1667 |
|
|
1668 |
|
if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127) |
1669 |
|
return LSCP_FAILED; |
1670 |
|
if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127) |
1671 |
|
return LSCP_FAILED; |
1672 |
|
if (pMidiInstr->program < 0 || pMidiInstr->program > 127) |
1673 |
|
return LSCP_FAILED; |
1674 |
|
if (pszEngineName == NULL || pszFileName == NULL) |
1675 |
|
return LSCP_FAILED; |
1676 |
|
|
1677 |
|
if (fVolume < 0.0f) |
1678 |
|
fVolume = 1.0f; |
1679 |
|
|
1680 |
|
sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g", |
1681 |
|
pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program, |
1682 |
|
pszEngineName, pszFileName, iInstrIndex, fVolume); |
1683 |
|
|
1684 |
|
switch (load_mode) { |
1685 |
|
case LSCP_LOAD_PERSISTENT: |
1686 |
|
strcat(szQuery, " PERSISTENT"); |
1687 |
|
break; |
1688 |
|
case LSCP_LOAD_ON_DEMAND_HOLD: |
1689 |
|
strcat(szQuery, " ON_DEMAND_HOLD"); |
1690 |
|
break; |
1691 |
|
case LSCP_LOAD_ON_DEMAND: |
1692 |
|
strcat(szQuery, " ON_DEMAND_HOLD"); |
1693 |
|
break; |
1694 |
|
case LSCP_LOAD_DEFAULT: |
1695 |
|
default: |
1696 |
|
break; |
1697 |
|
} |
1698 |
|
|
1699 |
|
if (pszName) |
1700 |
|
sprintf(szQuery + strlen(szQuery), " '%s'", pszName); |
1701 |
|
|
1702 |
|
strcat(szQuery, "\r\n"); |
1703 |
|
|
1704 |
|
return lscp_client_query(pClient, szQuery); |
1705 |
|
} |
1706 |
|
|
1707 |
|
|
1708 |
|
/** |
1709 |
|
* Remove an entry from the MIDI instrument map: |
1710 |
|
* UNMAP MIDI_INSTRUMENT <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
1711 |
|
* |
1712 |
|
* @param pClient Pointer to client instance structure. |
1713 |
|
* @param pMidiInstr MIDI instrument bank and program parameter key. |
1714 |
|
* |
1715 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1716 |
|
*/ |
1717 |
|
lscp_status_t lscp_unmap_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr ) |
1718 |
|
{ |
1719 |
|
char szQuery[LSCP_BUFSIZ]; |
1720 |
|
|
1721 |
|
if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127) |
1722 |
|
return LSCP_FAILED; |
1723 |
|
if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127) |
1724 |
|
return LSCP_FAILED; |
1725 |
|
if (pMidiInstr->program < 0 || pMidiInstr->program > 127) |
1726 |
|
return LSCP_FAILED; |
1727 |
|
|
1728 |
|
sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n", |
1729 |
|
pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program); |
1730 |
|
|
1731 |
|
return lscp_client_query(pClient, szQuery); |
1732 |
|
} |
1733 |
|
|
1734 |
|
|
1735 |
|
/** |
1736 |
|
* Get the total count of MIDI instrument map entries: |
1737 |
|
* GET MIDI_INSTRUMENTS |
1738 |
|
* |
1739 |
|
* @param pClient Pointer to client instance structure. |
1740 |
|
* |
1741 |
|
* @returns The current total number of MIDI instrument map entries |
1742 |
|
* on success, -1 otherwise. |
1743 |
|
*/ |
1744 |
|
int lscp_get_midi_instruments ( lscp_client_t *pClient ) |
1745 |
|
{ |
1746 |
|
int iInstruments = -1; |
1747 |
|
|
1748 |
|
// Lock this section up. |
1749 |
|
lscp_mutex_lock(pClient->mutex); |
1750 |
|
|
1751 |
|
if (lscp_client_call(pClient, "GET MIDI_INSTRUMENTS\r\n") == LSCP_OK) |
1752 |
|
iInstruments = atoi(lscp_client_get_result(pClient)); |
1753 |
|
|
1754 |
|
// Unlock this section down. |
1755 |
|
lscp_mutex_unlock(pClient->mutex); |
1756 |
|
|
1757 |
|
return iInstruments; |
1758 |
|
} |
1759 |
|
|
1760 |
|
|
1761 |
|
/** |
1762 |
|
* Getting information about a MIDI instrument map entry: |
1763 |
|
* GET MIDI_INSTRUMENT INFO <midi-bank-msb> <midi-bank-lsb> <midi-prog> |
1764 |
|
* |
1765 |
|
* @param pClient Pointer to client instance structure. |
1766 |
|
* @param pMidiInstr MIDI instrument bank and program parameter key. |
1767 |
|
* |
1768 |
|
* @returns A pointer to a @ref lscp_midi_instrument_info_t structure, |
1769 |
|
* with all the information of the given MIDI instrument map entry, |
1770 |
|
* or NULL in case of failure. |
1771 |
|
*/ |
1772 |
|
lscp_midi_instrument_info_t *lscp_get_midi_instrument_info ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr ) |
1773 |
|
{ |
1774 |
|
lscp_midi_instrument_info_t *pInstrInfo; |
1775 |
|
char szQuery[LSCP_BUFSIZ]; |
1776 |
|
const char *pszResult; |
1777 |
|
const char *pszSeps = ":"; |
1778 |
|
const char *pszCrlf = "\r\n"; |
1779 |
|
char *pszToken; |
1780 |
|
char *pch; |
1781 |
|
|
1782 |
|
if (pMidiInstr->bank_msb < 0 || pMidiInstr->bank_msb > 127) |
1783 |
|
return NULL; |
1784 |
|
if (pMidiInstr->bank_lsb < 0 || pMidiInstr->bank_lsb > 127) |
1785 |
|
return NULL; |
1786 |
|
if (pMidiInstr->program < 0 || pMidiInstr->program > 127) |
1787 |
|
return NULL; |
1788 |
|
|
1789 |
|
// Lock this section up. |
1790 |
|
lscp_mutex_lock(pClient->mutex); |
1791 |
|
|
1792 |
|
pInstrInfo = &(pClient->midi_instrument_info); |
1793 |
|
lscp_midi_instrument_info_reset(pInstrInfo); |
1794 |
|
|
1795 |
|
sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n", |
1796 |
|
pMidiInstr->bank_msb, pMidiInstr->bank_lsb, pMidiInstr->program); |
1797 |
|
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
1798 |
|
pszResult = lscp_client_get_result(pClient); |
1799 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1800 |
|
while (pszToken) { |
1801 |
|
if (strcasecmp(pszToken, "NAME") == 0) { |
1802 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1803 |
|
if (pszToken) |
1804 |
|
lscp_unquote_dup(&(pInstrInfo->name), &pszToken); |
1805 |
|
} |
1806 |
|
else if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
1807 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1808 |
|
if (pszToken) |
1809 |
|
lscp_unquote_dup(&(pInstrInfo->engine_name), &pszToken); |
1810 |
|
} |
1811 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
1812 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1813 |
|
if (pszToken) |
1814 |
|
lscp_unquote_dup(&(pInstrInfo->instrument_file), &pszToken); |
1815 |
|
} |
1816 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
1817 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1818 |
|
if (pszToken) |
1819 |
|
pInstrInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
1820 |
|
} |
1821 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { |
1822 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1823 |
|
if (pszToken) |
1824 |
|
lscp_unquote_dup(&(pInstrInfo->instrument_name), &pszToken); |
1825 |
|
} |
1826 |
|
else if (strcasecmp(pszToken, "LOAD_MODE") == 0) { |
1827 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1828 |
|
if (pszToken) { |
1829 |
|
pszToken = lscp_ltrim(pszToken); |
1830 |
|
if (strcasecmp(pszToken, "ON_DEMAND") == 0) |
1831 |
|
pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND; |
1832 |
|
else |
1833 |
|
if (strcasecmp(pszToken, "ON_DEMAND_HOLD") == 0) |
1834 |
|
pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND_HOLD; |
1835 |
|
else |
1836 |
|
if (strcasecmp(pszToken, "PERSISTENT") == 0) |
1837 |
|
pInstrInfo->load_mode = LSCP_LOAD_PERSISTENT; |
1838 |
|
else |
1839 |
|
pInstrInfo->load_mode = LSCP_LOAD_DEFAULT; |
1840 |
|
} |
1841 |
|
} |
1842 |
|
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
1843 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1844 |
|
if (pszToken) |
1845 |
|
pInstrInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
1846 |
|
} |
1847 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1848 |
|
} |
1849 |
|
} |
1850 |
|
else pInstrInfo = NULL; |
1851 |
|
|
1852 |
|
// Unlock this section down. |
1853 |
|
lscp_mutex_unlock(pClient->mutex); |
1854 |
|
|
1855 |
|
return pInstrInfo; |
1856 |
|
} |
1857 |
|
|
1858 |
|
|
1859 |
|
/** |
1860 |
|
* Clear the MIDI instrumnet map: |
1861 |
|
* CLEAR MIDI_INSTRUMENTS |
1862 |
|
* |
1863 |
|
* @param pClient Pointer to client instance structure. |
1864 |
|
* @param iSamplerChannel Sampler channel number. |
1865 |
|
* |
1866 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1867 |
|
*/ |
1868 |
|
lscp_status_t lscp_clear_midi_instruments ( lscp_client_t *pClient ) |
1869 |
|
{ |
1870 |
|
return lscp_client_query(pClient, "CLEAR MIDI_INSTRUMENTS\r\n"); |
1871 |
|
} |
1872 |
|
|
1873 |
|
|
1874 |
// end of client.c |
// end of client.c |