/[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 946 - (hide annotations) (download)
Mon Nov 27 18:33:02 2006 UTC (13 years, 6 months ago) by capela
File MIME type: text/plain
File size: 24639 byte(s)
* As of the LSCP 1.2 working draft document, added
  some missing client interface functions:
    lscp_get_total_voice_count();
    lscp_get_total_voice_count_max();
  and for the new MIDI instrument mapping features:
    lscp_map_midi_instrument();
    lscp_unmap_midi_instrument();
    lscp_get_midi_instruments();
    lscp_get_midi_instrument_info();
    lscp_clear_midi_instruments();

1 capela 103 // example_client.c
2     //
3     /****************************************************************************
4 capela 921 liblscp - LinuxSampler Control Protocol API
5 capela 869 Copyright (C) 2004-2006, 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 147 lscp_status_t ret = LSCP_FAILED;
39 capela 103
40 capela 147 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 capela 103 }
48    
49     return ret;
50     }
51    
52     ////////////////////////////////////////////////////////////////////////
53    
54 capela 188 int client_test_int ( int i )
55 capela 187 {
56     printf("%d\n", i);
57 capela 188 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     const char *pszStatus;
64 capela 188
65 capela 187 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 capela 188 return (s == LSCP_OK ? 0 : 1);
76 capela 187 }
77    
78    
79 capela 188 int client_test_isplit ( int *piSplit )
80 capela 187 {
81     int i;
82    
83     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 capela 188 return 0;
91 capela 187 }
92    
93 capela 189
94 capela 188 int client_test_szsplit ( char **ppszSplit )
95 capela 187 {
96     int i;
97    
98     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 capela 188 return 0;
106 capela 187 }
107    
108 capela 189
109 capela 188 int client_test_params ( lscp_param_t *pParams )
110 capela 187 {
111     int i;
112    
113     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 capela 188 return 0;
121 capela 187 }
122    
123 capela 189
124 capela 188 int client_test_param_info ( lscp_param_info_t *pParamInfo )
125 capela 187 {
126     const char *pszType;
127 capela 564
128 capela 187 if (pParamInfo == NULL) {
129     printf("(nil)\n");
130 capela 188 return 1;
131 capela 187 }
132     switch (pParamInfo->type) {
133     case LSCP_TYPE_BOOL: pszType = "BOOL"; break;
134     case LSCP_TYPE_INT: pszType = "INT"; break;
135     case LSCP_TYPE_FLOAT: pszType = "FLOAT"; break;
136     case LSCP_TYPE_STRING: pszType = "STRING"; break;
137     default: pszType = "NONE"; break;
138     }
139     printf("{\n");
140 capela 946 printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType);
141     printf(" param_info.description = %s\n", pParamInfo->description);
142     printf(" param_info.mandatory = %d\n", pParamInfo->mandatory);
143     printf(" param_info.fix = %d\n", pParamInfo->fix);
144     printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity);
145     printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends);
146     printf(" param_info.defaultv = %s\n", pParamInfo->defaultv);
147     printf(" param_info.range_min = %s\n", pParamInfo->range_min);
148     printf(" param_info.range_max = %s\n", pParamInfo->range_max);
149     printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities);
150 capela 187 printf(" }\n");
151 capela 188 return 0;
152 capela 187 }
153    
154 capela 189
155 capela 188 int client_test_driver_info ( lscp_driver_info_t *pDriverInfo )
156 capela 187 {
157     if (pDriverInfo == NULL) {
158     printf("(nil)\n");
159 capela 188 return 1;
160 capela 187 }
161     printf("{\n");
162 capela 946 printf(" driver_info.description = %s\n", pDriverInfo->description);
163     printf(" driver_info.version = %s\n", pDriverInfo->version);
164     printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters);
165 capela 187 printf(" }\n");
166 capela 188 return 0;
167 capela 187 }
168    
169 capela 189
170 capela 188 int client_test_device_info ( lscp_device_info_t *pDeviceInfo )
171 capela 187 {
172     if (pDeviceInfo == NULL) {
173     printf("(nil)\n");
174 capela 188 return 1;
175 capela 187 }
176     printf("{\n");
177 capela 946 printf(" device_info.driver = %s\n", pDeviceInfo->driver);
178     printf(" device_info.params = "); client_test_params(pDeviceInfo->params);
179 capela 187 printf(" }\n");
180 capela 188 return 0;
181 capela 187 }
182    
183 capela 189
184 capela 188 int client_test_device_port_info ( lscp_device_port_info_t *pDevicePortInfo )
185 capela 187 {
186     if (pDevicePortInfo == NULL) {
187     printf("(nil)\n");
188 capela 188 return 1;
189 capela 187 }
190     printf("{\n");
191 capela 946 printf(" device_port_info.name = %s\n", pDevicePortInfo->name);
192     printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params);
193 capela 187 printf(" }\n");
194 capela 188 return 0;
195 capela 187 }
196    
197 capela 189
198 capela 564 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 capela 946 printf(" server_info.description = %s\n", pServerInfo->description);
206     printf(" server_info.version = %s\n", pServerInfo->version);
207 capela 564 printf(" }\n");
208     return 0;
209     }
210    
211    
212 capela 188 int client_test_engine_info ( lscp_engine_info_t *pEngineInfo )
213 capela 187 {
214     if (pEngineInfo == NULL) {
215     printf("(nil)\n");
216 capela 188 return 1;
217 capela 187 }
218     printf("{\n");
219 capela 946 printf(" engine_info.description = %s\n", pEngineInfo->description);
220     printf(" engine_info.version = %s\n", pEngineInfo->version);
221 capela 187 printf(" }\n");
222 capela 188 return 0;
223 capela 187 }
224    
225 capela 189
226 capela 188 int client_test_channel_info ( lscp_channel_info_t *pChannelInfo )
227 capela 187 {
228     if (pChannelInfo == NULL) {
229     printf("(nil)\n");
230 capela 188 return 1;
231 capela 187 }
232     printf("{\n");
233     printf(" channel_info.engine_name = %s\n", pChannelInfo->engine_name);
234     printf(" channel_info.audio_device = %d\n", pChannelInfo->audio_device);
235     printf(" channel_info.audio_channels = %d\n", pChannelInfo->audio_channels);
236     printf(" channel_info.audio_routing = "); client_test_szsplit(pChannelInfo->audio_routing);
237     printf(" channel_info.instrument_file = %s\n", pChannelInfo->instrument_file);
238     printf(" channel_info.instrument_nr = %d\n", pChannelInfo->instrument_nr);
239 capela 380 printf(" channel_info.instrument_name = %s\n", pChannelInfo->instrument_name);
240 capela 187 printf(" channel_info.instrument_status = %d\n", pChannelInfo->instrument_status);
241     printf(" channel_info.midi_device = %d\n", pChannelInfo->midi_device);
242     printf(" channel_info.midi_port = %d\n", pChannelInfo->midi_port);
243     printf(" channel_info.midi_channel = %d\n", pChannelInfo->midi_channel);
244     printf(" channel_info.volume = %g\n", pChannelInfo->volume);
245 capela 735 printf(" channel_info.mute = %d\n", pChannelInfo->mute);
246     printf(" channel_info.solo = %d\n", pChannelInfo->solo);
247 capela 187 printf(" }\n");
248 capela 188 return 0;
249 capela 187 }
250    
251 capela 189
252 capela 188 int client_test_buffer_fill ( lscp_buffer_fill_t *pBufferFill )
253 capela 187 {
254 capela 188 if (pBufferFill == NULL) {
255     printf("(nil)\n");
256     return 1;
257     }
258 capela 187 printf("{ <%p> }\n", pBufferFill);
259 capela 188 return 0;
260 capela 187 }
261    
262 capela 189
263 capela 946 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 capela 187 ////////////////////////////////////////////////////////////////////////
298    
299 capela 188 static int g_test_step = 0;
300     static int g_test_count = 0;
301     static int g_test_fails = 0;
302 capela 187
303 capela 188
304 capela 103 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; }
306    
307 capela 946 typedef int * isplit;
308     typedef char ** szsplit;
309     typedef lscp_status_t status;
310     typedef lscp_driver_info_t * driver_info;
311     typedef lscp_device_info_t * device_info;
312     typedef lscp_device_port_info_t * device_port_info;
313     typedef lscp_param_info_t * param_info;
314     typedef lscp_server_info_t * server_info;
315     typedef lscp_engine_info_t * engine_info;
316     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 capela 103
320 capela 188 #define CLIENT_TEST(p, t, x) { clock_t c; void *v; g_test_count++; \
321 capela 187 printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \
322     printf(" elapsed=%gs errno=%d result='%s...' ret=", \
323     client_test_elapsed(&c), \
324     lscp_client_get_errno(p), \
325     lscp_client_get_result(p)); \
326 capela 188 if (client_test_##t((t)(v))) { g_test_fails++; getchar(); } \
327     else if (g_test_step) getchar(); }
328 capela 187
329    
330 capela 189 void client_test_engine ( lscp_client_t *pClient, const char *pszEngine, const char *pszAudioDriver, int iAudioDevice, const char *pszMidiDriver, int iMidiDevice )
331 capela 103 {
332 capela 189 int iSamplerChannel;
333 capela 946 lscp_midi_instrument_t midi_instr;
334 capela 564
335 capela 189 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));
337 capela 946 CLIENT_TEST(pClient, int, lscp_get_total_voice_count(pClient));
338     CLIENT_TEST(pClient, int, lscp_get_total_voice_count_max(pClient));
339 capela 189 CLIENT_TEST(pClient, int, lscp_get_channels(pClient));
340     CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient));
341     CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient));
342     printf("\n--- iSamplerChannel=%d ---\n", iSamplerChannel);
343     CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
344     CLIENT_TEST(pClient, status, lscp_load_engine(pClient, pszEngine, iSamplerChannel));
345     CLIENT_TEST(pClient, status, lscp_load_instrument(pClient, "DefaultInstrument.gig", 0, iSamplerChannel));
346     CLIENT_TEST(pClient, int, lscp_get_channel_voice_count(pClient, iSamplerChannel));
347     CLIENT_TEST(pClient, int, lscp_get_channel_stream_count(pClient, iSamplerChannel));
348     CLIENT_TEST(pClient, int, lscp_get_channel_stream_usage(pClient, iSamplerChannel));
349     CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_BYTES, iSamplerChannel));
350     CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_PERCENTAGE, iSamplerChannel));
351     CLIENT_TEST(pClient, status, lscp_set_channel_audio_type(pClient, iSamplerChannel, pszAudioDriver));
352     CLIENT_TEST(pClient, status, lscp_set_channel_audio_device(pClient, iSamplerChannel, 0));
353     CLIENT_TEST(pClient, status, lscp_set_channel_audio_channel(pClient, iSamplerChannel, 0, 1));
354     CLIENT_TEST(pClient, status, lscp_set_channel_midi_type(pClient, iSamplerChannel, pszMidiDriver));
355     CLIENT_TEST(pClient, status, lscp_set_channel_midi_device(pClient, iSamplerChannel, 0));
356     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));
358     CLIENT_TEST(pClient, status, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5));
359 capela 735 CLIENT_TEST(pClient, status, lscp_set_channel_mute(pClient, iSamplerChannel, 1));
360     CLIENT_TEST(pClient, status, lscp_set_channel_solo(pClient, iSamplerChannel, 1));
361 capela 189 CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
362     CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel));
363     CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel));
364 capela 946
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 capela 189 }
375    
376    
377     void client_test_midi_port ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
378     {
379     lscp_device_port_info_t *pMidiPortInfo;
380     const char *pszParam;
381     int i;
382    
383     printf("\n--- iMidiDevice=%d iMidiPort=%d ---\n", iMidiDevice, iMidiPort);
384     CLIENT_TEST(pClient, device_port_info, pMidiPortInfo = lscp_get_midi_port_info(pClient, iMidiDevice, iMidiPort));
385     if (pMidiPortInfo && pMidiPortInfo->params) {
386     for (i = 0; pMidiPortInfo->params[i].key; i++) {
387     pszParam = pMidiPortInfo->params[i].key;
388     printf("\n--- iMidiDevice=%d iMidiPort=%d pszParam=\"%s\" ---\n", iMidiDevice, iMidiPort, pszParam);
389     CLIENT_TEST(pClient, param_info, lscp_get_midi_port_param_info(pClient, iMidiDevice, iMidiPort, pszParam));
390     }
391     }
392     }
393    
394    
395     void client_test_audio_channel ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
396     {
397     lscp_device_port_info_t *pAudioChannelInfo;
398     const char *pszParam;
399     int i;
400    
401     printf("\n--- iAudioDevice=%d iAudioChannel=%d ---\n", iAudioDevice, iAudioChannel);
402     CLIENT_TEST(pClient, device_port_info, pAudioChannelInfo = lscp_get_audio_channel_info(pClient, iAudioDevice, iAudioChannel));
403     if (pAudioChannelInfo && pAudioChannelInfo->params) {
404     for (i = 0; pAudioChannelInfo->params[i].key; i++) {
405     pszParam = pAudioChannelInfo->params[i].key;
406     printf("\n--- iAudioDevice=%d iAudioChannel=%d pszParam=\"%s\" ---\n", iAudioDevice, iAudioChannel, pszParam);
407     CLIENT_TEST(pClient, param_info, lscp_get_audio_channel_param_info(pClient, iAudioDevice, iAudioChannel, pszParam));
408     }
409     }
410     }
411    
412    
413     void client_test_midi_device ( lscp_client_t *pClient, int iMidiDevice )
414     {
415     lscp_device_info_t *pDeviceInfo;
416     const char *pszValue;
417     int iMidiPort, iMidiPorts;
418    
419     printf("\n--- iMidiDevice=%d ---\n", iMidiDevice);
420     CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_midi_device_info(pClient, iMidiDevice));
421     if (pDeviceInfo && pDeviceInfo->params) {
422     pszValue = lscp_get_param_value(pDeviceInfo->params, "ports");
423     if (pszValue) {
424     iMidiPorts = atoi(pszValue);
425     for (iMidiPort = 0; iMidiPort < iMidiPorts; iMidiPort++)
426     client_test_midi_port(pClient, iMidiDevice, iMidiPort);
427     }
428     }
429     }
430    
431    
432     void client_test_audio_device ( lscp_client_t *pClient, int iAudioDevice )
433     {
434     lscp_device_info_t *pDeviceInfo;
435     const char *pszValue;
436     int iAudioChannel, iAudioChannels;
437    
438     printf("\n--- iAudioDevice=%d ---\n", iAudioDevice);
439     CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_audio_device_info(pClient, iAudioDevice));
440     if (pDeviceInfo && pDeviceInfo->params) {
441     pszValue = lscp_get_param_value(pDeviceInfo->params, "channels");
442     if (pszValue) {
443     iAudioChannels = atoi(pszValue);
444     for (iAudioChannel = 0; iAudioChannel < iAudioChannels; iAudioChannel++)
445     client_test_audio_channel(pClient, iAudioDevice, iAudioChannel);
446     }
447     }
448     }
449    
450    
451     void client_test_midi_driver ( lscp_client_t *pClient, const char *pszMidiDriver )
452     {
453     lscp_driver_info_t *pDriverInfo;
454     const char *pszParam;
455     int i;
456    
457     printf("\n--- pszMidiDriver=\"%s\" ---\n", pszMidiDriver);
458     CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_midi_driver_info(pClient, pszMidiDriver));
459     if (pDriverInfo && pDriverInfo->parameters) {
460     for (i = 0; pDriverInfo->parameters[i]; i++) {
461     pszParam = pDriverInfo->parameters[i];
462     printf("\n--- pszMidiDriver=\"%s\" pszParam=\"%s\" ---\n", pszMidiDriver, pszParam);
463     CLIENT_TEST(pClient, param_info, lscp_get_midi_driver_param_info(pClient, pszMidiDriver, pszParam, NULL));
464     }
465     }
466     }
467    
468    
469     void client_test_audio_driver ( lscp_client_t *pClient, const char *pszAudioDriver )
470     {
471     lscp_driver_info_t *pDriverInfo;
472     const char *pszParam;
473     int i;
474 capela 564
475 capela 189 printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver);
476     CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_audio_driver_info(pClient, pszAudioDriver));
477     if (pDriverInfo && pDriverInfo->parameters) {
478     for (i = 0; pDriverInfo->parameters[i]; i++) {
479     pszParam = pDriverInfo->parameters[i];
480     printf("\n--- pszAudioDriver=\"%s\" pszParam=\"%s\" ---\n", pszAudioDriver, pszParam);
481     CLIENT_TEST(pClient, param_info, lscp_get_audio_driver_param_info(pClient, pszAudioDriver, pszParam, NULL));
482     }
483     }
484     }
485    
486    
487 capela 213 void client_test_all ( lscp_client_t *pClient, int step )
488 capela 189 {
489 capela 103 const char **ppszAudioDrivers, **ppszMidiDrivers, **ppszEngines;
490     const char *pszAudioDriver, *pszMidiDriver, *pszEngine;
491     int iAudioDriver, iMidiDriver, iEngine;
492 capela 189 int iAudio, iAudioDevice, iMidi, iMidiDevice;
493     int iNewAudioDevice, iNewMidiDevice;
494     int *piAudioDevices, *piMidiDevices;
495 capela 103
496 capela 213 g_test_step = step;
497 capela 188 g_test_count = 0;
498     g_test_fails = 0;
499    
500 capela 564 CLIENT_TEST(pClient, server_info, lscp_get_server_info(pClient));
501    
502 capela 523 CLIENT_TEST(pClient, int, lscp_get_available_audio_drivers(pClient));
503     CLIENT_TEST(pClient, szsplit, ppszAudioDrivers = lscp_list_available_audio_drivers(pClient));
504 capela 103 if (ppszAudioDrivers == NULL) {
505     fprintf(stderr, "client_test: No audio drivers available.\n");
506     return;
507     }
508    
509 capela 523 CLIENT_TEST(pClient, int, lscp_get_available_midi_drivers(pClient));
510     CLIENT_TEST(pClient, szsplit, ppszMidiDrivers = lscp_list_available_midi_drivers(pClient));
511 capela 103 if (ppszMidiDrivers == NULL) {
512     fprintf(stderr, "client_test: No MIDI drivers available.\n");
513     return;
514     }
515    
516 capela 523 CLIENT_TEST(pClient, int, lscp_get_available_engines(pClient));
517     CLIENT_TEST(pClient, szsplit, ppszEngines = lscp_list_available_engines(pClient));
518 capela 103 if (ppszEngines == NULL) {
519     fprintf(stderr, "client_test: No engines available.\n");
520     return;
521     }
522    
523     for (iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) {
524 capela 189 pszAudioDriver = ppszAudioDrivers[iAudioDriver];
525     client_test_audio_driver(pClient, pszAudioDriver);
526     CLIENT_TEST(pClient, int, iNewAudioDevice = lscp_create_audio_device(pClient, pszAudioDriver, NULL));
527     CLIENT_TEST(pClient, int, lscp_get_audio_devices(pClient));
528     CLIENT_TEST(pClient, isplit, piAudioDevices = lscp_list_audio_devices(pClient));
529     for (iAudio = 0; piAudioDevices && piAudioDevices[iAudio] >= 0; iAudio++) {
530     iAudioDevice = piAudioDevices[iAudio];
531     client_test_audio_device(pClient, iAudioDevice);
532     for (iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) {
533     pszMidiDriver = ppszMidiDrivers[iMidiDriver];
534     client_test_midi_driver(pClient, pszMidiDriver);
535     CLIENT_TEST(pClient, int, iNewMidiDevice = lscp_create_midi_device(pClient, pszMidiDriver, NULL));
536     CLIENT_TEST(pClient, int, lscp_get_midi_devices(pClient));
537     CLIENT_TEST(pClient, isplit, piMidiDevices = lscp_list_midi_devices(pClient));
538     for (iMidi = 0; piMidiDevices && piMidiDevices[iMidi] >= 0; iMidi++) {
539     iMidiDevice = piMidiDevices[iMidi];
540     client_test_midi_device(pClient, iMidiDevice);
541     for (iEngine = 0; ppszEngines[iEngine]; iEngine++) {
542     pszEngine = ppszEngines[iEngine];
543     client_test_engine(pClient, pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice);
544     }
545     }
546     CLIENT_TEST(pClient, status, lscp_destroy_midi_device(pClient, iNewMidiDevice));
547     }
548     }
549     CLIENT_TEST(pClient, status, lscp_destroy_audio_device(pClient, iNewAudioDevice));
550 capela 103 }
551 capela 213
552     CLIENT_TEST(pClient, status, lscp_reset_sampler(pClient));
553    
554 capela 189 printf("\n\n");
555 capela 188 printf(" Total: %d tests, %d failed.\n\n", g_test_count, g_test_fails);
556 capela 103 }
557    
558 capela 189
559 capela 103 ////////////////////////////////////////////////////////////////////////
560    
561     void client_usage (void)
562     {
563     printf("\n %s %s (Build: %s)\n", lscp_client_package(), lscp_client_version(), lscp_client_build());
564    
565 capela 188 fputs("\n Available commands: help, test[step], exit, quit, subscribe, unsubscribe", stdout);
566 capela 103 fputs("\n (all else are sent verbatim to server)\n\n", stdout);
567    
568     }
569    
570     void client_prompt (void)
571     {
572     fputs("lscp_client> ", stdout);
573     }
574    
575     int main (int argc, char *argv[] )
576     {
577     lscp_client_t *pClient;
578     char *pszHost = "localhost";
579     char szLine[1024];
580     int cchLine;
581     lscp_status_t ret;
582    
583     #if defined(WIN32)
584     if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) {
585     fprintf(stderr, "lscp_client: WSAStartup failed.\n");
586     return -1;
587     }
588     #endif
589    
590     if (argc > 1)
591     pszHost = argv[1];
592    
593     pClient = lscp_client_create(pszHost, SERVER_PORT, client_callback, NULL);
594     if (pClient == NULL)
595     return -1;
596    
597     client_usage();
598     client_prompt();
599    
600     while (fgets(szLine, sizeof(szLine) - 3, stdin)) {
601    
602     cchLine = strlen(szLine);
603     while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r'))
604     cchLine--;
605     szLine[cchLine] = '\0';
606    
607     if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0)
608     break;
609     else
610     if (strcmp(szLine, "subscribe") == 0)
611 capela 146 lscp_client_subscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
612 capela 103 else
613     if (strcmp(szLine, "unsubscribe") == 0)
614 capela 146 lscp_client_unsubscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
615 capela 103 else
616     if (strcmp(szLine, "test") == 0)
617 capela 213 client_test_all(pClient, 0);
618 capela 103 else
619 capela 213 if (strcmp(szLine, "teststep") == 0 || strcmp(szLine, "test step") == 0)
620     client_test_all(pClient, 1);
621 capela 187 else
622 capela 103 if (cchLine > 0 && strcmp(szLine, "help") != 0) {
623     szLine[cchLine++] = '\r';
624     szLine[cchLine++] = '\n';
625     szLine[cchLine] = '\0';
626     ret = lscp_client_query(pClient, szLine);
627     printf("%s\n(errno = %d)\n", lscp_client_get_result(pClient), lscp_client_get_errno(pClient));
628     if (ret == LSCP_QUIT)
629     break;
630     }
631     else client_usage();
632    
633     client_prompt();
634     }
635    
636     lscp_client_destroy(pClient);
637    
638     #if defined(WIN32)
639     WSACleanup();
640     #endif
641    
642     return 0;
643     }
644    
645     // end of example_client.c

  ViewVC Help
Powered by ViewVC