1 |
// example_client.c |
// example_client.c |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
liblscp - LinuxSampler Control Protocol API |
5 |
|
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
18 |
along with this program; 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 |
|
|
121 |
} |
} |
122 |
|
|
123 |
|
|
124 |
|
int client_test_midi_instruments ( lscp_midi_instrument_t *pInstrs ) |
125 |
|
{ |
126 |
|
int i; |
127 |
|
|
128 |
|
printf("{"); |
129 |
|
for (i = 0; pInstrs && pInstrs[i].program >= 0; i++) { |
130 |
|
if (i > 0) |
131 |
|
printf(","); |
132 |
|
printf("{%d,%d,%d}", pInstrs[i].bank_msb, pInstrs[i].bank_lsb, pInstrs[i].program); |
133 |
|
} |
134 |
|
printf(" }\n"); |
135 |
|
return 0; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
int client_test_param_info ( lscp_param_info_t *pParamInfo ) |
int client_test_param_info ( lscp_param_info_t *pParamInfo ) |
140 |
{ |
{ |
141 |
const char *pszType; |
const char *pszType; |
152 |
default: pszType = "NONE"; break; |
default: pszType = "NONE"; break; |
153 |
} |
} |
154 |
printf("{\n"); |
printf("{\n"); |
155 |
printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType); |
printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType); |
156 |
printf(" param_info.description = %s\n", pParamInfo->description); |
printf(" param_info.description = %s\n", pParamInfo->description); |
157 |
printf(" param_info.mandatory = %d\n", pParamInfo->mandatory); |
printf(" param_info.mandatory = %d\n", pParamInfo->mandatory); |
158 |
printf(" param_info.fix = %d\n", pParamInfo->fix); |
printf(" param_info.fix = %d\n", pParamInfo->fix); |
159 |
printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity); |
printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity); |
160 |
printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends); |
printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends); |
161 |
printf(" param_info.defaultv = %s\n", pParamInfo->defaultv); |
printf(" param_info.defaultv = %s\n", pParamInfo->defaultv); |
162 |
printf(" param_info.range_min = %s\n", pParamInfo->range_min); |
printf(" param_info.range_min = %s\n", pParamInfo->range_min); |
163 |
printf(" param_info.range_max = %s\n", pParamInfo->range_max); |
printf(" param_info.range_max = %s\n", pParamInfo->range_max); |
164 |
printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities); |
printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities); |
165 |
printf(" }\n"); |
printf(" }\n"); |
166 |
return 0; |
return 0; |
167 |
} |
} |
174 |
return 1; |
return 1; |
175 |
} |
} |
176 |
printf("{\n"); |
printf("{\n"); |
177 |
printf(" driver_info.description = %s\n", pDriverInfo->description); |
printf(" driver_info.description = %s\n", pDriverInfo->description); |
178 |
printf(" driver_info.version = %s\n", pDriverInfo->version); |
printf(" driver_info.version = %s\n", pDriverInfo->version); |
179 |
printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters); |
printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters); |
180 |
printf(" }\n"); |
printf(" }\n"); |
181 |
return 0; |
return 0; |
182 |
} |
} |
189 |
return 1; |
return 1; |
190 |
} |
} |
191 |
printf("{\n"); |
printf("{\n"); |
192 |
printf(" device_info.driver = %s\n", pDeviceInfo->driver); |
printf(" device_info.driver = %s\n", pDeviceInfo->driver); |
193 |
printf(" device_info.params = "); client_test_params(pDeviceInfo->params); |
printf(" device_info.params = "); client_test_params(pDeviceInfo->params); |
194 |
printf(" }\n"); |
printf(" }\n"); |
195 |
return 0; |
return 0; |
196 |
} |
} |
203 |
return 1; |
return 1; |
204 |
} |
} |
205 |
printf("{\n"); |
printf("{\n"); |
206 |
printf(" device_port_info.name = %s\n", pDevicePortInfo->name); |
printf(" device_port_info.name = %s\n", pDevicePortInfo->name); |
207 |
printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params); |
printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params); |
208 |
printf(" }\n"); |
printf(" }\n"); |
209 |
return 0; |
return 0; |
210 |
} |
} |
217 |
return 1; |
return 1; |
218 |
} |
} |
219 |
printf("{\n"); |
printf("{\n"); |
220 |
printf(" server_info.description = %s\n", pServerInfo->description); |
printf(" server_info.description = %s\n", pServerInfo->description); |
221 |
printf(" server_info.version = %s\n", pServerInfo->version); |
printf(" server_info.version = %s\n", pServerInfo->version); |
222 |
printf(" }\n"); |
printf(" }\n"); |
223 |
return 0; |
return 0; |
224 |
} |
} |
231 |
return 1; |
return 1; |
232 |
} |
} |
233 |
printf("{\n"); |
printf("{\n"); |
234 |
printf(" engine_info.description = %s\n", pEngineInfo->description); |
printf(" engine_info.description = %s\n", pEngineInfo->description); |
235 |
printf(" engine_info.version = %s\n", pEngineInfo->version); |
printf(" engine_info.version = %s\n", pEngineInfo->version); |
236 |
printf(" }\n"); |
printf(" }\n"); |
237 |
return 0; |
return 0; |
238 |
} |
} |
275 |
} |
} |
276 |
|
|
277 |
|
|
278 |
|
int client_test_load_mode ( lscp_load_mode_t load_mode ) |
279 |
|
{ |
280 |
|
const char *pszLoadMode; |
281 |
|
|
282 |
|
switch (load_mode) { |
283 |
|
case LSCP_LOAD_ON_DEMAND: pszLoadMode = "ON_DEMAND"; break; |
284 |
|
case LSCP_LOAD_ON_DEMAND_HOLD: pszLoadMode = "ON_DEMAND_HOLD"; break; |
285 |
|
case LSCP_LOAD_PERSISTENT: pszLoadMode = "PERSISTENT"; break; |
286 |
|
default: pszLoadMode = "DEFAULT"; break; |
287 |
|
} |
288 |
|
printf("%s\n", pszLoadMode); |
289 |
|
return 0; |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
|
int client_test_midi_instrument_info ( lscp_midi_instrument_info_t *pInstrInfo ) |
294 |
|
{ |
295 |
|
if (pInstrInfo == NULL) { |
296 |
|
printf("(nil)\n"); |
297 |
|
return 1; |
298 |
|
} |
299 |
|
printf("{\n"); |
300 |
|
printf(" midi_instrument_info.name = %s\n", pInstrInfo->name); |
301 |
|
printf(" midi_instrument_info.engine_name = %s\n", pInstrInfo->engine_name); |
302 |
|
printf(" midi_instrument_info.instrument_file = %s\n", pInstrInfo->instrument_file); |
303 |
|
printf(" midi_instrument_info.instrument_nr = %d\n", pInstrInfo->instrument_nr); |
304 |
|
printf(" midi_instrument_info.instrument_name = %s\n", pInstrInfo->instrument_name); |
305 |
|
printf(" midi_instrument_info.load_mode = "); client_test_load_mode(pInstrInfo->load_mode); |
306 |
|
printf(" midi_instrument_info.volume = %g\n", pInstrInfo->volume); |
307 |
|
printf(" }\n"); |
308 |
|
return 0; |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
313 |
|
|
314 |
static int g_test_step = 0; |
static int g_test_step = 0; |
319 |
void client_test_start ( clock_t *pclk ) { *pclk = clock(); } |
void client_test_start ( clock_t *pclk ) { *pclk = clock(); } |
320 |
float client_test_elapsed ( clock_t *pclk ) { return (float) ((long) clock() - *pclk) / (float) CLOCKS_PER_SEC; } |
float client_test_elapsed ( clock_t *pclk ) { return (float) ((long) clock() - *pclk) / (float) CLOCKS_PER_SEC; } |
321 |
|
|
322 |
typedef int * isplit; |
typedef int * isplit; |
323 |
typedef char ** szsplit; |
typedef char ** szsplit; |
324 |
typedef lscp_status_t status; |
typedef lscp_status_t status; |
325 |
typedef lscp_driver_info_t * driver_info; |
typedef lscp_driver_info_t * driver_info; |
326 |
typedef lscp_device_info_t * device_info; |
typedef lscp_device_info_t * device_info; |
327 |
typedef lscp_device_port_info_t * device_port_info; |
typedef lscp_device_port_info_t * device_port_info; |
328 |
typedef lscp_param_info_t * param_info; |
typedef lscp_param_info_t * param_info; |
329 |
typedef lscp_server_info_t * server_info; |
typedef lscp_server_info_t * server_info; |
330 |
typedef lscp_engine_info_t * engine_info; |
typedef lscp_engine_info_t * engine_info; |
331 |
typedef lscp_channel_info_t * channel_info; |
typedef lscp_channel_info_t * channel_info; |
332 |
typedef lscp_buffer_fill_t * buffer_fill; |
typedef lscp_buffer_fill_t * buffer_fill; |
333 |
|
typedef lscp_midi_instrument_t * midi_instruments; |
334 |
|
typedef lscp_midi_instrument_info_t *midi_instrument_info; |
335 |
|
|
336 |
#define CLIENT_TEST(p, t, x) { clock_t c; void *v; g_test_count++; \ |
#define CLIENT_TEST(p, t, x) { clock_t c; void *v; g_test_count++; \ |
337 |
printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \ |
printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \ |
346 |
void client_test_engine ( lscp_client_t *pClient, const char *pszEngine, const char *pszAudioDriver, int iAudioDevice, const char *pszMidiDriver, int iMidiDevice ) |
void client_test_engine ( lscp_client_t *pClient, const char *pszEngine, const char *pszAudioDriver, int iAudioDevice, const char *pszMidiDriver, int iMidiDevice ) |
347 |
{ |
{ |
348 |
int iSamplerChannel; |
int iSamplerChannel; |
349 |
|
lscp_midi_instrument_t midi_instr; |
350 |
|
int i, j, k; |
351 |
|
|
352 |
printf("\n--- pszEngine=\"%s\" pszAudioDevice=\"%s\" iAudioDevice=%d pszMidiDevice=\"%s\" iMidiDevice=%d ---\n", pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice); |
printf("\n--- pszEngine=\"%s\" pszAudioDevice=\"%s\" iAudioDevice=%d pszMidiDevice=\"%s\" iMidiDevice=%d ---\n", pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice); |
353 |
CLIENT_TEST(pClient, engine_info, lscp_get_engine_info(pClient, pszEngine)); |
CLIENT_TEST(pClient, engine_info, lscp_get_engine_info(pClient, pszEngine)); |
354 |
|
CLIENT_TEST(pClient, int, lscp_get_total_voice_count(pClient)); |
355 |
|
CLIENT_TEST(pClient, int, lscp_get_total_voice_count_max(pClient)); |
356 |
CLIENT_TEST(pClient, int, lscp_get_channels(pClient)); |
CLIENT_TEST(pClient, int, lscp_get_channels(pClient)); |
357 |
CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient)); |
CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient)); |
358 |
CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient)); |
CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient)); |
378 |
CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel)); |
CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel)); |
379 |
CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel)); |
CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel)); |
380 |
CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel)); |
CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel)); |
381 |
|
|
382 |
|
for (i = 0; i < 2; i++) { |
383 |
|
for (j = 0; j < 4; j++) { |
384 |
|
for (k = 0; k < 8; k++) { |
385 |
|
midi_instr.bank_msb = i; |
386 |
|
midi_instr.bank_lsb = j; |
387 |
|
midi_instr.program = k; |
388 |
|
CLIENT_TEST(pClient, status, lscp_map_midi_instrument(pClient, &midi_instr, pszEngine, "DefaultInstrument.gig", 0, 1.0f, LSCP_LOAD_ON_DEMAND, "DummyName")); |
389 |
|
} |
390 |
|
} |
391 |
|
} |
392 |
|
|
393 |
|
CLIENT_TEST(pClient, int, lscp_get_midi_instruments(pClient)); |
394 |
|
CLIENT_TEST(pClient, midi_instruments, lscp_list_midi_instruments(pClient)); |
395 |
|
|
396 |
|
for (i = 0; i < 2; i++) { |
397 |
|
for (j = 0; j < 4; j++) { |
398 |
|
for (k = 0; k < 8; k++) { |
399 |
|
midi_instr.bank_msb = i; |
400 |
|
midi_instr.bank_lsb = j; |
401 |
|
midi_instr.program = k; |
402 |
|
CLIENT_TEST(pClient, midi_instrument_info, lscp_get_midi_instrument_info(pClient, &midi_instr)); |
403 |
|
CLIENT_TEST(pClient, status, lscp_unmap_midi_instrument(pClient, &midi_instr)); |
404 |
|
} |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
|
CLIENT_TEST(pClient, status, lscp_clear_midi_instruments(pClient)); |
409 |
} |
} |
410 |
|
|
411 |
|
|