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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 125 by capela, Mon Jun 14 21:04:04 2004 UTC revision 963 by capela, Sun Dec 3 18:30:04 2006 UTC
# Line 1  Line 1 
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
# Line 13  Line 14 
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    
# Line 32  static WSADATA _wsaData; Line 33  static WSADATA _wsaData;
33    
34  ////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////
35    
36  lscp_status_t client_callback ( lscp_client_t *pClient, const char *pchBuffer, int cchBuffer, void *pvData )  lscp_status_t client_callback ( lscp_client_t *pClient, lscp_event_t event, const char *pchData, int cchData, void *pvData )
37  {  {
38      lscp_status_t ret = LSCP_OK;          lscp_status_t ret = LSCP_FAILED;
39    
40      char *pszBuffer = (char *) malloc(cchBuffer + 1);          char *pszData = (char *) malloc(cchData + 1);
41      if (pszBuffer) {          if (pszData) {
42          memcpy(pszBuffer, pchBuffer, cchBuffer);                  memcpy(pszData, pchData, cchData);
43          pszBuffer[cchBuffer] = (char) 0;                  pszData[cchData] = (char) 0;
44          printf("client_callback: [%s]\n", pszBuffer);                  printf("client_callback: event=%s (0x%04x) [%s]\n", lscp_event_to_text(event), (int) event, pszData);
45          free(pszBuffer);                  free(pszData);
46      }                  ret = LSCP_OK;
47      else ret = LSCP_FAILED;          }
48    
49      return ret;          return ret;
50  }  }
51    
52  ////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////
53    
54    int client_test_int ( int i )
55    {
56            printf("%d\n", i);
57            return (i >= 0 ? 0 : 1);
58    }
59    
60    
61    int client_test_status ( lscp_status_t s )
62    {
63            const char *pszStatus;
64    
65            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    }
77    
78    
79    int client_test_isplit ( int *piSplit )
80    {
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            return 0;
91    }
92    
93    
94    int client_test_szsplit ( char **ppszSplit )
95    {
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            return 0;
106    }
107    
108    
109    int client_test_params ( lscp_param_t *pParams )
110    {
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            return 0;
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 )
140    {
141            const char *pszType;
142    
143            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    }
168    
169    
170    int client_test_driver_info ( lscp_driver_info_t *pDriverInfo )
171    {
172            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    }
183    
184    
185    int client_test_device_info ( lscp_device_info_t *pDeviceInfo )
186    {
187            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    }
197    
198    
199    int client_test_device_port_info ( lscp_device_port_info_t *pDevicePortInfo )
200    {
201            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    }
211    
212    
213    int client_test_server_info ( lscp_server_info_t *pServerInfo )
214    {
215            if (pServerInfo == NULL) {
216                    printf("(nil)\n");
217                    return 1;
218            }
219            printf("{\n");
220            printf("    server_info.description = %s\n", pServerInfo->description);
221            printf("    server_info.version     = %s\n", pServerInfo->version);
222            printf("  }\n");
223            return 0;
224    }
225    
226    
227    int client_test_engine_info ( lscp_engine_info_t *pEngineInfo )
228    {
229            if (pEngineInfo == NULL) {
230                    printf("(nil)\n");
231                    return 1;
232            }
233            printf("{\n");
234            printf("    engine_info.description = %s\n", pEngineInfo->description);
235            printf("    engine_info.version     = %s\n", pEngineInfo->version);
236            printf("  }\n");
237            return 0;
238    }
239    
240    
241    int client_test_channel_info ( lscp_channel_info_t *pChannelInfo )
242    {
243            if (pChannelInfo == NULL) {
244                    printf("(nil)\n");
245                    return 1;
246            }
247            printf("{\n");
248            printf("    channel_info.engine_name       = %s\n", pChannelInfo->engine_name);
249            printf("    channel_info.audio_device      = %d\n", pChannelInfo->audio_device);
250            printf("    channel_info.audio_channels    = %d\n", pChannelInfo->audio_channels);
251            printf("    channel_info.audio_routing     = "); client_test_szsplit(pChannelInfo->audio_routing);
252            printf("    channel_info.instrument_file   = %s\n", pChannelInfo->instrument_file);
253            printf("    channel_info.instrument_nr     = %d\n", pChannelInfo->instrument_nr);
254            printf("    channel_info.instrument_name   = %s\n", pChannelInfo->instrument_name);
255            printf("    channel_info.instrument_status = %d\n", pChannelInfo->instrument_status);
256            printf("    channel_info.midi_device       = %d\n", pChannelInfo->midi_device);
257            printf("    channel_info.midi_port         = %d\n", pChannelInfo->midi_port);
258            printf("    channel_info.midi_channel      = %d\n", pChannelInfo->midi_channel);
259            printf("    channel_info.volume            = %g\n", pChannelInfo->volume);
260            printf("    channel_info.mute              = %d\n", pChannelInfo->mute);
261            printf("    channel_info.solo              = %d\n", pChannelInfo->solo);
262            printf("  }\n");
263            return 0;
264    }
265    
266    
267    int client_test_buffer_fill ( lscp_buffer_fill_t *pBufferFill )
268    {
269            if (pBufferFill == NULL) {
270                    printf("(nil)\n");
271                    return 1;
272            }
273            printf("{ <%p> }\n", pBufferFill);
274            return 0;
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;
315    static int g_test_count = 0;
316    static int g_test_fails = 0;
317    
318    
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  #define CLIENT_TEST(p, x) { clock_t c; void *v;\  typedef int *                        isplit;
323      printf(#x ":\n"); client_test_start(&c); v = (void *) (x); \  typedef char **                      szsplit;
324      printf("  elapsed=%gs\n", client_test_elapsed(&c)); \  typedef lscp_status_t                status;
325      printf("  ret=%p (%d)\n", v, (int) v); \  typedef lscp_driver_info_t *         driver_info;
326      printf("  errno=%d\n", lscp_client_get_errno(p)); \  typedef lscp_device_info_t *         device_info;
327      printf("  result=\"%s\"\n", lscp_client_get_result(p)); }  typedef lscp_device_port_info_t *    device_port_info;
328    typedef lscp_param_info_t  *         param_info;
329  void client_test ( lscp_client_t *pClient )  typedef lscp_server_info_t *         server_info;
330  {  typedef lscp_engine_info_t *         engine_info;
331      const char **ppszAudioDrivers, **ppszMidiDrivers, **ppszEngines;  typedef lscp_channel_info_t *        channel_info;
332      const char *pszAudioDriver, *pszMidiDriver, *pszEngine;  typedef lscp_buffer_fill_t *         buffer_fill;
333      int iAudioDriver, iMidiDriver, iEngine;  typedef lscp_midi_instrument_t *     midi_instruments;
334      int iSamplerChannel;  typedef lscp_midi_instrument_info_t *midi_instrument_info;
335    
336      CLIENT_TEST(pClient, ppszAudioDrivers = lscp_get_available_audio_drivers(pClient));  #define CLIENT_TEST(p, t, x) { clock_t c; void *v; g_test_count++; \
337      if (ppszAudioDrivers == NULL) {          printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \
338          fprintf(stderr, "client_test: No audio drivers available.\n");          printf("  elapsed=%gs  errno=%d  result='%s...' ret=", \
339          return;                  client_test_elapsed(&c), \
340      }                  lscp_client_get_errno(p), \
341                    lscp_client_get_result(p)); \
342      CLIENT_TEST(pClient, ppszMidiDrivers = lscp_get_available_midi_drivers(pClient));          if (client_test_##t((t)(v))) { g_test_fails++; getchar(); } \
343      if (ppszMidiDrivers == NULL) {          else if (g_test_step) getchar(); }
344          fprintf(stderr, "client_test: No MIDI drivers available.\n");  
         return;  
     }  
   
     CLIENT_TEST(pClient, ppszEngines = lscp_get_available_engines(pClient));  
     if (ppszEngines == NULL) {  
         fprintf(stderr, "client_test: No engines available.\n");  
         return;  
     }  
   
     CLIENT_TEST(pClient, lscp_get_audio_devices(pClient));  
     CLIENT_TEST(pClient, lscp_list_audio_devices(pClient));  
   
     CLIENT_TEST(pClient, lscp_get_midi_devices(pClient));  
     CLIENT_TEST(pClient, lscp_list_midi_devices(pClient));  
   
     for (iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) {  
      pszAudioDriver = ppszAudioDrivers[iAudioDriver];  
      printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver);  
      CLIENT_TEST(pClient, lscp_get_audio_driver_info(pClient, pszAudioDriver));  
      for (iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) {  
       pszMidiDriver = ppszMidiDrivers[iMidiDriver];  
       printf("\n--- pszMidiDriver=\"%s\" ---\n", pszMidiDriver);  
       CLIENT_TEST(pClient, lscp_get_midi_driver_info(pClient, pszMidiDriver));  
       for (iEngine = 0; ppszEngines[iEngine]; iEngine++) {  
         pszEngine = ppszEngines[iEngine];  
         printf("\n--- pszEngine=\"%s\" ---\n", pszEngine);  
         CLIENT_TEST(pClient, lscp_get_engine_info(pClient, pszEngine));  
         CLIENT_TEST(pClient, lscp_get_channels(pClient));  
         CLIENT_TEST(pClient, lscp_list_channels(pClient));  
         CLIENT_TEST(pClient, iSamplerChannel = lscp_add_channel(pClient));  
         printf(">>> iSamplerChannel=\"%d\"\n", iSamplerChannel);  
         CLIENT_TEST(pClient, lscp_get_channel_info(pClient, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_load_engine(pClient, pszEngine, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_load_instrument(pClient, "DefaultInstrument.gig", 0, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_get_channel_voice_count(pClient, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_get_channel_stream_count(pClient, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_BYTES, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_PERCENTAGE, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_set_channel_audio_type(pClient, iSamplerChannel, pszAudioDriver));  
         CLIENT_TEST(pClient, lscp_set_channel_audio_channel(pClient, iSamplerChannel, 0, 1));  
         CLIENT_TEST(pClient, lscp_set_channel_midi_type(pClient, iSamplerChannel, pszMidiDriver));  
         CLIENT_TEST(pClient, lscp_set_channel_midi_channel(pClient, iSamplerChannel, 0));  
         CLIENT_TEST(pClient, lscp_set_channel_midi_port(pClient, iSamplerChannel, 0));  
         CLIENT_TEST(pClient, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5));  
         CLIENT_TEST(pClient, lscp_get_channel_info(pClient, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_reset_channel(pClient, iSamplerChannel));  
         CLIENT_TEST(pClient, lscp_remove_channel(pClient, iSamplerChannel));  
         printf("\n");  
       }  
      }  
     }  
345    
346    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;
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);
353            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));
357            CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient));
358            CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient));
359            printf("\n--- iSamplerChannel=%d ---\n", iSamplerChannel);
360            CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
361            CLIENT_TEST(pClient, status, lscp_load_engine(pClient, pszEngine, iSamplerChannel));
362            CLIENT_TEST(pClient, status, lscp_load_instrument(pClient, "DefaultInstrument.gig", 0, iSamplerChannel));
363            CLIENT_TEST(pClient, int, lscp_get_channel_voice_count(pClient, iSamplerChannel));
364            CLIENT_TEST(pClient, int, lscp_get_channel_stream_count(pClient, iSamplerChannel));
365            CLIENT_TEST(pClient, int, lscp_get_channel_stream_usage(pClient, iSamplerChannel));
366            CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_BYTES, iSamplerChannel));
367            CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_PERCENTAGE, iSamplerChannel));
368            CLIENT_TEST(pClient, status, lscp_set_channel_audio_type(pClient, iSamplerChannel, pszAudioDriver));
369            CLIENT_TEST(pClient, status, lscp_set_channel_audio_device(pClient, iSamplerChannel, 0));
370            CLIENT_TEST(pClient, status, lscp_set_channel_audio_channel(pClient, iSamplerChannel, 0, 1));
371            CLIENT_TEST(pClient, status, lscp_set_channel_midi_type(pClient, iSamplerChannel, pszMidiDriver));
372            CLIENT_TEST(pClient, status, lscp_set_channel_midi_device(pClient, iSamplerChannel, 0));
373            CLIENT_TEST(pClient, status, lscp_set_channel_midi_channel(pClient, iSamplerChannel, 0));
374            CLIENT_TEST(pClient, status, lscp_set_channel_midi_port(pClient, iSamplerChannel, 0));
375            CLIENT_TEST(pClient, status, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5));
376            CLIENT_TEST(pClient, status, lscp_set_channel_mute(pClient, iSamplerChannel, 1));
377            CLIENT_TEST(pClient, status, lscp_set_channel_solo(pClient, iSamplerChannel, 1));
378            CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
379            CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel));
380            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    
412    void client_test_midi_port ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
413    {
414            lscp_device_port_info_t *pMidiPortInfo;
415            const char *pszParam;
416            int i;
417    
418            printf("\n--- iMidiDevice=%d iMidiPort=%d ---\n", iMidiDevice, iMidiPort);
419            CLIENT_TEST(pClient, device_port_info, pMidiPortInfo = lscp_get_midi_port_info(pClient, iMidiDevice, iMidiPort));
420            if (pMidiPortInfo && pMidiPortInfo->params) {
421                    for (i = 0; pMidiPortInfo->params[i].key; i++) {
422                            pszParam = pMidiPortInfo->params[i].key;
423                            printf("\n--- iMidiDevice=%d iMidiPort=%d pszParam=\"%s\" ---\n", iMidiDevice, iMidiPort, pszParam);
424                            CLIENT_TEST(pClient, param_info, lscp_get_midi_port_param_info(pClient, iMidiDevice, iMidiPort, pszParam));
425                    }
426            }
427    }
428    
429    
430    void client_test_audio_channel ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
431    {
432            lscp_device_port_info_t *pAudioChannelInfo;
433            const char *pszParam;
434            int i;
435    
436            printf("\n--- iAudioDevice=%d iAudioChannel=%d ---\n", iAudioDevice, iAudioChannel);
437            CLIENT_TEST(pClient, device_port_info, pAudioChannelInfo = lscp_get_audio_channel_info(pClient, iAudioDevice, iAudioChannel));
438            if (pAudioChannelInfo && pAudioChannelInfo->params) {
439                    for (i = 0; pAudioChannelInfo->params[i].key; i++) {
440                            pszParam = pAudioChannelInfo->params[i].key;
441                            printf("\n--- iAudioDevice=%d iAudioChannel=%d pszParam=\"%s\" ---\n", iAudioDevice, iAudioChannel, pszParam);
442                            CLIENT_TEST(pClient, param_info, lscp_get_audio_channel_param_info(pClient, iAudioDevice, iAudioChannel, pszParam));
443                    }
444            }
445    }
446    
447    
448    void client_test_midi_device ( lscp_client_t *pClient, int iMidiDevice )
449    {
450            lscp_device_info_t *pDeviceInfo;
451            const char *pszValue;
452            int iMidiPort, iMidiPorts;
453    
454            printf("\n--- iMidiDevice=%d ---\n", iMidiDevice);
455            CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_midi_device_info(pClient, iMidiDevice));
456            if (pDeviceInfo && pDeviceInfo->params) {
457                    pszValue = lscp_get_param_value(pDeviceInfo->params, "ports");
458                    if (pszValue) {
459                            iMidiPorts = atoi(pszValue);
460                            for (iMidiPort = 0; iMidiPort < iMidiPorts; iMidiPort++)
461                                    client_test_midi_port(pClient, iMidiDevice, iMidiPort);
462                    }
463            }
464    }
465    
466    
467    void client_test_audio_device ( lscp_client_t *pClient, int iAudioDevice )
468    {
469            lscp_device_info_t *pDeviceInfo;
470            const char *pszValue;
471            int iAudioChannel, iAudioChannels;
472    
473            printf("\n--- iAudioDevice=%d ---\n", iAudioDevice);
474            CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_audio_device_info(pClient, iAudioDevice));
475            if (pDeviceInfo && pDeviceInfo->params) {
476                    pszValue = lscp_get_param_value(pDeviceInfo->params, "channels");
477                    if (pszValue) {
478                            iAudioChannels = atoi(pszValue);
479                            for (iAudioChannel = 0; iAudioChannel < iAudioChannels; iAudioChannel++)
480                                    client_test_audio_channel(pClient, iAudioDevice, iAudioChannel);
481                    }
482            }
483    }
484    
485    
486    void client_test_midi_driver ( lscp_client_t *pClient, const char *pszMidiDriver )
487    {
488            lscp_driver_info_t *pDriverInfo;
489            const char *pszParam;
490            int i;
491    
492            printf("\n--- pszMidiDriver=\"%s\" ---\n", pszMidiDriver);
493            CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_midi_driver_info(pClient, pszMidiDriver));
494            if (pDriverInfo && pDriverInfo->parameters) {
495                    for (i = 0; pDriverInfo->parameters[i]; i++) {
496                            pszParam = pDriverInfo->parameters[i];
497                            printf("\n--- pszMidiDriver=\"%s\" pszParam=\"%s\" ---\n", pszMidiDriver, pszParam);
498                            CLIENT_TEST(pClient, param_info, lscp_get_midi_driver_param_info(pClient, pszMidiDriver, pszParam, NULL));
499                    }
500            }
501    }
502    
503    
504    void client_test_audio_driver ( lscp_client_t *pClient, const char *pszAudioDriver )
505    {
506            lscp_driver_info_t *pDriverInfo;
507            const char *pszParam;
508            int i;
509    
510            printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver);
511            CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_audio_driver_info(pClient, pszAudioDriver));
512            if (pDriverInfo && pDriverInfo->parameters) {
513                    for (i = 0; pDriverInfo->parameters[i]; i++) {
514                            pszParam = pDriverInfo->parameters[i];
515                            printf("\n--- pszAudioDriver=\"%s\" pszParam=\"%s\" ---\n", pszAudioDriver, pszParam);
516                            CLIENT_TEST(pClient, param_info, lscp_get_audio_driver_param_info(pClient, pszAudioDriver, pszParam, NULL));
517                    }
518            }
519    }
520    
521    
522    void client_test_all ( lscp_client_t *pClient, int step )
523    {
524            const char **ppszAudioDrivers, **ppszMidiDrivers, **ppszEngines;
525            const char *pszAudioDriver, *pszMidiDriver, *pszEngine;
526            int iAudioDriver, iMidiDriver, iEngine;
527            int iAudio, iAudioDevice, iMidi, iMidiDevice;
528            int iNewAudioDevice, iNewMidiDevice;
529            int *piAudioDevices, *piMidiDevices;
530    
531            g_test_step  = step;
532            g_test_count = 0;
533            g_test_fails = 0;
534    
535            CLIENT_TEST(pClient, server_info, lscp_get_server_info(pClient));
536    
537            CLIENT_TEST(pClient, int, lscp_get_available_audio_drivers(pClient));
538            CLIENT_TEST(pClient, szsplit, ppszAudioDrivers = lscp_list_available_audio_drivers(pClient));
539            if (ppszAudioDrivers == NULL) {
540                    fprintf(stderr, "client_test: No audio drivers available.\n");
541                    return;
542            }
543    
544            CLIENT_TEST(pClient, int, lscp_get_available_midi_drivers(pClient));
545            CLIENT_TEST(pClient, szsplit, ppszMidiDrivers = lscp_list_available_midi_drivers(pClient));
546            if (ppszMidiDrivers == NULL) {
547                    fprintf(stderr, "client_test: No MIDI drivers available.\n");
548                    return;
549            }
550    
551            CLIENT_TEST(pClient, int, lscp_get_available_engines(pClient));
552            CLIENT_TEST(pClient, szsplit, ppszEngines = lscp_list_available_engines(pClient));
553            if (ppszEngines == NULL) {
554                    fprintf(stderr, "client_test: No engines available.\n");
555                    return;
556            }
557    
558            for (iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) {
559                    pszAudioDriver = ppszAudioDrivers[iAudioDriver];
560                    client_test_audio_driver(pClient, pszAudioDriver);
561                    CLIENT_TEST(pClient, int, iNewAudioDevice = lscp_create_audio_device(pClient, pszAudioDriver, NULL));
562                    CLIENT_TEST(pClient, int, lscp_get_audio_devices(pClient));
563                    CLIENT_TEST(pClient, isplit, piAudioDevices = lscp_list_audio_devices(pClient));
564                    for (iAudio = 0; piAudioDevices && piAudioDevices[iAudio] >= 0; iAudio++) {
565                            iAudioDevice = piAudioDevices[iAudio];
566                            client_test_audio_device(pClient, iAudioDevice);
567                            for (iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) {
568                                    pszMidiDriver = ppszMidiDrivers[iMidiDriver];
569                                    client_test_midi_driver(pClient, pszMidiDriver);
570                                    CLIENT_TEST(pClient, int, iNewMidiDevice = lscp_create_midi_device(pClient, pszMidiDriver, NULL));
571                                    CLIENT_TEST(pClient, int, lscp_get_midi_devices(pClient));
572                                    CLIENT_TEST(pClient, isplit, piMidiDevices = lscp_list_midi_devices(pClient));
573                                    for (iMidi = 0; piMidiDevices && piMidiDevices[iMidi] >= 0; iMidi++) {
574                                            iMidiDevice = piMidiDevices[iMidi];
575                                            client_test_midi_device(pClient, iMidiDevice);
576                                            for (iEngine = 0; ppszEngines[iEngine]; iEngine++) {
577                                                    pszEngine = ppszEngines[iEngine];
578                                                    client_test_engine(pClient, pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice);
579                                            }
580                                    }
581                                    CLIENT_TEST(pClient, status, lscp_destroy_midi_device(pClient, iNewMidiDevice));
582                            }
583                    }
584                    CLIENT_TEST(pClient, status, lscp_destroy_audio_device(pClient, iNewAudioDevice));
585            }
586    
587            CLIENT_TEST(pClient, status, lscp_reset_sampler(pClient));
588            
589            printf("\n\n");
590            printf("  Total: %d tests, %d failed.\n\n", g_test_count, g_test_fails);
591    }
592    
593    
594  ////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////
595    
596  void client_usage (void)  void client_usage (void)
597  {  {
598      printf("\n  %s %s (Build: %s)\n", lscp_client_package(), lscp_client_version(), lscp_client_build());          printf("\n  %s %s (Build: %s)\n", lscp_client_package(), lscp_client_version(), lscp_client_build());
599    
600      fputs("\n  Available client commands: help, test, exit, quit, subscribe, unsubscribe", stdout);          fputs("\n  Available commands: help, test[step], exit, quit, subscribe, unsubscribe", stdout);
601      fputs("\n  (all else are sent verbatim to server)\n\n", stdout);          fputs("\n  (all else are sent verbatim to server)\n\n", stdout);
602    
603  }  }
604    
605  void client_prompt (void)  void client_prompt (void)
606  {  {
607      fputs("lscp_client> ", stdout);          fputs("lscp_client> ", stdout);
608  }  }
609    
610  int main (int argc, char *argv[] )  int main (int argc, char *argv[] )
611  {  {
612      lscp_client_t *pClient;          lscp_client_t *pClient;
613      char *pszHost = "localhost";          char *pszHost = "localhost";
614      char  szLine[1024];          char  szLine[1024];
615      int  cchLine;          int  cchLine;
616      lscp_status_t ret;          lscp_status_t ret;
617    
618  #if defined(WIN32)  #if defined(WIN32)
619      if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) {          if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) {
620          fprintf(stderr, "lscp_client: WSAStartup failed.\n");                  fprintf(stderr, "lscp_client: WSAStartup failed.\n");
621          return -1;                  return -1;
622      }          }
623  #endif  #endif
624    
625      if (argc > 1)          if (argc > 1)
626          pszHost = argv[1];                  pszHost = argv[1];
627    
628      pClient = lscp_client_create(pszHost, SERVER_PORT, client_callback, NULL);          pClient = lscp_client_create(pszHost, SERVER_PORT, client_callback, NULL);
629      if (pClient == NULL)          if (pClient == NULL)
630          return -1;                  return -1;
631    
632      client_usage();          client_usage();
633      client_prompt();          client_prompt();
634    
635      while (fgets(szLine, sizeof(szLine) - 3, stdin)) {          while (fgets(szLine, sizeof(szLine) - 3, stdin)) {
636    
637          cchLine = strlen(szLine);                  cchLine = strlen(szLine);
638          while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r'))                  while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r'))
639              cchLine--;                          cchLine--;
640          szLine[cchLine] = '\0';                  szLine[cchLine] = '\0';
641    
642          if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0)                  if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0)
643              break;                          break;
644          else                  else
645          if (strcmp(szLine, "subscribe") == 0)                  if (strcmp(szLine, "subscribe") == 0)
646              lscp_client_subscribe(pClient);                          lscp_client_subscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
647          else                  else
648          if (strcmp(szLine, "unsubscribe") == 0)                  if (strcmp(szLine, "unsubscribe") == 0)
649              lscp_client_unsubscribe(pClient);                          lscp_client_unsubscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
650          else                  else
651          if (strcmp(szLine, "test") == 0)                  if (strcmp(szLine, "test") == 0)
652              client_test(pClient);                          client_test_all(pClient, 0);
653          else                  else
654          if (cchLine > 0 && strcmp(szLine, "help") != 0) {                  if (strcmp(szLine, "teststep") == 0 || strcmp(szLine, "test step") == 0)
655              szLine[cchLine++] = '\r';                          client_test_all(pClient, 1);
656              szLine[cchLine++] = '\n';                  else
657              szLine[cchLine]   = '\0';                  if (cchLine > 0 && strcmp(szLine, "help") != 0) {
658              ret = lscp_client_query(pClient, szLine);                          szLine[cchLine++] = '\r';
659              printf("%s\n(errno = %d)\n", lscp_client_get_result(pClient), lscp_client_get_errno(pClient));                          szLine[cchLine++] = '\n';
660              if (ret == LSCP_QUIT)                          szLine[cchLine]   = '\0';
661                  break;                          ret = lscp_client_query(pClient, szLine);
662          }                          printf("%s\n(errno = %d)\n", lscp_client_get_result(pClient), lscp_client_get_errno(pClient));
663          else client_usage();                          if (ret == LSCP_QUIT)
664                                    break;
665                    }
666                    else client_usage();
667    
668          client_prompt();                  client_prompt();
669      }          }
670    
671      lscp_client_destroy(pClient);          lscp_client_destroy(pClient);
672    
673  #if defined(WIN32)  #if defined(WIN32)
674      WSACleanup();          WSACleanup();
675  #endif  #endif
676    
677      return 0;          return 0;
678  }  }
679    
680  // end of example_client.c  // end of example_client.c

Legend:
Removed from v.125  
changed lines
  Added in v.963

  ViewVC Help
Powered by ViewVC