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-2007, 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 |
|
|
39 |
|
|
40 |
static void _lscp_client_evt_proc ( void *pvClient ) |
static void _lscp_client_evt_proc ( void *pvClient ) |
41 |
{ |
{ |
42 |
lscp_client_t *pClient = (lscp_client_t *) pvClient; |
lscp_client_t *pClient = (lscp_client_t *) pvClient; |
43 |
|
|
44 |
fd_set fds; // File descriptor list for select(). |
fd_set fds; // File descriptor list for select(). |
45 |
int fd, fdmax; // Maximum file descriptor number. |
int fd, fdmax; // Maximum file descriptor number. |
46 |
struct timeval tv; // For specifying a timeout value. |
struct timeval tv; // For specifying a timeout value. |
47 |
int iSelect; // Holds select return status. |
int iSelect; // Holds select return status. |
48 |
int iTimeout; |
int iTimeout; |
49 |
|
|
50 |
char achBuffer[LSCP_BUFSIZ]; |
char achBuffer[LSCP_BUFSIZ]; |
51 |
int cchBuffer; |
int cchBuffer; |
52 |
const char *pszSeps = ":\r\n"; |
const char *pszSeps = ":\r\n"; |
53 |
char * pszToken; |
char * pszToken; |
54 |
char * pch; |
char * pch; |
55 |
int cchToken; |
int cchToken; |
56 |
lscp_event_t event; |
lscp_event_t event; |
57 |
|
|
58 |
#ifdef DEBUG |
#ifdef DEBUG |
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 |
|
|
64 |
// Prepare for waiting on select... |
// Prepare for waiting on select... |
65 |
fd = (int) pClient->evt.sock; |
fd = (int) pClient->evt.sock; |
66 |
FD_ZERO(&fds); |
FD_ZERO(&fds); |
67 |
FD_SET((unsigned int) fd, &fds); |
FD_SET((unsigned int) fd, &fds); |
68 |
fdmax = fd; |
fdmax = fd; |
69 |
|
|
70 |
// Use the timeout (x10) select feature ... |
// Use the timeout (x10) select feature ... |
71 |
iTimeout = 10 * pClient->iTimeout; |
iTimeout = 10 * pClient->iTimeout; |
72 |
if (iTimeout > 1000) { |
if (iTimeout >= 1000) { |
73 |
tv.tv_sec = iTimeout / 1000; |
tv.tv_sec = iTimeout / 1000; |
74 |
iTimeout -= tv.tv_sec * 1000; |
iTimeout -= tv.tv_sec * 1000; |
75 |
} |
} |
76 |
else tv.tv_sec = 0; |
else tv.tv_sec = 0; |
77 |
tv.tv_usec = iTimeout * 1000; |
tv.tv_usec = iTimeout * 1000; |
78 |
|
|
79 |
// Wait for event... |
// Wait for event... |
80 |
iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv); |
iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv); |
81 |
if (iSelect > 0 && FD_ISSET(fd, &fds)) { |
if (iSelect > 0 && FD_ISSET(fd, &fds)) { |
82 |
// May recv now... |
// May recv now... |
83 |
cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0); |
cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0); |
84 |
if (cchBuffer > 0) { |
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 |
// Parse for the notification event message... |
// Parse for the notification event message... |
88 |
pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". |
pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". |
89 |
if (strcasecmp(pszToken, "NOTIFY") == 0) { |
if (strcasecmp(pszToken, "NOTIFY") == 0) { |
90 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
91 |
event = lscp_event_from_text(pszToken); |
event = lscp_event_from_text(pszToken); |
92 |
// And pick the rest of data... |
// And pick the rest of data... |
93 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
94 |
cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); |
cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); |
95 |
// Double-check if we're really up to it... |
// Double-check if we're really up to it... |
96 |
if (pClient->events & event) { |
if (pClient->events & event) { |
97 |
// Invoke the client event callback... |
// Invoke the client event callback... |
98 |
if ((*pClient->pfnCallback)( |
if ((*pClient->pfnCallback)( |
99 |
pClient, |
pClient, |
100 |
event, |
event, |
101 |
pszToken, |
pszToken, |
102 |
cchToken, |
cchToken, |
103 |
pClient->pvData) != LSCP_OK) { |
pClient->pvData) != LSCP_OK) { |
104 |
pClient->evt.iState = 0; |
pClient->evt.iState = 0; |
105 |
} |
} |
106 |
} |
} |
107 |
} |
} |
108 |
} else { |
} else { |
109 |
lscp_socket_perror("_lscp_client_evt_proc: recv"); |
lscp_socket_perror("_lscp_client_evt_proc: recv"); |
110 |
pClient->evt.iState = 0; |
pClient->evt.iState = 0; |
111 |
} |
} |
112 |
} // Check if select has in error. |
} // Check if select has in error. |
113 |
else if (iSelect < 0) { |
else if (iSelect < 0) { |
114 |
lscp_socket_perror("_lscp_client_call: select"); |
lscp_socket_perror("_lscp_client_evt_proc: select"); |
115 |
pClient->evt.iState = 0; |
pClient->evt.iState = 0; |
116 |
} |
} |
117 |
|
|
118 |
// Finally, always signal the event. |
// Finally, always signal the event. |
119 |
lscp_cond_signal(pClient->cond); |
lscp_cond_signal(pClient->cond); |
120 |
} |
} |
121 |
|
|
122 |
#ifdef DEBUG |
#ifdef DEBUG |
123 |
fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n"); |
fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n"); |
124 |
#endif |
#endif |
125 |
} |
} |
126 |
|
|
131 |
// Open the event service socket connection. |
// Open the event service socket connection. |
132 |
static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient ) |
static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient ) |
133 |
{ |
{ |
134 |
lscp_socket_t sock; |
lscp_socket_t sock; |
135 |
struct sockaddr_in addr; |
struct sockaddr_in addr; |
136 |
int cAddr; |
int cAddr; |
137 |
#if defined(WIN32) |
#if defined(WIN32) |
138 |
int iSockOpt = (-1); |
int iSockOpt = (-1); |
139 |
#endif |
#endif |
140 |
|
|
141 |
// Prepare the event connection socket... |
// Prepare the event connection socket... |
142 |
sock = socket(AF_INET, SOCK_STREAM, 0); |
sock = socket(AF_INET, SOCK_STREAM, 0); |
143 |
if (sock == INVALID_SOCKET) { |
if (sock == INVALID_SOCKET) { |
144 |
lscp_socket_perror("_lscp_client_evt_connect: socket"); |
lscp_socket_perror("_lscp_client_evt_connect: socket"); |
145 |
return LSCP_FAILED; |
return LSCP_FAILED; |
146 |
} |
} |
147 |
|
|
148 |
#if defined(WIN32) |
#if defined(WIN32) |
149 |
if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
150 |
lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)"); |
lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)"); |
151 |
#endif |
#endif |
152 |
|
|
153 |
#ifdef DEBUG |
#ifdef DEBUG |
154 |
lscp_socket_getopts("_lscp_client_evt_connect:", sock); |
lscp_socket_getopts("_lscp_client_evt_connect:", sock); |
155 |
#endif |
#endif |
156 |
|
|
157 |
// Use same address of the command connection. |
// Use same address of the command connection. |
158 |
cAddr = sizeof(struct sockaddr_in); |
cAddr = sizeof(struct sockaddr_in); |
159 |
memmove((char *) &addr, &(pClient->cmd.addr), cAddr); |
memmove((char *) &addr, &(pClient->cmd.addr), cAddr); |
160 |
|
|
161 |
// Start the connection... |
// Start the connection... |
162 |
if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
163 |
lscp_socket_perror("_lscp_client_evt_connect: connect"); |
lscp_socket_perror("_lscp_client_evt_connect: connect"); |
164 |
closesocket(sock); |
closesocket(sock); |
165 |
return LSCP_FAILED; |
return LSCP_FAILED; |
166 |
} |
} |
167 |
|
|
168 |
// Set our socket agent struct... |
// Set our socket agent struct... |
169 |
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
170 |
|
|
171 |
// And finally the service thread... |
// And finally the service thread... |
172 |
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
173 |
} |
} |
174 |
|
|
175 |
|
|
176 |
// Subscribe to a single event. |
// Subscribe to a single event. |
177 |
static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event ) |
static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event ) |
178 |
{ |
{ |
179 |
const char *pszEvent; |
const char *pszEvent; |
180 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
181 |
int cchQuery; |
int cchQuery; |
182 |
|
|
183 |
if (pClient == NULL) |
if (pClient == NULL) |
184 |
return LSCP_FAILED; |
return LSCP_FAILED; |
185 |
|
|
186 |
// Which (single) event? |
// Which (single) event? |
187 |
pszEvent = lscp_event_to_text(event); |
pszEvent = lscp_event_to_text(event); |
188 |
if (pszEvent == NULL) |
if (pszEvent == NULL) |
189 |
return LSCP_FAILED; |
return LSCP_FAILED; |
190 |
|
|
191 |
// Build the query string... |
// Build the query string... |
192 |
cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent); |
cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent); |
193 |
// Just send data, forget result... |
// Just send data, forget result... |
194 |
if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) { |
if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) { |
195 |
lscp_socket_perror("_lscp_client_evt_request: send"); |
lscp_socket_perror("_lscp_client_evt_request: send"); |
196 |
return LSCP_FAILED; |
return LSCP_FAILED; |
197 |
} |
} |
198 |
|
|
199 |
// Wait on response. |
// Wait on response. |
200 |
lscp_cond_wait(pClient->cond, pClient->mutex); |
lscp_cond_wait(pClient->cond, pClient->mutex); |
201 |
|
|
202 |
// Update as naively as we can... |
// Update as naively as we can... |
203 |
if (iSubscribe) |
if (iSubscribe) |
204 |
pClient->events |= event; |
pClient->events |= event; |
205 |
else |
else |
206 |
pClient->events &= ~event; |
pClient->events &= ~event; |
207 |
|
|
208 |
return LSCP_OK; |
return LSCP_OK; |
209 |
} |
} |
210 |
|
|
211 |
|
|
242 |
*/ |
*/ |
243 |
lscp_client_t* lscp_client_create ( const char *pszHost, int iPort, lscp_client_proc_t pfnCallback, void *pvData ) |
lscp_client_t* lscp_client_create ( const char *pszHost, int iPort, lscp_client_proc_t pfnCallback, void *pvData ) |
244 |
{ |
{ |
245 |
lscp_client_t *pClient; |
lscp_client_t *pClient; |
246 |
struct hostent *pHost; |
struct hostent *pHost; |
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) |
#if defined(WIN32) |
251 |
int iSockOpt = (-1); |
int iSockOpt = (-1); |
252 |
#endif |
#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"); |
256 |
return NULL; |
return NULL; |
257 |
} |
} |
258 |
|
|
259 |
pHost = gethostbyname(pszHost); |
pHost = gethostbyname(pszHost); |
260 |
if (pHost == NULL) { |
if (pHost == NULL) { |
261 |
lscp_socket_herror("lscp_client_create: gethostbyname"); |
lscp_socket_herror("lscp_client_create: gethostbyname"); |
262 |
return NULL; |
return NULL; |
263 |
} |
} |
264 |
|
|
265 |
// Allocate client descriptor... |
// Allocate client descriptor... |
266 |
|
|
267 |
pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t)); |
pClient = (lscp_client_t *) malloc(sizeof(lscp_client_t)); |
268 |
if (pClient == NULL) { |
if (pClient == NULL) { |
269 |
fprintf(stderr, "lscp_client_create: Out of memory.\n"); |
fprintf(stderr, "lscp_client_create: Out of memory.\n"); |
270 |
return NULL; |
return NULL; |
271 |
} |
} |
272 |
memset(pClient, 0, sizeof(lscp_client_t)); |
memset(pClient, 0, sizeof(lscp_client_t)); |
273 |
|
|
274 |
pClient->pfnCallback = pfnCallback; |
pClient->pfnCallback = pfnCallback; |
275 |
pClient->pvData = pvData; |
pClient->pvData = pvData; |
276 |
|
|
277 |
#ifdef DEBUG |
#ifdef DEBUG |
278 |
fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort); |
fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort); |
279 |
#endif |
#endif |
280 |
|
|
281 |
// Prepare the command connection socket... |
// Prepare the command connection socket... |
282 |
|
|
283 |
sock = socket(AF_INET, SOCK_STREAM, 0); |
sock = socket(AF_INET, SOCK_STREAM, 0); |
284 |
if (sock == INVALID_SOCKET) { |
if (sock == INVALID_SOCKET) { |
285 |
lscp_socket_perror("lscp_client_create: cmd: socket"); |
lscp_socket_perror("lscp_client_create: cmd: socket"); |
286 |
free(pClient); |
free(pClient); |
287 |
return NULL; |
return NULL; |
288 |
} |
} |
289 |
|
|
290 |
#if defined(WIN32) |
#if defined(WIN32) |
291 |
if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR) |
292 |
lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)"); |
lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)"); |
293 |
#endif |
#endif |
294 |
|
|
295 |
#ifdef DEBUG |
#ifdef DEBUG |
296 |
lscp_socket_getopts("lscp_client_create: cmd", sock); |
lscp_socket_getopts("lscp_client_create: cmd", sock); |
297 |
#endif |
#endif |
298 |
|
|
299 |
cAddr = sizeof(struct sockaddr_in); |
cAddr = sizeof(struct sockaddr_in); |
300 |
memset((char *) &addr, 0, cAddr); |
memset((char *) &addr, 0, cAddr); |
301 |
addr.sin_family = pHost->h_addrtype; |
addr.sin_family = pHost->h_addrtype; |
302 |
memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length); |
memmove((char *) &(addr.sin_addr), pHost->h_addr, pHost->h_length); |
303 |
addr.sin_port = htons((short) iPort); |
addr.sin_port = htons((short) iPort); |
304 |
|
|
305 |
if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) { |
306 |
lscp_socket_perror("lscp_client_create: cmd: connect"); |
lscp_socket_perror("lscp_client_create: cmd: connect"); |
307 |
closesocket(sock); |
closesocket(sock); |
308 |
free(pClient); |
free(pClient); |
309 |
return NULL; |
return NULL; |
310 |
} |
} |
311 |
|
|
312 |
// Initialize the command socket agent struct... |
// 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 |
// Initialize the event service socket struct... |
// Initialize the event service socket struct... |
320 |
lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0); |
lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0); |
321 |
// No events subscribed, yet. |
// No events subscribed, yet. |
322 |
pClient->events = LSCP_EVENT_NONE; |
pClient->events = LSCP_EVENT_NONE; |
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; |
326 |
pClient->audio_devices = NULL; |
pClient->audio_devices = 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_driver_info)); |
pClient->fxsends = NULL; |
331 |
lscp_driver_info_init(&(pClient->midi_driver_info)); |
pClient->midi_instruments = NULL; |
332 |
lscp_device_info_init(&(pClient->audio_device_info)); |
pClient->midi_maps = NULL; |
333 |
lscp_device_info_init(&(pClient->midi_device_info)); |
pClient->midi_map_name = NULL; |
334 |
lscp_param_info_init(&(pClient->audio_param_info)); |
lscp_driver_info_init(&(pClient->audio_driver_info)); |
335 |
lscp_param_info_init(&(pClient->midi_param_info)); |
lscp_driver_info_init(&(pClient->midi_driver_info)); |
336 |
lscp_device_port_info_init(&(pClient->audio_channel_info)); |
lscp_device_info_init(&(pClient->audio_device_info)); |
337 |
lscp_device_port_info_init(&(pClient->midi_port_info)); |
lscp_device_info_init(&(pClient->midi_device_info)); |
338 |
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
lscp_param_info_init(&(pClient->audio_param_info)); |
339 |
lscp_param_info_init(&(pClient->midi_port_param_info)); |
lscp_param_info_init(&(pClient->midi_param_info)); |
340 |
lscp_engine_info_init(&(pClient->engine_info)); |
lscp_device_port_info_init(&(pClient->audio_channel_info)); |
341 |
lscp_channel_info_init(&(pClient->channel_info)); |
lscp_device_port_info_init(&(pClient->midi_port_info)); |
342 |
// Initialize error stuff. |
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
343 |
pClient->pszResult = NULL; |
lscp_param_info_init(&(pClient->midi_port_param_info)); |
344 |
pClient->iErrno = -1; |
lscp_server_info_init(&(pClient->server_info)); |
345 |
// Stream usage stuff. |
lscp_engine_info_init(&(pClient->engine_info)); |
346 |
pClient->buffer_fill = NULL; |
lscp_channel_info_init(&(pClient->channel_info)); |
347 |
pClient->iStreamCount = 0; |
lscp_fxsend_info_init(&(pClient->fxsend_info)); |
348 |
// Default timeout value. |
lscp_midi_instrument_info_init(&(pClient->midi_instrument_info)); |
349 |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
// Initialize error stuff. |
350 |
|
pClient->pszResult = NULL; |
351 |
// Initialize the transaction mutex. |
pClient->iErrno = -1; |
352 |
lscp_mutex_init(pClient->mutex); |
// Stream usage stuff. |
353 |
lscp_cond_init(pClient->cond); |
pClient->buffer_fill = NULL; |
354 |
|
pClient->iStreamCount = 0; |
355 |
|
// Default timeout value. |
356 |
|
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
357 |
|
pClient->iTimeoutCount = 0; |
358 |
|
|
359 |
|
// Initialize the transaction mutex. |
360 |
|
lscp_mutex_init(pClient->mutex); |
361 |
|
lscp_cond_init(pClient->cond); |
362 |
|
|
363 |
// Finally we've some success... |
// Finally we've some success... |
364 |
return pClient; |
return pClient; |
365 |
} |
} |
366 |
|
|
367 |
|
|
372 |
*/ |
*/ |
373 |
lscp_status_t lscp_client_join ( lscp_client_t *pClient ) |
lscp_status_t lscp_client_join ( lscp_client_t *pClient ) |
374 |
{ |
{ |
375 |
if (pClient == NULL) |
if (pClient == NULL) |
376 |
return LSCP_FAILED; |
return LSCP_FAILED; |
377 |
|
|
378 |
#ifdef DEBUG |
#ifdef DEBUG |
379 |
fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient); |
fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient); |
380 |
#endif |
#endif |
381 |
|
|
382 |
// lscp_socket_agent_join(&(pClient->evt)); |
// lscp_socket_agent_join(&(pClient->evt)); |
383 |
lscp_socket_agent_join(&(pClient->cmd)); |
lscp_socket_agent_join(&(pClient->cmd)); |
384 |
|
|
385 |
return LSCP_OK; |
return LSCP_OK; |
386 |
} |
} |
387 |
|
|
388 |
|
|
395 |
*/ |
*/ |
396 |
lscp_status_t lscp_client_destroy ( lscp_client_t *pClient ) |
lscp_status_t lscp_client_destroy ( lscp_client_t *pClient ) |
397 |
{ |
{ |
398 |
if (pClient == NULL) |
if (pClient == NULL) |
399 |
return LSCP_FAILED; |
return LSCP_FAILED; |
400 |
|
|
401 |
#ifdef DEBUG |
#ifdef DEBUG |
402 |
fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient); |
fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient); |
403 |
#endif |
#endif |
404 |
|
|
405 |
// Lock this section up. |
// Lock this section up. |
406 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
407 |
|
|
408 |
// Free up all cached members. |
// Free up all cached members. |
409 |
lscp_channel_info_free(&(pClient->channel_info)); |
lscp_midi_instrument_info_free(&(pClient->midi_instrument_info)); |
410 |
lscp_engine_info_free(&(pClient->engine_info)); |
lscp_fxsend_info_free(&(pClient->fxsend_info)); |
411 |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
lscp_channel_info_free(&(pClient->channel_info)); |
412 |
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
lscp_engine_info_free(&(pClient->engine_info)); |
413 |
lscp_device_port_info_free(&(pClient->midi_port_info)); |
lscp_server_info_free(&(pClient->server_info)); |
414 |
lscp_device_port_info_free(&(pClient->audio_channel_info)); |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
415 |
lscp_param_info_free(&(pClient->midi_param_info)); |
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
416 |
lscp_param_info_free(&(pClient->audio_param_info)); |
lscp_device_port_info_free(&(pClient->midi_port_info)); |
417 |
lscp_device_info_free(&(pClient->midi_device_info)); |
lscp_device_port_info_free(&(pClient->audio_channel_info)); |
418 |
lscp_device_info_free(&(pClient->audio_device_info)); |
lscp_param_info_free(&(pClient->midi_param_info)); |
419 |
lscp_driver_info_free(&(pClient->midi_driver_info)); |
lscp_param_info_free(&(pClient->audio_param_info)); |
420 |
lscp_driver_info_free(&(pClient->audio_driver_info)); |
lscp_device_info_free(&(pClient->midi_device_info)); |
421 |
// Free available engine table. |
lscp_device_info_free(&(pClient->audio_device_info)); |
422 |
lscp_szsplit_destroy(pClient->audio_drivers); |
lscp_driver_info_free(&(pClient->midi_driver_info)); |
423 |
lscp_szsplit_destroy(pClient->midi_drivers); |
lscp_driver_info_free(&(pClient->audio_driver_info)); |
424 |
lscp_isplit_destroy(pClient->audio_devices); |
// Free available engine table. |
425 |
lscp_isplit_destroy(pClient->midi_devices); |
lscp_szsplit_destroy(pClient->audio_drivers); |
426 |
lscp_szsplit_destroy(pClient->engines); |
lscp_szsplit_destroy(pClient->midi_drivers); |
427 |
lscp_isplit_destroy(pClient->channels); |
lscp_isplit_destroy(pClient->audio_devices); |
428 |
// Make them null. |
lscp_isplit_destroy(pClient->midi_devices); |
429 |
pClient->audio_drivers = NULL; |
lscp_szsplit_destroy(pClient->engines); |
430 |
pClient->midi_drivers = NULL; |
lscp_isplit_destroy(pClient->channels); |
431 |
pClient->engines = NULL; |
lscp_isplit_destroy(pClient->fxsends); |
432 |
// Free result error stuff. |
lscp_midi_instruments_destroy(pClient->midi_instruments); |
433 |
lscp_client_set_result(pClient, NULL, 0); |
lscp_isplit_destroy(pClient->midi_maps); |
434 |
// Free stream usage stuff. |
if (pClient->midi_map_name) |
435 |
if (pClient->buffer_fill) |
free(pClient->midi_map_name); |
436 |
free(pClient->buffer_fill); |
// Make them null. |
437 |
pClient->buffer_fill = NULL; |
pClient->audio_drivers = NULL; |
438 |
pClient->iStreamCount = 0; |
pClient->midi_drivers = NULL; |
439 |
pClient->iTimeout = 0; |
pClient->audio_devices = NULL; |
440 |
|
pClient->midi_devices = NULL; |
441 |
// Free socket agents. |
pClient->engines = NULL; |
442 |
lscp_socket_agent_free(&(pClient->evt)); |
pClient->channels = NULL; |
443 |
lscp_socket_agent_free(&(pClient->cmd)); |
pClient->fxsends = NULL; |
444 |
|
pClient->midi_instruments = NULL; |
445 |
// Last but not least, free good ol'transaction mutex. |
pClient->midi_maps = NULL; |
446 |
lscp_mutex_unlock(pClient->mutex); |
pClient->midi_map_name = NULL; |
447 |
lscp_mutex_destroy(pClient->mutex); |
// Free result error stuff. |
448 |
lscp_cond_destroy(pClient->cond); |
lscp_client_set_result(pClient, NULL, 0); |
449 |
|
// Free stream usage stuff. |
450 |
|
if (pClient->buffer_fill) |
451 |
|
free(pClient->buffer_fill); |
452 |
|
pClient->buffer_fill = NULL; |
453 |
|
pClient->iStreamCount = 0; |
454 |
|
pClient->iTimeout = 0; |
455 |
|
|
456 |
|
// Free socket agents. |
457 |
|
lscp_socket_agent_free(&(pClient->evt)); |
458 |
|
lscp_socket_agent_free(&(pClient->cmd)); |
459 |
|
|
460 |
|
// Last but not least, free good ol'transaction mutex. |
461 |
|
lscp_mutex_unlock(pClient->mutex); |
462 |
|
lscp_mutex_destroy(pClient->mutex); |
463 |
|
lscp_cond_destroy(pClient->cond); |
464 |
|
|
465 |
free(pClient); |
free(pClient); |
466 |
|
|
467 |
return LSCP_OK; |
return LSCP_OK; |
468 |
} |
} |
469 |
|
|
470 |
|
|
478 |
*/ |
*/ |
479 |
lscp_status_t lscp_client_set_timeout ( lscp_client_t *pClient, int iTimeout ) |
lscp_status_t lscp_client_set_timeout ( lscp_client_t *pClient, int iTimeout ) |
480 |
{ |
{ |
481 |
if (pClient == NULL) |
if (pClient == NULL) |
482 |
return LSCP_FAILED; |
return LSCP_FAILED; |
483 |
if (iTimeout < 0) |
if (iTimeout < 0) |
484 |
return LSCP_FAILED; |
return LSCP_FAILED; |
485 |
|
|
486 |
pClient->iTimeout = iTimeout; |
pClient->iTimeout = iTimeout; |
487 |
return LSCP_OK; |
return LSCP_OK; |
488 |
} |
} |
489 |
|
|
490 |
|
|
497 |
*/ |
*/ |
498 |
int lscp_client_get_timeout ( lscp_client_t *pClient ) |
int lscp_client_get_timeout ( lscp_client_t *pClient ) |
499 |
{ |
{ |
500 |
if (pClient == NULL) |
if (pClient == NULL) |
501 |
return -1; |
return -1; |
502 |
|
|
503 |
return pClient->iTimeout; |
return pClient->iTimeout; |
504 |
} |
} |
505 |
|
|
506 |
|
|
522 |
*/ |
*/ |
523 |
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 ) |
524 |
{ |
{ |
525 |
lscp_status_t ret; |
lscp_status_t ret; |
526 |
|
|
527 |
// Lock this section up. |
if (pClient == NULL) |
528 |
lscp_mutex_lock(pClient->mutex); |
return LSCP_FAILED; |
529 |
|
|
530 |
// Just make the now guarded call. |
// Lock this section up. |
531 |
ret = lscp_client_call(pClient, pszQuery); |
lscp_mutex_lock(pClient->mutex); |
532 |
|
|
533 |
// Unlock this section down. |
// Just make the now guarded call. |
534 |
lscp_mutex_unlock(pClient->mutex); |
ret = lscp_client_call(pClient, pszQuery, 0); |
535 |
|
|
536 |
return ret; |
// Unlock this section down. |
537 |
|
lscp_mutex_unlock(pClient->mutex); |
538 |
|
|
539 |
|
return ret; |
540 |
} |
} |
541 |
|
|
542 |
/** |
/** |
550 |
*/ |
*/ |
551 |
const char *lscp_client_get_result ( lscp_client_t *pClient ) |
const char *lscp_client_get_result ( lscp_client_t *pClient ) |
552 |
{ |
{ |
553 |
if (pClient == NULL) |
if (pClient == NULL) |
554 |
return NULL; |
return NULL; |
555 |
|
|
556 |
return pClient->pszResult; |
return pClient->pszResult; |
557 |
} |
} |
558 |
|
|
559 |
|
|
567 |
*/ |
*/ |
568 |
int lscp_client_get_errno ( lscp_client_t *pClient ) |
int lscp_client_get_errno ( lscp_client_t *pClient ) |
569 |
{ |
{ |
570 |
if (pClient == NULL) |
if (pClient == NULL) |
571 |
return -1; |
return -1; |
572 |
|
|
573 |
return pClient->iErrno; |
return pClient->iErrno; |
574 |
} |
} |
575 |
|
|
576 |
|
|
579 |
|
|
580 |
/** |
/** |
581 |
* Register frontend for receiving event messages: |
* Register frontend for receiving event messages: |
582 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT |
583 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT |
584 |
|
* | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO |
585 |
|
* | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO |
586 |
|
* | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO |
587 |
|
* | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO |
588 |
|
* | MISCELLANEOUS |
589 |
* |
* |
590 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
591 |
* @param events Bit-wise OR'ed event flags to subscribe. |
* @param events Bit-wise OR'ed event flags to subscribe. |
594 |
*/ |
*/ |
595 |
lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events ) |
lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events ) |
596 |
{ |
{ |
597 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
598 |
|
|
599 |
if (pClient == NULL) |
if (pClient == NULL) |
600 |
return LSCP_FAILED; |
return LSCP_FAILED; |
601 |
|
|
602 |
// Lock this section up. |
// Lock this section up. |
603 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
604 |
|
|
605 |
// If applicable, start the alternate connection... |
// If applicable, start the alternate connection... |
606 |
if (pClient->events == LSCP_EVENT_NONE) |
if (pClient->events == LSCP_EVENT_NONE) |
607 |
ret = _lscp_client_evt_connect(pClient); |
ret = _lscp_client_evt_connect(pClient); |
608 |
|
|
609 |
// Send the subscription commands. |
// Send the subscription commands. |
610 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
611 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT); |
612 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
613 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
614 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
615 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT); |
616 |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
617 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL); |
618 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
619 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO); |
620 |
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT)) |
621 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_TOTAL_VOICE_COUNT); |
622 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT)) |
623 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT); |
624 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO)) |
625 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO); |
626 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT)) |
627 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT); |
628 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO)) |
629 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO); |
630 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT)) |
631 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT); |
632 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO)) |
633 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO); |
634 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT)) |
635 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_COUNT); |
636 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO)) |
637 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MIDI_INSTRUMENT_INFO); |
638 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
639 |
|
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS); |
640 |
|
|
641 |
// Unlock this section down. |
// Unlock this section down. |
642 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
643 |
|
|
644 |
return ret; |
return ret; |
645 |
} |
} |
646 |
|
|
647 |
|
|
648 |
/** |
/** |
649 |
* Deregister frontend from receiving UDP event messages anymore: |
* Deregister frontend from receiving UDP event messages anymore: |
650 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* UNSUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT |
651 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | BUFFER_FILL | CHANNEL_INFO | TOTAL_VOICE_COUNT |
652 |
|
* | AUDIO_OUTPUT_DEVICE_COUNT | AUDIO_OUTPUT_DEVICE_INFO |
653 |
|
* | MIDI_INPUT_DEVICE_COUNT | MIDI_INPUT_DEVICE_INFO |
654 |
|
* | MIDI_INSTRUMENT_MAP_COUNT | MIDI_INSTRUMENT_MAP_INFO |
655 |
|
* | MIDI_INSTRUMENT_COUNT | MIDI_INSTRUMENT_INFO |
656 |
|
* | MISCELLANEOUS |
657 |
* |
* |
658 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
659 |
* @param events Bit-wise OR'ed event flags to unsubscribe. |
* @param events Bit-wise OR'ed event flags to unsubscribe. |
662 |
*/ |
*/ |
663 |
lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events ) |
lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events ) |
664 |
{ |
{ |
665 |
lscp_status_t ret = LSCP_OK; |
lscp_status_t ret = LSCP_OK; |
666 |
|
|
667 |
if (pClient == NULL) |
if (pClient == NULL) |
668 |
return LSCP_FAILED; |
return LSCP_FAILED; |
669 |
|
|
670 |
// Lock this section up. |
// Lock this section up. |
671 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
672 |
|
|
673 |
// Send the unsubscription commands. |
// Send the unsubscription commands. |
674 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
675 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT); |
676 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
677 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
678 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
679 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT); |
680 |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL)) |
681 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL); |
682 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO)) |
683 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO); |
684 |
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_TOTAL_VOICE_COUNT)) |
685 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_TOTAL_VOICE_COUNT); |
686 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT)) |
687 |
// If necessary, close the alternate connection... |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT); |
688 |
if (pClient->events == LSCP_EVENT_NONE) |
if (ret == LSCP_OK && (events & LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO)) |
689 |
lscp_socket_agent_free(&(pClient->evt)); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO); |
690 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT)) |
691 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT); |
692 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INPUT_DEVICE_INFO)) |
693 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO); |
694 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT)) |
695 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_COUNT); |
696 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO)) |
697 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_MAP_INFO); |
698 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_COUNT)) |
699 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_COUNT); |
700 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MIDI_INSTRUMENT_INFO)) |
701 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MIDI_INSTRUMENT_INFO); |
702 |
|
if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS)) |
703 |
|
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS); |
704 |
|
|
705 |
|
// If necessary, close the alternate connection... |
706 |
|
if (pClient->events == LSCP_EVENT_NONE) |
707 |
|
lscp_socket_agent_free(&(pClient->evt)); |
708 |
|
|
709 |
// Unlock this section down. |
// Unlock this section down. |
710 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
711 |
|
|
712 |
return ret; |
return ret; |
713 |
} |
} |
714 |
|
|
715 |
|
|
722 |
*/ |
*/ |
723 |
lscp_event_t lscp_client_get_events ( lscp_client_t *pClient ) |
lscp_event_t lscp_client_get_events ( lscp_client_t *pClient ) |
724 |
{ |
{ |
725 |
if (pClient == NULL) |
if (pClient == NULL) |
726 |
return LSCP_EVENT_NONE; |
return LSCP_EVENT_NONE; |
727 |
|
|
728 |
return pClient->events; |
return pClient->events; |
729 |
} |
} |
730 |
|
|
731 |
|
|
745 |
*/ |
*/ |
746 |
lscp_status_t lscp_load_instrument ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel ) |
lscp_status_t lscp_load_instrument ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel ) |
747 |
{ |
{ |
748 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
749 |
|
|
750 |
if (pszFileName == NULL || iSamplerChannel < 0) |
if (pszFileName == NULL || iSamplerChannel < 0) |
751 |
return LSCP_FAILED; |
return LSCP_FAILED; |
752 |
|
|
753 |
sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
754 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
755 |
} |
} |
756 |
|
|
757 |
|
|
768 |
*/ |
*/ |
769 |
lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel ) |
lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel ) |
770 |
{ |
{ |
771 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
772 |
|
|
773 |
if (pszFileName == NULL || iSamplerChannel < 0) |
if (pszFileName == NULL || iSamplerChannel < 0) |
774 |
return LSCP_FAILED; |
return LSCP_FAILED; |
775 |
|
|
776 |
sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel); |
777 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
778 |
} |
} |
779 |
|
|
780 |
|
|
790 |
*/ |
*/ |
791 |
lscp_status_t lscp_load_engine ( lscp_client_t *pClient, const char *pszEngineName, int iSamplerChannel ) |
lscp_status_t lscp_load_engine ( lscp_client_t *pClient, const char *pszEngineName, int iSamplerChannel ) |
792 |
{ |
{ |
793 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
794 |
|
|
795 |
if (pszEngineName == NULL || iSamplerChannel < 0) |
if (pszEngineName == NULL || iSamplerChannel < 0) |
796 |
return LSCP_FAILED; |
return LSCP_FAILED; |
797 |
|
|
798 |
sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel); |
sprintf(szQuery, "LOAD ENGINE %s %d\r\n", pszEngineName, iSamplerChannel); |
799 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
800 |
} |
} |
801 |
|
|
802 |
|
|
811 |
*/ |
*/ |
812 |
int lscp_get_channels ( lscp_client_t *pClient ) |
int lscp_get_channels ( lscp_client_t *pClient ) |
813 |
{ |
{ |
814 |
int iChannels = -1; |
int iChannels = -1; |
815 |
|
|
816 |
// Lock this section up. |
if (pClient == NULL) |
817 |
lscp_mutex_lock(pClient->mutex); |
return -1; |
818 |
|
|
819 |
if (lscp_client_call(pClient, "GET CHANNELS\r\n") == LSCP_OK) |
// Lock this section up. |
820 |
iChannels = atoi(lscp_client_get_result(pClient)); |
lscp_mutex_lock(pClient->mutex); |
821 |
|
|
822 |
// Unlock this section doen. |
if (lscp_client_call(pClient, "GET CHANNELS\r\n", 0) == LSCP_OK) |
823 |
lscp_mutex_unlock(pClient->mutex); |
iChannels = atoi(lscp_client_get_result(pClient)); |
824 |
|
|
825 |
return iChannels; |
// Unlock this section doen. |
826 |
|
lscp_mutex_unlock(pClient->mutex); |
827 |
|
|
828 |
|
return iChannels; |
829 |
} |
} |
830 |
|
|
831 |
|
|
840 |
*/ |
*/ |
841 |
int *lscp_list_channels ( lscp_client_t *pClient ) |
int *lscp_list_channels ( lscp_client_t *pClient ) |
842 |
{ |
{ |
843 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
844 |
|
|
845 |
|
if (pClient == NULL) |
846 |
|
return NULL; |
847 |
|
|
848 |
if (pClient == NULL) |
// Lock this section up. |
849 |
return NULL; |
lscp_mutex_lock(pClient->mutex); |
|
|
|
|
// Lock this section up. |
|
|
lscp_mutex_lock(pClient->mutex); |
|
|
|
|
|
if (pClient->channels) { |
|
|
lscp_isplit_destroy(pClient->channels); |
|
|
pClient->channels = NULL; |
|
|
} |
|
850 |
|
|
851 |
if (lscp_client_call(pClient, "LIST CHANNELS\r\n") == LSCP_OK) |
if (pClient->channels) { |
852 |
pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
lscp_isplit_destroy(pClient->channels); |
853 |
|
pClient->channels = NULL; |
854 |
|
} |
855 |
|
|
856 |
// Unlock this section down. |
if (lscp_client_call(pClient, "LIST CHANNELS\r\n", 0) == LSCP_OK) |
857 |
lscp_mutex_unlock(pClient->mutex); |
pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
858 |
|
|
859 |
return pClient->channels; |
// Unlock this section down. |
860 |
|
lscp_mutex_unlock(pClient->mutex); |
861 |
|
|
862 |
|
return pClient->channels; |
863 |
} |
} |
864 |
|
|
865 |
|
|
874 |
*/ |
*/ |
875 |
int lscp_add_channel ( lscp_client_t *pClient ) |
int lscp_add_channel ( lscp_client_t *pClient ) |
876 |
{ |
{ |
877 |
int iSamplerChannel = -1; |
int iSamplerChannel = -1; |
878 |
|
|
879 |
|
if (pClient == NULL) |
880 |
|
return -1; |
881 |
|
|
882 |
|
// Lock this section up. |
883 |
|
lscp_mutex_lock(pClient->mutex); |
884 |
|
|
885 |
// Lock this section up. |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n", 0) == LSCP_OK) |
886 |
lscp_mutex_lock(pClient->mutex); |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
887 |
|
|
888 |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
// Unlock this section down. |
889 |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
lscp_mutex_unlock(pClient->mutex); |
|
|
|
|
// Unlock this section down. |
|
|
lscp_mutex_unlock(pClient->mutex); |
|
890 |
|
|
891 |
return iSamplerChannel; |
return iSamplerChannel; |
892 |
} |
} |
893 |
|
|
894 |
|
|
903 |
*/ |
*/ |
904 |
lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel ) |
lscp_status_t lscp_remove_channel ( lscp_client_t *pClient, int iSamplerChannel ) |
905 |
{ |
{ |
906 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
907 |
|
|
908 |
if (iSamplerChannel < 0) |
if (iSamplerChannel < 0) |
909 |
return LSCP_FAILED; |
return LSCP_FAILED; |
910 |
|
|
911 |
sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel); |
sprintf(szQuery, "REMOVE CHANNEL %d\r\n", iSamplerChannel); |
912 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
913 |
} |
} |
914 |
|
|
915 |
|
|
916 |
/** |
/** |
917 |
* Getting all available engines: |
* Getting all available engines count: |
918 |
* GET AVAILABLE_ENGINES |
* GET AVAILABLE_ENGINES |
919 |
* |
* |
920 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
921 |
* |
* |
922 |
|
* @returns The current total number of sampler engines on success, |
923 |
|
* -1 otherwise. |
924 |
|
*/ |
925 |
|
int lscp_get_available_engines ( lscp_client_t *pClient ) |
926 |
|
{ |
927 |
|
int iAvailableEngines = -1; |
928 |
|
|
929 |
|
if (pClient == NULL) |
930 |
|
return -1; |
931 |
|
|
932 |
|
// Lock this section up. |
933 |
|
lscp_mutex_lock(pClient->mutex); |
934 |
|
|
935 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n", 0) == LSCP_OK) |
936 |
|
iAvailableEngines = atoi(lscp_client_get_result(pClient)); |
937 |
|
|
938 |
|
// Unlock this section down. |
939 |
|
lscp_mutex_unlock(pClient->mutex); |
940 |
|
|
941 |
|
return iAvailableEngines; |
942 |
|
} |
943 |
|
|
944 |
|
|
945 |
|
/** |
946 |
|
* Getting all available engines: |
947 |
|
* LIST AVAILABLE_ENGINES |
948 |
|
* |
949 |
|
* @param pClient Pointer to client instance structure. |
950 |
|
* |
951 |
* @returns A NULL terminated array of engine name strings, |
* @returns A NULL terminated array of engine name strings, |
952 |
* or NULL in case of failure. |
* or NULL in case of failure. |
953 |
*/ |
*/ |
954 |
const char **lscp_get_available_engines ( lscp_client_t *pClient ) |
const char **lscp_list_available_engines ( lscp_client_t *pClient ) |
955 |
{ |
{ |
956 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
957 |
|
|
958 |
|
if (pClient == NULL) |
959 |
|
return NULL; |
960 |
|
|
961 |
// Lock this section up. |
// Lock this section up. |
962 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
963 |
|
|
964 |
if (pClient->engines) { |
if (pClient->engines) { |
965 |
lscp_szsplit_destroy(pClient->engines); |
lscp_szsplit_destroy(pClient->engines); |
966 |
pClient->engines = NULL; |
pClient->engines = NULL; |
967 |
} |
} |
968 |
|
|
969 |
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n", 0) == LSCP_OK) |
970 |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
971 |
|
|
972 |
// Unlock this section down. |
// Unlock this section down. |
973 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
974 |
|
|
975 |
return (const char **) pClient->engines; |
return (const char **) pClient->engines; |
976 |
} |
} |
977 |
|
|
978 |
|
|
988 |
*/ |
*/ |
989 |
lscp_engine_info_t *lscp_get_engine_info ( lscp_client_t *pClient, const char *pszEngineName ) |
lscp_engine_info_t *lscp_get_engine_info ( lscp_client_t *pClient, const char *pszEngineName ) |
990 |
{ |
{ |
991 |
lscp_engine_info_t *pEngineInfo; |
lscp_engine_info_t *pEngineInfo; |
992 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
993 |
const char *pszResult; |
const char *pszResult; |
994 |
const char *pszSeps = ":"; |
const char *pszSeps = ":"; |
995 |
const char *pszCrlf = "\r\n"; |
const char *pszCrlf = "\r\n"; |
996 |
char *pszToken; |
char *pszToken; |
997 |
char *pch; |
char *pch; |
998 |
|
|
999 |
if (pszEngineName == NULL) |
if (pClient == NULL) |
1000 |
return NULL; |
return NULL; |
1001 |
|
if (pszEngineName == NULL) |
1002 |
// Lock this section up. |
return NULL; |
1003 |
lscp_mutex_lock(pClient->mutex); |
|
1004 |
|
// Lock this section up. |
1005 |
pEngineInfo = &(pClient->engine_info); |
lscp_mutex_lock(pClient->mutex); |
1006 |
lscp_engine_info_reset(pEngineInfo); |
|
1007 |
|
pEngineInfo = &(pClient->engine_info); |
1008 |
sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName); |
lscp_engine_info_reset(pEngineInfo); |
1009 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
|
1010 |
pszResult = lscp_client_get_result(pClient); |
sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName); |
1011 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
1012 |
while (pszToken) { |
pszResult = lscp_client_get_result(pClient); |
1013 |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1014 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
while (pszToken) { |
1015 |
if (pszToken) |
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
1016 |
lscp_unquote_dup(&(pEngineInfo->description), &pszToken); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1017 |
} |
if (pszToken) |
1018 |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
lscp_unquote_dup(&(pEngineInfo->description), &pszToken); |
1019 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1020 |
if (pszToken) |
else if (strcasecmp(pszToken, "VERSION") == 0) { |
1021 |
lscp_unquote_dup(&(pEngineInfo->version), &pszToken); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1022 |
} |
if (pszToken) |
1023 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
lscp_unquote_dup(&(pEngineInfo->version), &pszToken); |
1024 |
} |
} |
1025 |
} |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1026 |
else pEngineInfo = NULL; |
} |
1027 |
|
} |
1028 |
// Unlock this section down. |
else pEngineInfo = NULL; |
|
lscp_mutex_unlock(pClient->mutex); |
|
1029 |
|
|
1030 |
return pEngineInfo; |
// Unlock this section down. |
1031 |
|
lscp_mutex_unlock(pClient->mutex); |
1032 |
|
|
1033 |
|
return pEngineInfo; |
1034 |
} |
} |
1035 |
|
|
1036 |
|
|
1046 |
*/ |
*/ |
1047 |
lscp_channel_info_t *lscp_get_channel_info ( lscp_client_t *pClient, int iSamplerChannel ) |
lscp_channel_info_t *lscp_get_channel_info ( lscp_client_t *pClient, int iSamplerChannel ) |
1048 |
{ |
{ |
1049 |
lscp_channel_info_t *pChannelInfo; |
lscp_channel_info_t *pChannelInfo; |
1050 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1051 |
const char *pszResult; |
const char *pszResult; |
1052 |
const char *pszSeps = ":"; |
const char *pszSeps = ":"; |
1053 |
const char *pszCrlf = "\r\n"; |
const char *pszCrlf = "\r\n"; |
1054 |
char *pszToken; |
char *pszToken; |
1055 |
char *pch; |
char *pch; |
1056 |
|
|
1057 |
if (iSamplerChannel < 0) |
if (pClient == NULL) |
1058 |
return NULL; |
return NULL; |
1059 |
|
if (iSamplerChannel < 0) |
1060 |
// Lock this section up. |
return NULL; |
1061 |
lscp_mutex_lock(pClient->mutex); |
|
1062 |
|
// Lock this section up. |
1063 |
pChannelInfo = &(pClient->channel_info); |
lscp_mutex_lock(pClient->mutex); |
1064 |
lscp_channel_info_reset(pChannelInfo); |
|
1065 |
|
pChannelInfo = &(pClient->channel_info); |
1066 |
sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel); |
lscp_channel_info_reset(pChannelInfo); |
1067 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
|
1068 |
pszResult = lscp_client_get_result(pClient); |
sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel); |
1069 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
1070 |
while (pszToken) { |
pszResult = lscp_client_get_result(pClient); |
1071 |
if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1072 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
while (pszToken) { |
1073 |
if (pszToken) |
if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
1074 |
lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1075 |
} |
if (pszToken) |
1076 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) { |
lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken); |
1077 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1078 |
if (pszToken) |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) { |
1079 |
pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1080 |
} |
if (pszToken) |
1081 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) { |
pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken)); |
1082 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1083 |
if (pszToken) |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) { |
1084 |
pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1085 |
} |
if (pszToken) |
1086 |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken)); |
1087 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1088 |
if (pszToken) { |
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
1089 |
if (pChannelInfo->audio_routing) |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1090 |
lscp_szsplit_destroy(pChannelInfo->audio_routing); |
if (pszToken) { |
1091 |
pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ","); |
if (pChannelInfo->audio_routing) |
1092 |
} |
lscp_isplit_destroy(pChannelInfo->audio_routing); |
1093 |
} |
pChannelInfo->audio_routing = lscp_isplit_create(pszToken, ","); |
1094 |
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
} |
1095 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1096 |
if (pszToken) |
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
1097 |
lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1098 |
} |
if (pszToken) |
1099 |
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken); |
1100 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1101 |
if (pszToken) |
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
1102 |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1103 |
} |
if (pszToken) |
1104 |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
1105 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1106 |
if (pszToken) |
else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { |
1107 |
pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1108 |
} |
if (pszToken) |
1109 |
else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) { |
lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken); |
1110 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1111 |
if (pszToken) |
else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { |
1112 |
pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1113 |
} |
if (pszToken) |
1114 |
else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) { |
pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken)); |
1115 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1116 |
if (pszToken) |
else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) { |
1117 |
pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1118 |
} |
if (pszToken) |
1119 |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken)); |
1120 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1121 |
if (pszToken) |
else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) { |
1122 |
pChannelInfo->midi_channel = atoi(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1123 |
} |
if (pszToken) |
1124 |
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken)); |
1125 |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
} |
1126 |
if (pszToken) |
else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) { |
1127 |
pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1128 |
} |
if (pszToken) { |
1129 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_ltrim(pszToken); |
1130 |
} |
if (strcasecmp(pszToken, "ALL") == 0) |
1131 |
} |
pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL; |
1132 |
else pChannelInfo = NULL; |
else |
1133 |
|
pChannelInfo->midi_channel = atoi(pszToken); |
1134 |
// Unlock this section up. |
} |
1135 |
lscp_mutex_unlock(pClient->mutex); |
} |
1136 |
|
else if (strcasecmp(pszToken, "MIDI_INSTRUMENT_MAP") == 0) { |
1137 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1138 |
|
if (pszToken) { |
1139 |
|
pszToken = lscp_ltrim(pszToken); |
1140 |
|
if (strcasecmp(pszToken, "NONE") == 0) |
1141 |
|
pChannelInfo->midi_map = LSCP_MIDI_MAP_NONE; |
1142 |
|
else |
1143 |
|
if (strcasecmp(pszToken, "DEFAULT") == 0) |
1144 |
|
pChannelInfo->midi_map = LSCP_MIDI_MAP_DEFAULT; |
1145 |
|
else |
1146 |
|
pChannelInfo->midi_map = atoi(pszToken); |
1147 |
|
} |
1148 |
|
} |
1149 |
|
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
1150 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1151 |
|
if (pszToken) |
1152 |
|
pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
1153 |
|
} |
1154 |
|
else if (strcasecmp(pszToken, "MUTE") == 0) { |
1155 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1156 |
|
if (pszToken) |
1157 |
|
pChannelInfo->mute = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
1158 |
|
} |
1159 |
|
else if (strcasecmp(pszToken, "SOLO") == 0) { |
1160 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1161 |
|
if (pszToken) |
1162 |
|
pChannelInfo->solo = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0); |
1163 |
|
} |
1164 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1165 |
|
} |
1166 |
|
} |
1167 |
|
else pChannelInfo = NULL; |
1168 |
|
|
1169 |
|
// Unlock this section up. |
1170 |
|
lscp_mutex_unlock(pClient->mutex); |
1171 |
|
|
1172 |
return pChannelInfo; |
return pChannelInfo; |
1173 |
} |
} |
1174 |
|
|
1175 |
|
|
1184 |
*/ |
*/ |
1185 |
int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel ) |
int lscp_get_channel_voice_count ( lscp_client_t *pClient, int iSamplerChannel ) |
1186 |
{ |
{ |
1187 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1188 |
int iVoiceCount = -1; |
int iVoiceCount = -1; |
1189 |
|
|
1190 |
if (iSamplerChannel < 0) |
if (pClient == NULL) |
1191 |
return iVoiceCount; |
return -1; |
1192 |
|
if (iSamplerChannel < 0) |
1193 |
|
return -1; |
1194 |
|
|
1195 |
// Lock this section up. |
// Lock this section up. |
1196 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
1197 |
|
|
1198 |
sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel); |
sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel); |
1199 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1200 |
iVoiceCount = atoi(lscp_client_get_result(pClient)); |
iVoiceCount = atoi(lscp_client_get_result(pClient)); |
1201 |
|
|
1202 |
// Unlock this section down. |
// Unlock this section down. |
1203 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1204 |
|
|
1205 |
return iVoiceCount; |
return iVoiceCount; |
1206 |
} |
} |
1207 |
|
|
1208 |
|
|
1217 |
*/ |
*/ |
1218 |
int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) |
int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) |
1219 |
{ |
{ |
1220 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1221 |
int iStreamCount = -1; |
int iStreamCount = -1; |
1222 |
|
|
1223 |
if (iSamplerChannel < 0) |
if (pClient == NULL) |
1224 |
return iStreamCount; |
return -1; |
1225 |
|
if (iSamplerChannel < 0) |
1226 |
|
return -1; |
1227 |
|
|
1228 |
// Lock this section up. |
// Lock this section up. |
1229 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
1230 |
|
|
1231 |
sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel); |
sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel); |
1232 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) |
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1233 |
iStreamCount = atoi(lscp_client_get_result(pClient)); |
iStreamCount = atoi(lscp_client_get_result(pClient)); |
1234 |
|
|
1235 |
// Unlock this section down. |
// Unlock this section down. |
1236 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1237 |
|
|
1238 |
return iStreamCount; |
return iStreamCount; |
1239 |
} |
} |
1240 |
|
|
1241 |
|
|
1250 |
*/ |
*/ |
1251 |
int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel ) |
int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel ) |
1252 |
{ |
{ |
1253 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1254 |
int iStreamUsage = -1; |
int iStreamUsage = -1; |
1255 |
const char *pszResult; |
const char *pszResult; |
1256 |
const char *pszSeps = "[]%,"; |
const char *pszSeps = "[]%,"; |
1257 |
char *pszToken; |
char *pszToken; |
1258 |
char *pch; |
char *pch; |
1259 |
int iStream; |
int iStream; |
1260 |
int iPercent; |
int iPercent; |
1261 |
|
|
1262 |
if (iSamplerChannel < 0) |
if (pClient == NULL) |
1263 |
return iStreamUsage; |
return -1; |
1264 |
|
if (iSamplerChannel < 0) |
1265 |
// Lock this section up. |
return -1; |
1266 |
lscp_mutex_lock(pClient->mutex); |
|
1267 |
|
// Lock this section up. |
1268 |
iStream = 0; |
lscp_mutex_lock(pClient->mutex); |
1269 |
sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel); |
|
1270 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
iStream = 0; |
1271 |
pszResult = lscp_client_get_result(pClient); |
sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel); |
1272 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) { |
1273 |
while (pszToken) { |
pszResult = lscp_client_get_result(pClient); |
1274 |
if (*pszToken) { |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1275 |
// Skip stream id. |
while (pszToken) { |
1276 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
if (*pszToken) { |
1277 |
if (pszToken == NULL) |
// Skip stream id. |
1278 |
break; |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1279 |
// Get least buffer fill percentage. |
if (pszToken == NULL) |
1280 |
iPercent = atol(pszToken); |
break; |
1281 |
if (iStreamUsage > iPercent || iStream == 0) |
// Get least buffer fill percentage. |
1282 |
iStreamUsage = iPercent; |
iPercent = atol(pszToken); |
1283 |
iStream++; |
if (iStreamUsage > iPercent || iStream == 0) |
1284 |
} |
iStreamUsage = iPercent; |
1285 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
iStream++; |
1286 |
} |
} |
1287 |
} |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1288 |
|
} |
1289 |
|
} |
1290 |
|
|
1291 |
// Unlock this section down. |
// Unlock this section down. |
1292 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1293 |
|
|
1294 |
return iStreamUsage; |
return iStreamUsage; |
1295 |
} |
} |
1296 |
|
|
1297 |
|
|
1311 |
*/ |
*/ |
1312 |
lscp_buffer_fill_t *lscp_get_channel_buffer_fill ( lscp_client_t *pClient, lscp_usage_t usage_type, int iSamplerChannel ) |
lscp_buffer_fill_t *lscp_get_channel_buffer_fill ( lscp_client_t *pClient, lscp_usage_t usage_type, int iSamplerChannel ) |
1313 |
{ |
{ |
1314 |
lscp_buffer_fill_t *pBufferFill; |
lscp_buffer_fill_t *pBufferFill; |
1315 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1316 |
int iStreamCount; |
int iStreamCount; |
1317 |
const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE"); |
const char *pszUsageType = (usage_type == LSCP_USAGE_BYTES ? "BYTES" : "PERCENTAGE"); |
1318 |
const char *pszResult; |
const char *pszResult; |
1319 |
const char *pszSeps = "[]%,"; |
const char *pszSeps = "[]%,"; |
1320 |
char *pszToken; |
char *pszToken; |
1321 |
char *pch; |
char *pch; |
1322 |
int iStream; |
int iStream; |
1323 |
|
|
1324 |
// Retrieve a channel stream estimation. |
// Retrieve a channel stream estimation. |
1325 |
iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel); |
iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel); |
1326 |
if (pClient->iStreamCount < 0) |
if (iStreamCount < 0) |
1327 |
return NULL; |
return NULL; |
1328 |
|
|
1329 |
// Lock this section up. |
// Lock this section up. |
1330 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
1331 |
|
|
1332 |
// Check if we need to reallocate the stream usage array. |
// Check if we need to reallocate the stream usage array. |
1333 |
if (pClient->iStreamCount != iStreamCount) { |
if (pClient->iStreamCount != iStreamCount) { |
1334 |
if (pClient->buffer_fill) |
if (pClient->buffer_fill) |
1335 |
free(pClient->buffer_fill); |
free(pClient->buffer_fill); |
1336 |
if (iStreamCount > 0) |
if (iStreamCount > 0) |
1337 |
pClient->buffer_fill = (lscp_buffer_fill_t *) malloc(iStreamCount * sizeof(lscp_buffer_fill_t)); |
pClient->buffer_fill = (lscp_buffer_fill_t *) malloc(iStreamCount * sizeof(lscp_buffer_fill_t)); |
1338 |
else |
else |
1339 |
pClient->buffer_fill = NULL; |
pClient->buffer_fill = NULL; |
1340 |
pClient->iStreamCount = iStreamCount; |
pClient->iStreamCount = iStreamCount; |
1341 |
} |
} |
1342 |
|
|
1343 |
// Get buffer fill usage... |
// Get buffer fill usage... |
1344 |
pBufferFill = pClient->buffer_fill; |
pBufferFill = pClient->buffer_fill; |
1345 |
if (pBufferFill && iStreamCount > 0) { |
if (pBufferFill && iStreamCount > 0) { |
1346 |
iStream = 0; |
iStream = 0; |
1347 |
pBufferFill = pClient->buffer_fill; |
pBufferFill = pClient->buffer_fill; |
1348 |
sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel); |
sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel); |
1349 |
if (lscp_client_call(pClient, szQuery) == LSCP_OK) { |
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) { |
1350 |
pszResult = lscp_client_get_result(pClient); |
pszResult = lscp_client_get_result(pClient); |
1351 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1352 |
while (pszToken && iStream < pClient->iStreamCount) { |
while (pszToken && iStream < pClient->iStreamCount) { |
1353 |
if (*pszToken) { |
if (*pszToken) { |
1354 |
pBufferFill[iStream].stream_id = atol(pszToken); |
pBufferFill[iStream].stream_id = atol(pszToken); |
1355 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1356 |
if (pszToken == NULL) |
if (pszToken == NULL) |
1357 |
break; |
break; |
1358 |
pBufferFill[iStream].stream_usage = atol(pszToken); |
pBufferFill[iStream].stream_usage = atol(pszToken); |
1359 |
iStream++; |
iStream++; |
1360 |
} |
} |
1361 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1362 |
} |
} |
1363 |
} // Reset the usage, whatever it was before. |
} // Reset the usage, whatever it was before. |
1364 |
else while (iStream < pClient->iStreamCount) |
else while (iStream < pClient->iStreamCount) |
1365 |
pBufferFill[iStream++].stream_usage = 0; |
pBufferFill[iStream++].stream_usage = 0; |
1366 |
} |
} |
1367 |
|
|
1368 |
// Unlock this section down. |
// Unlock this section down. |
1369 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1370 |
|
|
1371 |
return pBufferFill; |
return pBufferFill; |
1372 |
} |
} |
1373 |
|
|
1374 |
|
|
1379 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1380 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1381 |
* @param pszAudioDriver Audio output driver type (e.g. "ALSA" or "JACK"). |
* @param pszAudioDriver Audio output driver type (e.g. "ALSA" or "JACK"). |
1382 |
|
* |
1383 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1384 |
*/ |
*/ |
1385 |
lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver ) |
lscp_status_t lscp_set_channel_audio_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszAudioDriver ) |
1386 |
{ |
{ |
1387 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1388 |
|
|
1389 |
if (iSamplerChannel < 0 || pszAudioDriver == NULL) |
if (iSamplerChannel < 0 || pszAudioDriver == NULL) |
1390 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1391 |
|
|
1392 |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_TYPE %d %s\r\n", iSamplerChannel, pszAudioDriver); |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_TYPE %d %s\r\n", iSamplerChannel, pszAudioDriver); |
1393 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1394 |
} |
} |
1395 |
|
|
1396 |
|
|
1401 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1402 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1403 |
* @param iAudioDevice Audio output device number identifier. |
* @param iAudioDevice Audio output device number identifier. |
1404 |
|
* |
1405 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1406 |
*/ |
*/ |
1407 |
lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice ) |
lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice ) |
1408 |
{ |
{ |
1409 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1410 |
|
|
1411 |
if (iSamplerChannel < 0 || iAudioDevice < 0) |
if (iSamplerChannel < 0 || iAudioDevice < 0) |
1412 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1413 |
|
|
1414 |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice); |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice); |
1415 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1416 |
} |
} |
1417 |
|
|
1418 |
|
|
1429 |
*/ |
*/ |
1430 |
lscp_status_t lscp_set_channel_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iAudioOut, int iAudioIn ) |
lscp_status_t lscp_set_channel_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iAudioOut, int iAudioIn ) |
1431 |
{ |
{ |
1432 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1433 |
|
|
1434 |
if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0) |
if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0) |
1435 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1436 |
|
|
1437 |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn); |
sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn); |
1438 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1439 |
} |
} |
1440 |
|
|
1441 |
|
|
1451 |
*/ |
*/ |
1452 |
lscp_status_t lscp_set_channel_midi_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszMidiDriver ) |
lscp_status_t lscp_set_channel_midi_type ( lscp_client_t *pClient, int iSamplerChannel, const char *pszMidiDriver ) |
1453 |
{ |
{ |
1454 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1455 |
|
|
1456 |
if (iSamplerChannel < 0 || pszMidiDriver == NULL) |
if (iSamplerChannel < 0 || pszMidiDriver == NULL) |
1457 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1458 |
|
|
1459 |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_TYPE %d %s\r\n", iSamplerChannel, pszMidiDriver); |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_TYPE %d %s\r\n", iSamplerChannel, pszMidiDriver); |
1460 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1461 |
} |
} |
1462 |
|
|
1463 |
|
|
1468 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1469 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1470 |
* @param iMidiDevice MIDI input device number identifier. |
* @param iMidiDevice MIDI input device number identifier. |
1471 |
|
* |
1472 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1473 |
*/ |
*/ |
1474 |
lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice ) |
lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice ) |
1475 |
{ |
{ |
1476 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1477 |
|
|
1478 |
if (iSamplerChannel < 0 || iMidiDevice < 0) |
if (iSamplerChannel < 0 || iMidiDevice < 0) |
1479 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1480 |
|
|
1481 |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice); |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice); |
1482 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1483 |
} |
} |
1484 |
|
|
1485 |
|
|
1495 |
*/ |
*/ |
1496 |
lscp_status_t lscp_set_channel_midi_port ( lscp_client_t *pClient, int iSamplerChannel, int iMidiPort ) |
lscp_status_t lscp_set_channel_midi_port ( lscp_client_t *pClient, int iSamplerChannel, int iMidiPort ) |
1497 |
{ |
{ |
1498 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1499 |
|
|
1500 |
if (iSamplerChannel < 0 || iMidiPort < 0) |
if (iSamplerChannel < 0 || iMidiPort < 0) |
1501 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1502 |
|
|
1503 |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_PORT %d %d\r\n", iSamplerChannel, iMidiPort); |
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_PORT %d %d\r\n", iSamplerChannel, iMidiPort); |
1504 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1505 |
} |
} |
1506 |
|
|
1507 |
|
|
1511 |
* |
* |
1512 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
1513 |
* @param iSamplerChannel Sampler channel number. |
* @param iSamplerChannel Sampler channel number. |
1514 |
* @param iMidiChannel MIDI channel number to listen (1-16) or |
* @param iMidiChannel MIDI channel address number to listen (0-15) or |
1515 |
* LSCP_MIDI_CHANNEL_ALL (0) to listen on all channels. |
* @ref LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels. |
1516 |
* |
* |
1517 |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1518 |
*/ |
*/ |
1519 |
lscp_status_t lscp_set_channel_midi_channel ( lscp_client_t *pClient, int iSamplerChannel, int iMidiChannel ) |
lscp_status_t lscp_set_channel_midi_channel ( lscp_client_t *pClient, int iSamplerChannel, int iMidiChannel ) |
1520 |
{ |
{ |
1521 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1522 |
|
|
1523 |
|
if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16) |
1524 |
|
return LSCP_FAILED; |
1525 |
|
|
1526 |
|
if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL) |
1527 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel); |
1528 |
|
else |
1529 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel); |
1530 |
|
return lscp_client_query(pClient, szQuery); |
1531 |
|
} |
1532 |
|
|
1533 |
|
|
1534 |
|
/** |
1535 |
|
* Setting MIDI instrument map: |
1536 |
|
* SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map> |
1537 |
|
* |
1538 |
|
* @param pClient Pointer to client instance structure. |
1539 |
|
* @param iSamplerChannel Sampler channel number. |
1540 |
|
* @param iMidiMap MIDI instrument map number, or either |
1541 |
|
* @ref LSCP_MIDI_MAP_NONE or |
1542 |
|
* @ref LSCP_MIDI_MAP_DEFAULT . |
1543 |
|
* |
1544 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1545 |
|
*/ |
1546 |
|
lscp_status_t lscp_set_channel_midi_map ( lscp_client_t *pClient, int iSamplerChannel, int iMidiMap ) |
1547 |
|
{ |
1548 |
|
char szQuery[LSCP_BUFSIZ]; |
1549 |
|
|
1550 |
|
if (iSamplerChannel < 0) |
1551 |
|
return LSCP_FAILED; |
1552 |
|
|
1553 |
|
sprintf(szQuery, "SET CHANNEL MIDI_INSTRUMENT_MAP %d ", iSamplerChannel); |
1554 |
|
if (iMidiMap == LSCP_MIDI_MAP_NONE) |
1555 |
|
strcat(szQuery , "NONE"); |
1556 |
|
else |
1557 |
|
if (iMidiMap == LSCP_MIDI_MAP_DEFAULT) |
1558 |
|
strcat(szQuery , "DEFAULT"); |
1559 |
|
else |
1560 |
|
sprintf(szQuery + strlen(szQuery), "%d", iMidiMap); |
1561 |
|
|
1562 |
if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16) |
strcat(szQuery, "\r\n"); |
|
return LSCP_FAILED; |
|
1563 |
|
|
1564 |
if (iMidiChannel > 0) |
return lscp_client_query(pClient, szQuery); |
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel); |
|
|
else |
|
|
sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel); |
|
|
return lscp_client_query(pClient, szQuery); |
|
1565 |
} |
} |
1566 |
|
|
1567 |
|
|
1579 |
*/ |
*/ |
1580 |
lscp_status_t lscp_set_channel_volume ( lscp_client_t *pClient, int iSamplerChannel, float fVolume ) |
lscp_status_t lscp_set_channel_volume ( lscp_client_t *pClient, int iSamplerChannel, float fVolume ) |
1581 |
{ |
{ |
1582 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1583 |
|
|
1584 |
if (iSamplerChannel < 0 || fVolume < 0.0) |
if (iSamplerChannel < 0 || fVolume < 0.0f) |
1585 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1586 |
|
|
1587 |
sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume); |
sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume); |
1588 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1589 |
|
} |
1590 |
|
|
1591 |
|
|
1592 |
|
/** |
1593 |
|
* Muting a sampler channel: |
1594 |
|
* SET CHANNEL MUTE <sampler-channel> <mute> |
1595 |
|
* |
1596 |
|
* @param pClient Pointer to client instance structure. |
1597 |
|
* @param iSamplerChannel Sampler channel number. |
1598 |
|
* @param iMute Sampler channel mute state as a boolean value, |
1599 |
|
* either 1 (one) to mute the channel or 0 (zero) |
1600 |
|
* to unmute the channel. |
1601 |
|
* |
1602 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1603 |
|
*/ |
1604 |
|
lscp_status_t lscp_set_channel_mute ( lscp_client_t *pClient, int iSamplerChannel, int iMute ) |
1605 |
|
{ |
1606 |
|
char szQuery[LSCP_BUFSIZ]; |
1607 |
|
|
1608 |
|
if (iSamplerChannel < 0 || iMute < 0 || iMute > 1) |
1609 |
|
return LSCP_FAILED; |
1610 |
|
|
1611 |
|
sprintf(szQuery, "SET CHANNEL MUTE %d %d\r\n", iSamplerChannel, iMute); |
1612 |
|
return lscp_client_query(pClient, szQuery); |
1613 |
|
} |
1614 |
|
|
1615 |
|
|
1616 |
|
/** |
1617 |
|
* Soloing a sampler channel: |
1618 |
|
* SET CHANNEL SOLO <sampler-channel> <solo> |
1619 |
|
* |
1620 |
|
* @param pClient Pointer to client instance structure. |
1621 |
|
* @param iSamplerChannel Sampler channel number. |
1622 |
|
* @param iSolo Sampler channel solo state as a boolean value, |
1623 |
|
* either 1 (one) to solo the channel or 0 (zero) |
1624 |
|
* to unsolo the channel. |
1625 |
|
* |
1626 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1627 |
|
*/ |
1628 |
|
lscp_status_t lscp_set_channel_solo ( lscp_client_t *pClient, int iSamplerChannel, int iSolo ) |
1629 |
|
{ |
1630 |
|
char szQuery[LSCP_BUFSIZ]; |
1631 |
|
|
1632 |
|
if (iSamplerChannel < 0 || iSolo < 0 || iSolo > 1) |
1633 |
|
return LSCP_FAILED; |
1634 |
|
|
1635 |
|
sprintf(szQuery, "SET CHANNEL SOLO %d %d\r\n", iSamplerChannel, iSolo); |
1636 |
|
return lscp_client_query(pClient, szQuery); |
1637 |
} |
} |
1638 |
|
|
1639 |
|
|
1648 |
*/ |
*/ |
1649 |
lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel ) |
lscp_status_t lscp_reset_channel ( lscp_client_t *pClient, int iSamplerChannel ) |
1650 |
{ |
{ |
1651 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1652 |
|
|
1653 |
if (iSamplerChannel < 0) |
if (iSamplerChannel < 0) |
1654 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1655 |
|
|
1656 |
sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel); |
sprintf(szQuery, "RESET CHANNEL %d\r\n", iSamplerChannel); |
1657 |
return lscp_client_query(pClient, szQuery); |
return lscp_client_query(pClient, szQuery); |
1658 |
} |
} |
1659 |
|
|
1660 |
|
|
1668 |
*/ |
*/ |
1669 |
lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient ) |
lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient ) |
1670 |
{ |
{ |
1671 |
return lscp_client_query(pClient, "RESET\r\n"); |
// Do actual whole sampler reset... |
1672 |
|
return lscp_client_query(pClient, "RESET\r\n"); |
1673 |
|
} |
1674 |
|
|
1675 |
|
|
1676 |
|
/** |
1677 |
|
* Getting information about the server. |
1678 |
|
* GET SERVER INFO |
1679 |
|
* |
1680 |
|
* @param pClient Pointer to client instance structure. |
1681 |
|
* |
1682 |
|
* @returns A pointer to a @ref lscp_server_info_t structure, with all the |
1683 |
|
* information of the current connected server, or NULL in case of failure. |
1684 |
|
*/ |
1685 |
|
lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient ) |
1686 |
|
{ |
1687 |
|
lscp_server_info_t *pServerInfo; |
1688 |
|
const char *pszResult; |
1689 |
|
const char *pszSeps = ":"; |
1690 |
|
const char *pszCrlf = "\r\n"; |
1691 |
|
char *pszToken; |
1692 |
|
char *pch; |
1693 |
|
|
1694 |
|
if (pClient == NULL) |
1695 |
|
return NULL; |
1696 |
|
|
1697 |
|
// Lock this section up. |
1698 |
|
lscp_mutex_lock(pClient->mutex); |
1699 |
|
|
1700 |
|
pServerInfo = &(pClient->server_info); |
1701 |
|
lscp_server_info_reset(pServerInfo); |
1702 |
|
|
1703 |
|
if (lscp_client_call(pClient, "GET SERVER INFO\r\n", 1) == LSCP_OK) { |
1704 |
|
pszResult = lscp_client_get_result(pClient); |
1705 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1706 |
|
while (pszToken) { |
1707 |
|
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
1708 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1709 |
|
if (pszToken) |
1710 |
|
lscp_unquote_dup(&(pServerInfo->description), &pszToken); |
1711 |
|
} |
1712 |
|
else if (strcasecmp(pszToken, "VERSION") == 0) { |
1713 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1714 |
|
if (pszToken) |
1715 |
|
lscp_unquote_dup(&(pServerInfo->version), &pszToken); |
1716 |
|
} |
1717 |
|
else if (strcasecmp(pszToken, "PROTOCOL_VERSION") == 0) { |
1718 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1719 |
|
if (pszToken) |
1720 |
|
lscp_unquote_dup(&(pServerInfo->protocol_version), &pszToken); |
1721 |
|
} |
1722 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1723 |
|
} |
1724 |
|
} |
1725 |
|
else pServerInfo = NULL; |
1726 |
|
|
1727 |
|
// Unlock this section down. |
1728 |
|
lscp_mutex_unlock(pClient->mutex); |
1729 |
|
|
1730 |
|
return pServerInfo; |
1731 |
|
} |
1732 |
|
|
1733 |
|
|
1734 |
|
/** |
1735 |
|
* Current total number of active voices: |
1736 |
|
* GET TOTAL_VOICE_COUNT |
1737 |
|
* |
1738 |
|
* @param pClient Pointer to client instance structure. |
1739 |
|
* |
1740 |
|
* @returns The total number of voices currently active, |
1741 |
|
* -1 in case of failure. |
1742 |
|
*/ |
1743 |
|
int lscp_get_total_voice_count ( lscp_client_t *pClient ) |
1744 |
|
{ |
1745 |
|
int iVoiceCount = -1; |
1746 |
|
|
1747 |
|
if (pClient == NULL) |
1748 |
|
return -1; |
1749 |
|
|
1750 |
|
// Lock this section up. |
1751 |
|
lscp_mutex_lock(pClient->mutex); |
1752 |
|
|
1753 |
|
if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT\r\n", 0) == LSCP_OK) |
1754 |
|
iVoiceCount = atoi(lscp_client_get_result(pClient)); |
1755 |
|
|
1756 |
|
// Unlock this section down. |
1757 |
|
lscp_mutex_unlock(pClient->mutex); |
1758 |
|
|
1759 |
|
return iVoiceCount; |
1760 |
|
} |
1761 |
|
|
1762 |
|
|
1763 |
|
/** |
1764 |
|
* Maximum amount of active voices: |
1765 |
|
* GET TOTAL_VOICE_COUNT_MAX |
1766 |
|
* |
1767 |
|
* @param pClient Pointer to client instance structure. |
1768 |
|
* |
1769 |
|
* @returns The maximum amount of voices currently active, |
1770 |
|
* -1 in case of failure. |
1771 |
|
*/ |
1772 |
|
int lscp_get_total_voice_count_max ( lscp_client_t *pClient ) |
1773 |
|
{ |
1774 |
|
int iVoiceCount = -1; |
1775 |
|
|
1776 |
|
if (pClient == NULL) |
1777 |
|
return -1; |
1778 |
|
|
1779 |
|
// Lock this section up. |
1780 |
|
lscp_mutex_lock(pClient->mutex); |
1781 |
|
|
1782 |
|
if (lscp_client_call(pClient, "GET TOTAL_VOICE_COUNT_MAX\r\n", 0) == LSCP_OK) |
1783 |
|
iVoiceCount = atoi(lscp_client_get_result(pClient)); |
1784 |
|
|
1785 |
|
// Unlock this section down. |
1786 |
|
lscp_mutex_unlock(pClient->mutex); |
1787 |
|
|
1788 |
|
return iVoiceCount; |
1789 |
|
} |
1790 |
|
|
1791 |
|
|
1792 |
|
/** |
1793 |
|
* Get global volume attenuation: |
1794 |
|
* GET VOLUME |
1795 |
|
* |
1796 |
|
* @param pClient Pointer to client instance structure. |
1797 |
|
* |
1798 |
|
* @returns The global volume as positive floating point value usually in |
1799 |
|
* the range between 0.0 and 1.0; in case of failure 0.0 is returned. |
1800 |
|
*/ |
1801 |
|
float lscp_get_volume ( lscp_client_t *pClient ) |
1802 |
|
{ |
1803 |
|
float fVolume = 0.0f; |
1804 |
|
|
1805 |
|
if (pClient == NULL) |
1806 |
|
return 0.0f; |
1807 |
|
|
1808 |
|
// Lock this section up. |
1809 |
|
lscp_mutex_lock(pClient->mutex); |
1810 |
|
|
1811 |
|
if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK) |
1812 |
|
fVolume = (float) atof(lscp_client_get_result(pClient)); |
1813 |
|
|
1814 |
|
// Unlock this section down. |
1815 |
|
lscp_mutex_unlock(pClient->mutex); |
1816 |
|
|
1817 |
|
return fVolume; |
1818 |
|
} |
1819 |
|
|
1820 |
|
|
1821 |
|
/** |
1822 |
|
* Setting global volume attenuation: |
1823 |
|
* SET VOLUME <volume> |
1824 |
|
* |
1825 |
|
* @param pClient Pointer to client instance structure. |
1826 |
|
* @param fVolume Global volume parameter as positive floating point |
1827 |
|
* value usually be in the range between 0.0 and 1.0, |
1828 |
|
* that is for attenuating the overall volume. |
1829 |
|
* |
1830 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1831 |
|
*/ |
1832 |
|
lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume ) |
1833 |
|
{ |
1834 |
|
char szQuery[LSCP_BUFSIZ]; |
1835 |
|
|
1836 |
|
if (fVolume < 0.0f) |
1837 |
|
return LSCP_FAILED; |
1838 |
|
|
1839 |
|
sprintf(szQuery, "SET VOLUME %g\r\n", fVolume); |
1840 |
|
return lscp_client_query(pClient, szQuery); |
1841 |
|
} |
1842 |
|
|
1843 |
|
|
1844 |
|
/** |
1845 |
|
* Add an effect send to a sampler channel: |
1846 |
|
* CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>] |
1847 |
|
* |
1848 |
|
* @param pClient Pointer to client instance structure. |
1849 |
|
* @param iSamplerChannel Sampler channel number. |
1850 |
|
* @param iMidiController MIDI controller used to alter the effect, |
1851 |
|
* usually a number between 0 and 127. |
1852 |
|
* @param pszName Optional name for the effect send entity, |
1853 |
|
* does not have to be unique. |
1854 |
|
* |
1855 |
|
* @returns The new effect send number identifier, or -1 in case of failure. |
1856 |
|
*/ |
1857 |
|
int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName ) |
1858 |
|
{ |
1859 |
|
int iFxSend = -1; |
1860 |
|
char szQuery[LSCP_BUFSIZ]; |
1861 |
|
|
1862 |
|
if (pClient == NULL) |
1863 |
|
return -1; |
1864 |
|
if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127) |
1865 |
|
return -1; |
1866 |
|
|
1867 |
|
// Lock this section up. |
1868 |
|
lscp_mutex_lock(pClient->mutex); |
1869 |
|
|
1870 |
|
sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController); |
1871 |
|
|
1872 |
|
if (pszFxName) |
1873 |
|
sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName); |
1874 |
|
|
1875 |
|
strcat(szQuery, "\r\n"); |
1876 |
|
|
1877 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1878 |
|
iFxSend = atoi(lscp_client_get_result(pClient)); |
1879 |
|
|
1880 |
|
// Unlock this section down. |
1881 |
|
lscp_mutex_unlock(pClient->mutex); |
1882 |
|
|
1883 |
|
return iFxSend; |
1884 |
|
} |
1885 |
|
|
1886 |
|
|
1887 |
|
/** |
1888 |
|
* Remove an effect send from a sampler channel: |
1889 |
|
* DESTROY FX_SEND <sampler-channel> <fx-send-id> |
1890 |
|
* |
1891 |
|
* @param pClient Pointer to client instance structure. |
1892 |
|
* @param iSamplerChannel Sampler channel number. |
1893 |
|
* @param iFxSend Effect send number. |
1894 |
|
* |
1895 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1896 |
|
*/ |
1897 |
|
lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend ) |
1898 |
|
{ |
1899 |
|
char szQuery[LSCP_BUFSIZ]; |
1900 |
|
|
1901 |
|
if (iSamplerChannel < 0 || iFxSend < 0) |
1902 |
|
return LSCP_FAILED; |
1903 |
|
|
1904 |
|
sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend); |
1905 |
|
|
1906 |
|
return lscp_client_query(pClient, szQuery); |
1907 |
|
} |
1908 |
|
|
1909 |
|
|
1910 |
|
/** |
1911 |
|
* Get amount of effect sends on a sampler channel: |
1912 |
|
* GET FX_SENDS <sampler-channel> |
1913 |
|
* |
1914 |
|
* @param pClient Pointer to client instance structure. |
1915 |
|
* @param iSamplerChannel Sampler channel number. |
1916 |
|
* |
1917 |
|
* @returns The current total number of effect sends of the sampler channel |
1918 |
|
* on success, -1 otherwise. |
1919 |
|
*/ |
1920 |
|
int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel ) |
1921 |
|
{ |
1922 |
|
int iFxSends = -1; |
1923 |
|
char szQuery[LSCP_BUFSIZ]; |
1924 |
|
|
1925 |
|
if (pClient == NULL) |
1926 |
|
return -1; |
1927 |
|
if (iSamplerChannel < 0) |
1928 |
|
return -1; |
1929 |
|
|
1930 |
|
// Lock this section up. |
1931 |
|
lscp_mutex_lock(pClient->mutex); |
1932 |
|
|
1933 |
|
sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel); |
1934 |
|
|
1935 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1936 |
|
iFxSends = atoi(lscp_client_get_result(pClient)); |
1937 |
|
|
1938 |
|
// Unlock this section doen. |
1939 |
|
lscp_mutex_unlock(pClient->mutex); |
1940 |
|
|
1941 |
|
return iFxSends; |
1942 |
|
} |
1943 |
|
|
1944 |
|
|
1945 |
|
/** |
1946 |
|
* List all effect sends on a sampler channel: |
1947 |
|
* LIST FX_SENDS <sampler-channel> |
1948 |
|
* |
1949 |
|
* @param pClient Pointer to client instance structure. |
1950 |
|
* @param iSamplerChannel Sampler channel number. |
1951 |
|
* |
1952 |
|
* @returns An array of the effect sends identifiers as positive integers, |
1953 |
|
* terminated with -1 on success, NULL otherwise. |
1954 |
|
*/ |
1955 |
|
int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel ) |
1956 |
|
{ |
1957 |
|
const char *pszSeps = ","; |
1958 |
|
char szQuery[LSCP_BUFSIZ]; |
1959 |
|
|
1960 |
|
if (pClient == NULL) |
1961 |
|
return NULL; |
1962 |
|
|
1963 |
|
// Lock this section up. |
1964 |
|
lscp_mutex_lock(pClient->mutex); |
1965 |
|
|
1966 |
|
if (pClient->fxsends) { |
1967 |
|
lscp_isplit_destroy(pClient->fxsends); |
1968 |
|
pClient->fxsends = NULL; |
1969 |
|
} |
1970 |
|
|
1971 |
|
sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel); |
1972 |
|
|
1973 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1974 |
|
pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
1975 |
|
|
1976 |
|
// Unlock this section down. |
1977 |
|
lscp_mutex_unlock(pClient->mutex); |
1978 |
|
|
1979 |
|
return pClient->fxsends; |
1980 |
|
} |
1981 |
|
|
1982 |
|
|
1983 |
|
/** |
1984 |
|
* Getting effect send information |
1985 |
|
* GET FX_SEND INFO <sampler-channel> <fx-send-id> |
1986 |
|
* |
1987 |
|
* @param pClient Pointer to client instance structure. |
1988 |
|
* @param iSamplerChannel Sampler channel number. |
1989 |
|
* @param iFxSend Effect send number. |
1990 |
|
* |
1991 |
|
* @returns A pointer to a @ref lscp_fxsend_info_t structure, with the |
1992 |
|
* information of the given FX send, or NULL in case of failure. |
1993 |
|
*/ |
1994 |
|
lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend ) |
1995 |
|
{ |
1996 |
|
lscp_fxsend_info_t *pFxSendInfo; |
1997 |
|
char szQuery[LSCP_BUFSIZ]; |
1998 |
|
const char *pszResult; |
1999 |
|
const char *pszSeps = ":"; |
2000 |
|
const char *pszCrlf = "\r\n"; |
2001 |
|
char *pszToken; |
2002 |
|
char *pch; |
2003 |
|
|
2004 |
|
if (pClient == NULL) |
2005 |
|
return NULL; |
2006 |
|
if (iSamplerChannel < 0 || iFxSend < 0) |
2007 |
|
return NULL; |
2008 |
|
|
2009 |
|
// Lock this section up. |
2010 |
|
lscp_mutex_lock(pClient->mutex); |
2011 |
|
|
2012 |
|
pFxSendInfo = &(pClient->fxsend_info); |
2013 |
|
lscp_fxsend_info_reset(pFxSendInfo); |
2014 |
|
|
2015 |
|
sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend); |
2016 |
|
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
2017 |
|
pszResult = lscp_client_get_result(pClient); |
2018 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
2019 |
|
while (pszToken) { |
2020 |
|
if (strcasecmp(pszToken, "NAME") == 0) { |
2021 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2022 |
|
if (pszToken) |
2023 |
|
lscp_unquote_dup(&(pFxSendInfo->name), &pszToken); |
2024 |
|
} |
2025 |
|
else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) { |
2026 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2027 |
|
if (pszToken) |
2028 |
|
pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken)); |
2029 |
|
} |
2030 |
|
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
2031 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2032 |
|
if (pszToken) { |
2033 |
|
if (pFxSendInfo->audio_routing) |
2034 |
|
lscp_isplit_destroy(pFxSendInfo->audio_routing); |
2035 |
|
pFxSendInfo->audio_routing = lscp_isplit_create(pszToken, ","); |
2036 |
|
} |
2037 |
|
} |
2038 |
|
else if (strcasecmp(pszToken, "LEVEL") == 0) { |
2039 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2040 |
|
if (pszToken) |
2041 |
|
pFxSendInfo->level = (float) atof(lscp_ltrim(pszToken)); |
2042 |
|
} |
2043 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
2044 |
|
} |
2045 |
|
} |
2046 |
|
else pFxSendInfo = NULL; |
2047 |
|
|
2048 |
|
// Unlock this section up. |
2049 |
|
lscp_mutex_unlock(pClient->mutex); |
2050 |
|
|
2051 |
|
return pFxSendInfo; |
2052 |
|
} |
2053 |
|
|
2054 |
|
|
2055 |
|
/** |
2056 |
|
* Alter effect send's audio routing: |
2057 |
|
* SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id> |
2058 |
|
* <audio-src> <audio-dst> |
2059 |
|
* |
2060 |
|
* @param pClient Pointer to client instance structure. |
2061 |
|
* @param iSamplerChannel Sampler channel number. |
2062 |
|
* @param iFxSend Effect send number. |
2063 |
|
* @param iAudioSrc Audio output device channel to be routed from. |
2064 |
|
* @param iAudioDst Audio output device channel to be routed into. |
2065 |
|
* |
2066 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2067 |
|
*/ |
2068 |
|
lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst ) |
2069 |
|
{ |
2070 |
|
char szQuery[LSCP_BUFSIZ]; |
2071 |
|
|
2072 |
|
if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0) |
2073 |
|
return LSCP_FAILED; |
2074 |
|
|
2075 |
|
sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst); |
2076 |
|
return lscp_client_query(pClient, szQuery); |
2077 |
|
} |
2078 |
|
|
2079 |
|
|
2080 |
|
/** |
2081 |
|
* Alter effect send's MIDI controller: |
2082 |
|
* SET FX_SEND MIDI_CONTROLLER <sampler-chan> <fx-send-id> <midi-ctrl> |
2083 |
|
* |
2084 |
|
* @param pClient Pointer to client instance structure. |
2085 |
|
* @param iSamplerChannel Sampler channel number. |
2086 |
|
* @param iFxSend Effect send number. |
2087 |
|
* @param iMidiController MIDI controller used to alter the effect, |
2088 |
|
* usually a number between 0 and 127. |
2089 |
|
* |
2090 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2091 |
|
*/ |
2092 |
|
lscp_status_t lscp_set_fxsend_midi_controller ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iMidiController ) |
2093 |
|
{ |
2094 |
|
char szQuery[LSCP_BUFSIZ]; |
2095 |
|
|
2096 |
|
if (iSamplerChannel < 0 || iFxSend < 0 || iMidiController < 0 || iMidiController > 127) |
2097 |
|
return LSCP_FAILED; |
2098 |
|
|
2099 |
|
sprintf(szQuery, "SET FX_SEND MIDI_CONTROLLER %d %d %d\r\n", iSamplerChannel, iFxSend, iMidiController); |
2100 |
|
return lscp_client_query(pClient, szQuery); |
2101 |
|
} |
2102 |
|
|
2103 |
|
|
2104 |
|
/** |
2105 |
|
* Alter effect send's audio level: |
2106 |
|
* SET FX_SEND LEVEL <sampler-chan> <fx-send-id> <level> |
2107 |
|
* |
2108 |
|
* @param pClient Pointer to client instance structure. |
2109 |
|
* @param iSamplerChannel Sampler channel number. |
2110 |
|
* @param iFxSend Effect send number. |
2111 |
|
* @param fLevel Effect send volume level. |
2112 |
|
* |
2113 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2114 |
|
*/ |
2115 |
|
lscp_status_t lscp_set_fxsend_level ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, float fLevel ) |
2116 |
|
{ |
2117 |
|
char szQuery[LSCP_BUFSIZ]; |
2118 |
|
|
2119 |
|
if (iSamplerChannel < 0 || iFxSend < 0 || fLevel < 0.0f) |
2120 |
|
return LSCP_FAILED; |
2121 |
|
|
2122 |
|
sprintf(szQuery, "SET FX_SEND LEVEL %d %d %f\r\n", iSamplerChannel, iFxSend, fLevel); |
2123 |
|
return lscp_client_query(pClient, szQuery); |
2124 |
|
} |
2125 |
|
|
2126 |
|
|
2127 |
|
/** |
2128 |
|
* Create a new MIDI instrument map: |
2129 |
|
* ADD MIDI_INSTRUMENT_MAP [<name>] |
2130 |
|
* |
2131 |
|
* @param pClient Pointer to client instance structure. |
2132 |
|
* @param pszMapName MIDI instrument map name (optional) |
2133 |
|
* |
2134 |
|
* @returns The new MIDI instrument map number identifier, |
2135 |
|
* or -1 in case of failure. |
2136 |
|
*/ |
2137 |
|
int lscp_add_midi_instrument_map ( lscp_client_t *pClient, const char *pszMapName ) |
2138 |
|
{ |
2139 |
|
int iMidiMap = -1; |
2140 |
|
char szQuery[LSCP_BUFSIZ]; |
2141 |
|
|
2142 |
|
if (pClient == NULL) |
2143 |
|
return -1; |
2144 |
|
|
2145 |
|
// Lock this section up. |
2146 |
|
lscp_mutex_lock(pClient->mutex); |
2147 |
|
|
2148 |
|
strcpy(szQuery, "ADD MIDI_INSTRUMENT_MAP"); |
2149 |
|
|
2150 |
|
if (pszMapName) |
2151 |
|
sprintf(szQuery + strlen(szQuery), " '%s'", pszMapName); |
2152 |
|
|
2153 |
|
strcat(szQuery, "\r\n"); |
2154 |
|
|
2155 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
2156 |
|
iMidiMap = atoi(lscp_client_get_result(pClient)); |
2157 |
|
|
2158 |
|
// Unlock this section down. |
2159 |
|
lscp_mutex_unlock(pClient->mutex); |
2160 |
|
|
2161 |
|
return iMidiMap; |
2162 |
|
} |
2163 |
|
|
2164 |
|
|
2165 |
|
/** |
2166 |
|
* Delete one particular or all MIDI instrument maps: |
2167 |
|
* REMOVE MIDI_INSTRUMENT_MAP <midi-map> |
2168 |
|
* |
2169 |
|
* @param pClient Pointer to client instance structure. |
2170 |
|
* @param iMidiMap MIDI instrument map number. |
2171 |
|
* |
2172 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2173 |
|
*/ |
2174 |
|
lscp_status_t lscp_remove_midi_instrument_map ( lscp_client_t *pClient, int iMidiMap ) |
2175 |
|
{ |
2176 |
|
char szQuery[LSCP_BUFSIZ]; |
2177 |
|
|
2178 |
|
if (iMidiMap < 0) |
2179 |
|
return LSCP_FAILED; |
2180 |
|
|
2181 |
|
sprintf(szQuery, "REMOVE MIDI_INSTRUMENT_MAP %d\r\n", iMidiMap); |
2182 |
|
|
2183 |
|
return lscp_client_query(pClient, szQuery); |
2184 |
|
} |
2185 |
|
|
2186 |
|
|
2187 |
|
/** |
2188 |
|
* Get amount of existing MIDI instrument maps: |
2189 |
|
* GET MIDI_INSTRUMENT_MAPS |
2190 |
|
* |
2191 |
|
* @param pClient Pointer to client instance structure. |
2192 |
|
* |
2193 |
|
* @returns The current total number of MIDI instrument maps |
2194 |
|
* on success, -1 otherwise. |
2195 |
|
*/ |
2196 |
|
int lscp_get_midi_instrument_maps ( lscp_client_t *pClient ) |
2197 |
|
{ |
2198 |
|
int iMidiMaps = -1; |
2199 |
|
|
2200 |
|
if (pClient == NULL) |
2201 |
|
return -1; |
2202 |
|
|
2203 |
|
// Lock this section up. |
2204 |
|
lscp_mutex_lock(pClient->mutex); |
2205 |
|
|
2206 |
|
if (lscp_client_call(pClient, "GET MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK) |
2207 |
|
iMidiMaps = atoi(lscp_client_get_result(pClient)); |
2208 |
|
|
2209 |
|
// Unlock this section doen. |
2210 |
|
lscp_mutex_unlock(pClient->mutex); |
2211 |
|
|
2212 |
|
return iMidiMaps; |
2213 |
|
} |
2214 |
|
|
2215 |
|
|
2216 |
|
/** |
2217 |
|
* Getting all created MIDI instrument maps: |
2218 |
|
* LIST MIDI_INSTRUMENT_MAPS |
2219 |
|
* |
2220 |
|
* @param pClient Pointer to client instance structure. |
2221 |
|
* |
2222 |
|
* @returns An array of the MIDI instrument map identifiers as positive |
2223 |
|
* integers, terminated with -1 on success, NULL otherwise. |
2224 |
|
*/ |
2225 |
|
int *lscp_list_midi_instrument_maps ( lscp_client_t *pClient ) |
2226 |
|
{ |
2227 |
|
const char *pszSeps = ","; |
2228 |
|
|
2229 |
|
if (pClient == NULL) |
2230 |
|
return NULL; |
2231 |
|
|
2232 |
|
// Lock this section up. |
2233 |
|
lscp_mutex_lock(pClient->mutex); |
2234 |
|
|
2235 |
|
if (pClient->midi_maps) { |
2236 |
|
lscp_isplit_destroy(pClient->midi_maps); |
2237 |
|
pClient->midi_maps = NULL; |
2238 |
|
} |
2239 |
|
|
2240 |
|
if (lscp_client_call(pClient, "LIST MIDI_INSTRUMENT_MAPS\r\n", 0) == LSCP_OK) |
2241 |
|
pClient->midi_maps = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
2242 |
|
|
2243 |
|
// Unlock this section down. |
2244 |
|
lscp_mutex_unlock(pClient->mutex); |
2245 |
|
|
2246 |
|
return pClient->midi_maps; |
2247 |
|
} |
2248 |
|
|
2249 |
|
|
2250 |
|
/** |
2251 |
|
* Getting a MIDI instrument map name: |
2252 |
|
* GET MIDI_INSTRUMENT_MAP INFO <midi-map> |
2253 |
|
* |
2254 |
|
* @param pClient Pointer to client instance structure. |
2255 |
|
* @param iMidiMap MIDI instrument map number. |
2256 |
|
* |
2257 |
|
* @returns The MIDI instrument map name on success, NULL on failure. |
2258 |
|
*/ |
2259 |
|
const char *lscp_get_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap ) |
2260 |
|
{ |
2261 |
|
char szQuery[LSCP_BUFSIZ]; |
2262 |
|
const char *pszResult; |
2263 |
|
const char *pszSeps = ":"; |
2264 |
|
const char *pszCrlf = "\r\n"; |
2265 |
|
char *pszToken; |
2266 |
|
char *pch; |
2267 |
|
|
2268 |
|
if (pClient == NULL) |
2269 |
|
return NULL; |
2270 |
|
if (iMidiMap < 0) |
2271 |
|
return NULL; |
2272 |
|
|
2273 |
|
// Lock this section up. |
2274 |
|
lscp_mutex_lock(pClient->mutex); |
2275 |
|
|
2276 |
|
if (pClient->midi_map_name) { |
2277 |
|
free(pClient->midi_map_name); |
2278 |
|
pClient->midi_map_name = NULL; |
2279 |
|
} |
2280 |
|
|
2281 |
|
sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap); |
2282 |
|
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
2283 |
|
pszResult = lscp_client_get_result(pClient); |
2284 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
2285 |
|
while (pszToken) { |
2286 |
|
if (strcasecmp(pszToken, "NAME") == 0) { |
2287 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2288 |
|
if (pszToken) |
2289 |
|
lscp_unquote_dup(&(pClient->midi_map_name), &pszToken); |
2290 |
|
} |
2291 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
2292 |
|
} |
2293 |
|
} |
2294 |
|
|
2295 |
|
// Unlock this section down. |
2296 |
|
lscp_mutex_unlock(pClient->mutex); |
2297 |
|
|
2298 |
|
return pClient->midi_map_name; |
2299 |
|
} |
2300 |
|
|
2301 |
|
|
2302 |
|
/** |
2303 |
|
* Renaming a MIDI instrument map: |
2304 |
|
* SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name> |
2305 |
|
* |
2306 |
|
* @param pClient Pointer to client instance structure. |
2307 |
|
* @param iMidiMap MIDI instrument map number. |
2308 |
|
* @param pszMapName MIDI instrument map name. |
2309 |
|
* |
2310 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2311 |
|
*/ |
2312 |
|
lscp_status_t lscp_set_midi_instrument_map_name ( lscp_client_t *pClient, int iMidiMap, const char *pszMapName ) |
2313 |
|
{ |
2314 |
|
char szQuery[LSCP_BUFSIZ]; |
2315 |
|
|
2316 |
|
if (iMidiMap < 0) |
2317 |
|
return LSCP_FAILED; |
2318 |
|
if (pszMapName == NULL) |
2319 |
|
return LSCP_FAILED; |
2320 |
|
|
2321 |
|
sprintf(szQuery, "SET MIDI_INSTRUMENT_MAP NAME %d '%s'\r\n", |
2322 |
|
iMidiMap, pszMapName); |
2323 |
|
|
2324 |
|
return lscp_client_query(pClient, szQuery); |
2325 |
|
} |
2326 |
|
|
2327 |
|
|
2328 |
|
/** |
2329 |
|
* Create or replace a MIDI instrumnet map entry: |
2330 |
|
* MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
2331 |
|
* <engine-name> <filename> <instr-index> <volume> [<load-mode> [<name>]} |
2332 |
|
* |
2333 |
|
* @param pClient Pointer to client instance structure. |
2334 |
|
* @param pMidiInstr MIDI instrument bank and program parameter key. |
2335 |
|
* @param pszEngineName Engine name. |
2336 |
|
* @param pszFileName Instrument file name. |
2337 |
|
* @param iInstrIndex Instrument index number. |
2338 |
|
* @param fVolume Reflects the master volume of the instrument as |
2339 |
|
* a positive floating point number, where a value |
2340 |
|
* less than 1.0 for attenuation, and greater than |
2341 |
|
* 1.0 for amplification. |
2342 |
|
* @param load_mode Instrument load life-time strategy, either |
2343 |
|
* @ref LSCP_LOAD_DEFAULT, or |
2344 |
|
* @ref LSCP_LOAD_ON_DEMAND, or |
2345 |
|
* @ref LSCP_LOAD_ON_DEMAND_HOLD, or |
2346 |
|
* @ref LSCP_LOAD_PERSISTENT. |
2347 |
|
* @param pszName Instrument custom name for the map entry (optional). |
2348 |
|
* |
2349 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2350 |
|
*/ |
2351 |
|
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 ) |
2352 |
|
{ |
2353 |
|
char szQuery[LSCP_BUFSIZ]; |
2354 |
|
|
2355 |
|
if (pMidiInstr->map < 0) |
2356 |
|
return LSCP_FAILED; |
2357 |
|
if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383) |
2358 |
|
return LSCP_FAILED; |
2359 |
|
if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127) |
2360 |
|
return LSCP_FAILED; |
2361 |
|
if (pszEngineName == NULL || pszFileName == NULL) |
2362 |
|
return LSCP_FAILED; |
2363 |
|
|
2364 |
|
if (fVolume < 0.0f) |
2365 |
|
fVolume = 1.0f; |
2366 |
|
|
2367 |
|
sprintf(szQuery, "MAP MIDI_INSTRUMENT %d %d %d %s '%s' %d %g", |
2368 |
|
pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog, |
2369 |
|
pszEngineName, pszFileName, iInstrIndex, fVolume); |
2370 |
|
|
2371 |
|
switch (load_mode) { |
2372 |
|
case LSCP_LOAD_PERSISTENT: |
2373 |
|
strcat(szQuery, " PERSISTENT"); |
2374 |
|
break; |
2375 |
|
case LSCP_LOAD_ON_DEMAND_HOLD: |
2376 |
|
strcat(szQuery, " ON_DEMAND_HOLD"); |
2377 |
|
break; |
2378 |
|
case LSCP_LOAD_ON_DEMAND: |
2379 |
|
strcat(szQuery, " ON_DEMAND"); |
2380 |
|
break; |
2381 |
|
case LSCP_LOAD_DEFAULT: |
2382 |
|
default: |
2383 |
|
break; |
2384 |
|
} |
2385 |
|
|
2386 |
|
if (pszName) |
2387 |
|
sprintf(szQuery + strlen(szQuery), " '%s'", pszName); |
2388 |
|
|
2389 |
|
strcat(szQuery, "\r\n"); |
2390 |
|
|
2391 |
|
return lscp_client_query(pClient, szQuery); |
2392 |
|
} |
2393 |
|
|
2394 |
|
|
2395 |
|
/** |
2396 |
|
* Remove an entry from the MIDI instrument map: |
2397 |
|
* UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
2398 |
|
* |
2399 |
|
* @param pClient Pointer to client instance structure. |
2400 |
|
* @param pMidiInstr MIDI instrument bank and program parameter key. |
2401 |
|
* |
2402 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2403 |
|
*/ |
2404 |
|
lscp_status_t lscp_unmap_midi_instrument ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr ) |
2405 |
|
{ |
2406 |
|
char szQuery[LSCP_BUFSIZ]; |
2407 |
|
|
2408 |
|
if (pMidiInstr->map < 0) |
2409 |
|
return LSCP_FAILED; |
2410 |
|
if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383) |
2411 |
|
return LSCP_FAILED; |
2412 |
|
if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127) |
2413 |
|
return LSCP_FAILED; |
2414 |
|
|
2415 |
|
sprintf(szQuery, "UNMAP MIDI_INSTRUMENT %d %d %d\r\n", |
2416 |
|
pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog); |
2417 |
|
|
2418 |
|
return lscp_client_query(pClient, szQuery); |
2419 |
|
} |
2420 |
|
|
2421 |
|
|
2422 |
|
/** |
2423 |
|
* Get the total count of MIDI instrument map entries: |
2424 |
|
* GET MIDI_INSTRUMENTS ALL|<midi-map> |
2425 |
|
* |
2426 |
|
* @param pClient Pointer to client instance structure. |
2427 |
|
* @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL . |
2428 |
|
* |
2429 |
|
* @returns The current total number of MIDI instrument map entries |
2430 |
|
* on success, -1 otherwise. |
2431 |
|
*/ |
2432 |
|
int lscp_get_midi_instruments ( lscp_client_t *pClient, int iMidiMap ) |
2433 |
|
{ |
2434 |
|
int iInstruments = -1; |
2435 |
|
char szQuery[LSCP_BUFSIZ]; |
2436 |
|
|
2437 |
|
if (pClient == NULL) |
2438 |
|
return -1; |
2439 |
|
|
2440 |
|
// Lock this section up. |
2441 |
|
lscp_mutex_lock(pClient->mutex); |
2442 |
|
|
2443 |
|
strcpy(szQuery, "GET MIDI_INSTRUMENTS "); |
2444 |
|
|
2445 |
|
if (iMidiMap < 0) |
2446 |
|
strcat(szQuery, "ALL"); |
2447 |
|
else |
2448 |
|
sprintf(szQuery + strlen(szQuery), "%d", iMidiMap); |
2449 |
|
|
2450 |
|
strcat(szQuery, "\r\n"); |
2451 |
|
|
2452 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
2453 |
|
iInstruments = atoi(lscp_client_get_result(pClient)); |
2454 |
|
|
2455 |
|
// Unlock this section down. |
2456 |
|
lscp_mutex_unlock(pClient->mutex); |
2457 |
|
|
2458 |
|
return iInstruments; |
2459 |
|
} |
2460 |
|
|
2461 |
|
|
2462 |
|
/** |
2463 |
|
* Getting indeces of all MIDI instrument map entries: |
2464 |
|
* LIST MIDI_INSTRUMENTS ALL|<midi-map> |
2465 |
|
* |
2466 |
|
* @param pClient Pointer to client instance structure. |
2467 |
|
* @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL . |
2468 |
|
* |
2469 |
|
* @returns An array of @ref lscp_midi_instrument_t, terminated with the |
2470 |
|
* {-1,-1,-1} triplet, NULL otherwise. |
2471 |
|
*/ |
2472 |
|
lscp_midi_instrument_t *lscp_list_midi_instruments ( lscp_client_t *pClient, int iMidiMap ) |
2473 |
|
{ |
2474 |
|
char szQuery[LSCP_BUFSIZ]; |
2475 |
|
|
2476 |
|
if (pClient == NULL) |
2477 |
|
return NULL; |
2478 |
|
|
2479 |
|
// Lock this section up. |
2480 |
|
lscp_mutex_lock(pClient->mutex); |
2481 |
|
|
2482 |
|
if (pClient->midi_instruments) { |
2483 |
|
lscp_midi_instruments_destroy(pClient->midi_instruments); |
2484 |
|
pClient->midi_instruments = NULL; |
2485 |
|
} |
2486 |
|
|
2487 |
|
strcpy(szQuery, "LIST MIDI_INSTRUMENTS "); |
2488 |
|
|
2489 |
|
if (iMidiMap < 0) |
2490 |
|
strcat(szQuery, "ALL"); |
2491 |
|
else |
2492 |
|
sprintf(szQuery + strlen(szQuery), "%d", iMidiMap); |
2493 |
|
|
2494 |
|
strcat(szQuery, "\r\n"); |
2495 |
|
|
2496 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
2497 |
|
pClient->midi_instruments = lscp_midi_instruments_create(lscp_client_get_result(pClient)); |
2498 |
|
|
2499 |
|
// Unlock this section down. |
2500 |
|
lscp_mutex_unlock(pClient->mutex); |
2501 |
|
|
2502 |
|
return pClient->midi_instruments; |
2503 |
|
} |
2504 |
|
|
2505 |
|
|
2506 |
|
/** |
2507 |
|
* Getting information about a MIDI instrument map entry: |
2508 |
|
* GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog> |
2509 |
|
* |
2510 |
|
* @param pClient Pointer to client instance structure. |
2511 |
|
* @param pMidiInstr MIDI instrument bank and program parameter key. |
2512 |
|
* |
2513 |
|
* @returns A pointer to a @ref lscp_midi_instrument_info_t structure, |
2514 |
|
* with all the information of the given MIDI instrument map entry, |
2515 |
|
* or NULL in case of failure. |
2516 |
|
*/ |
2517 |
|
lscp_midi_instrument_info_t *lscp_get_midi_instrument_info ( lscp_client_t *pClient, lscp_midi_instrument_t *pMidiInstr ) |
2518 |
|
{ |
2519 |
|
lscp_midi_instrument_info_t *pInstrInfo; |
2520 |
|
char szQuery[LSCP_BUFSIZ]; |
2521 |
|
const char *pszResult; |
2522 |
|
const char *pszSeps = ":"; |
2523 |
|
const char *pszCrlf = "\r\n"; |
2524 |
|
char *pszToken; |
2525 |
|
char *pch; |
2526 |
|
|
2527 |
|
if (pClient == NULL) |
2528 |
|
return NULL; |
2529 |
|
if (pMidiInstr->map < 0) |
2530 |
|
return NULL; |
2531 |
|
if (pMidiInstr->bank < 0 || pMidiInstr->bank > 16383) |
2532 |
|
return NULL; |
2533 |
|
if (pMidiInstr->prog < 0 || pMidiInstr->prog > 127) |
2534 |
|
return NULL; |
2535 |
|
|
2536 |
|
// Lock this section up. |
2537 |
|
lscp_mutex_lock(pClient->mutex); |
2538 |
|
|
2539 |
|
pInstrInfo = &(pClient->midi_instrument_info); |
2540 |
|
lscp_midi_instrument_info_reset(pInstrInfo); |
2541 |
|
|
2542 |
|
sprintf(szQuery, "GET MIDI_INSTRUMENT INFO %d %d %d\r\n", |
2543 |
|
pMidiInstr->map, pMidiInstr->bank, pMidiInstr->prog); |
2544 |
|
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
2545 |
|
pszResult = lscp_client_get_result(pClient); |
2546 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
2547 |
|
while (pszToken) { |
2548 |
|
if (strcasecmp(pszToken, "NAME") == 0) { |
2549 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2550 |
|
if (pszToken) |
2551 |
|
lscp_unquote_dup(&(pInstrInfo->name), &pszToken); |
2552 |
|
} |
2553 |
|
else if (strcasecmp(pszToken, "ENGINE_NAME") == 0) { |
2554 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2555 |
|
if (pszToken) |
2556 |
|
lscp_unquote_dup(&(pInstrInfo->engine_name), &pszToken); |
2557 |
|
} |
2558 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) { |
2559 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2560 |
|
if (pszToken) |
2561 |
|
lscp_unquote_dup(&(pInstrInfo->instrument_file), &pszToken); |
2562 |
|
} |
2563 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) { |
2564 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2565 |
|
if (pszToken) |
2566 |
|
pInstrInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); |
2567 |
|
} |
2568 |
|
else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { |
2569 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2570 |
|
if (pszToken) |
2571 |
|
lscp_unquote_dup(&(pInstrInfo->instrument_name), &pszToken); |
2572 |
|
} |
2573 |
|
else if (strcasecmp(pszToken, "LOAD_MODE") == 0) { |
2574 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2575 |
|
if (pszToken) { |
2576 |
|
pszToken = lscp_ltrim(pszToken); |
2577 |
|
if (strcasecmp(pszToken, "ON_DEMAND") == 0) |
2578 |
|
pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND; |
2579 |
|
else |
2580 |
|
if (strcasecmp(pszToken, "ON_DEMAND_HOLD") == 0) |
2581 |
|
pInstrInfo->load_mode = LSCP_LOAD_ON_DEMAND_HOLD; |
2582 |
|
else |
2583 |
|
if (strcasecmp(pszToken, "PERSISTENT") == 0) |
2584 |
|
pInstrInfo->load_mode = LSCP_LOAD_PERSISTENT; |
2585 |
|
else |
2586 |
|
pInstrInfo->load_mode = LSCP_LOAD_DEFAULT; |
2587 |
|
} |
2588 |
|
} |
2589 |
|
else if (strcasecmp(pszToken, "VOLUME") == 0) { |
2590 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2591 |
|
if (pszToken) |
2592 |
|
pInstrInfo->volume = (float) atof(lscp_ltrim(pszToken)); |
2593 |
|
} |
2594 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
2595 |
|
} |
2596 |
|
} |
2597 |
|
else pInstrInfo = NULL; |
2598 |
|
|
2599 |
|
// Unlock this section down. |
2600 |
|
lscp_mutex_unlock(pClient->mutex); |
2601 |
|
|
2602 |
|
return pInstrInfo; |
2603 |
|
} |
2604 |
|
|
2605 |
|
|
2606 |
|
/** |
2607 |
|
* Clear the MIDI instrumnet map: |
2608 |
|
* CLEAR MIDI_INSTRUMENTS ALL|<midi-map> |
2609 |
|
* |
2610 |
|
* @param pClient Pointer to client instance structure. |
2611 |
|
* @param iMidiMap MIDI instrument map number, or @ref LSCP_MIDI_MAP_ALL . |
2612 |
|
* |
2613 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2614 |
|
*/ |
2615 |
|
lscp_status_t lscp_clear_midi_instruments ( lscp_client_t *pClient, int iMidiMap ) |
2616 |
|
{ |
2617 |
|
char szQuery[LSCP_BUFSIZ]; |
2618 |
|
|
2619 |
|
strcpy(szQuery, "CLEAR MIDI_INSTRUMENTS "); |
2620 |
|
|
2621 |
|
if (iMidiMap < 0) |
2622 |
|
strcat(szQuery, "ALL"); |
2623 |
|
else |
2624 |
|
sprintf(szQuery + strlen(szQuery), "%d", iMidiMap); |
2625 |
|
|
2626 |
|
strcat(szQuery, "\r\n"); |
2627 |
|
|
2628 |
|
return lscp_client_query(pClient, szQuery); |
2629 |
|
} |
2630 |
|
|
2631 |
|
/** |
2632 |
|
* Open an instrument editor application for the instrument on the given |
2633 |
|
* sampler channel: |
2634 |
|
* EDIT INSTRUMENT <sampler-channel> |
2635 |
|
* |
2636 |
|
* @param pClient Pointer to client instance structure. |
2637 |
|
* @param iSamplerChannel Sampler Channel. |
2638 |
|
* |
2639 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2640 |
|
*/ |
2641 |
|
lscp_status_t lscp_edit_instrument (lscp_client_t *pClient, int iSamplerChannel) |
2642 |
|
{ |
2643 |
|
char szQuery[LSCP_BUFSIZ]; |
2644 |
|
snprintf(szQuery, LSCP_BUFSIZ, "EDIT INSTRUMENT %d\r\n", iSamplerChannel); |
2645 |
|
return lscp_client_query(pClient, szQuery); |
2646 |
} |
} |
2647 |
|
|
2648 |
|
|