/[svn]/liblscp/trunk/examples/example_client.c
ViewVC logotype

Annotation of /liblscp/trunk/examples/example_client.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1020 - (hide annotations) (download)
Thu Jan 11 15:25:04 2007 UTC (15 years, 7 months ago) by capela
File MIME type: text/plain
File size: 24407 byte(s)
* Audio routing representation changed to integer array.

1 capela 103 // example_client.c
2     //
3     /****************************************************************************
4 capela 921 liblscp - LinuxSampler Control Protocol API
5 capela 1019 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 103
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17 capela 921 You should have received a copy of the GNU General Public License along
18     with this program; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 capela 103
21     *****************************************************************************/
22    
23     #include "lscp/client.h"
24     #include "lscp/device.h"
25    
26     #include <time.h>
27    
28     #define SERVER_PORT 8888
29    
30     #if defined(WIN32)
31     static WSADATA _wsaData;
32     #endif
33    
34     ////////////////////////////////////////////////////////////////////////
35    
36 capela 147 lscp_status_t client_callback ( lscp_client_t *pClient, lscp_event_t event, const char *pchData, int cchData, void *pvData )
37 capela 103 {
38 capela 963 lscp_status_t ret = LSCP_FAILED;
39 capela 103
40 capela 963 char *pszData = (char *) malloc(cchData + 1);
41     if (pszData) {
42     memcpy(pszData, pchData, cchData);
43     pszData[cchData] = (char) 0;
44     printf("client_callback: event=%s (0x%04x) [%s]\n", lscp_event_to_text(event), (int) event, pszData);
45     free(pszData);
46     ret = LSCP_OK;
47     }
48 capela 103
49 capela 963 return ret;
50 capela 103 }
51    
52     ////////////////////////////////////////////////////////////////////////
53    
54 capela 188 int client_test_int ( int i )
55 capela 187 {
56 capela 963 printf("%d\n", i);
57     return (i >= 0 ? 0 : 1);
58 capela 187 }
59    
60 capela 189
61 capela 188 int client_test_status ( lscp_status_t s )
62 capela 187 {
63 capela 963 const char *pszStatus;
64 capela 188
65 capela 963 switch (s) {
66     case LSCP_OK: pszStatus = "OK"; break;
67     case LSCP_FAILED: pszStatus = "FAILED"; break;
68     case LSCP_ERROR: pszStatus = "ERROR"; break;
69     case LSCP_WARNING: pszStatus = "WARNING"; break;
70     case LSCP_TIMEOUT: pszStatus = "TIMEOUT"; break;
71     case LSCP_QUIT: pszStatus = "QUIT"; break;
72     default: pszStatus = "NONE"; break;
73     }
74     printf("%s\n", pszStatus);
75     return (s == LSCP_OK ? 0 : 1);
76 capela 187 }
77    
78    
79 capela 188 int client_test_isplit ( int *piSplit )
80 capela 187 {
81 capela 963 int i;
82 capela 187
83 capela 963 printf("{");
84     for (i = 0; piSplit && piSplit[i] >= 0; i++) {
85     if (i > 0)
86     printf(",");
87     printf(" %d", piSplit[i]);
88     }
89     printf(" }\n");
90     return 0;
91 capela 187 }
92    
93 capela 189
94 capela 188 int client_test_szsplit ( char **ppszSplit )
95 capela 187 {
96 capela 963 int i;
97 capela 187
98 capela 963 printf("{");
99     for (i = 0; ppszSplit && ppszSplit[i]; i++) {
100     if (i > 0)
101     printf(",");
102     printf(" %s", ppszSplit[i]);
103     }
104     printf(" }\n");
105     return 0;
106 capela 187 }
107    
108 capela 189
109 capela 188 int client_test_params ( lscp_param_t *pParams )
110 capela 187 {
111 capela 963 int i;
112 capela 187
113 capela 963 printf("{");
114     for (i = 0; pParams && pParams[i].key; i++) {
115     if (i > 0)
116     printf(",");
117     printf(" %s='%s'", pParams[i].key, pParams[i].value);
118     }
119     printf(" }\n");
120     return 0;
121 capela 187 }
122    
123 capela 189
124 capela 948 int client_test_midi_instruments ( lscp_midi_instrument_t *pInstrs )
125     {
126 capela 963 int i;
127 capela 948
128 capela 963 printf("{");
129 capela 975 for (i = 0; pInstrs && pInstrs[i].prog >= 0; i++) {
130 capela 963 if (i > 0)
131     printf(",");
132 capela 975 printf("{%d,%d,%d}", pInstrs[i].map, pInstrs[i].bank, pInstrs[i].prog);
133 capela 963 }
134     printf(" }\n");
135     return 0;
136 capela 948 }
137    
138    
139 capela 188 int client_test_param_info ( lscp_param_info_t *pParamInfo )
140 capela 187 {
141 capela 963 const char *pszType;
142 capela 564
143 capela 963 if (pParamInfo == NULL) {
144     printf("(nil)\n");
145     return 1;
146     }
147     switch (pParamInfo->type) {
148     case LSCP_TYPE_BOOL: pszType = "BOOL"; break;
149     case LSCP_TYPE_INT: pszType = "INT"; break;
150     case LSCP_TYPE_FLOAT: pszType = "FLOAT"; break;
151     case LSCP_TYPE_STRING: pszType = "STRING"; break;
152     default: pszType = "NONE"; break;
153     }
154     printf("{\n");
155     printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType);
156     printf(" param_info.description = %s\n", pParamInfo->description);
157     printf(" param_info.mandatory = %d\n", pParamInfo->mandatory);
158     printf(" param_info.fix = %d\n", pParamInfo->fix);
159     printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity);
160     printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends);
161     printf(" param_info.defaultv = %s\n", pParamInfo->defaultv);
162     printf(" param_info.range_min = %s\n", pParamInfo->range_min);
163     printf(" param_info.range_max = %s\n", pParamInfo->range_max);
164     printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities);
165     printf(" }\n");
166     return 0;
167 capela 187 }
168    
169 capela 189
170 capela 188 int client_test_driver_info ( lscp_driver_info_t *pDriverInfo )
171 capela 187 {
172 capela 963 if (pDriverInfo == NULL) {
173     printf("(nil)\n");
174     return 1;
175     }
176     printf("{\n");
177     printf(" driver_info.description = %s\n", pDriverInfo->description);
178     printf(" driver_info.version = %s\n", pDriverInfo->version);
179     printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters);
180     printf(" }\n");
181     return 0;
182 capela 187 }
183    
184 capela 189
185 capela 188 int client_test_device_info ( lscp_device_info_t *pDeviceInfo )
186 capela 187 {
187 capela 963 if (pDeviceInfo == NULL) {
188     printf("(nil)\n");
189     return 1;
190     }
191     printf("{\n");
192     printf(" device_info.driver = %s\n", pDeviceInfo->driver);
193     printf(" device_info.params = "); client_test_params(pDeviceInfo->params);
194     printf(" }\n");
195     return 0;
196 capela 187 }
197    
198 capela 189
199 capela 188 int client_test_device_port_info ( lscp_device_port_info_t *pDevicePortInfo )
200 capela 187 {
201 capela 963 if (pDevicePortInfo == NULL) {
202     printf("(nil)\n");
203     return 1;
204     }
205     printf("{\n");
206     printf(" device_port_info.name = %s\n", pDevicePortInfo->name);
207     printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params);
208     printf(" }\n");
209     return 0;
210 capela 187 }
211    
212 capela 189
213 capela 564 int client_test_server_info ( lscp_server_info_t *pServerInfo )
214     {
215 capela 963 if (pServerInfo == NULL) {
216     printf("(nil)\n");
217     return 1;
218     }
219     printf("{\n");
220 capela 977 printf(" server_info.description = %s\n", pServerInfo->description);
221     printf(" server_info.version = %s\n", pServerInfo->version);
222     printf(" server_info.protocol_version = %s\n", pServerInfo->protocol_version);
223 capela 963 printf(" }\n");
224     return 0;
225 capela 564 }
226    
227    
228 capela 188 int client_test_engine_info ( lscp_engine_info_t *pEngineInfo )
229 capela 187 {
230 capela 963 if (pEngineInfo == NULL) {
231     printf("(nil)\n");
232     return 1;
233     }
234     printf("{\n");
235     printf(" engine_info.description = %s\n", pEngineInfo->description);
236     printf(" engine_info.version = %s\n", pEngineInfo->version);
237     printf(" }\n");
238     return 0;
239 capela 187 }
240    
241 capela 189
242 capela 188 int client_test_channel_info ( lscp_channel_info_t *pChannelInfo )
243 capela 187 {
244 capela 963 if (pChannelInfo == NULL) {
245     printf("(nil)\n");
246     return 1;
247     }
248     printf("{\n");
249     printf(" channel_info.engine_name = %s\n", pChannelInfo->engine_name);
250     printf(" channel_info.audio_device = %d\n", pChannelInfo->audio_device);
251     printf(" channel_info.audio_channels = %d\n", pChannelInfo->audio_channels);
252 capela 1020 printf(" channel_info.audio_routing = "); client_test_isplit(pChannelInfo->audio_routing);
253 capela 963 printf(" channel_info.instrument_file = %s\n", pChannelInfo->instrument_file);
254     printf(" channel_info.instrument_nr = %d\n", pChannelInfo->instrument_nr);
255     printf(" channel_info.instrument_name = %s\n", pChannelInfo->instrument_name);
256     printf(" channel_info.instrument_status = %d\n", pChannelInfo->instrument_status);
257     printf(" channel_info.midi_device = %d\n", pChannelInfo->midi_device);
258     printf(" channel_info.midi_port = %d\n", pChannelInfo->midi_port);
259     printf(" channel_info.midi_channel = %d\n", pChannelInfo->midi_channel);
260 capela 983 printf(" channel_info.midi_map = %d\n", pChannelInfo->midi_map);
261 capela 963 printf(" channel_info.volume = %g\n", pChannelInfo->volume);
262     printf(" channel_info.mute = %d\n", pChannelInfo->mute);
263     printf(" channel_info.solo = %d\n", pChannelInfo->solo);
264     printf(" }\n");
265     return 0;
266 capela 187 }
267    
268 capela 189
269 capela 1020 int client_test_fxsend_info ( lscp_fxsend_info_t *pFxSendInfo )
270     {
271     if (pFxSendInfo == NULL) {
272     printf("(nil)\n");
273     return 1;
274     }
275     printf("{\n");
276     printf(" fxsend_info.engine_name = %s\n", pFxSendInfo->name);
277     printf(" fxsend_info.midi_controller = %d\n", pFxSendInfo->midi_controller);
278     printf(" fxsend_info.audio_routing = "); client_test_isplit(pFxSendInfo->audio_routing);
279     printf(" }\n");
280     return 0;
281     }
282    
283    
284 capela 188 int client_test_buffer_fill ( lscp_buffer_fill_t *pBufferFill )
285 capela 187 {
286 capela 963 if (pBufferFill == NULL) {
287     printf("(nil)\n");
288     return 1;
289     }
290     printf("{ <%p> }\n", pBufferFill);
291     return 0;
292 capela 187 }
293    
294 capela 189
295 capela 946 int client_test_load_mode ( lscp_load_mode_t load_mode )
296     {
297     const char *pszLoadMode;
298    
299 capela 963 switch (load_mode) {
300     case LSCP_LOAD_ON_DEMAND: pszLoadMode = "ON_DEMAND"; break;
301     case LSCP_LOAD_ON_DEMAND_HOLD: pszLoadMode = "ON_DEMAND_HOLD"; break;
302     case LSCP_LOAD_PERSISTENT: pszLoadMode = "PERSISTENT"; break;
303     default: pszLoadMode = "DEFAULT"; break;
304     }
305     printf("%s\n", pszLoadMode);
306     return 0;
307 capela 946 }
308    
309    
310     int client_test_midi_instrument_info ( lscp_midi_instrument_info_t *pInstrInfo )
311     {
312 capela 963 if (pInstrInfo == NULL) {
313     printf("(nil)\n");
314     return 1;
315     }
316     printf("{\n");
317     printf(" midi_instrument_info.name = %s\n", pInstrInfo->name);
318     printf(" midi_instrument_info.engine_name = %s\n", pInstrInfo->engine_name);
319     printf(" midi_instrument_info.instrument_file = %s\n", pInstrInfo->instrument_file);
320     printf(" midi_instrument_info.instrument_nr = %d\n", pInstrInfo->instrument_nr);
321     printf(" midi_instrument_info.instrument_name = %s\n", pInstrInfo->instrument_name);
322     printf(" midi_instrument_info.load_mode = "); client_test_load_mode(pInstrInfo->load_mode);
323     printf(" midi_instrument_info.volume = %g\n", pInstrInfo->volume);
324     printf(" }\n");
325     return 0;
326 capela 946 }
327    
328    
329 capela 187 ////////////////////////////////////////////////////////////////////////
330    
331 capela 188 static int g_test_step = 0;
332     static int g_test_count = 0;
333     static int g_test_fails = 0;
334 capela 187
335 capela 188
336 capela 103 void client_test_start ( clock_t *pclk ) { *pclk = clock(); }
337     float client_test_elapsed ( clock_t *pclk ) { return (float) ((long) clock() - *pclk) / (float) CLOCKS_PER_SEC; }
338    
339 capela 946 typedef int * isplit;
340     typedef char ** szsplit;
341     typedef lscp_status_t status;
342     typedef lscp_driver_info_t * driver_info;
343     typedef lscp_device_info_t * device_info;
344     typedef lscp_device_port_info_t * device_port_info;
345     typedef lscp_param_info_t * param_info;
346     typedef lscp_server_info_t * server_info;
347     typedef lscp_engine_info_t * engine_info;
348     typedef lscp_channel_info_t * channel_info;
349     typedef lscp_buffer_fill_t * buffer_fill;
350 capela 948 typedef lscp_midi_instrument_t * midi_instruments;
351 capela 946 typedef lscp_midi_instrument_info_t *midi_instrument_info;
352 capela 103
353 capela 188 #define CLIENT_TEST(p, t, x) { clock_t c; void *v; g_test_count++; \
354 capela 963 printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \
355     printf(" elapsed=%gs errno=%d result='%s...' ret=", \
356     client_test_elapsed(&c), \
357     lscp_client_get_errno(p), \
358     lscp_client_get_result(p)); \
359     if (client_test_##t((t)(v))) { g_test_fails++; getchar(); } \
360     else if (g_test_step) getchar(); }
361 capela 187
362    
363 capela 189 void client_test_engine ( lscp_client_t *pClient, const char *pszEngine, const char *pszAudioDriver, int iAudioDevice, const char *pszMidiDriver, int iMidiDevice )
364 capela 103 {
365 capela 963 int iSamplerChannel;
366 capela 946 lscp_midi_instrument_t midi_instr;
367 capela 948 int i, j, k;
368 capela 564
369 capela 963 printf("\n--- pszEngine=\"%s\" pszAudioDevice=\"%s\" iAudioDevice=%d pszMidiDevice=\"%s\" iMidiDevice=%d ---\n", pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice);
370     CLIENT_TEST(pClient, engine_info, lscp_get_engine_info(pClient, pszEngine));
371     CLIENT_TEST(pClient, int, lscp_get_total_voice_count(pClient));
372     CLIENT_TEST(pClient, int, lscp_get_total_voice_count_max(pClient));
373     CLIENT_TEST(pClient, int, lscp_get_channels(pClient));
374     CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient));
375     CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient));
376     printf("\n--- iSamplerChannel=%d ---\n", iSamplerChannel);
377     CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
378     CLIENT_TEST(pClient, status, lscp_load_engine(pClient, pszEngine, iSamplerChannel));
379     CLIENT_TEST(pClient, status, lscp_load_instrument(pClient, "DefaultInstrument.gig", 0, iSamplerChannel));
380     CLIENT_TEST(pClient, int, lscp_get_channel_voice_count(pClient, iSamplerChannel));
381     CLIENT_TEST(pClient, int, lscp_get_channel_stream_count(pClient, iSamplerChannel));
382     CLIENT_TEST(pClient, int, lscp_get_channel_stream_usage(pClient, iSamplerChannel));
383     CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_BYTES, iSamplerChannel));
384     CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_PERCENTAGE, iSamplerChannel));
385     CLIENT_TEST(pClient, status, lscp_set_channel_audio_type(pClient, iSamplerChannel, pszAudioDriver));
386     CLIENT_TEST(pClient, status, lscp_set_channel_audio_device(pClient, iSamplerChannel, 0));
387     CLIENT_TEST(pClient, status, lscp_set_channel_audio_channel(pClient, iSamplerChannel, 0, 1));
388     CLIENT_TEST(pClient, status, lscp_set_channel_midi_type(pClient, iSamplerChannel, pszMidiDriver));
389     CLIENT_TEST(pClient, status, lscp_set_channel_midi_device(pClient, iSamplerChannel, 0));
390     CLIENT_TEST(pClient, status, lscp_set_channel_midi_channel(pClient, iSamplerChannel, 0));
391     CLIENT_TEST(pClient, status, lscp_set_channel_midi_port(pClient, iSamplerChannel, 0));
392     CLIENT_TEST(pClient, status, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5));
393     CLIENT_TEST(pClient, status, lscp_set_channel_mute(pClient, iSamplerChannel, 1));
394     CLIENT_TEST(pClient, status, lscp_set_channel_solo(pClient, iSamplerChannel, 1));
395     CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
396     CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel));
397     CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel));
398 capela 946
399 capela 963 for (i = 0; i < 2; i++) {
400 capela 983 CLIENT_TEST(pClient, int, lscp_add_midi_instrument_map(pClient, NULL));
401 capela 963 for (j = 0; j < 4; j++) {
402     for (k = 0; k < 8; k++) {
403 capela 975 midi_instr.map = i;
404     midi_instr.bank = j;
405     midi_instr.prog = k;
406 capela 963 CLIENT_TEST(pClient, status, lscp_map_midi_instrument(pClient, &midi_instr, pszEngine, "DefaultInstrument.gig", 0, 1.0f, LSCP_LOAD_ON_DEMAND, "DummyName"));
407     }
408     }
409 capela 983 CLIENT_TEST(pClient, status, lscp_set_midi_instrument_map_name(pClient, i, "DummyMapName"));
410 capela 963 }
411 capela 948
412 capela 975 CLIENT_TEST(pClient, int, lscp_get_midi_instruments(pClient, LSCP_MIDI_MAP_ALL));
413     CLIENT_TEST(pClient, midi_instruments, lscp_list_midi_instruments(pClient, LSCP_MIDI_MAP_ALL));
414 capela 948
415 capela 963 for (i = 0; i < 2; i++) {
416     for (j = 0; j < 4; j++) {
417     for (k = 0; k < 8; k++) {
418 capela 975 midi_instr.map = i;
419     midi_instr.bank = j;
420     midi_instr.prog = k;
421 capela 963 CLIENT_TEST(pClient, midi_instrument_info, lscp_get_midi_instrument_info(pClient, &midi_instr));
422     CLIENT_TEST(pClient, status, lscp_unmap_midi_instrument(pClient, &midi_instr));
423     }
424     }
425 capela 983 CLIENT_TEST(pClient, int, lscp_remove_midi_instrument_map(pClient, i));
426 capela 963 }
427    
428 capela 975 CLIENT_TEST(pClient, status, lscp_clear_midi_instruments(pClient, LSCP_MIDI_MAP_ALL));
429 capela 189 }
430    
431    
432     void client_test_midi_port ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
433     {
434 capela 963 lscp_device_port_info_t *pMidiPortInfo;
435     const char *pszParam;
436     int i;
437 capela 189
438 capela 963 printf("\n--- iMidiDevice=%d iMidiPort=%d ---\n", iMidiDevice, iMidiPort);
439     CLIENT_TEST(pClient, device_port_info, pMidiPortInfo = lscp_get_midi_port_info(pClient, iMidiDevice, iMidiPort));
440     if (pMidiPortInfo && pMidiPortInfo->params) {
441     for (i = 0; pMidiPortInfo->params[i].key; i++) {
442     pszParam = pMidiPortInfo->params[i].key;
443     printf("\n--- iMidiDevice=%d iMidiPort=%d pszParam=\"%s\" ---\n", iMidiDevice, iMidiPort, pszParam);
444     CLIENT_TEST(pClient, param_info, lscp_get_midi_port_param_info(pClient, iMidiDevice, iMidiPort, pszParam));
445     }
446     }
447 capela 189 }
448    
449    
450     void client_test_audio_channel ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
451     {
452 capela 963 lscp_device_port_info_t *pAudioChannelInfo;
453     const char *pszParam;
454     int i;
455 capela 189
456 capela 963 printf("\n--- iAudioDevice=%d iAudioChannel=%d ---\n", iAudioDevice, iAudioChannel);
457     CLIENT_TEST(pClient, device_port_info, pAudioChannelInfo = lscp_get_audio_channel_info(pClient, iAudioDevice, iAudioChannel));
458     if (pAudioChannelInfo && pAudioChannelInfo->params) {
459     for (i = 0; pAudioChannelInfo->params[i].key; i++) {
460     pszParam = pAudioChannelInfo->params[i].key;
461     printf("\n--- iAudioDevice=%d iAudioChannel=%d pszParam=\"%s\" ---\n", iAudioDevice, iAudioChannel, pszParam);
462     CLIENT_TEST(pClient, param_info, lscp_get_audio_channel_param_info(pClient, iAudioDevice, iAudioChannel, pszParam));
463     }
464     }
465 capela 189 }
466    
467    
468     void client_test_midi_device ( lscp_client_t *pClient, int iMidiDevice )
469     {
470 capela 963 lscp_device_info_t *pDeviceInfo;
471     const char *pszValue;
472     int iMidiPort, iMidiPorts;
473 capela 189
474 capela 963 printf("\n--- iMidiDevice=%d ---\n", iMidiDevice);
475     CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_midi_device_info(pClient, iMidiDevice));
476     if (pDeviceInfo && pDeviceInfo->params) {
477     pszValue = lscp_get_param_value(pDeviceInfo->params, "ports");
478     if (pszValue) {
479     iMidiPorts = atoi(pszValue);
480     for (iMidiPort = 0; iMidiPort < iMidiPorts; iMidiPort++)
481     client_test_midi_port(pClient, iMidiDevice, iMidiPort);
482     }
483     }
484 capela 189 }
485    
486    
487     void client_test_audio_device ( lscp_client_t *pClient, int iAudioDevice )
488     {
489 capela 963 lscp_device_info_t *pDeviceInfo;
490     const char *pszValue;
491     int iAudioChannel, iAudioChannels;
492 capela 189
493 capela 963 printf("\n--- iAudioDevice=%d ---\n", iAudioDevice);
494     CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_audio_device_info(pClient, iAudioDevice));
495     if (pDeviceInfo && pDeviceInfo->params) {
496     pszValue = lscp_get_param_value(pDeviceInfo->params, "channels");
497     if (pszValue) {
498     iAudioChannels = atoi(pszValue);
499     for (iAudioChannel = 0; iAudioChannel < iAudioChannels; iAudioChannel++)
500     client_test_audio_channel(pClient, iAudioDevice, iAudioChannel);
501     }
502     }
503 capela 189 }
504    
505    
506     void client_test_midi_driver ( lscp_client_t *pClient, const char *pszMidiDriver )
507     {
508 capela 963 lscp_driver_info_t *pDriverInfo;
509     const char *pszParam;
510     int i;
511 capela 189
512 capela 963 printf("\n--- pszMidiDriver=\"%s\" ---\n", pszMidiDriver);
513     CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_midi_driver_info(pClient, pszMidiDriver));
514     if (pDriverInfo && pDriverInfo->parameters) {
515     for (i = 0; pDriverInfo->parameters[i]; i++) {
516     pszParam = pDriverInfo->parameters[i];
517     printf("\n--- pszMidiDriver=\"%s\" pszParam=\"%s\" ---\n", pszMidiDriver, pszParam);
518     CLIENT_TEST(pClient, param_info, lscp_get_midi_driver_param_info(pClient, pszMidiDriver, pszParam, NULL));
519     }
520     }
521 capela 189 }
522    
523    
524     void client_test_audio_driver ( lscp_client_t *pClient, const char *pszAudioDriver )
525     {
526 capela 963 lscp_driver_info_t *pDriverInfo;
527     const char *pszParam;
528     int i;
529 capela 564
530 capela 963 printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver);
531     CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_audio_driver_info(pClient, pszAudioDriver));
532     if (pDriverInfo && pDriverInfo->parameters) {
533     for (i = 0; pDriverInfo->parameters[i]; i++) {
534     pszParam = pDriverInfo->parameters[i];
535     printf("\n--- pszAudioDriver=\"%s\" pszParam=\"%s\" ---\n", pszAudioDriver, pszParam);
536     CLIENT_TEST(pClient, param_info, lscp_get_audio_driver_param_info(pClient, pszAudioDriver, pszParam, NULL));
537     }
538     }
539 capela 189 }
540    
541    
542 capela 213 void client_test_all ( lscp_client_t *pClient, int step )
543 capela 189 {
544 capela 963 const char **ppszAudioDrivers, **ppszMidiDrivers, **ppszEngines;
545     const char *pszAudioDriver, *pszMidiDriver, *pszEngine;
546     int iAudioDriver, iMidiDriver, iEngine;
547     int iAudio, iAudioDevice, iMidi, iMidiDevice;
548     int iNewAudioDevice, iNewMidiDevice;
549     int *piAudioDevices, *piMidiDevices;
550 capela 103
551 capela 963 g_test_step = step;
552     g_test_count = 0;
553     g_test_fails = 0;
554 capela 188
555 capela 963 CLIENT_TEST(pClient, server_info, lscp_get_server_info(pClient));
556 capela 564
557 capela 963 CLIENT_TEST(pClient, int, lscp_get_available_audio_drivers(pClient));
558     CLIENT_TEST(pClient, szsplit, ppszAudioDrivers = lscp_list_available_audio_drivers(pClient));
559     if (ppszAudioDrivers == NULL) {
560     fprintf(stderr, "client_test: No audio drivers available.\n");
561     return;
562     }
563 capela 103
564 capela 963 CLIENT_TEST(pClient, int, lscp_get_available_midi_drivers(pClient));
565     CLIENT_TEST(pClient, szsplit, ppszMidiDrivers = lscp_list_available_midi_drivers(pClient));
566     if (ppszMidiDrivers == NULL) {
567     fprintf(stderr, "client_test: No MIDI drivers available.\n");
568     return;
569     }
570 capela 103
571 capela 963 CLIENT_TEST(pClient, int, lscp_get_available_engines(pClient));
572     CLIENT_TEST(pClient, szsplit, ppszEngines = lscp_list_available_engines(pClient));
573     if (ppszEngines == NULL) {
574     fprintf(stderr, "client_test: No engines available.\n");
575     return;
576     }
577 capela 103
578 capela 963 for (iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) {
579     pszAudioDriver = ppszAudioDrivers[iAudioDriver];
580     client_test_audio_driver(pClient, pszAudioDriver);
581     CLIENT_TEST(pClient, int, iNewAudioDevice = lscp_create_audio_device(pClient, pszAudioDriver, NULL));
582     CLIENT_TEST(pClient, int, lscp_get_audio_devices(pClient));
583     CLIENT_TEST(pClient, isplit, piAudioDevices = lscp_list_audio_devices(pClient));
584     for (iAudio = 0; piAudioDevices && piAudioDevices[iAudio] >= 0; iAudio++) {
585     iAudioDevice = piAudioDevices[iAudio];
586     client_test_audio_device(pClient, iAudioDevice);
587     for (iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) {
588     pszMidiDriver = ppszMidiDrivers[iMidiDriver];
589     client_test_midi_driver(pClient, pszMidiDriver);
590     CLIENT_TEST(pClient, int, iNewMidiDevice = lscp_create_midi_device(pClient, pszMidiDriver, NULL));
591     CLIENT_TEST(pClient, int, lscp_get_midi_devices(pClient));
592     CLIENT_TEST(pClient, isplit, piMidiDevices = lscp_list_midi_devices(pClient));
593     for (iMidi = 0; piMidiDevices && piMidiDevices[iMidi] >= 0; iMidi++) {
594     iMidiDevice = piMidiDevices[iMidi];
595     client_test_midi_device(pClient, iMidiDevice);
596     for (iEngine = 0; ppszEngines[iEngine]; iEngine++) {
597     pszEngine = ppszEngines[iEngine];
598     client_test_engine(pClient, pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice);
599     }
600     }
601     CLIENT_TEST(pClient, status, lscp_destroy_midi_device(pClient, iNewMidiDevice));
602     }
603     }
604     CLIENT_TEST(pClient, status, lscp_destroy_audio_device(pClient, iNewAudioDevice));
605     }
606 capela 213
607 capela 1019 CLIENT_TEST(pClient, status, lscp_set_volume(pClient, 0.123f));
608     CLIENT_TEST(pClient, int, (int) (100.0f * lscp_get_volume(pClient)));
609    
610 capela 963 CLIENT_TEST(pClient, status, lscp_reset_sampler(pClient));
611    
612     printf("\n\n");
613     printf(" Total: %d tests, %d failed.\n\n", g_test_count, g_test_fails);
614 capela 103 }
615    
616 capela 189
617 capela 103 ////////////////////////////////////////////////////////////////////////
618    
619     void client_usage (void)
620     {
621 capela 963 printf("\n %s %s (Build: %s)\n", lscp_client_package(), lscp_client_version(), lscp_client_build());
622 capela 103
623 capela 963 fputs("\n Available commands: help, test[step], exit, quit, subscribe, unsubscribe", stdout);
624     fputs("\n (all else are sent verbatim to server)\n\n", stdout);
625 capela 103
626     }
627    
628     void client_prompt (void)
629     {
630 capela 963 fputs("lscp_client> ", stdout);
631 capela 103 }
632    
633     int main (int argc, char *argv[] )
634     {
635 capela 963 lscp_client_t *pClient;
636     char *pszHost = "localhost";
637     char szLine[1024];
638     int cchLine;
639     lscp_status_t ret;
640 capela 103
641     #if defined(WIN32)
642 capela 963 if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) {
643     fprintf(stderr, "lscp_client: WSAStartup failed.\n");
644     return -1;
645     }
646 capela 103 #endif
647    
648 capela 963 if (argc > 1)
649     pszHost = argv[1];
650 capela 103
651 capela 963 pClient = lscp_client_create(pszHost, SERVER_PORT, client_callback, NULL);
652     if (pClient == NULL)
653     return -1;
654 capela 103
655 capela 963 client_usage();
656     client_prompt();
657 capela 103
658 capela 963 while (fgets(szLine, sizeof(szLine) - 3, stdin)) {
659 capela 103
660 capela 963 cchLine = strlen(szLine);
661     while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r'))
662     cchLine--;
663     szLine[cchLine] = '\0';
664 capela 103
665 capela 963 if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0)
666     break;
667     else
668     if (strcmp(szLine, "subscribe") == 0)
669     lscp_client_subscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
670     else
671     if (strcmp(szLine, "unsubscribe") == 0)
672     lscp_client_unsubscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
673     else
674     if (strcmp(szLine, "test") == 0)
675     client_test_all(pClient, 0);
676     else
677     if (strcmp(szLine, "teststep") == 0 || strcmp(szLine, "test step") == 0)
678     client_test_all(pClient, 1);
679     else
680     if (cchLine > 0 && strcmp(szLine, "help") != 0) {
681     szLine[cchLine++] = '\r';
682     szLine[cchLine++] = '\n';
683     szLine[cchLine] = '\0';
684     ret = lscp_client_query(pClient, szLine);
685     printf("%s\n(errno = %d)\n", lscp_client_get_result(pClient), lscp_client_get_errno(pClient));
686     if (ret == LSCP_QUIT)
687     break;
688     }
689     else client_usage();
690 capela 103
691 capela 963 client_prompt();
692     }
693 capela 103
694 capela 963 lscp_client_destroy(pClient);
695 capela 103
696     #if defined(WIN32)
697 capela 963 WSACleanup();
698 capela 103 #endif
699    
700 capela 963 return 0;
701 capela 103 }
702    
703     // end of example_client.c

  ViewVC Help
Powered by ViewVC