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 |
|
|
28 |
|
|
29 |
// Local prototypes. |
// Local prototypes. |
30 |
|
|
31 |
static void _lscp_client_evt_proc (void *pvClient); |
static void _lscp_client_evt_proc (void *pvClient); |
32 |
|
|
33 |
|
static lscp_status_t _lscp_client_evt_connect (lscp_client_t *pClient); |
34 |
|
static lscp_status_t _lscp_client_evt_request (lscp_client_t *pClient, int iSubscribe, lscp_event_t event); |
35 |
|
|
36 |
|
|
37 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
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 |
struct sockaddr_in addr; |
|
44 |
int cAddr; |
fd_set fds; // File descriptor list for select(). |
45 |
char achBuffer[LSCP_BUFSIZ]; |
int fd, fdmax; // Maximum file descriptor number. |
46 |
int cchBuffer; |
struct timeval tv; // For specifying a timeout value. |
47 |
const char *pszSeps = " \r\n"; |
int iSelect; // Holds select return status. |
48 |
char *pszToken; |
int iTimeout; |
49 |
char *pch; |
|
50 |
|
char achBuffer[LSCP_BUFSIZ]; |
51 |
|
int cchBuffer; |
52 |
|
const char *pszSeps = ":\r\n"; |
53 |
|
char * pszToken; |
54 |
|
char * pch; |
55 |
|
int cchToken; |
56 |
|
lscp_event_t event; |
57 |
|
|
58 |
#ifdef DEBUG |
#ifdef DEBUG |
59 |
fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n"); |
fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n"); |
60 |
#endif |
#endif |
61 |
|
|
62 |
while (pClient->evt.iState) { |
while (pClient->evt.iState) { |
63 |
cAddr = sizeof(struct sockaddr_in); |
|
64 |
cchBuffer = recvfrom(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0, (struct sockaddr *) &addr, &cAddr); |
// Prepare for waiting on select... |
65 |
if (cchBuffer > 0) { |
fd = (int) pClient->evt.sock; |
66 |
#ifdef DEBUG |
FD_ZERO(&fds); |
67 |
lscp_socket_trace("_lscp_client_evt_proc: recvfrom", &addr, achBuffer, cchBuffer); |
FD_SET((unsigned int) fd, &fds); |
68 |
#endif |
fdmax = fd; |
69 |
if (strncasecmp(achBuffer, "PING ", 5) == 0) { |
|
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... |
80 |
|
iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv); |
81 |
|
if (iSelect > 0 && FD_ISSET(fd, &fds)) { |
82 |
|
// May recv now... |
83 |
|
cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0); |
84 |
|
if (cchBuffer > 0) { |
85 |
// Make sure received buffer it's null terminated. |
// Make sure received buffer it's null terminated. |
86 |
achBuffer[cchBuffer] = (char) 0; |
achBuffer[cchBuffer] = (char) 0; |
87 |
lscp_strtok(achBuffer, pszSeps, &(pch)); // Skip "PING" |
// Parse for the notification event message... |
88 |
lscp_strtok(NULL, pszSeps, &(pch)); // Skip port (must be the same as in addr) |
pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". |
89 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); // Have session-id. |
if (strcasecmp(pszToken, "NOTIFY") == 0) { |
90 |
if (pszToken) { |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
91 |
// Set now client's session-id, if not already |
event = lscp_event_from_text(pszToken); |
92 |
if (pClient->sessid == NULL) |
// And pick the rest of data... |
93 |
pClient->sessid = strdup(pszToken); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
94 |
if (pClient->sessid && strcmp(pszToken, pClient->sessid) == 0) { |
cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); |
95 |
sprintf(achBuffer, "PONG %s\r\n", pClient->sessid); |
// Double-check if we're really up to it... |
96 |
cchBuffer = strlen(achBuffer); |
if (pClient->events & event) { |
97 |
if (sendto(pClient->evt.sock, achBuffer, cchBuffer, 0, (struct sockaddr *) &addr, cAddr) < cchBuffer) |
// Invoke the client event callback... |
98 |
lscp_socket_perror("_lscp_client_evt_proc: sendto"); |
if ((*pClient->pfnCallback)( |
99 |
#ifdef DEBUG |
pClient, |
100 |
fprintf(stderr, "> %s", achBuffer); |
event, |
101 |
#endif |
pszToken, |
102 |
|
cchToken, |
103 |
|
pClient->pvData) != LSCP_OK) { |
104 |
|
pClient->evt.iState = 0; |
105 |
|
} |
106 |
} |
} |
107 |
} |
} |
|
// Done with life proof. |
|
108 |
} else { |
} else { |
109 |
// |
lscp_socket_perror("_lscp_client_evt_proc: recv"); |
110 |
if ((*pClient->pfnCallback)( |
pClient->evt.iState = 0; |
|
pClient, |
|
|
achBuffer, |
|
|
cchBuffer, |
|
|
pClient->pvData) != LSCP_OK) { |
|
|
pClient->evt.iState = 0; |
|
|
} |
|
111 |
} |
} |
112 |
} else { |
} // Check if select has in error. |
113 |
lscp_socket_perror("_lscp_client_evt_proc: recvfrom"); |
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 |
126 |
|
|
127 |
|
|
128 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
129 |
|
// Event subscription helpers. |
130 |
|
|
131 |
|
// Open the event service socket connection. |
132 |
|
static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient ) |
133 |
|
{ |
134 |
|
lscp_socket_t sock; |
135 |
|
struct sockaddr_in addr; |
136 |
|
int cAddr; |
137 |
|
#if defined(WIN32) |
138 |
|
int iSockOpt = (-1); |
139 |
|
#endif |
140 |
|
|
141 |
|
// Prepare the event connection socket... |
142 |
|
sock = socket(AF_INET, SOCK_STREAM, 0); |
143 |
|
if (sock == INVALID_SOCKET) { |
144 |
|
lscp_socket_perror("_lscp_client_evt_connect: socket"); |
145 |
|
return LSCP_FAILED; |
146 |
|
} |
147 |
|
|
148 |
|
#if defined(WIN32) |
149 |
|
if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
150 |
|
lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)"); |
151 |
|
#endif |
152 |
|
|
153 |
|
#ifdef DEBUG |
154 |
|
lscp_socket_getopts("_lscp_client_evt_connect:", sock); |
155 |
|
#endif |
156 |
|
|
157 |
|
// Use same address of the command connection. |
158 |
|
cAddr = sizeof(struct sockaddr_in); |
159 |
|
memmove((char *) &addr, &(pClient->cmd.addr), cAddr); |
160 |
|
|
161 |
|
// Start the connection... |
162 |
|
if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
163 |
|
lscp_socket_perror("_lscp_client_evt_connect: connect"); |
164 |
|
closesocket(sock); |
165 |
|
return LSCP_FAILED; |
166 |
|
} |
167 |
|
|
168 |
|
// Set our socket agent struct... |
169 |
|
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
170 |
|
|
171 |
|
// And finally the service thread... |
172 |
|
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
// Subscribe to a single event. |
177 |
|
static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event ) |
178 |
|
{ |
179 |
|
const char *pszEvent; |
180 |
|
char szQuery[LSCP_BUFSIZ]; |
181 |
|
int cchQuery; |
182 |
|
|
183 |
|
if (pClient == NULL) |
184 |
|
return LSCP_FAILED; |
185 |
|
|
186 |
|
// Which (single) event? |
187 |
|
pszEvent = lscp_event_to_text(event); |
188 |
|
if (pszEvent == NULL) |
189 |
|
return LSCP_FAILED; |
190 |
|
|
191 |
|
// Build the query string... |
192 |
|
cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent); |
193 |
|
// Just send data, forget result... |
194 |
|
if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) { |
195 |
|
lscp_socket_perror("_lscp_client_evt_request: send"); |
196 |
|
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... |
203 |
|
if (iSubscribe) |
204 |
|
pClient->events |= event; |
205 |
|
else |
206 |
|
pClient->events &= ~event; |
207 |
|
|
208 |
|
return LSCP_OK; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
//------------------------------------------------------------------------- |
213 |
// Client versioning teller fuunction. |
// Client versioning teller fuunction. |
214 |
|
|
215 |
|
|
247 |
lscp_socket_t sock; |
lscp_socket_t sock; |
248 |
struct sockaddr_in addr; |
struct sockaddr_in addr; |
249 |
int cAddr; |
int cAddr; |
250 |
|
#if defined(WIN32) |
251 |
int iSockOpt = (-1); |
int iSockOpt = (-1); |
252 |
|
#endif |
253 |
|
|
254 |
if (pfnCallback == NULL) { |
if (pfnCallback == NULL) { |
255 |
fprintf(stderr, "lscp_client_create: Invalid client callback function.\n"); |
fprintf(stderr, "lscp_client_create: Invalid client callback function.\n"); |
309 |
return NULL; |
return NULL; |
310 |
} |
} |
311 |
|
|
312 |
|
// Initialize the command socket agent struct... |
313 |
lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr); |
lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr); |
314 |
|
|
315 |
#ifdef DEBUG |
#ifdef DEBUG |
316 |
fprintf(stderr, "lscp_client_create: cmd: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->cmd.sock, inet_ntoa(pClient->cmd.addr.sin_addr), ntohs(pClient->cmd.addr.sin_port)); |
fprintf(stderr, "lscp_client_create: cmd: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->cmd.sock, inet_ntoa(pClient->cmd.addr.sin_addr), ntohs(pClient->cmd.addr.sin_port)); |
317 |
#endif |
#endif |
318 |
|
|
319 |
// Prepare the event datagram service socket... |
// Initialize the event service socket struct... |
320 |
|
lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0); |
321 |
sock = socket(AF_INET, SOCK_DGRAM, 0); |
// No events subscribed, yet. |
322 |
if (sock == INVALID_SOCKET) { |
pClient->events = LSCP_EVENT_NONE; |
|
lscp_socket_perror("lscp_client_create: evt: socket"); |
|
|
lscp_socket_agent_free(&(pClient->cmd)); |
|
|
free(pClient); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
|
|
lscp_socket_perror("lscp_client_create: evt: setsockopt(SO_REUSEADDR)"); |
|
|
|
|
|
#ifdef DEBUG |
|
|
lscp_socket_getopts("lscp_client_create: evt", sock); |
|
|
#endif |
|
|
|
|
|
cAddr = sizeof(struct sockaddr_in); |
|
|
memset((char *) &addr, 0, cAddr); |
|
|
addr.sin_family = AF_INET; |
|
|
addr.sin_addr.s_addr = htonl(INADDR_ANY); |
|
|
addr.sin_port = htons(0); |
|
|
|
|
|
if (bind(sock, (const struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
|
|
lscp_socket_perror("lscp_client_create: evt: bind"); |
|
|
lscp_socket_agent_free(&(pClient->cmd)); |
|
|
closesocket(sock); |
|
|
free(pClient); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
if (getsockname(sock, (struct sockaddr *) &addr, &cAddr) == SOCKET_ERROR) { |
|
|
lscp_socket_perror("lscp_client_create: evt: getsockname"); |
|
|
lscp_socket_agent_free(&(pClient->cmd)); |
|
|
closesocket(sock); |
|
|
free(pClient); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
|
|
|
|
|
#ifdef DEBUG |
|
|
fprintf(stderr, "lscp_client_create: evt: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->evt.sock, inet_ntoa(pClient->evt.addr.sin_addr), ntohs(pClient->evt.addr.sin_port)); |
|
|
#endif |
|
|
|
|
|
// No session id, yet. |
|
|
pClient->sessid = NULL; |
|
323 |
// Initialize cached members. |
// Initialize cached members. |
324 |
pClient->audio_drivers = NULL; |
pClient->audio_drivers = NULL; |
325 |
pClient->midi_drivers = NULL; |
pClient->midi_drivers = NULL; |
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. |
348 |
pClient->iStreamCount = 0; |
pClient->iStreamCount = 0; |
349 |
// Default timeout value. |
// Default timeout value. |
350 |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
351 |
|
pClient->iTimeoutCount = 0; |
352 |
|
|
353 |
// Initialize the transaction mutex. |
// Initialize the transaction mutex. |
354 |
lscp_mutex_init(pClient->mutex); |
lscp_mutex_init(pClient->mutex); |
355 |
|
lscp_cond_init(pClient->cond); |
|
// Now's finally time to startup threads... |
|
|
// Event service thread... |
|
|
if (lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0) != LSCP_OK) { |
|
|
lscp_socket_agent_free(&(pClient->cmd)); |
|
|
lscp_socket_agent_free(&(pClient->evt)); |
|
|
lscp_mutex_destroy(pClient->mutex); |
|
|
free(pClient); |
|
|
return NULL; |
|
|
} |
|
356 |
|
|
357 |
// Finally we've some success... |
// Finally we've some success... |
358 |
return pClient; |
return pClient; |
398 |
|
|
399 |
// Lock this section up. |
// Lock this section up. |
400 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
401 |
|
|
|
// Free session-id, if any. |
|
|
if (pClient->sessid) |
|
|
free(pClient->sessid); |
|
|
pClient->sessid = NULL; |
|
402 |
// Free up all cached members. |
// Free up all cached members. |
403 |
lscp_channel_info_reset(&(pClient->channel_info)); |
lscp_channel_info_free(&(pClient->channel_info)); |
404 |
lscp_engine_info_reset(&(pClient->engine_info)); |
lscp_engine_info_free(&(pClient->engine_info)); |
405 |
lscp_driver_info_reset(&(pClient->midi_info)); |
lscp_server_info_free(&(pClient->server_info)); |
406 |
lscp_driver_info_reset(&(pClient->audio_info)); |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
407 |
|
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
408 |
|
lscp_device_port_info_free(&(pClient->midi_port_info)); |
409 |
|
lscp_device_port_info_free(&(pClient->audio_channel_info)); |
410 |
|
lscp_param_info_free(&(pClient->midi_param_info)); |
411 |
|
lscp_param_info_free(&(pClient->audio_param_info)); |
412 |
|
lscp_device_info_free(&(pClient->midi_device_info)); |
413 |
|
lscp_device_info_free(&(pClient->audio_device_info)); |
414 |
|
lscp_driver_info_free(&(pClient->midi_driver_info)); |
415 |
|
lscp_driver_info_free(&(pClient->audio_driver_info)); |
416 |
// Free available engine table. |
// Free available engine table. |
417 |
lscp_szsplit_destroy(pClient->audio_drivers); |
lscp_szsplit_destroy(pClient->audio_drivers); |
418 |
lscp_szsplit_destroy(pClient->midi_drivers); |
lscp_szsplit_destroy(pClient->midi_drivers); |
426 |
pClient->engines = NULL; |
pClient->engines = NULL; |
427 |
// Free result error stuff. |
// Free result error stuff. |
428 |
lscp_client_set_result(pClient, NULL, 0); |
lscp_client_set_result(pClient, NULL, 0); |
429 |
// Frre stream usage stuff. |
// Free stream usage stuff. |
430 |
if (pClient->buffer_fill) |
if (pClient->buffer_fill) |
431 |
free(pClient->buffer_fill); |
free(pClient->buffer_fill); |
432 |
pClient->buffer_fill = NULL; |
pClient->buffer_fill = NULL; |
440 |
// Last but not least, free good ol'transaction mutex. |
// Last but not least, free good ol'transaction mutex. |
441 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
442 |
lscp_mutex_destroy(pClient->mutex); |
lscp_mutex_destroy(pClient->mutex); |
443 |
|
lscp_cond_destroy(pClient->cond); |
444 |
|
|
445 |
free(pClient); |
free(pClient); |
446 |
|
|
503 |
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 ) |
504 |
{ |
{ |
505 |
lscp_status_t ret; |
lscp_status_t ret; |
506 |
|
|
507 |
// Lock this section up. |
// Lock this section up. |
508 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
509 |
|
|
510 |
// Just make the now guarded call. |
// Just make the now guarded call. |
511 |
ret = lscp_client_call(pClient, pszQuery); |
ret = lscp_client_call(pClient, pszQuery); |
512 |
|
|
513 |
// Unlock this section down. |
// Unlock this section down. |
514 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
515 |
|
|
516 |
return ret; |
return ret; |
517 |
} |
} |
518 |
|
|
555 |
// Client registration protocol functions. |
// Client registration protocol functions. |
556 |
|
|
557 |
/** |
/** |
558 |
* Register frontend for receiving UDP event messages: |
* Register frontend for receiving event messages: |
559 |
* SUBSCRIBE NOTIFICATION <udp-port> |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
560 |
|
* | CHANNEL_INFO | MISCELLANEOUS |
561 |
* |
* |
562 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
563 |
|
* @param events Bit-wise OR'ed event flags to subscribe. |
564 |
* |
* |
565 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
566 |
*/ |
*/ |
567 |
lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient ) |
lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events ) |
568 |
{ |
{ |
569 |
lscp_status_t ret; |
lscp_status_t ret = LSCP_FAILED; |
|
char szQuery[LSCP_BUFSIZ]; |
|
|
const char *pszResult; |
|
|
const char *pszSeps = "[]"; |
|
|
char *pszToken; |
|
|
char *pch; |
|
570 |
|
|
571 |
if (pClient == NULL || pClient->sessid) |
if (pClient == NULL) |
572 |
return LSCP_FAILED; |
return LSCP_FAILED; |
573 |
|
|
574 |
// Lock this section up. |
// Lock this section up. |
575 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
576 |
|
|
577 |
sprintf(szQuery, "SUBSCRIBE NOTIFICATION %d\r\n", ntohs(pClient->evt.addr.sin_port)); |
// If applicable, start the alternate connection... |
578 |
ret = lscp_client_call(pClient, szQuery); |
if (pClient->events == LSCP_EVENT_NONE) |
579 |
if (ret == LSCP_OK) { |
ret = _lscp_client_evt_connect(pClient); |
580 |
pszResult = lscp_client_get_result(pClient); |
|
581 |
#ifdef DEBUG |
// Send the subscription commands. |
582 |
fprintf(stderr, "lscp_client_subscribe: %s\n", pszResult); |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
583 |
#endif |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT); |
584 |
// Check for the session-id on "OK[sessid]" response. |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
585 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
586 |
if (pszToken && strcasecmp(pszToken, "OK") == 0) { |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
587 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT); |
588 |
if (pszToken) |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
589 |
pClient->sessid = strdup(pszToken); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL); |
590 |
} |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
591 |
} |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO); |
592 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
593 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS); |
594 |
|
|
595 |
// Unlock this section down. |
// Unlock this section down. |
596 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
600 |
|
|
601 |
|
|
602 |
/** |
/** |
603 |
* Deregister frontend for not receiving UDP event messages anymore: |
* Deregister frontend from receiving UDP event messages anymore: |
604 |
* UNSUBSCRIBE NOTIFICATION <session-id> |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
605 |
|
* | CHANNEL_INFO | MISCELLANEOUS |
606 |
* |
* |
607 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
608 |
|
* @param events Bit-wise OR'ed event flags to unsubscribe. |
609 |
* |
* |
610 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
611 |
*/ |
*/ |
612 |
lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient ) |
lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events ) |
613 |
{ |
{ |
614 |
lscp_status_t ret; |
lscp_status_t ret = LSCP_OK; |
|
char szQuery[LSCP_BUFSIZ]; |
|
615 |
|
|
616 |
if (pClient == NULL) |
if (pClient == NULL) |
617 |
return LSCP_FAILED; |
return LSCP_FAILED; |
|
if (pClient->sessid == NULL) |
|
|
return LSCP_FAILED; |
|
618 |
|
|
619 |
// Lock this section up. |
// Lock this section up. |
620 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
621 |
|
|
622 |
sprintf(szQuery, "UNSUBSCRIBE NOTIFICATION %s\n\n", pClient->sessid); |
// Send the unsubscription commands. |
623 |
ret = lscp_client_call(pClient, szQuery); |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
624 |
if (ret == LSCP_OK) { |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT); |
625 |
#ifdef DEBUG |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
626 |
fprintf(stderr, "lscp_client_unsubscribe: %s\n", lscp_client_get_result(pClient)); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
627 |
#endif |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
628 |
// Bail out session-id string. |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT); |
629 |
free(pClient->sessid); |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
630 |
pClient->sessid = NULL; |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL); |
631 |
} |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
632 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO); |
633 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
634 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS); |
635 |
|
|
636 |
|
// If necessary, close the alternate connection... |
637 |
|
if (pClient->events == LSCP_EVENT_NONE) |
638 |
|
lscp_socket_agent_free(&(pClient->evt)); |
639 |
|
|
640 |
// Unlock this section down. |
// Unlock this section down. |
641 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
644 |
} |
} |
645 |
|
|
646 |
|
|
647 |
|
/** |
648 |
|
* Getting current subscribed events. |
649 |
|
* |
650 |
|
* @param pClient Pointer to client instance structure. |
651 |
|
* |
652 |
|
* @returns The current subscrived bit-wise OR'ed event flags. |
653 |
|
*/ |
654 |
|
lscp_event_t lscp_client_get_events ( lscp_client_t *pClient ) |
655 |
|
{ |
656 |
|
if (pClient == NULL) |
657 |
|
return LSCP_EVENT_NONE; |
658 |
|
|
659 |
|
return pClient->events; |
660 |
|
} |
661 |
|
|
662 |
|
|
663 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
664 |
// Client command protocol functions. |
// Client command protocol functions. |
665 |
|
|
681 |
if (pszFileName == NULL || iSamplerChannel < 0) |
if (pszFileName == NULL || iSamplerChannel < 0) |
682 |
return LSCP_FAILED; |
return LSCP_FAILED; |
683 |
|
|
684 |
sprintf(szQuery, "LOAD INSTRUMENT %s %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
685 |
|
return lscp_client_query(pClient, szQuery); |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
/** |
690 |
|
* Loading an instrument in the background (non modal): |
691 |
|
* LOAD INSTRUMENT NON_MODAL <filename> <instr-index> <sampler-channel> |
692 |
|
* |
693 |
|
* @param pClient Pointer to client instance structure. |
694 |
|
* @param pszFileName Instrument file name. |
695 |
|
* @param iInstrIndex Instrument index number. |
696 |
|
* @param iSamplerChannel Sampler Channel. |
697 |
|
* |
698 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
699 |
|
*/ |
700 |
|
lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel ) |
701 |
|
{ |
702 |
|
char szQuery[LSCP_BUFSIZ]; |
703 |
|
|
704 |
|
if (pszFileName == NULL || iSamplerChannel < 0) |
705 |
|
return LSCP_FAILED; |
706 |
|
|
707 |
|
sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
708 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
709 |
} |
} |
710 |
|
|
772 |
|
|
773 |
if (pClient == NULL) |
if (pClient == NULL) |
774 |
return NULL; |
return NULL; |
775 |
|
|
776 |
// Lock this section up. |
// Lock this section up. |
777 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
778 |
|
|
809 |
|
|
810 |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
811 |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
812 |
|
|
813 |
// Unlock this section down. |
// Unlock this section down. |
814 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
815 |
|
|
839 |
|
|
840 |
|
|
841 |
/** |
/** |
842 |
* Getting all available engines: |
* Getting all available engines count: |
843 |
* GET AVAILABLE_ENGINES |
* GET AVAILABLE_ENGINES |
844 |
* |
* |
845 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
846 |
* |
* |
847 |
|
* @returns The current total number of sampler engines on success, |
848 |
|
* -1 otherwise. |
849 |
|
*/ |
850 |
|
int lscp_get_available_engines ( lscp_client_t *pClient ) |
851 |
|
{ |
852 |
|
int iAvailableEngines = -1; |
853 |
|
|
854 |
|
// Lock this section up. |
855 |
|
lscp_mutex_lock(pClient->mutex); |
856 |
|
|
857 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
858 |
|
iAvailableEngines = atoi(lscp_client_get_result(pClient)); |
859 |
|
|
860 |
|
// Unlock this section down. |
861 |
|
lscp_mutex_unlock(pClient->mutex); |
862 |
|
|
863 |
|
return iAvailableEngines; |
864 |
|
} |
865 |
|
|
866 |
|
|
867 |
|
/** |
868 |
|
* Getting all available engines: |
869 |
|
* LIST AVAILABLE_ENGINES |
870 |
|
* |
871 |
|
* @param pClient Pointer to client instance structure. |
872 |
|
* |
873 |
* @returns A NULL terminated array of engine name strings, |
* @returns A NULL terminated array of engine name strings, |
874 |
* or NULL in case of failure. |
* or NULL in case of failure. |
875 |
*/ |
*/ |
876 |
const char **lscp_get_available_engines ( lscp_client_t *pClient ) |
const char **lscp_list_available_engines ( lscp_client_t *pClient ) |
877 |
{ |
{ |
878 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
879 |
|
|
885 |
pClient->engines = NULL; |
pClient->engines = NULL; |
886 |
} |
} |
887 |
|
|
888 |
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK) |
889 |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
890 |
|
|
891 |
// Unlock this section down. |
// Unlock this section down. |
932 |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
933 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
934 |
if (pszToken) |
if (pszToken) |
935 |
pEngineInfo->description = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pEngineInfo->description), &pszToken); |
936 |
} |
} |
937 |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
938 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
939 |
if (pszToken) |
if (pszToken) |
940 |
pEngineInfo->version = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pEngineInfo->version), &pszToken); |
941 |
} |
} |
942 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
943 |
} |
} |
944 |
} |
} |
945 |
else pEngineInfo = NULL; |
else pEngineInfo = NULL; |
946 |
|
|
947 |
// Unlock this section down. |
// Unlock this section down. |
948 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
949 |
|
|
976 |
|
|
977 |
// Lock this section up. |
// Lock this section up. |
978 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
979 |
|
|
980 |
pChannelInfo = &(pClient->channel_info); |
pChannelInfo = &(pClient->channel_info); |
981 |
lscp_channel_info_reset(pChannelInfo); |
lscp_channel_info_reset(pChannelInfo); |
982 |
|
|
988 |
if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
989 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
990 |
if (pszToken) |
if (pszToken) |
991 |
pChannelInfo->engine_name = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken); |
992 |
} |
} |
993 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) { |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) { |
994 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1002 |
} |
} |
1003 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
1004 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1005 |
if (pszToken) |
if (pszToken) { |
1006 |
|
if (pChannelInfo->audio_routing) |
1007 |
|
lscp_szsplit_destroy(pChannelInfo->audio_routing); |
1008 |
pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ","); |
pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ","); |
1009 |
|
} |
1010 |
} |
} |
1011 |
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
1012 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1013 |
if (pszToken) |
if (pszToken) |
1014 |
pChannelInfo->instrument_file = lscp_unquote(&pszToken, 1); |
lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken); |
1015 |
} |
} |
1016 |
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
1017 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1018 |
if (pszToken) |
if (pszToken) |
1019 |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
1020 |
} |
} |
1021 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { |
1022 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1023 |
|
if (pszToken) |
1024 |
|
lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken); |
1025 |
|
} |
1026 |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
1027 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1028 |
if (pszToken) |
if (pszToken) |
1040 |
} |
} |
1041 |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
1042 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1043 |
if (pszToken) |
if (pszToken) { |
1044 |
pChannelInfo->midi_channel = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_ltrim(pszToken); |
1045 |
|
if (strcasecmp(pszToken, "ALL") == 0) |
1046 |
|
pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL; |
1047 |
|
else |
1048 |
|
pChannelInfo->midi_channel = atoi(pszToken); |
1049 |
|
} |
1050 |
} |
} |
1051 |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
1052 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1053 |
if (pszToken) |
if (pszToken) |
1054 |
pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
1055 |
} |
} |
1056 |
|
else if (strcasecmp(pszToken, "MUTE") == 0) { |
1057 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1058 |
|
if (pszToken) |
1059 |
|
pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
1060 |
|
} |
1061 |
|
else if (strcasecmp(pszToken, "SOLO") == 0) { |
1062 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1063 |
|
if (pszToken) |
1064 |
|
pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
1065 |
|
} |
1066 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1067 |
} |
} |
1068 |
} |
} |
1069 |
else pChannelInfo = NULL; |
else pChannelInfo = NULL; |
1070 |
|
|
1071 |
// Unlock this section up. |
// Unlock this section up. |
1072 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1073 |
|
|
1110 |
* Current number of active disk streams: |
* Current number of active disk streams: |
1111 |
* GET CHANNEL STREAM_COUNT <sampler-channel> |
* GET CHANNEL STREAM_COUNT <sampler-channel> |
1112 |
* |
* |
1113 |
|
* @param pClient Pointer to client instance structure. |
1114 |
|
* @param iSamplerChannel Sampler channel number. |
1115 |
|
* |
1116 |
* @returns The number of active disk streams on success, -1 otherwise. |
* @returns The number of active disk streams on success, -1 otherwise. |
1117 |
*/ |
*/ |
1118 |
int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) |
int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) |
1138 |
|
|
1139 |
|
|
1140 |
/** |
/** |
1141 |
|
* Current least usage of active disk streams. |
1142 |
|
* |
1143 |
|
* @param pClient Pointer to client instance structure. |
1144 |
|
* @param iSamplerChannel Sampler channel number. |
1145 |
|
* |
1146 |
|
* @returns The usage percentage of the least filled active disk stream |
1147 |
|
* on success, -1 otherwise. |
1148 |
|
*/ |
1149 |
|
int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel ) |
1150 |
|
{ |
1151 |
|
char szQuery[LSCP_BUFSIZ]; |
1152 |
|
int iStreamUsage = -1; |
1153 |
|
const char *pszResult; |
1154 |
|
const char *pszSeps = "[]%,"; |
1155 |
|
char *pszToken; |
1156 |
|
char *pch; |
1157 |
|
int iStream; |
1158 |
|
int iPercent; |
1159 |
|
|
1160 |
|
if (iSamplerChannel < 0) |
1161 |
|
return iStreamUsage; |
1162 |
|
|
1163 |
|
// Lock this section up. |
1164 |
|
lscp_mutex_lock(pClient->mutex); |
1165 |
|
|
1166 |
|
iStream = 0; |
1167 |
|
sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel); |
1168 |
|
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
1169 |
|
pszResult = lscp_client_get_result(pClient); |
1170 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1171 |
|
while (pszToken) { |
1172 |
|
if (*pszToken) { |
1173 |
|
// Skip stream id. |
1174 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1175 |
|
if (pszToken == NULL) |
1176 |
|
break; |
1177 |
|
// Get least buffer fill percentage. |
1178 |
|
iPercent = atol(pszToken); |
1179 |
|
if (iStreamUsage > iPercent || iStream == 0) |
1180 |
|
iStreamUsage = iPercent; |
1181 |
|
iStream++; |
1182 |
|
} |
1183 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1184 |
|
} |
1185 |
|
} |
1186 |
|
|
1187 |
|
// Unlock this section down. |
1188 |
|
lscp_mutex_unlock(pClient->mutex); |
1189 |
|
|
1190 |
|
return iStreamUsage; |
1191 |
|
} |
1192 |
|
|
1193 |
|
|
1194 |
|
/** |
1195 |
* Current fill state of disk stream buffers: |
* Current fill state of disk stream buffers: |
1196 |
* GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel> |
* GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel> |
1197 |
* |
* |
1260 |
else while (iStream < pClient->iStreamCount) |
else while (iStream < pClient->iStreamCount) |
1261 |
pBufferFill[iStream++].stream_usage = 0; |
pBufferFill[iStream++].stream_usage = 0; |
1262 |
} |
} |
1263 |
|
|
1264 |
// Unlock this section down. |
// Unlock this section down. |
1265 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1266 |
|
|
1289 |
|
|
1290 |
|
|
1291 |
/** |
/** |
1292 |
|
* Setting audio output device: |
1293 |
|
* SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id> |
1294 |
|
* |
1295 |
|
* @param pClient Pointer to client instance structure. |
1296 |
|
* @param iSamplerChannel Sampler channel number. |
1297 |
|
* @param iAudioDevice Audio output device number identifier. |
1298 |
|
*/ |
1299 |
|
lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice ) |
1300 |
|
{ |
1301 |
|
char szQuery[LSCP_BUFSIZ]; |
1302 |
|
|
1303 |
|
if (iSamplerChannel < 0 || iAudioDevice < 0) |
1304 |
|
return LSCP_FAILED; |
1305 |
|
|
1306 |
|
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice); |
1307 |
|
return lscp_client_query(pClient, szQuery); |
1308 |
|
} |
1309 |
|
|
1310 |
|
|
1311 |
|
/** |
1312 |
* Setting audio output channel: |
* Setting audio output channel: |
1313 |
* SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan> |
* SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan> |
1314 |
* |
* |
1326 |
if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0) |
if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0) |
1327 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1328 |
|
|
1329 |
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); |
1330 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1331 |
} |
} |
1332 |
|
|
1354 |
|
|
1355 |
|
|
1356 |
/** |
/** |
1357 |
|
* Setting MIDI input device: |
1358 |
|
* SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id> |
1359 |
|
* |
1360 |
|
* @param pClient Pointer to client instance structure. |
1361 |
|
* @param iSamplerChannel Sampler channel number. |
1362 |
|
* @param iMidiDevice MIDI input device number identifier. |
1363 |
|
*/ |
1364 |
|
lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice ) |
1365 |
|
{ |
1366 |
|
char szQuery[LSCP_BUFSIZ]; |
1367 |
|
|
1368 |
|
if (iSamplerChannel < 0 || iMidiDevice < 0) |
1369 |
|
return LSCP_FAILED; |
1370 |
|
|
1371 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice); |
1372 |
|
return lscp_client_query(pClient, szQuery); |
1373 |
|
} |
1374 |
|
|
1375 |
|
|
1376 |
|
/** |
1377 |
* Setting MIDI input port: |
* Setting MIDI input port: |
1378 |
* SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port> |
* SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port> |
1379 |
* |
* |
1401 |
* |
* |
1402 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1403 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1404 |
* @param iMidiChannel MIDI channel number to listen (1-16) or |
* @param iMidiChannel MIDI channel address number to listen (0-15) or |
1405 |
* zero (0) to listen on all channels. |
* LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels. |
1406 |
* |
* |
1407 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1408 |
*/ |
*/ |
1413 |
if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16) |
if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16) |
1414 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1415 |
|
|
1416 |
if (iMidiChannel > 0) |
if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL) |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel); |
|
|
else |
|
1417 |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel); |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel); |
1418 |
|
else |
1419 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel); |
1420 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1421 |
} |
} |
1422 |
|
|
1446 |
|
|
1447 |
|
|
1448 |
/** |
/** |
1449 |
|
* Muting a sampler channel: |
1450 |
|
* SET CHANNEL MUTE <sampler-channel> <mute> |
1451 |
|
* |
1452 |
|
* @param pClient Pointer to client instance structure. |
1453 |
|
* @param iSamplerChannel Sampler channel number. |
1454 |
|
* @param iMute Sampler channel mute state as a boolean value, |
1455 |
|
* either 1 (one) to mute the channel or 0 (zero) |
1456 |
|
* to unmute the channel. |
1457 |
|
* |
1458 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1459 |
|
*/ |
1460 |
|
lscp_status_t lscp_set_channel_mute ( lscp_client_t *pClient, int iSamplerChannel, int iMute ) |
1461 |
|
{ |
1462 |
|
char szQuery[LSCP_BUFSIZ]; |
1463 |
|
|
1464 |
|
if (iSamplerChannel < 0 || iMute < 0 || iMute > 1) |
1465 |
|
return LSCP_FAILED; |
1466 |
|
|
1467 |
|
sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute); |
1468 |
|
return lscp_client_query(pClient, szQuery); |
1469 |
|
} |
1470 |
|
|
1471 |
|
|
1472 |
|
/** |
1473 |
|
* Soloing a sampler channel: |
1474 |
|
* SET CHANNEL SOLO <sampler-channel> <solo> |
1475 |
|
* |
1476 |
|
* @param pClient Pointer to client instance structure. |
1477 |
|
* @param iSamplerChannel Sampler channel number. |
1478 |
|
* @param iSolo Sampler channel solo state as a boolean value, |
1479 |
|
* either 1 (one) to solo the channel or 0 (zero) |
1480 |
|
* to unsolo the channel. |
1481 |
|
* |
1482 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1483 |
|
*/ |
1484 |
|
lscp_status_t lscp_set_channel_solo ( lscp_client_t *pClient, int iSamplerChannel, int iSolo ) |
1485 |
|
{ |
1486 |
|
char szQuery[LSCP_BUFSIZ]; |
1487 |
|
|
1488 |
|
if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1) |
1489 |
|
return LSCP_FAILED; |
1490 |
|
|
1491 |
|
sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo); |
1492 |
|
return lscp_client_query(pClient, szQuery); |
1493 |
|
} |
1494 |
|
|
1495 |
|
|
1496 |
|
/** |
1497 |
* Resetting a sampler channel: |
* Resetting a sampler channel: |
1498 |
* RESET CHANNEL <sampler-channel> |
* RESET CHANNEL <sampler-channel> |
1499 |
* |
* |
1514 |
} |
} |
1515 |
|
|
1516 |
|
|
1517 |
|
/** |
1518 |
|
* Resetting the sampler: |
1519 |
|
* RESET |
1520 |
|
* |
1521 |
|
* @param pClient Pointer to client instance structure. |
1522 |
|
* |
1523 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1524 |
|
*/ |
1525 |
|
lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient ) |
1526 |
|
{ |
1527 |
|
return lscp_client_query(pClient, "RESET\r\n"); |
1528 |
|
} |
1529 |
|
|
1530 |
|
|
1531 |
|
/** |
1532 |
|
* Getting information about the server. |
1533 |
|
* GET SERVER INFO |
1534 |
|
* |
1535 |
|
* @param pClient Pointer to client instance structure. |
1536 |
|
* |
1537 |
|
* @returns A pointer to a @ref lscp_server_info_t structure, with all the |
1538 |
|
* information of the current connected server, or NULL in case of failure. |
1539 |
|
*/ |
1540 |
|
lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient ) |
1541 |
|
{ |
1542 |
|
lscp_server_info_t *pServerInfo; |
1543 |
|
const char *pszResult; |
1544 |
|
const char *pszSeps = ":"; |
1545 |
|
const char *pszCrlf = "\r\n"; |
1546 |
|
char *pszToken; |
1547 |
|
char *pch; |
1548 |
|
|
1549 |
|
// Lock this section up. |
1550 |
|
lscp_mutex_lock(pClient->mutex); |
1551 |
|
|
1552 |
|
pServerInfo = &(pClient->server_info); |
1553 |
|
lscp_server_info_reset(pServerInfo); |
1554 |
|
|
1555 |
|
if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) { |
1556 |
|
pszResult = lscp_client_get_result(pClient); |
1557 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1558 |
|
while (pszToken) { |
1559 |
|
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
1560 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1561 |
|
if (pszToken) |
1562 |
|
lscp_unquote_dup(&(pServerInfo->description), &pszToken); |
1563 |
|
} |
1564 |
|
else if (strcasecmp(pszToken, "VERSION") == 0) { |
1565 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1566 |
|
if (pszToken) |
1567 |
|
lscp_unquote_dup(&(pServerInfo->version), &pszToken); |
1568 |
|
} |
1569 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1570 |
|
} |
1571 |
|
} |
1572 |
|
else pServerInfo = NULL; |
1573 |
|
|
1574 |
|
// Unlock this section down. |
1575 |
|
lscp_mutex_unlock(pClient->mutex); |
1576 |
|
|
1577 |
|
return pServerInfo; |
1578 |
|
} |
1579 |
|
|
1580 |
|
|
1581 |
// end of client.c |
// end of client.c |