1 |
// example_client.c |
// example_client.c |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004, 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 |
|
|
124 |
int client_test_param_info ( lscp_param_info_t *pParamInfo ) |
int client_test_param_info ( lscp_param_info_t *pParamInfo ) |
125 |
{ |
{ |
126 |
const char *pszType; |
const char *pszType; |
127 |
|
|
128 |
if (pParamInfo == NULL) { |
if (pParamInfo == NULL) { |
129 |
printf("(nil)\n"); |
printf("(nil)\n"); |
130 |
return 1; |
return 1; |
137 |
default: pszType = "NONE"; break; |
default: pszType = "NONE"; break; |
138 |
} |
} |
139 |
printf("{\n"); |
printf("{\n"); |
140 |
printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType); |
printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType); |
141 |
printf(" param_info.description = %s\n", pParamInfo->description); |
printf(" param_info.description = %s\n", pParamInfo->description); |
142 |
printf(" param_info.mandatory = %d\n", pParamInfo->mandatory); |
printf(" param_info.mandatory = %d\n", pParamInfo->mandatory); |
143 |
printf(" param_info.fix = %d\n", pParamInfo->fix); |
printf(" param_info.fix = %d\n", pParamInfo->fix); |
144 |
printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity); |
printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity); |
145 |
printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends); |
printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends); |
146 |
printf(" param_info.defaultv = %s\n", pParamInfo->defaultv); |
printf(" param_info.defaultv = %s\n", pParamInfo->defaultv); |
147 |
printf(" param_info.range_min = %s\n", pParamInfo->range_min); |
printf(" param_info.range_min = %s\n", pParamInfo->range_min); |
148 |
printf(" param_info.range_max = %s\n", pParamInfo->range_max); |
printf(" param_info.range_max = %s\n", pParamInfo->range_max); |
149 |
printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities); |
printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities); |
150 |
printf(" }\n"); |
printf(" }\n"); |
151 |
return 0; |
return 0; |
152 |
} |
} |
159 |
return 1; |
return 1; |
160 |
} |
} |
161 |
printf("{\n"); |
printf("{\n"); |
162 |
printf(" driver_info.description = %s\n", pDriverInfo->description); |
printf(" driver_info.description = %s\n", pDriverInfo->description); |
163 |
printf(" driver_info.version = %s\n", pDriverInfo->version); |
printf(" driver_info.version = %s\n", pDriverInfo->version); |
164 |
printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters); |
printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters); |
165 |
printf(" }\n"); |
printf(" }\n"); |
166 |
return 0; |
return 0; |
167 |
} |
} |
174 |
return 1; |
return 1; |
175 |
} |
} |
176 |
printf("{\n"); |
printf("{\n"); |
177 |
printf(" device_info.driver = %s\n", pDeviceInfo->driver); |
printf(" device_info.driver = %s\n", pDeviceInfo->driver); |
178 |
printf(" device_info.params = "); client_test_params(pDeviceInfo->params); |
printf(" device_info.params = "); client_test_params(pDeviceInfo->params); |
179 |
printf(" }\n"); |
printf(" }\n"); |
180 |
return 0; |
return 0; |
181 |
} |
} |
188 |
return 1; |
return 1; |
189 |
} |
} |
190 |
printf("{\n"); |
printf("{\n"); |
191 |
printf(" device_port_info.name = %s\n", pDevicePortInfo->name); |
printf(" device_port_info.name = %s\n", pDevicePortInfo->name); |
192 |
printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params); |
printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params); |
193 |
|
printf(" }\n"); |
194 |
|
return 0; |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
int client_test_server_info ( lscp_server_info_t *pServerInfo ) |
199 |
|
{ |
200 |
|
if (pServerInfo == NULL) { |
201 |
|
printf("(nil)\n"); |
202 |
|
return 1; |
203 |
|
} |
204 |
|
printf("{\n"); |
205 |
|
printf(" server_info.description = %s\n", pServerInfo->description); |
206 |
|
printf(" server_info.version = %s\n", pServerInfo->version); |
207 |
printf(" }\n"); |
printf(" }\n"); |
208 |
return 0; |
return 0; |
209 |
} |
} |
216 |
return 1; |
return 1; |
217 |
} |
} |
218 |
printf("{\n"); |
printf("{\n"); |
219 |
printf(" engine_info.description = %s\n", pEngineInfo->description); |
printf(" engine_info.description = %s\n", pEngineInfo->description); |
220 |
printf(" engine_info.version = %s\n", pEngineInfo->version); |
printf(" engine_info.version = %s\n", pEngineInfo->version); |
221 |
printf(" }\n"); |
printf(" }\n"); |
222 |
return 0; |
return 0; |
223 |
} |
} |
236 |
printf(" channel_info.audio_routing = "); client_test_szsplit(pChannelInfo->audio_routing); |
printf(" channel_info.audio_routing = "); client_test_szsplit(pChannelInfo->audio_routing); |
237 |
printf(" channel_info.instrument_file = %s\n", pChannelInfo->instrument_file); |
printf(" channel_info.instrument_file = %s\n", pChannelInfo->instrument_file); |
238 |
printf(" channel_info.instrument_nr = %d\n", pChannelInfo->instrument_nr); |
printf(" channel_info.instrument_nr = %d\n", pChannelInfo->instrument_nr); |
239 |
|
printf(" channel_info.instrument_name = %s\n", pChannelInfo->instrument_name); |
240 |
printf(" channel_info.instrument_status = %d\n", pChannelInfo->instrument_status); |
printf(" channel_info.instrument_status = %d\n", pChannelInfo->instrument_status); |
241 |
printf(" channel_info.midi_device = %d\n", pChannelInfo->midi_device); |
printf(" channel_info.midi_device = %d\n", pChannelInfo->midi_device); |
242 |
printf(" channel_info.midi_port = %d\n", pChannelInfo->midi_port); |
printf(" channel_info.midi_port = %d\n", pChannelInfo->midi_port); |
243 |
printf(" channel_info.midi_channel = %d\n", pChannelInfo->midi_channel); |
printf(" channel_info.midi_channel = %d\n", pChannelInfo->midi_channel); |
244 |
printf(" channel_info.volume = %g\n", pChannelInfo->volume); |
printf(" channel_info.volume = %g\n", pChannelInfo->volume); |
245 |
|
printf(" channel_info.mute = %d\n", pChannelInfo->mute); |
246 |
|
printf(" channel_info.solo = %d\n", pChannelInfo->solo); |
247 |
printf(" }\n"); |
printf(" }\n"); |
248 |
return 0; |
return 0; |
249 |
} |
} |
260 |
} |
} |
261 |
|
|
262 |
|
|
263 |
|
int client_test_load_mode ( lscp_load_mode_t load_mode ) |
264 |
|
{ |
265 |
|
const char *pszLoadMode; |
266 |
|
|
267 |
|
switch (load_mode) { |
268 |
|
case LSCP_LOAD_ON_DEMAND: pszLoadMode = "ON_DEMAND"; break; |
269 |
|
case LSCP_LOAD_ON_DEMAND_HOLD: pszLoadMode = "ON_DEMAND_HOLD"; break; |
270 |
|
case LSCP_LOAD_PERSISTENT: pszLoadMode = "PERSISTENT"; break; |
271 |
|
default: pszLoadMode = "DEFAULT"; break; |
272 |
|
} |
273 |
|
printf("%s\n", pszLoadMode); |
274 |
|
return 0; |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
int client_test_midi_instrument_info ( lscp_midi_instrument_info_t *pInstrInfo ) |
279 |
|
{ |
280 |
|
if (pInstrInfo == NULL) { |
281 |
|
printf("(nil)\n"); |
282 |
|
return 1; |
283 |
|
} |
284 |
|
printf("{\n"); |
285 |
|
printf(" midi_instrument_info.name = %s\n", pInstrInfo->name); |
286 |
|
printf(" midi_instrument_info.engine_name = %s\n", pInstrInfo->engine_name); |
287 |
|
printf(" midi_instrument_info.instrument_file = %s\n", pInstrInfo->instrument_file); |
288 |
|
printf(" midi_instrument_info.instrument_nr = %d\n", pInstrInfo->instrument_nr); |
289 |
|
printf(" midi_instrument_info.instrument_name = %s\n", pInstrInfo->instrument_name); |
290 |
|
printf(" midi_instrument_info.load_mode = "); client_test_load_mode(pInstrInfo->load_mode); |
291 |
|
printf(" midi_instrument_info.volume = %g\n", pInstrInfo->volume); |
292 |
|
printf(" }\n"); |
293 |
|
return 0; |
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
//////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////// |
298 |
|
|
299 |
static int g_test_step = 0; |
static int g_test_step = 0; |
304 |
void client_test_start ( clock_t *pclk ) { *pclk = clock(); } |
void client_test_start ( clock_t *pclk ) { *pclk = clock(); } |
305 |
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; } |
306 |
|
|
307 |
typedef int * isplit; |
typedef int * isplit; |
308 |
typedef char ** szsplit; |
typedef char ** szsplit; |
309 |
typedef lscp_status_t status; |
typedef lscp_status_t status; |
310 |
typedef lscp_driver_info_t * driver_info; |
typedef lscp_driver_info_t * driver_info; |
311 |
typedef lscp_device_info_t * device_info; |
typedef lscp_device_info_t * device_info; |
312 |
typedef lscp_device_port_info_t * device_port_info; |
typedef lscp_device_port_info_t * device_port_info; |
313 |
typedef lscp_param_info_t * param_info; |
typedef lscp_param_info_t * param_info; |
314 |
typedef lscp_engine_info_t * engine_info; |
typedef lscp_server_info_t * server_info; |
315 |
typedef lscp_channel_info_t * channel_info; |
typedef lscp_engine_info_t * engine_info; |
316 |
typedef lscp_buffer_fill_t * buffer_fill; |
typedef lscp_channel_info_t * channel_info; |
317 |
|
typedef lscp_buffer_fill_t * buffer_fill; |
318 |
|
typedef lscp_midi_instrument_info_t *midi_instrument_info; |
319 |
|
|
320 |
#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++; \ |
321 |
printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \ |
printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \ |
330 |
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 ) |
331 |
{ |
{ |
332 |
int iSamplerChannel; |
int iSamplerChannel; |
333 |
|
lscp_midi_instrument_t midi_instr; |
334 |
|
|
335 |
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); |
336 |
CLIENT_TEST(pClient, engine_info, lscp_get_engine_info(pClient, pszEngine)); |
CLIENT_TEST(pClient, engine_info, lscp_get_engine_info(pClient, pszEngine)); |
337 |
|
CLIENT_TEST(pClient, int, lscp_get_total_voice_count(pClient)); |
338 |
|
CLIENT_TEST(pClient, int, lscp_get_total_voice_count_max(pClient)); |
339 |
CLIENT_TEST(pClient, int, lscp_get_channels(pClient)); |
CLIENT_TEST(pClient, int, lscp_get_channels(pClient)); |
340 |
CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient)); |
CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient)); |
341 |
CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient)); |
CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient)); |
356 |
CLIENT_TEST(pClient, status, lscp_set_channel_midi_channel(pClient, iSamplerChannel, 0)); |
CLIENT_TEST(pClient, status, lscp_set_channel_midi_channel(pClient, iSamplerChannel, 0)); |
357 |
CLIENT_TEST(pClient, status, lscp_set_channel_midi_port(pClient, iSamplerChannel, 0)); |
CLIENT_TEST(pClient, status, lscp_set_channel_midi_port(pClient, iSamplerChannel, 0)); |
358 |
CLIENT_TEST(pClient, status, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5)); |
CLIENT_TEST(pClient, status, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5)); |
359 |
|
CLIENT_TEST(pClient, status, lscp_set_channel_mute(pClient, iSamplerChannel, 1)); |
360 |
|
CLIENT_TEST(pClient, status, lscp_set_channel_solo(pClient, iSamplerChannel, 1)); |
361 |
CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel)); |
CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel)); |
362 |
CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel)); |
CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel)); |
363 |
CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel)); |
CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel)); |
364 |
|
|
365 |
|
midi_instr.bank_msb = 0; |
366 |
|
midi_instr.bank_lsb = 0; |
367 |
|
midi_instr.program = 0; |
368 |
|
printf("\n--- midi_instr={%d,%d,%d} ---\n", midi_instr.bank_msb, midi_instr.bank_lsb, midi_instr.program); |
369 |
|
CLIENT_TEST(pClient, status, lscp_map_midi_instrument(pClient, &midi_instr, pszEngine, "DefaultInstrument.gig", 0, 1.0f, LSCP_LOAD_ON_DEMAND, "DummyName")); |
370 |
|
CLIENT_TEST(pClient, int, lscp_get_midi_instruments(pClient)); |
371 |
|
CLIENT_TEST(pClient, midi_instrument_info, lscp_get_midi_instrument_info(pClient, &midi_instr)); |
372 |
|
CLIENT_TEST(pClient, status, lscp_unmap_midi_instrument(pClient, &midi_instr)); |
373 |
|
CLIENT_TEST(pClient, status, lscp_clear_midi_instruments(pClient)); |
374 |
} |
} |
375 |
|
|
376 |
|
|
471 |
lscp_driver_info_t *pDriverInfo; |
lscp_driver_info_t *pDriverInfo; |
472 |
const char *pszParam; |
const char *pszParam; |
473 |
int i; |
int i; |
474 |
|
|
475 |
printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver); |
printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver); |
476 |
CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_audio_driver_info(pClient, pszAudioDriver)); |
CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_audio_driver_info(pClient, pszAudioDriver)); |
477 |
if (pDriverInfo && pDriverInfo->parameters) { |
if (pDriverInfo && pDriverInfo->parameters) { |
497 |
g_test_count = 0; |
g_test_count = 0; |
498 |
g_test_fails = 0; |
g_test_fails = 0; |
499 |
|
|
500 |
CLIENT_TEST(pClient, szsplit, ppszAudioDrivers = lscp_get_available_audio_drivers(pClient)); |
CLIENT_TEST(pClient, server_info, lscp_get_server_info(pClient)); |
501 |
|
|
502 |
|
CLIENT_TEST(pClient, int, lscp_get_available_audio_drivers(pClient)); |
503 |
|
CLIENT_TEST(pClient, szsplit, ppszAudioDrivers = lscp_list_available_audio_drivers(pClient)); |
504 |
if (ppszAudioDrivers == NULL) { |
if (ppszAudioDrivers == NULL) { |
505 |
fprintf(stderr, "client_test: No audio drivers available.\n"); |
fprintf(stderr, "client_test: No audio drivers available.\n"); |
506 |
return; |
return; |
507 |
} |
} |
508 |
|
|
509 |
CLIENT_TEST(pClient, szsplit, ppszMidiDrivers = lscp_get_available_midi_drivers(pClient)); |
CLIENT_TEST(pClient, int, lscp_get_available_midi_drivers(pClient)); |
510 |
|
CLIENT_TEST(pClient, szsplit, ppszMidiDrivers = lscp_list_available_midi_drivers(pClient)); |
511 |
if (ppszMidiDrivers == NULL) { |
if (ppszMidiDrivers == NULL) { |
512 |
fprintf(stderr, "client_test: No MIDI drivers available.\n"); |
fprintf(stderr, "client_test: No MIDI drivers available.\n"); |
513 |
return; |
return; |
514 |
} |
} |
515 |
|
|
516 |
CLIENT_TEST(pClient, szsplit, ppszEngines = lscp_get_available_engines(pClient)); |
CLIENT_TEST(pClient, int, lscp_get_available_engines(pClient)); |
517 |
|
CLIENT_TEST(pClient, szsplit, ppszEngines = lscp_list_available_engines(pClient)); |
518 |
if (ppszEngines == NULL) { |
if (ppszEngines == NULL) { |
519 |
fprintf(stderr, "client_test: No engines available.\n"); |
fprintf(stderr, "client_test: No engines available.\n"); |
520 |
return; |
return; |