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; |
|
struct sockaddr_in addr; |
|
|
int cAddr; |
|
43 |
char achBuffer[LSCP_BUFSIZ]; |
char achBuffer[LSCP_BUFSIZ]; |
44 |
int cchBuffer; |
int cchBuffer; |
45 |
const char *pszSeps = " \r\n"; |
const char *pszSeps = ":\r\n"; |
46 |
char *pszToken; |
char *pszToken; |
47 |
char *pch; |
char *pch; |
48 |
|
int cchToken; |
49 |
|
lscp_event_t event = LSCP_EVENT_NONE; |
50 |
|
|
51 |
#ifdef DEBUG |
#ifdef DEBUG |
52 |
fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n"); |
fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n"); |
53 |
#endif |
#endif |
54 |
|
|
55 |
while (pClient->evt.iState) { |
while (pClient->evt.iState) { |
56 |
cAddr = sizeof(struct sockaddr_in); |
// Wait for event... |
57 |
cchBuffer = recvfrom(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0, (struct sockaddr *) &addr, &cAddr); |
cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0); |
58 |
if (cchBuffer > 0) { |
if (cchBuffer > 0) { |
59 |
#ifdef DEBUG |
// Make sure received buffer it's null terminated. |
60 |
lscp_socket_trace("_lscp_client_evt_proc: recvfrom", &addr, achBuffer, cchBuffer); |
achBuffer[cchBuffer] = (char) 0; |
61 |
#endif |
// Parse for the notification event message... |
62 |
if (strncasecmp(achBuffer, "PING ", 5) == 0) { |
pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". |
63 |
// Make sure received buffer it's null terminated. |
if (strcasecmp(pszToken, "NOTIFY") == 0) { |
64 |
achBuffer[cchBuffer] = (char) 0; |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
65 |
lscp_strtok(achBuffer, pszSeps, &(pch)); // Skip "PING" |
if (strcasecmp(pszToken, "CHANNELS") == 0) |
66 |
lscp_strtok(NULL, pszSeps, &(pch)); // Skip port (must be the same as in addr) |
event = LSCP_EVENT_CHANNELS; |
67 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); // Have session-id. |
else if (strcasecmp(pszToken, "VOICE_COUNT") == 0) |
68 |
if (pszToken) { |
event = LSCP_EVENT_VOICE_COUNT; |
69 |
// Set now client's session-id, if not already |
else if (strcasecmp(pszToken, "STREAM_COUNT") == 0) |
70 |
if (pClient->sessid == NULL) |
event = LSCP_EVENT_STREAM_COUNT; |
71 |
pClient->sessid = strdup(pszToken); |
else if (strcasecmp(pszToken, "BUFFER_FILL") == 0) |
72 |
if (pClient->sessid && strcmp(pszToken, pClient->sessid) == 0) { |
event = LSCP_EVENT_BUFFER_FILL; |
73 |
sprintf(achBuffer, "PONG %s\r\n", pClient->sessid); |
else if (strcasecmp(pszToken, "CHANNEL_INFO") == 0) |
74 |
cchBuffer = strlen(achBuffer); |
event = LSCP_EVENT_CHANNEL_INFO; |
75 |
if (sendto(pClient->evt.sock, achBuffer, cchBuffer, 0, (struct sockaddr *) &addr, cAddr) < cchBuffer) |
else if (strcasecmp(pszToken, "MISCELLANEOUS") == 0) |
76 |
lscp_socket_perror("_lscp_client_evt_proc: sendto"); |
event = LSCP_EVENT_MISCELLANEOUS; |
77 |
#ifdef DEBUG |
// And pick the rest of data... |
78 |
fprintf(stderr, "> %s", achBuffer); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
79 |
#endif |
cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); |
80 |
|
// Double-check if we're really up to it... |
81 |
|
if (pClient->events & event) { |
82 |
|
// Invoke the client event callback... |
83 |
|
if ((*pClient->pfnCallback)( |
84 |
|
pClient, |
85 |
|
event, |
86 |
|
pszToken, |
87 |
|
cchToken, |
88 |
|
pClient->pvData) != LSCP_OK) { |
89 |
|
pClient->evt.iState = 0; |
90 |
} |
} |
91 |
} |
} |
|
// Done with life proof. |
|
|
} else { |
|
|
// |
|
|
if ((*pClient->pfnCallback)( |
|
|
pClient, |
|
|
achBuffer, |
|
|
cchBuffer, |
|
|
pClient->pvData) != LSCP_OK) { |
|
|
pClient->evt.iState = 0; |
|
|
} |
|
92 |
} |
} |
93 |
} else { |
} else { |
94 |
lscp_socket_perror("_lscp_client_evt_proc: recvfrom"); |
lscp_socket_perror("_lscp_client_evt_proc: recv"); |
95 |
pClient->evt.iState = 0; |
pClient->evt.iState = 0; |
96 |
} |
} |
97 |
} |
} |
103 |
|
|
104 |
|
|
105 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
106 |
|
// Event subscription helpers. |
107 |
|
|
108 |
|
// Open the event service socket connection. |
109 |
|
static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient ) |
110 |
|
{ |
111 |
|
lscp_socket_t sock; |
112 |
|
struct sockaddr_in addr; |
113 |
|
int cAddr; |
114 |
|
#if defined(WIN32) |
115 |
|
int iSockOpt = (-1); |
116 |
|
#endif |
117 |
|
|
118 |
|
// Prepare the event connection socket... |
119 |
|
sock = socket(AF_INET, SOCK_STREAM, 0); |
120 |
|
if (sock == INVALID_SOCKET) { |
121 |
|
lscp_socket_perror("_lscp_client_evt_connect: socket"); |
122 |
|
return LSCP_FAILED; |
123 |
|
} |
124 |
|
|
125 |
|
#if defined(WIN32) |
126 |
|
if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
127 |
|
lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)"); |
128 |
|
#endif |
129 |
|
|
130 |
|
#ifdef DEBUG |
131 |
|
lscp_socket_getopts("_lscp_client_evt_connect:", sock); |
132 |
|
#endif |
133 |
|
|
134 |
|
// Use same address of the command connection. |
135 |
|
cAddr = sizeof(struct sockaddr_in); |
136 |
|
memmove((char *) &addr, &(pClient->cmd.addr), cAddr); |
137 |
|
|
138 |
|
// Start the connection... |
139 |
|
if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
140 |
|
lscp_socket_perror("_lscp_client_evt_connect: connect"); |
141 |
|
closesocket(sock); |
142 |
|
return LSCP_FAILED; |
143 |
|
} |
144 |
|
|
145 |
|
// Set our socket agent struct... |
146 |
|
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
147 |
|
|
148 |
|
// And finally the service thread... |
149 |
|
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
// Subscribe to a single event. |
154 |
|
static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event ) |
155 |
|
{ |
156 |
|
char *pszEvent; |
157 |
|
char szQuery[LSCP_BUFSIZ]; |
158 |
|
int cchQuery; |
159 |
|
|
160 |
|
if (pClient == NULL) |
161 |
|
return LSCP_FAILED; |
162 |
|
|
163 |
|
// Which (single) event? |
164 |
|
switch (event) { |
165 |
|
case LSCP_EVENT_CHANNELS: |
166 |
|
pszEvent = "CHANNELS"; |
167 |
|
break; |
168 |
|
case LSCP_EVENT_VOICE_COUNT: |
169 |
|
pszEvent = "VOICE_COUNT"; |
170 |
|
break; |
171 |
|
case LSCP_EVENT_STREAM_COUNT: |
172 |
|
pszEvent = "STREAM_COUNT"; |
173 |
|
break; |
174 |
|
case LSCP_EVENT_BUFFER_FILL: |
175 |
|
pszEvent = "BUFFER_FILL"; |
176 |
|
break; |
177 |
|
case LSCP_EVENT_CHANNEL_INFO: |
178 |
|
pszEvent = "CHANNEL_INFO"; |
179 |
|
break; |
180 |
|
case LSCP_EVENT_MISCELLANEOUS: |
181 |
|
pszEvent = "CHANNEL_INFO"; |
182 |
|
break; |
183 |
|
default: |
184 |
|
return LSCP_FAILED; |
185 |
|
} |
186 |
|
|
187 |
|
// Build the query string... |
188 |
|
cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent); |
189 |
|
// Just send data, forget result... |
190 |
|
if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) { |
191 |
|
lscp_socket_perror("_lscp_client_evt_request: send"); |
192 |
|
return LSCP_FAILED; |
193 |
|
} |
194 |
|
|
195 |
|
// Update as naively as we can... |
196 |
|
if (iSubscribe) |
197 |
|
pClient->events |= event; |
198 |
|
else |
199 |
|
pClient->events &= ~event; |
200 |
|
|
201 |
|
return LSCP_OK; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
//------------------------------------------------------------------------- |
206 |
// Client versioning teller fuunction. |
// Client versioning teller fuunction. |
207 |
|
|
208 |
|
|
240 |
lscp_socket_t sock; |
lscp_socket_t sock; |
241 |
struct sockaddr_in addr; |
struct sockaddr_in addr; |
242 |
int cAddr; |
int cAddr; |
243 |
|
#if defined(WIN32) |
244 |
int iSockOpt = (-1); |
int iSockOpt = (-1); |
245 |
|
#endif |
246 |
|
|
247 |
if (pfnCallback == NULL) { |
if (pfnCallback == NULL) { |
248 |
fprintf(stderr, "lscp_client_create: Invalid client callback function.\n"); |
fprintf(stderr, "lscp_client_create: Invalid client callback function.\n"); |
302 |
return NULL; |
return NULL; |
303 |
} |
} |
304 |
|
|
305 |
|
// Initialize the command socket agent struct... |
306 |
lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr); |
lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr); |
307 |
|
|
308 |
#ifdef DEBUG |
#ifdef DEBUG |
309 |
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)); |
310 |
#endif |
#endif |
311 |
|
|
312 |
// Prepare the event datagram service socket... |
// Initialize the event service socket struct... |
313 |
|
lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0); |
314 |
sock = socket(AF_INET, SOCK_DGRAM, 0); |
// No events subscribed, yet. |
315 |
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; |
|
316 |
// Initialize cached members. |
// Initialize cached members. |
317 |
pClient->audio_drivers = NULL; |
pClient->audio_drivers = NULL; |
318 |
pClient->midi_drivers = NULL; |
pClient->midi_drivers = NULL; |
336 |
// Initialize the transaction mutex. |
// Initialize the transaction mutex. |
337 |
lscp_mutex_init(pClient->mutex); |
lscp_mutex_init(pClient->mutex); |
338 |
|
|
|
// 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; |
|
|
} |
|
|
|
|
339 |
// Finally we've some success... |
// Finally we've some success... |
340 |
return pClient; |
return pClient; |
341 |
} |
} |
381 |
// Lock this section up. |
// Lock this section up. |
382 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
383 |
|
|
|
// Free session-id, if any. |
|
|
if (pClient->sessid) |
|
|
free(pClient->sessid); |
|
|
pClient->sessid = NULL; |
|
384 |
// Free up all cached members. |
// Free up all cached members. |
385 |
lscp_channel_info_reset(&(pClient->channel_info)); |
lscp_channel_info_reset(&(pClient->channel_info)); |
386 |
lscp_engine_info_reset(&(pClient->engine_info)); |
lscp_engine_info_reset(&(pClient->engine_info)); |
527 |
// Client registration protocol functions. |
// Client registration protocol functions. |
528 |
|
|
529 |
/** |
/** |
530 |
* Register frontend for receiving UDP event messages: |
* Register frontend for receiving event messages: |
531 |
* SUBSCRIBE NOTIFICATION <udp-port> |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
532 |
|
* | CHANNEL_INFO | MISCELLANEOUS |
533 |
* |
* |
534 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
535 |
|
* @param events Bit-wise OR'ed event flags to subscribe. |
536 |
* |
* |
537 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
538 |
*/ |
*/ |
539 |
lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient ) |
lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events ) |
540 |
{ |
{ |
541 |
lscp_status_t ret; |
lscp_status_t ret = LSCP_FAILED; |
|
char szQuery[LSCP_BUFSIZ]; |
|
|
const char *pszResult; |
|
|
const char *pszSeps = "[]"; |
|
|
char *pszToken; |
|
|
char *pch; |
|
542 |
|
|
543 |
if (pClient == NULL || pClient->sessid) |
if (pClient == NULL) |
544 |
return LSCP_FAILED; |
return LSCP_FAILED; |
545 |
|
|
546 |
// Lock this section up. |
// Lock this section up. |
547 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
548 |
|
|
549 |
|
// If applicable, start the alternate connection... |
550 |
|
if (pClient->events == LSCP_EVENT_NONE) |
551 |
|
ret = _lscp_client_evt_connect(pClient); |
552 |
|
|
553 |
sprintf(szQuery, "SUBSCRIBE NOTIFICATION %d\r\n", ntohs(pClient->evt.addr.sin_port)); |
// Send the subscription commands. |
554 |
ret = lscp_client_call(pClient, szQuery); |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
555 |
if (ret == LSCP_OK) { |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS); |
556 |
pszResult = lscp_client_get_result(pClient); |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
557 |
#ifdef DEBUG |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
558 |
fprintf(stderr, "lscp_client_subscribe: %s\n", pszResult); |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
559 |
#endif |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT); |
560 |
// Check for the session-id on "OK[sessid]" response. |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
561 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL); |
562 |
if (pszToken && strcasecmp(pszToken, "OK") == 0) { |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
563 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO); |
564 |
if (pszToken) |
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
565 |
pClient->sessid = strdup(pszToken); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS); |
|
} |
|
|
} |
|
566 |
|
|
567 |
// Unlock this section down. |
// Unlock this section down. |
568 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
572 |
|
|
573 |
|
|
574 |
/** |
/** |
575 |
* Deregister frontend for not receiving UDP event messages anymore: |
* Deregister frontend from receiving UDP event messages anymore: |
576 |
* UNSUBSCRIBE NOTIFICATION <session-id> |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
577 |
|
* | CHANNEL_INFO | MISCELLANEOUS |
578 |
* |
* |
579 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
580 |
|
* @param events Bit-wise OR'ed event flags to unsubscribe. |
581 |
* |
* |
582 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
583 |
*/ |
*/ |
584 |
lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient ) |
lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events ) |
585 |
{ |
{ |
586 |
lscp_status_t ret; |
lscp_status_t ret = LSCP_OK; |
|
char szQuery[LSCP_BUFSIZ]; |
|
587 |
|
|
588 |
if (pClient == NULL) |
if (pClient == NULL) |
589 |
return LSCP_FAILED; |
return LSCP_FAILED; |
|
if (pClient->sessid == NULL) |
|
|
return LSCP_FAILED; |
|
590 |
|
|
591 |
// Lock this section up. |
// Lock this section up. |
592 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
593 |
|
|
594 |
sprintf(szQuery, "UNSUBSCRIBE NOTIFICATION %s\n\n", pClient->sessid); |
// Send the unsubscription commands. |
595 |
ret = lscp_client_call(pClient, szQuery); |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
596 |
if (ret == LSCP_OK) { |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS); |
597 |
#ifdef DEBUG |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
598 |
fprintf(stderr, "lscp_client_unsubscribe: %s\n", lscp_client_get_result(pClient)); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
599 |
#endif |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
600 |
// Bail out session-id string. |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT); |
601 |
free(pClient->sessid); |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
602 |
pClient->sessid = NULL; |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL); |
603 |
} |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
604 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO); |
605 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
606 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS); |
607 |
|
|
608 |
|
// If necessary, close the alternate connection... |
609 |
|
if (pClient->events == LSCP_EVENT_NONE) |
610 |
|
lscp_socket_agent_free(&(pClient->evt)); |
611 |
|
|
612 |
// Unlock this section down. |
// Unlock this section down. |
613 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
637 |
if (pszFileName == NULL || iSamplerChannel < 0) |
if (pszFileName == NULL || iSamplerChannel < 0) |
638 |
return LSCP_FAILED; |
return LSCP_FAILED; |
639 |
|
|
640 |
sprintf(szQuery, "LOAD INSTRUMENT %s %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
641 |
|
return lscp_client_query(pClient, szQuery); |
642 |
|
} |
643 |
|
|
644 |
|
|
645 |
|
/** |
646 |
|
* Loading an instrument in the background (non modal): |
647 |
|
* LOAD INSTRUMENT NON_MODAL <filename> <instr-index> <sampler-channel> |
648 |
|
* |
649 |
|
* @param pClient Pointer to client instance structure. |
650 |
|
* @param pszFileName Instrument file name. |
651 |
|
* @param iInstrIndex Instrument index number. |
652 |
|
* @param iSamplerChannel Sampler Channel. |
653 |
|
* |
654 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
655 |
|
*/ |
656 |
|
lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel ) |
657 |
|
{ |
658 |
|
char szQuery[LSCP_BUFSIZ]; |
659 |
|
|
660 |
|
if (pszFileName == NULL || iSamplerChannel < 0) |
661 |
|
return LSCP_FAILED; |
662 |
|
|
663 |
|
sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
664 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
665 |
} |
} |
666 |
|
|
1139 |
|
|
1140 |
|
|
1141 |
/** |
/** |
1142 |
|
* Setting audio output device: |
1143 |
|
* SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id> |
1144 |
|
* |
1145 |
|
* @param pClient Pointer to client instance structure. |
1146 |
|
* @param iSamplerChannel Sampler channel number. |
1147 |
|
* @param iAudioDevice Audio output device number identifier. |
1148 |
|
*/ |
1149 |
|
lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice ) |
1150 |
|
{ |
1151 |
|
char szQuery[LSCP_BUFSIZ]; |
1152 |
|
|
1153 |
|
if (iSamplerChannel < 0 || iAudioDevice < 0) |
1154 |
|
return LSCP_FAILED; |
1155 |
|
|
1156 |
|
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice); |
1157 |
|
return lscp_client_query(pClient, szQuery); |
1158 |
|
} |
1159 |
|
|
1160 |
|
|
1161 |
|
/** |
1162 |
* Setting audio output channel: |
* Setting audio output channel: |
1163 |
* 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> |
1164 |
* |
* |
1202 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1203 |
} |
} |
1204 |
|
|
1205 |
|
|
1206 |
|
/** |
1207 |
|
* Setting MIDI input device: |
1208 |
|
* SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id> |
1209 |
|
* |
1210 |
|
* @param pClient Pointer to client instance structure. |
1211 |
|
* @param iSamplerChannel Sampler channel number. |
1212 |
|
* @param iMidiDevice MIDI input device number identifier. |
1213 |
|
*/ |
1214 |
|
lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice ) |
1215 |
|
{ |
1216 |
|
char szQuery[LSCP_BUFSIZ]; |
1217 |
|
|
1218 |
|
if (iSamplerChannel < 0 || iMidiDevice < 0) |
1219 |
|
return LSCP_FAILED; |
1220 |
|
|
1221 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice); |
1222 |
|
return lscp_client_query(pClient, szQuery); |
1223 |
|
} |
1224 |
|
|
1225 |
|
|
1226 |
/** |
/** |
1227 |
* Setting MIDI input port: |
* Setting MIDI input port: |