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-2005, 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 14have received a copy of the GNU Lesser General Public |
18 |
License along with this library; if not, write to the Free Software |
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 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
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 |
char achBuffer[LSCP_BUFSIZ]; |
|
44 |
int cchBuffer; |
fd_set fds; // File descriptor list for select(). |
45 |
|
int fd, fdmax; // Maximum file descriptor number. |
46 |
|
struct timeval tv; // For specifying a timeout value. |
47 |
|
int iSelect; // Holds select return status. |
48 |
|
int iTimeout; |
49 |
|
|
50 |
|
char achBuffer[LSCP_BUFSIZ]; |
51 |
|
int cchBuffer; |
52 |
const char *pszSeps = ":\r\n"; |
const char *pszSeps = ":\r\n"; |
53 |
char *pszToken; |
char * pszToken; |
54 |
char *pch; |
char * pch; |
55 |
int cchToken; |
int cchToken; |
56 |
lscp_event_t event; |
lscp_event_t event; |
57 |
|
|
58 |
#ifdef DEBUG |
#ifdef DEBUG |
60 |
#endif |
#endif |
61 |
|
|
62 |
while (pClient->evt.iState) { |
while (pClient->evt.iState) { |
63 |
|
|
64 |
|
// Prepare for waiting on select... |
65 |
|
fd = (int) pClient->evt.sock; |
66 |
|
FD_ZERO(&fds); |
67 |
|
FD_SET((unsigned int) fd, &fds); |
68 |
|
fdmax = fd; |
69 |
|
|
70 |
|
// Use the timeout (x10) select feature ... |
71 |
|
iTimeout = 10 * pClient->iTimeout; |
72 |
|
if (iTimeout > 1000) { |
73 |
|
tv.tv_sec = iTimeout / 1000; |
74 |
|
iTimeout -= tv.tv_sec * 1000; |
75 |
|
} |
76 |
|
else tv.tv_sec = 0; |
77 |
|
tv.tv_usec = iTimeout * 1000; |
78 |
|
|
79 |
// Wait for event... |
// Wait for event... |
80 |
cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0); |
iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv); |
81 |
if (cchBuffer > 0) { |
if (iSelect > 0 && FD_ISSET(fd, &fds)) { |
82 |
// Make sure received buffer it's null terminated. |
// May recv now... |
83 |
achBuffer[cchBuffer] = (char) 0; |
cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0); |
84 |
// Parse for the notification event message... |
if (cchBuffer > 0) { |
85 |
pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". |
// Make sure received buffer it's null terminated. |
86 |
if (strcasecmp(pszToken, "NOTIFY") == 0) { |
achBuffer[cchBuffer] = (char) 0; |
87 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
// Parse for the notification event message... |
88 |
event = lscp_event_from_text(pszToken); |
pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". |
89 |
// And pick the rest of data... |
if (strcasecmp(pszToken, "NOTIFY") == 0) { |
90 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
91 |
cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); |
event = lscp_event_from_text(pszToken); |
92 |
// Double-check if we're really up to it... |
// And pick the rest of data... |
93 |
if (pClient->events & event) { |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
94 |
// Invoke the client event callback... |
cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); |
95 |
if ((*pClient->pfnCallback)( |
// Double-check if we're really up to it... |
96 |
pClient, |
if (pClient->events & event) { |
97 |
event, |
// Invoke the client event callback... |
98 |
pszToken, |
if ((*pClient->pfnCallback)( |
99 |
cchToken, |
pClient, |
100 |
pClient->pvData) != LSCP_OK) { |
event, |
101 |
pClient->evt.iState = 0; |
pszToken, |
102 |
|
cchToken, |
103 |
|
pClient->pvData) != LSCP_OK) { |
104 |
|
pClient->evt.iState = 0; |
105 |
|
} |
106 |
} |
} |
107 |
} |
} |
108 |
|
} else { |
109 |
|
lscp_socket_perror("_lscp_client_evt_proc: recv"); |
110 |
|
pClient->evt.iState = 0; |
111 |
} |
} |
112 |
} else { |
} // Check if select has in error. |
113 |
lscp_socket_perror("_lscp_client_evt_proc: recv"); |
else if (iSelect < 0) { |
114 |
|
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. |
119 |
|
lscp_cond_signal(pClient->cond); |
120 |
} |
} |
121 |
|
|
122 |
#ifdef DEBUG |
#ifdef DEBUG |
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 |
} |
} |
196 |
return LSCP_FAILED; |
return LSCP_FAILED; |
197 |
} |
} |
198 |
|
|
199 |
|
// Wait on response. |
200 |
|
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; |
327 |
pClient->midi_devices = NULL; |
pClient->midi_devices = NULL; |
328 |
pClient->engines = NULL; |
pClient->engines = NULL; |
329 |
pClient->channels = NULL; |
pClient->channels = NULL; |
330 |
lscp_driver_info_init(&(pClient->audio_info)); |
lscp_driver_info_init(&(pClient->audio_driver_info)); |
331 |
lscp_driver_info_init(&(pClient->midi_info)); |
lscp_driver_info_init(&(pClient->midi_driver_info)); |
332 |
|
lscp_device_info_init(&(pClient->audio_device_info)); |
333 |
|
lscp_device_info_init(&(pClient->midi_device_info)); |
334 |
|
lscp_param_info_init(&(pClient->audio_param_info)); |
335 |
|
lscp_param_info_init(&(pClient->midi_param_info)); |
336 |
|
lscp_device_port_info_init(&(pClient->audio_channel_info)); |
337 |
|
lscp_device_port_info_init(&(pClient->midi_port_info)); |
338 |
|
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
339 |
|
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 |
// Initialize error stuff. |
// Initialize error stuff. |
351 |
|
|
352 |
// Initialize the transaction mutex. |
// Initialize the transaction mutex. |
353 |
lscp_mutex_init(pClient->mutex); |
lscp_mutex_init(pClient->mutex); |
354 |
|
lscp_cond_init(pClient->cond); |
355 |
|
|
356 |
// Finally we've some success... |
// Finally we've some success... |
357 |
return pClient; |
return pClient; |
397 |
|
|
398 |
// Lock this section up. |
// Lock this section up. |
399 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
400 |
|
|
401 |
// Free up all cached members. |
// Free up all cached members. |
402 |
lscp_channel_info_reset(&(pClient->channel_info)); |
lscp_channel_info_free(&(pClient->channel_info)); |
403 |
lscp_engine_info_reset(&(pClient->engine_info)); |
lscp_engine_info_free(&(pClient->engine_info)); |
404 |
lscp_driver_info_reset(&(pClient->midi_info)); |
lscp_server_info_free(&(pClient->server_info)); |
405 |
lscp_driver_info_reset(&(pClient->audio_info)); |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
406 |
|
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
407 |
|
lscp_device_port_info_free(&(pClient->midi_port_info)); |
408 |
|
lscp_device_port_info_free(&(pClient->audio_channel_info)); |
409 |
|
lscp_param_info_free(&(pClient->midi_param_info)); |
410 |
|
lscp_param_info_free(&(pClient->audio_param_info)); |
411 |
|
lscp_device_info_free(&(pClient->midi_device_info)); |
412 |
|
lscp_device_info_free(&(pClient->audio_device_info)); |
413 |
|
lscp_driver_info_free(&(pClient->midi_driver_info)); |
414 |
|
lscp_driver_info_free(&(pClient->audio_driver_info)); |
415 |
// Free available engine table. |
// Free available engine table. |
416 |
lscp_szsplit_destroy(pClient->audio_drivers); |
lscp_szsplit_destroy(pClient->audio_drivers); |
417 |
lscp_szsplit_destroy(pClient->midi_drivers); |
lscp_szsplit_destroy(pClient->midi_drivers); |
425 |
pClient->engines = NULL; |
pClient->engines = NULL; |
426 |
// Free result error stuff. |
// Free result error stuff. |
427 |
lscp_client_set_result(pClient, NULL, 0); |
lscp_client_set_result(pClient, NULL, 0); |
428 |
// Frre stream usage stuff. |
// Free stream usage stuff. |
429 |
if (pClient->buffer_fill) |
if (pClient->buffer_fill) |
430 |
free(pClient->buffer_fill); |
free(pClient->buffer_fill); |
431 |
pClient->buffer_fill = NULL; |
pClient->buffer_fill = NULL; |
439 |
// Last but not least, free good ol'transaction mutex. |
// Last but not least, free good ol'transaction mutex. |
440 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
441 |
lscp_mutex_destroy(pClient->mutex); |
lscp_mutex_destroy(pClient->mutex); |
442 |
|
lscp_cond_destroy(pClient->cond); |
443 |
|
|
444 |
free(pClient); |
free(pClient); |
445 |
|
|
502 |
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 ) |
503 |
{ |
{ |
504 |
lscp_status_t ret; |
lscp_status_t ret; |
505 |
|
|
506 |
// Lock this section up. |
// Lock this section up. |
507 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
508 |
|
|
509 |
// Just make the now guarded call. |
// Just make the now guarded call. |
510 |
ret = lscp_client_call(pClient, pszQuery); |
ret = lscp_client_call(pClient, pszQuery); |
511 |
|
|
512 |
// Unlock this section down. |
// Unlock this section down. |
513 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
514 |
|
|
515 |
return ret; |
return ret; |
516 |
} |
} |
517 |
|
|
555 |
|
|
556 |
/** |
/** |
557 |
* Register frontend for receiving event messages: |
* Register frontend for receiving event messages: |
558 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
559 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | CHANNEL_INFO | MISCELLANEOUS |
560 |
* |
* |
561 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
576 |
// If applicable, start the alternate connection... |
// If applicable, start the alternate connection... |
577 |
if (pClient->events == LSCP_EVENT_NONE) |
if (pClient->events == LSCP_EVENT_NONE) |
578 |
ret = _lscp_client_evt_connect(pClient); |
ret = _lscp_client_evt_connect(pClient); |
579 |
|
|
580 |
// Send the subscription commands. |
// Send the subscription commands. |
581 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
582 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT); |
583 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
584 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
585 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
600 |
|
|
601 |
/** |
/** |
602 |
* Deregister frontend from receiving UDP event messages anymore: |
* Deregister frontend from receiving UDP event messages anymore: |
603 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
604 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | CHANNEL_INFO | MISCELLANEOUS |
605 |
* |
* |
606 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
619 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
620 |
|
|
621 |
// Send the unsubscription commands. |
// Send the unsubscription commands. |
622 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
623 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT); |
624 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
625 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
626 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
643 |
} |
} |
644 |
|
|
645 |
|
|
646 |
|
/** |
647 |
|
* Getting current subscribed events. |
648 |
|
* |
649 |
|
* @param pClient Pointer to client instance structure. |
650 |
|
* |
651 |
|
* @returns The current subscrived bit-wise OR'ed event flags. |
652 |
|
*/ |
653 |
|
lscp_event_t lscp_client_get_events ( lscp_client_t *pClient ) |
654 |
|
{ |
655 |
|
if (pClient == NULL) |
656 |
|
return LSCP_EVENT_NONE; |
657 |
|
|
658 |
|
return pClient->events; |
659 |
|
} |
660 |
|
|
661 |
|
|
662 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
663 |
// Client command protocol functions. |
// Client command protocol functions. |
664 |
|
|
771 |
|
|
772 |
if (pClient == NULL) |
if (pClient == NULL) |
773 |
return NULL; |
return NULL; |
774 |
|
|
775 |
// Lock this section up. |
// Lock this section up. |
776 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
777 |
|
|
808 |
|
|
809 |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
810 |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
811 |
|
|
812 |
// Unlock this section down. |
// Unlock this section down. |
813 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
814 |
|
|
838 |
|
|
839 |
|
|
840 |
/** |
/** |
841 |
* Getting all available engines: |
* Getting all available engines count: |
842 |
* GET AVAILABLE_ENGINES |
* GET AVAILABLE_ENGINES |
843 |
* |
* |
844 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
845 |
* |
* |
846 |
|
* @returns The current total number of sampler engines on success, |
847 |
|
* -1 otherwise. |
848 |
|
*/ |
849 |
|
int lscp_get_available_engines ( lscp_client_t *pClient ) |
850 |
|
{ |
851 |
|
int iAvailableEngines = -1; |
852 |
|
|
853 |
|
// Lock this section up. |
854 |
|
lscp_mutex_lock(pClient->mutex); |
855 |
|
|
856 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
857 |
|
iAvailableEngines = atoi(lscp_client_get_result(pClient)); |
858 |
|
|
859 |
|
// Unlock this section down. |
860 |
|
lscp_mutex_unlock(pClient->mutex); |
861 |
|
|
862 |
|
return iAvailableEngines; |
863 |
|
} |
864 |
|
|
865 |
|
|
866 |
|
/** |
867 |
|
* Getting all available engines: |
868 |
|
* LIST AVAILABLE_ENGINES |
869 |
|
* |
870 |
|
* @param pClient Pointer to client instance structure. |
871 |
|
* |
872 |
* @returns A NULL terminated array of engine name strings, |
* @returns A NULL terminated array of engine name strings, |
873 |
* or NULL in case of failure. |
* or NULL in case of failure. |
874 |
*/ |
*/ |
875 |
const char **lscp_get_available_engines ( lscp_client_t *pClient ) |
const char **lscp_list_available_engines ( lscp_client_t *pClient ) |
876 |
{ |
{ |
877 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
878 |
|
|
884 |
pClient->engines = NULL; |
pClient->engines = NULL; |
885 |
} |
} |
886 |
|
|
887 |
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK) |
888 |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
889 |
|
|
890 |
// Unlock this section down. |
// Unlock this section down. |
931 |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
932 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
933 |
if (pszToken) |
if (pszToken) |
934 |
pEngineInfo->description = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pEngineInfo->description), &pszToken); |
935 |
} |
} |
936 |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
937 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
938 |
if (pszToken) |
if (pszToken) |
939 |
pEngineInfo->version = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pEngineInfo->version), &pszToken); |
940 |
} |
} |
941 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
942 |
} |
} |
943 |
} |
} |
944 |
else pEngineInfo = NULL; |
else pEngineInfo = NULL; |
945 |
|
|
946 |
// Unlock this section down. |
// Unlock this section down. |
947 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
948 |
|
|
975 |
|
|
976 |
// Lock this section up. |
// Lock this section up. |
977 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
978 |
|
|
979 |
pChannelInfo = &(pClient->channel_info); |
pChannelInfo = &(pClient->channel_info); |
980 |
lscp_channel_info_reset(pChannelInfo); |
lscp_channel_info_reset(pChannelInfo); |
981 |
|
|
987 |
if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
988 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
989 |
if (pszToken) |
if (pszToken) |
990 |
pChannelInfo->engine_name = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken); |
991 |
} |
} |
992 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) { |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) { |
993 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1001 |
} |
} |
1002 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
1003 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1004 |
if (pszToken) |
if (pszToken) { |
1005 |
|
if (pChannelInfo->audio_routing) |
1006 |
|
lscp_szsplit_destroy(pChannelInfo->audio_routing); |
1007 |
pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ","); |
pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ","); |
1008 |
|
} |
1009 |
} |
} |
1010 |
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
1011 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1012 |
if (pszToken) |
if (pszToken) |
1013 |
pChannelInfo->instrument_file = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken); |
1014 |
} |
} |
1015 |
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
1016 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1017 |
if (pszToken) |
if (pszToken) |
1018 |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
1019 |
} |
} |
1020 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { |
1021 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1022 |
|
if (pszToken) |
1023 |
|
lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken); |
1024 |
|
} |
1025 |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
1026 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1027 |
if (pszToken) |
if (pszToken) |
1039 |
} |
} |
1040 |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
1041 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1042 |
if (pszToken) |
if (pszToken) { |
1043 |
pChannelInfo->midi_channel = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_ltrim(pszToken); |
1044 |
|
if (strcasecmp(pszToken, "ALL") == 0) |
1045 |
|
pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL; |
1046 |
|
else |
1047 |
|
pChannelInfo->midi_channel = atoi(pszToken); |
1048 |
|
} |
1049 |
} |
} |
1050 |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
1051 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1056 |
} |
} |
1057 |
} |
} |
1058 |
else pChannelInfo = NULL; |
else pChannelInfo = NULL; |
1059 |
|
|
1060 |
// Unlock this section up. |
// Unlock this section up. |
1061 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1062 |
|
|
1099 |
* Current number of active disk streams: |
* Current number of active disk streams: |
1100 |
* GET CHANNEL STREAM_COUNT <sampler-channel> |
* GET CHANNEL STREAM_COUNT <sampler-channel> |
1101 |
* |
* |
1102 |
|
* @param pClient Pointer to client instance structure. |
1103 |
|
* @param iSamplerChannel Sampler channel number. |
1104 |
|
* |
1105 |
* @returns The number of active disk streams on success, -1 otherwise. |
* @returns The number of active disk streams on success, -1 otherwise. |
1106 |
*/ |
*/ |
1107 |
int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) |
int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) |
1127 |
|
|
1128 |
|
|
1129 |
/** |
/** |
1130 |
|
* Current least usage of active disk streams. |
1131 |
|
* |
1132 |
|
* @param pClient Pointer to client instance structure. |
1133 |
|
* @param iSamplerChannel Sampler channel number. |
1134 |
|
* |
1135 |
|
* @returns The usage percentage of the least filled active disk stream |
1136 |
|
* on success, -1 otherwise. |
1137 |
|
*/ |
1138 |
|
int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel ) |
1139 |
|
{ |
1140 |
|
char szQuery[LSCP_BUFSIZ]; |
1141 |
|
int iStreamUsage = -1; |
1142 |
|
const char *pszResult; |
1143 |
|
const char *pszSeps = "[]%,"; |
1144 |
|
char *pszToken; |
1145 |
|
char *pch; |
1146 |
|
int iStream; |
1147 |
|
int iPercent; |
1148 |
|
|
1149 |
|
if (iSamplerChannel < 0) |
1150 |
|
return iStreamUsage; |
1151 |
|
|
1152 |
|
// Lock this section up. |
1153 |
|
lscp_mutex_lock(pClient->mutex); |
1154 |
|
|
1155 |
|
iStream = 0; |
1156 |
|
sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel); |
1157 |
|
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
1158 |
|
pszResult = lscp_client_get_result(pClient); |
1159 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1160 |
|
while (pszToken) { |
1161 |
|
if (*pszToken) { |
1162 |
|
// Skip stream id. |
1163 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1164 |
|
if (pszToken == NULL) |
1165 |
|
break; |
1166 |
|
// Get least buffer fill percentage. |
1167 |
|
iPercent = atol(pszToken); |
1168 |
|
if (iStreamUsage > iPercent || iStream == 0) |
1169 |
|
iStreamUsage = iPercent; |
1170 |
|
iStream++; |
1171 |
|
} |
1172 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1173 |
|
} |
1174 |
|
} |
1175 |
|
|
1176 |
|
// Unlock this section down. |
1177 |
|
lscp_mutex_unlock(pClient->mutex); |
1178 |
|
|
1179 |
|
return iStreamUsage; |
1180 |
|
} |
1181 |
|
|
1182 |
|
|
1183 |
|
/** |
1184 |
* Current fill state of disk stream buffers: |
* Current fill state of disk stream buffers: |
1185 |
* GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel> |
* GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel> |
1186 |
* |
* |
1249 |
else while (iStream < pClient->iStreamCount) |
else while (iStream < pClient->iStreamCount) |
1250 |
pBufferFill[iStream++].stream_usage = 0; |
pBufferFill[iStream++].stream_usage = 0; |
1251 |
} |
} |
1252 |
|
|
1253 |
// Unlock this section down. |
// Unlock this section down. |
1254 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1255 |
|
|
1315 |
if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0) |
if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0) |
1316 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1317 |
|
|
1318 |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNELS %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn); |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn); |
1319 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1320 |
} |
} |
1321 |
|
|
1390 |
* |
* |
1391 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1392 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1393 |
* @param iMidiChannel MIDI channel number to listen (1-16) or |
* @param iMidiChannel MIDI channel address number to listen (0-15) or |
1394 |
* zero (0) to listen on all channels. |
* LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels. |
1395 |
* |
* |
1396 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1397 |
*/ |
*/ |
1402 |
if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16) |
if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16) |
1403 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1404 |
|
|
1405 |
if (iMidiChannel > 0) |
if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL) |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel); |
|
|
else |
|
1406 |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel); |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel); |
1407 |
|
else |
1408 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel); |
1409 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1410 |
} |
} |
1411 |
|
|
1455 |
} |
} |
1456 |
|
|
1457 |
|
|
1458 |
|
/** |
1459 |
|
* Resetting the sampler: |
1460 |
|
* RESET |
1461 |
|
* |
1462 |
|
* @param pClient Pointer to client instance structure. |
1463 |
|
* |
1464 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1465 |
|
*/ |
1466 |
|
lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient ) |
1467 |
|
{ |
1468 |
|
return lscp_client_query(pClient, "RESET\r\n"); |
1469 |
|
} |
1470 |
|
|
1471 |
|
|
1472 |
|
/** |
1473 |
|
* Getting information about the server. |
1474 |
|
* GET SERVER INFO |
1475 |
|
* |
1476 |
|
* @param pClient Pointer to client instance structure. |
1477 |
|
* |
1478 |
|
* @returns A pointer to a @ref lscp_server_info_t structure, with all the |
1479 |
|
* information of the current connected server, or NULL in case of failure. |
1480 |
|
*/ |
1481 |
|
lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient ) |
1482 |
|
{ |
1483 |
|
lscp_server_info_t *pServerInfo; |
1484 |
|
const char *pszResult; |
1485 |
|
const char *pszSeps = ":"; |
1486 |
|
const char *pszCrlf = "\r\n"; |
1487 |
|
char *pszToken; |
1488 |
|
char *pch; |
1489 |
|
|
1490 |
|
// Lock this section up. |
1491 |
|
lscp_mutex_lock(pClient->mutex); |
1492 |
|
|
1493 |
|
pServerInfo = &(pClient->server_info); |
1494 |
|
lscp_server_info_reset(pServerInfo); |
1495 |
|
|
1496 |
|
if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) { |
1497 |
|
pszResult = lscp_client_get_result(pClient); |
1498 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1499 |
|
while (pszToken) { |
1500 |
|
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
1501 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1502 |
|
if (pszToken) |
1503 |
|
lscp_unquote_dup(&(pServerInfo->description), &pszToken); |
1504 |
|
} |
1505 |
|
else if (strcasecmp(pszToken, "VERSION") == 0) { |
1506 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1507 |
|
if (pszToken) |
1508 |
|
lscp_unquote_dup(&(pServerInfo->version), &pszToken); |
1509 |
|
} |
1510 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1511 |
|
} |
1512 |
|
} |
1513 |
|
else pServerInfo = NULL; |
1514 |
|
|
1515 |
|
// Unlock this section down. |
1516 |
|
lscp_mutex_unlock(pClient->mutex); |
1517 |
|
|
1518 |
|
return pServerInfo; |
1519 |
|
} |
1520 |
|
|
1521 |
|
|
1522 |
// end of client.c |
// end of client.c |