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

Contents of /liblscp/trunk/src/client.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 946 - (show annotations) (download)
Mon Nov 27 18:33:02 2006 UTC (17 years, 4 months ago) by capela
File MIME type: text/plain
File size: 61746 byte(s)
* As of the LSCP 1.2 working draft document, added
  some missing client interface functions:
    lscp_get_total_voice_count();
    lscp_get_total_voice_count_max();
  and for the new MIDI instrument mapping features:
    lscp_map_midi_instrument();
    lscp_unmap_midi_instrument();
    lscp_get_midi_instruments();
    lscp_get_midi_instrument_info();
    lscp_clear_midi_instruments();

1 // client.c
2 //
3 /****************************************************************************
4 liblscp - LinuxSampler Control Protocol API
5 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
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 *****************************************************************************/
22
23 #include "common.h"
24
25 // Default timeout value (in milliseconds).
26 #define LSCP_TIMEOUT_MSECS 500
27
28
29 // Local prototypes.
30
31 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 //-------------------------------------------------------------------------
38 // Event service (datagram oriented).
39
40 static void _lscp_client_evt_proc ( void *pvClient )
41 {
42 lscp_client_t *pClient = (lscp_client_t *) pvClient;
43
44 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";
53 char * pszToken;
54 char * pch;
55 int cchToken;
56 lscp_event_t event;
57
58 #ifdef DEBUG
59 fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");
60 #endif
61
62 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...
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.
86 achBuffer[cchBuffer] = (char) 0;
87 // Parse for the notification event message...
88 pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".
89 if (strcasecmp(pszToken, "NOTIFY") == 0) {
90 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
91 event = lscp_event_from_text(pszToken);
92 // And pick the rest of data...
93 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
94 cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
95 // Double-check if we're really up to it...
96 if (pClient->events & event) {
97 // Invoke the client event callback...
98 if ((*pClient->pfnCallback)(
99 pClient,
100 event,
101 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 } // Check if select has in error.
113 else if (iSelect < 0) {
114 lscp_socket_perror("_lscp_client_evt_proc: select");
115 pClient->evt.iState = 0;
116 }
117
118 // Finally, always signal the event.
119 lscp_cond_signal(pClient->cond);
120 }
121
122 #ifdef DEBUG
123 fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n");
124 #endif
125 }
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.
214
215
216 /** Retrieve the current client library version string. */
217 const char* lscp_client_package (void) { return LSCP_PACKAGE; }
218
219 /** Retrieve the current client library version string. */
220 const char* lscp_client_version (void) { return LSCP_VERSION; }
221
222 /** Retrieve the current client library build timestamp string. */
223 const char* lscp_client_build (void) { return __DATE__ " " __TIME__; }
224
225
226 //-------------------------------------------------------------------------
227 // Client socket functions.
228
229 /**
230 * Create a client instance, estabilishing a connection to a server hostname,
231 * which must be listening on the given port. A client callback function is
232 * also supplied for server notification event handling.
233 *
234 * @param pszHost Hostname of the linuxsampler listening server.
235 * @param iPort Port number of the linuxsampler listening server.
236 * @param pfnCallback Callback function to receive event notifications.
237 * @param pvData User context opaque data, that will be passed
238 * to the callback function.
239 *
240 * @returns The new client instance pointer if successfull, which shall be
241 * used on all subsequent client calls, NULL otherwise.
242 */
243 lscp_client_t* lscp_client_create ( const char *pszHost, int iPort, lscp_client_proc_t pfnCallback, void *pvData )
244 {
245 lscp_client_t *pClient;
246 struct hostent *pHost;
247 lscp_socket_t sock;
248 struct sockaddr_in addr;
249 int cAddr;
250 #if defined(WIN32)
251 int iSockOpt = (-1);
252 #endif
253
254 if (pfnCallback == NULL) {
255 fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");
256 return NULL;
257 }
258
259 pHost = gethostbyname(pszHost);
260 if (pHost == NULL) {
261 lscp_socket_herror("lscp_client_create: gethostbyname");
262 return NULL;
263 }
264
265 // Allocate client descriptor...
266
267 pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t));
268 if (pClient == NULL) {
269 fprintf(stderr, "lscp_client_create: Out of memory.\n");
270 return NULL;
271 }
272 memset(pClient, 0, sizeof(lscp_client_t));
273
274 pClient->pfnCallback = pfnCallback;
275 pClient->pvData = pvData;
276
277 #ifdef DEBUG
278 fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort);
279 #endif
280
281 // Prepare the command connection socket...
282
283 sock = socket(AF_INET, SOCK_STREAM, 0);
284 if (sock == INVALID_SOCKET) {
285 lscp_socket_perror("lscp_client_create: cmd: socket");
286 free(pClient);
287 return NULL;
288 }
289
290 #if defined(WIN32)
291 if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)
292 lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)");
293 #endif
294
295 #ifdef DEBUG
296 lscp_socket_getopts("lscp_client_create: cmd", sock);
297 #endif
298
299 cAddr = sizeof(struct sockaddr_in);
300 memset((char *) &addr, 0, cAddr);
301 addr.sin_family = pHost->h_addrtype;
302 memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length);
303 addr.sin_port = htons((short) iPort);
304
305 if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
306 lscp_socket_perror("lscp_client_create: cmd: connect");
307 closesocket(sock);
308 free(pClient);
309 return NULL;
310 }
311
312 // Initialize the command socket agent struct...
313 lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);
314
315 #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));
317 #endif
318
319 // Initialize the event service socket struct...
320 lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);
321 // No events subscribed, yet.
322 pClient->events = LSCP_EVENT_NONE;
323 // Initialize cached members.
324 pClient->audio_drivers = NULL;
325 pClient->midi_drivers = NULL;
326 pClient->audio_devices = NULL;
327 pClient->midi_devices = NULL;
328 pClient->engines = NULL;
329 pClient->channels = NULL;
330 lscp_driver_info_init(&(pClient->audio_driver_info));
331 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));
342 lscp_channel_info_init(&(pClient->channel_info));
343 lscp_midi_instrument_info_init(&(pClient->midi_instrument_info));
344 // Initialize error stuff.
345 pClient->pszResult = NULL;
346 pClient->iErrno = -1;
347 // Stream usage stuff.
348 pClient->buffer_fill = NULL;
349 pClient->iStreamCount = 0;
350 // Default timeout value.
351 pClient->iTimeout = LSCP_TIMEOUT_MSECS;
352 pClient->iTimeoutCount = 0;
353
354 // Initialize the transaction mutex.
355 lscp_mutex_init(pClient->mutex);
356 lscp_cond_init(pClient->cond);
357
358 // Finally we've some success...
359 return pClient;
360 }
361
362
363 /**
364 * Wait for a client instance to terminate graciously.
365 *
366 * @param pClient Pointer to client instance structure.
367 */
368 lscp_status_t lscp_client_join ( lscp_client_t *pClient )
369 {
370 if (pClient == NULL)
371 return LSCP_FAILED;
372
373 #ifdef DEBUG
374 fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);
375 #endif
376
377 // lscp_socket_agent_join(&(pClient->evt));
378 lscp_socket_agent_join(&(pClient->cmd));
379
380 return LSCP_OK;
381 }
382
383
384 /**
385 * Terminate and destroy a client instance.
386 *
387 * @param pClient Pointer to client instance structure.
388 *
389 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
390 */
391 lscp_status_t lscp_client_destroy ( lscp_client_t *pClient )
392 {
393 if (pClient == NULL)
394 return LSCP_FAILED;
395
396 #ifdef DEBUG
397 fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);
398 #endif
399
400 // Lock this section up.
401 lscp_mutex_lock(pClient->mutex);
402
403 // Free up all cached members.
404 lscp_midi_instrument_info_free(&(pClient->midi_instrument_info));
405 lscp_channel_info_free(&(pClient->channel_info));
406 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));
409 lscp_param_info_free(&(pClient->audio_channel_param_info));
410 lscp_device_port_info_free(&(pClient->midi_port_info));
411 lscp_device_port_info_free(&(pClient->audio_channel_info));
412 lscp_param_info_free(&(pClient->midi_param_info));
413 lscp_param_info_free(&(pClient->audio_param_info));
414 lscp_device_info_free(&(pClient->midi_device_info));
415 lscp_device_info_free(&(pClient->audio_device_info));
416 lscp_driver_info_free(&(pClient->midi_driver_info));
417 lscp_driver_info_free(&(pClient->audio_driver_info));
418 // Free available engine table.
419 lscp_szsplit_destroy(pClient->audio_drivers);
420 lscp_szsplit_destroy(pClient->midi_drivers);
421 lscp_isplit_destroy(pClient->audio_devices);
422 lscp_isplit_destroy(pClient->midi_devices);
423 lscp_szsplit_destroy(pClient->engines);
424 lscp_isplit_destroy(pClient->channels);
425 // Make them null.
426 pClient->audio_drivers = NULL;
427 pClient->midi_drivers = NULL;
428 pClient->engines = NULL;
429 // Free result error stuff.
430 lscp_client_set_result(pClient, NULL, 0);
431 // Free stream usage stuff.
432 if (pClient->buffer_fill)
433 free(pClient->buffer_fill);
434 pClient->buffer_fill = NULL;
435 pClient->iStreamCount = 0;
436 pClient->iTimeout = 0;
437
438 // Free socket agents.
439 lscp_socket_agent_free(&(pClient->evt));
440 lscp_socket_agent_free(&(pClient->cmd));
441
442 // Last but not least, free good ol'transaction mutex.
443 lscp_mutex_unlock(pClient->mutex);
444 lscp_mutex_destroy(pClient->mutex);
445 lscp_cond_destroy(pClient->cond);
446
447 free(pClient);
448
449 return LSCP_OK;
450 }
451
452
453 /**
454 * Set the client transaction timeout interval.
455 *
456 * @param pClient Pointer to client instance structure.
457 * @param iTimeout Transaction timeout in milliseconds.
458 *
459 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
460 */
461 lscp_status_t lscp_client_set_timeout ( lscp_client_t *pClient, int iTimeout )
462 {
463 if (pClient == NULL)
464 return LSCP_FAILED;
465 if (iTimeout < 0)
466 return LSCP_FAILED;
467
468 pClient->iTimeout = iTimeout;
469 return LSCP_OK;
470 }
471
472
473 /**
474 * Get the client transaction timeout interval.
475 *
476 * @param pClient Pointer to client instance structure.
477 *
478 * @returns The current timeout value milliseconds, -1 in case of failure.
479 */
480 int lscp_client_get_timeout ( lscp_client_t *pClient )
481 {
482 if (pClient == NULL)
483 return -1;
484
485 return pClient->iTimeout;
486 }
487
488
489 //-------------------------------------------------------------------------
490 // Client common protocol functions.
491
492 /**
493 * Submit a command query line string to the server. The query string
494 * must be cr/lf and null terminated. Besides the return code, the
495 * specific server response to the command request is made available
496 * by the @ref lscp_client_get_result and @ref lscp_client_get_errno
497 * function calls.
498 *
499 * @param pClient Pointer to client instance structure.
500 * @param pszQuery Command request line to be sent to server,
501 * must be cr/lf and null terminated.
502 *
503 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
504 */
505 lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery )
506 {
507 lscp_status_t ret;
508
509 // Lock this section up.
510 lscp_mutex_lock(pClient->mutex);
511
512 // Just make the now guarded call.
513 ret = lscp_client_call(pClient, pszQuery);
514
515 // Unlock this section down.
516 lscp_mutex_unlock(pClient->mutex);
517
518 return ret;
519 }
520
521 /**
522 * Get the last received result string. In case of error or warning,
523 * this is the text of the error or warning message issued.
524 *
525 * @param pClient Pointer to client instance structure.
526 *
527 * @returns A pointer to the literal null-terminated result string as
528 * of the last command request.
529 */
530 const char *lscp_client_get_result ( lscp_client_t *pClient )
531 {
532 if (pClient == NULL)
533 return NULL;
534
535 return pClient->pszResult;
536 }
537
538
539 /**
540 * Get the last error/warning number received.
541 *
542 * @param pClient Pointer to client instance structure.
543 *
544 * @returns The numerical value of the last error or warning
545 * response code received.
546 */
547 int lscp_client_get_errno ( lscp_client_t *pClient )
548 {
549 if (pClient == NULL)
550 return -1;
551
552 return pClient->iErrno;
553 }
554
555
556 //-------------------------------------------------------------------------
557 // Client registration protocol functions.
558
559 /**
560 * Register frontend for receiving event messages:
561 * SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
562 * | CHANNEL_INFO | MISCELLANEOUS
563 *
564 * @param pClient Pointer to client instance structure.
565 * @param events Bit-wise OR'ed event flags to subscribe.
566 *
567 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
568 */
569 lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
570 {
571 lscp_status_t ret = LSCP_FAILED;
572
573 if (pClient == NULL)
574 return LSCP_FAILED;
575
576 // Lock this section up.
577 lscp_mutex_lock(pClient->mutex);
578
579 // If applicable, start the alternate connection...
580 if (pClient->events == LSCP_EVENT_NONE)
581 ret = _lscp_client_evt_connect(pClient);
582
583 // Send the subscription commands.
584 if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
585 ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);
586 if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
587 ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);
588 if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
589 ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);
590 if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
591 ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
592 if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
593 ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
594 if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
595 ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
596
597 // Unlock this section down.
598 lscp_mutex_unlock(pClient->mutex);
599
600 return ret;
601 }
602
603
604 /**
605 * Deregister frontend from receiving UDP event messages anymore:
606 * SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
607 * | CHANNEL_INFO | MISCELLANEOUS
608 *
609 * @param pClient Pointer to client instance structure.
610 * @param events Bit-wise OR'ed event flags to unsubscribe.
611 *
612 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
613 */
614 lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )
615 {
616 lscp_status_t ret = LSCP_OK;
617
618 if (pClient == NULL)
619 return LSCP_FAILED;
620
621 // Lock this section up.
622 lscp_mutex_lock(pClient->mutex);
623
624 // Send the unsubscription commands.
625 if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
626 ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);
627 if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
628 ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);
629 if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
630 ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);
631 if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
632 ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
633 if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
634 ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
635 if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
636 ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
637
638 // If necessary, close the alternate connection...
639 if (pClient->events == LSCP_EVENT_NONE)
640 lscp_socket_agent_free(&(pClient->evt));
641
642 // Unlock this section down.
643 lscp_mutex_unlock(pClient->mutex);
644
645 return ret;
646 }
647
648
649 /**
650 * Getting current subscribed events.
651 *
652 * @param pClient Pointer to client instance structure.
653 *
654 * @returns The current subscrived bit-wise OR'ed event flags.
655 */
656 lscp_event_t lscp_client_get_events ( lscp_client_t *pClient )
657 {
658 if (pClient == NULL)
659 return LSCP_EVENT_NONE;
660
661 return pClient->events;
662 }
663
664
665 //-------------------------------------------------------------------------
666 // Client command protocol functions.
667
668 /**
669 * Loading an instrument:
670 * LOAD INSTRUMENT <filename> <instr-index> <sampler-channel>
671 *
672 * @param pClient Pointer to client instance structure.
673 * @param pszFileName Instrument file name.
674 * @param iInstrIndex Instrument index number.
675 * @param iSamplerChannel Sampler Channel.
676 *
677 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
678 */
679 lscp_status_t lscp_load_instrument ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )
680 {
681 char szQuery[LSCP_BUFSIZ];
682
683 if (pszFileName == NULL || iSamplerChannel < 0)
684 return LSCP_FAILED;
685
686 sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
687 return lscp_client_query(pClient, szQuery);
688 }
689
690
691 /**
692 * Loading an instrument in the background (non modal):
693 * LOAD INSTRUMENT NON_MODAL <filename> <instr-index> <sampler-channel>
694 *
695 * @param pClient Pointer to client instance structure.
696 * @param pszFileName Instrument file name.
697 * @param iInstrIndex Instrument index number.
698 * @param iSamplerChannel Sampler Channel.
699 *
700 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
701 */
702 lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )
703 {
704 char szQuery[LSCP_BUFSIZ];
705
706 if (pszFileName == NULL || iSamplerChannel < 0)
707 return LSCP_FAILED;
708
709 sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
710 return lscp_client_query(pClient, szQuery);
711 }
712
713
714 /**
715 * Loading a sampler engine:
716 * LOAD ENGINE <engine-name> <sampler-channel>
717 *
718 * @param pClient Pointer to client instance structure.
719 * @param pszEngineName Engine name.
720 * @param iSamplerChannel Sampler channel number.
721 *
722 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
723 */
724 lscp_status_t lscp_load_engine ( lscp_client_t *pClient, const char *pszEngineName, int iSamplerChannel )
725 {
726 char szQuery[LSCP_BUFSIZ];
727
728 if (pszEngineName == NULL || iSamplerChannel < 0)
729 return LSCP_FAILED;
730
731 sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel);
732 return lscp_client_query(pClient, szQuery);
733 }
734
735
736 /**
737 * Current number of sampler channels:
738 * GET CHANNELS
739 *
740 * @param pClient Pointer to client instance structure.
741 *
742 * @returns The current total number of sampler channels on success,
743 * -1 otherwise.
744 */
745 int lscp_get_channels ( lscp_client_t *pClient )
746 {
747 int iChannels = -1;
748
749 // Lock this section up.
750 lscp_mutex_lock(pClient->mutex);
751
752 if (lscp_client_call(pClient, "GET CHANNELS\r\n") == LSCP_OK)
753 iChannels = atoi(lscp_client_get_result(pClient));
754
755 // Unlock this section doen.
756 lscp_mutex_unlock(pClient->mutex);
757
758 return iChannels;
759 }
760
761
762 /**
763 * List current sampler channels number identifiers:
764 * LIST CHANNELS
765 *
766 * @param pClient Pointer to client instance structure.
767 *
768 * @returns An array of the sampler channels identifiers as positive integers,
769 * terminated with -1 on success, NULL otherwise.
770 */
771 int *lscp_list_channels ( lscp_client_t *pClient )
772 {
773 const char *pszSeps = ",";
774
775 if (pClient == NULL)
776 return NULL;
777
778 // Lock this section up.
779 lscp_mutex_lock(pClient->mutex);
780
781 if (pClient->channels) {
782 lscp_isplit_destroy(pClient->channels);
783 pClient->channels = NULL;
784 }
785
786 if (lscp_client_call(pClient, "LIST CHANNELS\r\n") == LSCP_OK)
787 pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
788
789 // Unlock this section down.
790 lscp_mutex_unlock(pClient->mutex);
791
792 return pClient->channels;
793 }
794
795
796 /**
797 * Adding a new sampler channel:
798 * ADD CHANNEL
799 *
800 * @param pClient Pointer to client instance structure.
801 *
802 * @returns The new sampler channel number identifier,
803 * or -1 in case of failure.
804 */
805 int lscp_add_channel ( lscp_client_t *pClient )
806 {
807 int iSamplerChannel = -1;
808
809 // Lock this section up.
810 lscp_mutex_lock(pClient->mutex);
811
812 if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK)
813 iSamplerChannel = atoi(lscp_client_get_result(pClient));
814
815 // Unlock this section down.
816 lscp_mutex_unlock(pClient->mutex);
817
818 return iSamplerChannel;
819 }
820
821
822 /**
823 * Removing a sampler channel:
824 * REMOVE CHANNEL <sampler-channel>
825 *
826 * @param pClient Pointer to client instance structure.
827 * @param iSamplerChannel Sampler channel number.
828 *
829 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
830 */
831 lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel )
832 {
833 char szQuery[LSCP_BUFSIZ];
834
835 if (iSamplerChannel < 0)
836 return LSCP_FAILED;
837
838 sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel);
839 return lscp_client_query(pClient, szQuery);
840 }
841
842
843 /**
844 * Getting all available engines count:
845 * GET AVAILABLE_ENGINES
846 *
847 * @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,
876 * or NULL in case of failure.
877 */
878 const char **lscp_list_available_engines ( lscp_client_t *pClient )
879 {
880 const char *pszSeps = ",";
881
882 // Lock this section up.
883 lscp_mutex_lock(pClient->mutex);
884
885 if (pClient->engines) {
886 lscp_szsplit_destroy(pClient->engines);
887 pClient->engines = NULL;
888 }
889
890 if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK)
891 pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
892
893 // Unlock this section down.
894 lscp_mutex_unlock(pClient->mutex);
895
896 return (const char **) pClient->engines;
897 }
898
899
900 /**
901 * Getting information about an engine.
902 * GET ENGINE INFO <engine-name>
903 *
904 * @param pClient Pointer to client instance structure.
905 * @param pszEngineName Engine name.
906 *
907 * @returns A pointer to a @ref lscp_engine_info_t structure, with all the
908 * information of the given sampler engine, or NULL in case of failure.
909 */
910 lscp_engine_info_t *lscp_get_engine_info ( lscp_client_t *pClient, const char *pszEngineName )
911 {
912 lscp_engine_info_t *pEngineInfo;
913 char szQuery[LSCP_BUFSIZ];
914 const char *pszResult;
915 const char *pszSeps = ":";
916 const char *pszCrlf = "\r\n";
917 char *pszToken;
918 char *pch;
919
920 if (pszEngineName == NULL)
921 return NULL;
922
923 // Lock this section up.
924 lscp_mutex_lock(pClient->mutex);
925
926 pEngineInfo = &(pClient->engine_info);
927 lscp_engine_info_reset(pEngineInfo);
928
929 sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);
930 if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
931 pszResult = lscp_client_get_result(pClient);
932 pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
933 while (pszToken) {
934 if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
935 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
936 if (pszToken)
937 lscp_unquote_dup(&(pEngineInfo->description), &pszToken);
938 }
939 else if (strcasecmp(pszToken, "VERSION") == 0) {
940 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
941 if (pszToken)
942 lscp_unquote_dup(&(pEngineInfo->version), &pszToken);
943 }
944 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
945 }
946 }
947 else pEngineInfo = NULL;
948
949 // Unlock this section down.
950 lscp_mutex_unlock(pClient->mutex);
951
952 return pEngineInfo;
953 }
954
955
956 /**
957 * Getting sampler channel informations:
958 * GET CHANNEL INFO <sampler-channel>
959 *
960 * @param pClient Pointer to client instance structure.
961 * @param iSamplerChannel Sampler channel number.
962 *
963 * @returns A pointer to a @ref lscp_channel_info_t structure, with all the
964 * information of the given sampler channel, or NULL in case of failure.
965 */
966 lscp_channel_info_t *lscp_get_channel_info ( lscp_client_t *pClient, int iSamplerChannel )
967 {
968 lscp_channel_info_t *pChannelInfo;
969 char szQuery[LSCP_BUFSIZ];
970 const char *pszResult;
971 const char *pszSeps = ":";
972 const char *pszCrlf = "\r\n";
973 char *pszToken;
974 char *pch;
975
976 if (iSamplerChannel < 0)
977 return NULL;
978
979 // Lock this section up.
980 lscp_mutex_lock(pClient->mutex);
981
982 pChannelInfo = &(pClient->channel_info);
983 lscp_channel_info_reset(pChannelInfo);
984
985 sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);
986 if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
987 pszResult = lscp_client_get_result(pClient);
988 pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
989 while (pszToken) {
990 if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
991 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
992 if (pszToken)
993 lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken);
994 }
995 else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {
996 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
997 if (pszToken)
998 pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));
999 }
1000 else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {
1001 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1002 if (pszToken)
1003 pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));
1004 }
1005 else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
1006 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1007 if (pszToken) {
1008 if (pChannelInfo->audio_routing)
1009 lscp_szsplit_destroy(pChannelInfo->audio_routing);
1010 pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");
1011 }
1012 }
1013 else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
1014 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1015 if (pszToken)
1016 lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken);
1017 }
1018 else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
1019 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1020 if (pszToken)
1021 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) {
1029 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1030 if (pszToken)
1031 pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken));
1032 }
1033 else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {
1034 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1035 if (pszToken)
1036 pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));
1037 }
1038 else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {
1039 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1040 if (pszToken)
1041 pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));
1042 }
1043 else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {
1044 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1045 if (pszToken) {
1046 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) {
1054 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1055 if (pszToken)
1056 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));
1069 }
1070 }
1071 else pChannelInfo = NULL;
1072
1073 // Unlock this section up.
1074 lscp_mutex_unlock(pClient->mutex);
1075
1076 return pChannelInfo;
1077 }
1078
1079
1080 /**
1081 * Current number of active voices:
1082 * GET CHANNEL VOICE_COUNT <sampler-channel>
1083 *
1084 * @param pClient Pointer to client instance structure.
1085 * @param iSamplerChannel Sampler channel number.
1086 *
1087 * @returns The number of voices currently active, -1 in case of failure.
1088 */
1089 int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel )
1090 {
1091 char szQuery[LSCP_BUFSIZ];
1092 int iVoiceCount = -1;
1093
1094 if (iSamplerChannel < 0)
1095 return iVoiceCount;
1096
1097 // Lock this section up.
1098 lscp_mutex_lock(pClient->mutex);
1099
1100 sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);
1101 if (lscp_client_call(pClient, szQuery) == LSCP_OK)
1102 iVoiceCount = atoi(lscp_client_get_result(pClient));
1103
1104 // Unlock this section down.
1105 lscp_mutex_unlock(pClient->mutex);
1106
1107 return iVoiceCount;
1108 }
1109
1110
1111 /**
1112 * Current number of active disk streams:
1113 * GET CHANNEL STREAM_COUNT <sampler-channel>
1114 *
1115 * @param pClient Pointer to client instance structure.
1116 * @param iSamplerChannel Sampler channel number.
1117 *
1118 * @returns The number of active disk streams on success, -1 otherwise.
1119 */
1120 int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )
1121 {
1122 char szQuery[LSCP_BUFSIZ];
1123 int iStreamCount = -1;
1124
1125 if (iSamplerChannel < 0)
1126 return iStreamCount;
1127
1128 // Lock this section up.
1129 lscp_mutex_lock(pClient->mutex);
1130
1131 sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);
1132 if (lscp_client_call(pClient, szQuery) == LSCP_OK)
1133 iStreamCount = atoi(lscp_client_get_result(pClient));
1134
1135 // Unlock this section down.
1136 lscp_mutex_unlock(pClient->mutex);
1137
1138 return iStreamCount;
1139 }
1140
1141
1142 /**
1143 * Current least usage of active disk streams.
1144 *
1145 * @param pClient Pointer to client instance structure.
1146 * @param iSamplerChannel Sampler channel number.
1147 *
1148 * @returns The usage percentage of the least filled active disk stream
1149 * on success, -1 otherwise.
1150 */
1151 int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1152 {
1153 char szQuery[LSCP_BUFSIZ];
1154 int iStreamUsage = -1;
1155 const char *pszResult;
1156 const char *pszSeps = "[]%,";
1157 char *pszToken;
1158 char *pch;
1159 int iStream;
1160 int iPercent;
1161
1162 if (iSamplerChannel < 0)
1163 return iStreamUsage;
1164
1165 // Lock this section up.
1166 lscp_mutex_lock(pClient->mutex);
1167
1168 iStream = 0;
1169 sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1170 if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1171 pszResult = lscp_client_get_result(pClient);
1172 pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1173 while (pszToken) {
1174 if (*pszToken) {
1175 // Skip stream id.
1176 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1177 if (pszToken == NULL)
1178 break;
1179 // Get least buffer fill percentage.
1180 iPercent = atol(pszToken);
1181 if (iStreamUsage > iPercent || iStream == 0)
1182 iStreamUsage = iPercent;
1183 iStream++;
1184 }
1185 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1186 }
1187 }
1188
1189 // Unlock this section down.
1190 lscp_mutex_unlock(pClient->mutex);
1191
1192 return iStreamUsage;
1193 }
1194
1195
1196 /**
1197 * Current fill state of disk stream buffers:
1198 * GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>
1199 *
1200 * @param pClient Pointer to client instance structure.
1201 * @param usage_type Usage type to be returned, either
1202 * @ref LSCP_USAGE_BYTES, or
1203 * @ref LSCP_USAGE_PERCENTAGE.
1204 * @param iSamplerChannel Sampler channel number.
1205 *
1206 * @returns A pointer to a @ref lscp_buffer_fill_t structure, with the
1207 * information of the current disk stream buffer fill usage, for the given
1208 * sampler channel, or NULL in case of failure.
1209 */
1210 lscp_buffer_fill_t *lscp_get_channel_buffer_fill ( lscp_client_t *pClient, lscp_usage_t usage_type, int iSamplerChannel )
1211 {
1212 lscp_buffer_fill_t *pBufferFill;
1213 char szQuery[LSCP_BUFSIZ];
1214 int iStreamCount;
1215 const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE");
1216 const char *pszResult;
1217 const char *pszSeps = "[]%,";
1218 char *pszToken;
1219 char *pch;
1220 int iStream;
1221
1222 // Retrieve a channel stream estimation.
1223 iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1224 if (pClient->iStreamCount < 0)
1225 return NULL;
1226
1227 // Lock this section up.
1228 lscp_mutex_lock(pClient->mutex);
1229
1230 // Check if we need to reallocate the stream usage array.
1231 if (pClient->iStreamCount != iStreamCount) {
1232 if (pClient->buffer_fill)
1233 free(pClient->buffer_fill);
1234 if (iStreamCount > 0)
1235 pClient->buffer_fill = (lscp_buffer_fill_t *) malloc(iStreamCount * sizeof(lscp_buffer_fill_t));
1236 else
1237 pClient->buffer_fill = NULL;
1238 pClient->iStreamCount = iStreamCount;
1239 }
1240
1241 // Get buffer fill usage...
1242 pBufferFill = pClient->buffer_fill;
1243 if (pBufferFill && iStreamCount > 0) {
1244 iStream = 0;
1245 pBufferFill = pClient->buffer_fill;
1246 sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);
1247 if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1248 pszResult = lscp_client_get_result(pClient);
1249 pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1250 while (pszToken && iStream < pClient->iStreamCount) {
1251 if (*pszToken) {
1252 pBufferFill[iStream].stream_id = atol(pszToken);
1253 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1254 if (pszToken == NULL)
1255 break;
1256 pBufferFill[iStream].stream_usage = atol(pszToken);
1257 iStream++;
1258 }
1259 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1260 }
1261 } // Reset the usage, whatever it was before.
1262 else while (iStream < pClient->iStreamCount)
1263 pBufferFill[iStream++].stream_usage = 0;
1264 }
1265
1266 // Unlock this section down.
1267 lscp_mutex_unlock(pClient->mutex);
1268
1269 return pBufferFill;
1270 }
1271
1272
1273 /**
1274 * Setting audio output type:
1275 * SET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> <audio-output-type>
1276 *
1277 * @param pClient Pointer to client instance structure.
1278 * @param iSamplerChannel Sampler channel number.
1279 * @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 )
1284 {
1285 char szQuery[LSCP_BUFSIZ];
1286
1287 if (iSamplerChannel < 0 || pszAudioDriver == NULL)
1288 return LSCP_FAILED;
1289
1290 sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_TYPE %d %s\r\n", iSamplerChannel, pszAudioDriver);
1291 return lscp_client_query(pClient, szQuery);
1292 }
1293
1294
1295 /**
1296 * Setting audio output device:
1297 * SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id>
1298 *
1299 * @param pClient Pointer to client instance structure.
1300 * @param iSamplerChannel Sampler channel number.
1301 * @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 )
1306 {
1307 char szQuery[LSCP_BUFSIZ];
1308
1309 if (iSamplerChannel < 0 || iAudioDevice < 0)
1310 return LSCP_FAILED;
1311
1312 sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice);
1313 return lscp_client_query(pClient, szQuery);
1314 }
1315
1316
1317 /**
1318 * Setting audio output channel:
1319 * SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan>
1320 *
1321 * @param pClient Pointer to client instance structure.
1322 * @param iSamplerChannel Sampler channel number.
1323 * @param iAudioOut Audio output device channel to be routed from.
1324 * @param iAudioIn Audio output device channel to be routed into.
1325 *
1326 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1327 */
1328 lscp_status_t lscp_set_channel_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iAudioOut, int iAudioIn )
1329 {
1330 char szQuery[LSCP_BUFSIZ];
1331
1332 if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)
1333 return LSCP_FAILED;
1334
1335 sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn);
1336 return lscp_client_query(pClient, szQuery);
1337 }
1338
1339
1340 /**
1341 * Setting MIDI input type:
1342 * SET CHANNEL MIDI_INPUT_TYPE <sampler-channel> <midi-input-type>
1343 *
1344 * @param pClient Pointer to client instance structure.
1345 * @param iSamplerChannel Sampler channel number.
1346 * @param pszMidiDriver MIDI input driver type (e.g. "ALSA").
1347 *
1348 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1349 */
1350 lscp_status_t lscp_set_channel_midi_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszMidiDriver )
1351 {
1352 char szQuery[LSCP_BUFSIZ];
1353
1354 if (iSamplerChannel < 0 || pszMidiDriver == NULL)
1355 return LSCP_FAILED;
1356
1357 sprintf(szQuery, "SET CHANNEL MIDI_INPUT_TYPE %d %s\r\n", iSamplerChannel, pszMidiDriver);
1358 return lscp_client_query(pClient, szQuery);
1359 }
1360
1361
1362 /**
1363 * Setting MIDI input device:
1364 * SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id>
1365 *
1366 * @param pClient Pointer to client instance structure.
1367 * @param iSamplerChannel Sampler channel number.
1368 * @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 )
1373 {
1374 char szQuery[LSCP_BUFSIZ];
1375
1376 if (iSamplerChannel < 0 || iMidiDevice < 0)
1377 return LSCP_FAILED;
1378
1379 sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice);
1380 return lscp_client_query(pClient, szQuery);
1381 }
1382
1383
1384 /**
1385 * Setting MIDI input port:
1386 * SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port>
1387 *
1388 * @param pClient Pointer to client instance structure.
1389 * @param iSamplerChannel Sampler channel number.
1390 * @param iMidiPort MIDI input driver virtual port number.
1391 *
1392 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1393 */
1394 lscp_status_t lscp_set_channel_midi_port ( lscp_client_t *pClient, int iSamplerChannel, int iMidiPort )
1395 {
1396 char szQuery[LSCP_BUFSIZ];
1397
1398 if (iSamplerChannel < 0 || iMidiPort < 0)
1399 return LSCP_FAILED;
1400
1401 sprintf(szQuery, "SET CHANNEL MIDI_INPUT_PORT %d %d\r\n", iSamplerChannel, iMidiPort);
1402 return lscp_client_query(pClient, szQuery);
1403 }
1404
1405
1406 /**
1407 * Setting MIDI input channel:
1408 * SET CHANNEL MIDI_INPUT_CHANNEL <sampler-channel> <midi-input-chan>
1409 *
1410 * @param pClient Pointer to client instance structure.
1411 * @param iSamplerChannel Sampler channel number.
1412 * @param iMidiChannel MIDI channel address number to listen (0-15) or
1413 * LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.
1414 *
1415 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1416 */
1417 lscp_status_t lscp_set_channel_midi_channel ( lscp_client_t *pClient, int iSamplerChannel, int iMidiChannel )
1418 {
1419 char szQuery[LSCP_BUFSIZ];
1420
1421 if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)
1422 return LSCP_FAILED;
1423
1424 if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL)
1425 sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);
1426 else
1427 sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);
1428 return lscp_client_query(pClient, szQuery);
1429 }
1430
1431
1432 /**
1433 * Setting channel volume:
1434 * SET CHANNEL VOLUME <sampler-channel> <volume>
1435 *
1436 * @param pClient Pointer to client instance structure.
1437 * @param iSamplerChannel Sampler channel number.
1438 * @param fVolume Sampler channel volume as a positive floating point
1439 * number, where a value less than 1.0 for attenuation,
1440 * and greater than 1.0 for amplification.
1441 *
1442 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1443 */
1444 lscp_status_t lscp_set_channel_volume ( lscp_client_t *pClient, int iSamplerChannel, float fVolume )
1445 {
1446 char szQuery[LSCP_BUFSIZ];
1447
1448 if (iSamplerChannel < 0 || fVolume < 0.0)
1449 return LSCP_FAILED;
1450
1451 sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume);
1452 return lscp_client_query(pClient, szQuery);
1453 }
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:
1506 * RESET CHANNEL <sampler-channel>
1507 *
1508 * @param pClient Pointer to client instance structure.
1509 * @param iSamplerChannel Sampler channel number.
1510 *
1511 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1512 */
1513 lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel )
1514 {
1515 char szQuery[LSCP_BUFSIZ];
1516
1517 if (iSamplerChannel < 0)
1518 return LSCP_FAILED;
1519
1520 sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel);
1521 return lscp_client_query(pClient, szQuery);
1522 }
1523
1524
1525 /**
1526 * Resetting the sampler:
1527 * RESET
1528 *
1529 * @param pClient Pointer to client instance structure.
1530 *
1531 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
1532 */
1533 lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1534 {
1535 return lscp_client_query(pClient, "RESET\r\n");
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

  ViewVC Help
Powered by ViewVC