/[svn]/liblscp/trunk/src/device.c
ViewVC logotype

Contents of /liblscp/trunk/src/device.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 107 - (show annotations) (download)
Fri Jun 4 21:06:59 2004 UTC (16 years, 6 months ago) by capela
File MIME type: text/plain
File size: 19018 byte(s)
Initial alpha release.

1 // device.c
2 //
3 /****************************************************************************
4 liblscp - LinuxSampler Control Protocol API
5 Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library 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 GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 *****************************************************************************/
22
23 #include "common.h"
24
25
26 // Local prototypes.
27
28 static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery);
29
30
31 //-------------------------------------------------------------------------
32 // Local funtions.
33
34 // Common driver type query command.
35 static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery )
36 {
37 const char *pszResult;
38 const char *pszSeps = ":";
39 const char *pszCrlf = "\r\n";
40 char *pszToken;
41 char *pch;
42
43 lscp_driver_info_reset(pDriverInfo);
44
45 if (lscp_client_query(pClient, pszQuery) != LSCP_OK)
46 return NULL;
47
48 pszResult = lscp_client_get_result(pClient);
49 pszToken = lscp_strtok(pszResult, pszSeps, &(pch));
50 while (pszToken) {
51 if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
52 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
53 if (pszToken)
54 pDriverInfo->description = lscp_unquote(&pszToken, 1);
55 }
56 else if (strcasecmp(pszToken, "VERSION") == 0) {
57 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
58 if (pszToken)
59 pDriverInfo->version = lscp_unquote(&pszToken, 1);
60 }
61 else if (strcasecmp(pszToken, "PARAMETERS") == 0) {
62 pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
63 if (pszToken)
64 pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");
65 }
66 pszToken = lscp_strtok(NULL, pszSeps, &(pch));
67 }
68
69 return pDriverInfo;
70 }
71
72
73 //-------------------------------------------------------------------------
74 // Audio driver control functions.
75
76 /**
77 * Getting all available audio output drivers.
78 * GET AVAILABLE_AUDIO_OUTPUT_DRIVERS
79 *
80 * @param pClient Pointer to client instance structure.
81 *
82 * @returns A NULL terminated array of audio output driver type
83 * name strings, or NULL in case of failure.
84 */
85 const char ** lscp_get_available_audio_drivers ( lscp_client_t *pClient )
86 {
87 const char *pszSeps = ",";
88
89 if (pClient->audio_drivers) {
90 lscp_szsplit_destroy(pClient->audio_drivers);
91 pClient->audio_drivers = NULL;
92 }
93
94 if (lscp_client_query(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)
95 pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
96
97 return (const char **) pClient->audio_drivers;
98 }
99
100
101 /**
102 * Getting informations about a specific audio output driver.
103 * GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type>
104 *
105 * @param pClient Pointer to client instance structure.
106 * @param pszAudioDriver Audio driver type string (e.g. "ALSA").
107 *
108 * @returns A pointer to a @ref lscp_driver_info_t structure, with
109 * the given audio driver information, or NULL in case of failure.
110 */
111 lscp_driver_info_t* lscp_get_audio_driver_info ( lscp_client_t *pClient, const char *pszAudioDriver )
112 {
113 char szQuery[LSCP_BUFSIZ];
114
115 if (pszAudioDriver == NULL)
116 return NULL;
117
118 sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER INFO %s\r\n", pszAudioDriver);
119 return _lscp_driver_info_query(pClient, &(pClient->audio_info), szQuery);
120 }
121
122
123 /**
124 * Getting informations about specific audio output driver parameter.
125 * GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-driver> <param> [<dep-list>]
126 *
127 * @param pClient Pointer to client instance structure.
128 * @param pszAudioDriver Audio driver type string (e.g. "ALSA").
129 * @param pszParam Audio driver parameter name.
130 * @param pDepList Pointer to specific dependencies parameter list.
131 *
132 * @returns A pointer to a @ref lscp_param_info_t structure, with
133 * the given audio driver parameter information, or NULL in case of failure.
134 */
135 lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList )
136 {
137 lscp_param_info_t *pParamInfo = NULL;
138
139 if (pClient == NULL)
140 return NULL;
141 if (pszAudioDriver == NULL)
142 return NULL;
143 if (pszParam == NULL)
144 return NULL;
145 if (pDepList == NULL)
146 return NULL;
147
148 return pParamInfo;
149 }
150
151
152 //-------------------------------------------------------------------------
153 // Audio device control functions.
154
155 /**
156 * Creating an audio output device.
157 * CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>]
158 *
159 * @param pClient Pointer to client instance structure.
160 * @param pszAudioDriver Audio driver type string (e.g. "ALSA").
161 * @param pParams Pointer to specific parameter list.
162 *
163 * @returns The new audio device number identifier on success,
164 * or -1 in case of failure.
165 */
166 int lscp_create_audio_device ( lscp_client_t *pClient, const char *pszAudioDriver, lscp_param_t *pParams )
167 {
168 int iAudioDevice = -1;
169
170 if (pClient == NULL)
171 return -1;
172 if (pszAudioDriver == NULL)
173 return -1;
174 if (pParams == NULL)
175 return -1;
176
177 return iAudioDevice;
178 }
179
180
181 /**
182 * Destroying an audio output device.
183 * DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id>
184 *
185 * @param pClient Pointer to client instance structure.
186 * @param iAudioDevice Audio device number identifier.
187 *
188 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
189 */
190 lscp_status_t lscp_destroy_audio_device ( lscp_client_t *pClient, int iAudioDevice )
191 {
192 lscp_status_t ret = LSCP_FAILED;
193
194 if (pClient == NULL)
195 return ret;
196 if (iAudioDevice < 0)
197 return ret;
198
199 return ret;
200 }
201
202
203 /**
204 * Getting all created audio output devices.
205 * GET AUDIO_OUTPUT_DEVICES
206 *
207 * @param pClient Pointer to client instance structure.
208 *
209 * @returns An array of audio device number identifiers,
210 * terminated with -1 on success, or NULL in case of failure.
211 */
212 int *lscp_get_audio_devices ( lscp_client_t *pClient )
213 {
214 int *piAudioDevices = NULL;
215
216 if (pClient == NULL)
217 return NULL;
218
219 return piAudioDevices;
220 }
221
222
223 /**
224 * Getting current settings of an audio output device.
225 * GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id>
226 *
227 * @param pClient Pointer to client instance structure.
228 * @param iAudioDevice Audio device number identifier.
229 *
230 * @returns A pointer to a @ref lscp_device_info_t structure, with
231 * the given audio device information, or NULL in case of failure.
232 */
233 lscp_device_info_t *lscp_get_audio_device_info ( lscp_client_t *pClient, int iAudioDevice )
234 {
235 lscp_device_info_t *pDeviceInfo = NULL;
236
237 if (pClient == NULL)
238 return NULL;
239 if (iAudioDevice < 0)
240 return NULL;
241
242 return pDeviceInfo;
243 }
244
245
246 /**
247 * Changing settings of audio output devices.
248 * SET AUDIO_OUTPUT_DEVICE_PARAMETER <audio-device-id> <param> <value>
249 *
250 * @param pClient Pointer to client instance structure.
251 * @param iAudioDevice Audio device number identifier.
252 * @param pParam Pointer to a key-valued audio device parameter.
253 *
254 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
255 */
256 lscp_status_t lscp_set_audio_device_param ( lscp_client_t *pClient, int iAudioDevice, lscp_param_t *pParam )
257 {
258 lscp_status_t ret = LSCP_FAILED;
259
260 if (pClient == NULL)
261 return ret;
262 if (iAudioDevice < 0)
263 return ret;
264 if (pParam == NULL)
265 return ret;
266
267 return ret;
268 }
269
270
271 /**
272 * Getting informations about an audio channel.
273 * GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel>
274 *
275 * @param pClient Pointer to client instance structure.
276 * @param iAudioDevice Audio device number identifier.
277 * @param iAudioChannel Audio channel number.
278 *
279 * @returns A pointer to a @ref lscp_device_channel_info_t structure,
280 * with the given audio channel information, or NULL in case of failure.
281 */
282 lscp_device_channel_info_t* lscp_get_audio_channel_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
283 {
284 lscp_device_channel_info_t *pDevChannelInfo = NULL;
285
286 if (pClient == NULL)
287 return NULL;
288 if (iAudioDevice < 0)
289 return NULL;
290 if (iAudioChannel < 0)
291 return NULL;
292
293 return pDevChannelInfo;
294 }
295
296
297 /**
298 * Getting informations about specific audio channel parameter.
299 * GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param>
300 *
301 * @param pClient Pointer to client instance structure.
302 * @param iAudioDevice Audio device number identifier.
303 * @param iAudioChannel Audio channel number.
304 * @param pszParam Audio channel parameter name.
305 *
306 * @returns A pointer to a @ref lscp_param_info_t structure, with
307 * the given audio channel parameter information, or NULL in case of failure.
308 */
309 lscp_param_info_t* lscp_get_audio_channel_param_info ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, const char *pszParam )
310 {
311 lscp_param_info_t *pParamInfo = NULL;
312
313 if (pClient == NULL)
314 return NULL;
315 if (iAudioDevice < 0)
316 return NULL;
317 if (iAudioChannel < 0)
318 return NULL;
319 if (pszParam == NULL)
320 return NULL;
321
322 return pParamInfo;
323 }
324
325
326 /**
327 * Changing settings of audio output channels.
328 * SET AUDIO_OUTPUT_CHANNEL_PARAMETER <audio-device-id> <audio-channel> <param> <value>
329 *
330 * @param pClient Pointer to client instance structure.
331 * @param iAudioDevice Audio device number identifier.
332 * @param iAudioChannel Audio channel number.
333 * @param pParam Pointer to a key-valued audio channel parameter.
334 *
335 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
336 */
337 lscp_status_t lscp_set_audio_channel_param ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel, lscp_param_t *pParam )
338 {
339 lscp_status_t ret = LSCP_FAILED;
340
341 if (pClient == NULL)
342 return ret;
343 if (iAudioDevice < 0)
344 return ret;
345 if (iAudioChannel < 0)
346 return ret;
347 if (pParam == NULL)
348 return ret;
349
350 return ret;
351 }
352
353
354 //-------------------------------------------------------------------------
355 // MIDI driver control functions.
356
357 /**
358 * Getting all available MIDI input drivers.
359 * GET AVAILABLE_MIDI_INPUT_DRIVERS
360 *
361 * @param pClient Pointer to client instance structure.
362 *
363 * @returns A NULL terminated array of MIDI input driver type
364 * name strings, or NULL in case of failure.
365 */
366 const char** lscp_get_available_midi_drivers ( lscp_client_t *pClient )
367 {
368 const char *pszSeps = ",";
369
370 if (pClient->midi_drivers) {
371 lscp_szsplit_destroy(pClient->midi_drivers);
372 pClient->midi_drivers = NULL;
373 }
374
375 if (lscp_client_query(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)
376 pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
377
378 return (const char **) pClient->midi_drivers;
379 }
380
381
382 /**
383 * Getting informations about a specific MIDI input driver.
384 * GET MIDI_INPUT_DRIVER INFO <midi-input-type>
385 *
386 * @param pClient Pointer to client instance structure.
387 * @param pszMidiDriver MIDI driver type string (e.g. "ALSA").
388 *
389 * @returns A pointer to a @ref lscp_driver_info_t structure, with
390 * the given MIDI driver information, or NULL in case of failure.
391 */
392 lscp_driver_info_t* lscp_get_midi_driver_info ( lscp_client_t *pClient, const char *pszMidiDriver )
393 {
394 char szQuery[LSCP_BUFSIZ];
395
396 if (pszMidiDriver == NULL)
397 return NULL;
398
399 sprintf(szQuery, "GET MIDI_INPUT_DRIVER INFO %s\r\n", pszMidiDriver);
400 return _lscp_driver_info_query(pClient, &(pClient->midi_info), szQuery);
401 }
402
403
404 /**
405 * Getting informations about specific MIDI input driver parameter.
406 * GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-driver> <param> [<dep-list>]
407 *
408 * @param pClient Pointer to client instance structure.
409 * @param pszMidiDriver MIDI driver type string (e.g. "ALSA").
410 * @param pszParam MIDI driver parameter name.
411 * @param pDepList Pointer to specific dependencies parameter list.
412 *
413 * @returns A pointer to a @ref lscp_param_info_t structure, with
414 * the given MIDI driver parameter information, or NULL in case of failure.
415 *
416 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
417 */
418 lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList )
419 {
420 lscp_param_info_t *pParamInfo = NULL;
421
422 if (pClient == NULL)
423 return NULL;
424 if (pszMidiDriver == NULL)
425 return NULL;
426 if (pszParam == NULL)
427 return NULL;
428 if (pDepList == NULL)
429 return NULL;
430
431 return pParamInfo;
432 }
433
434
435 //-------------------------------------------------------------------------
436 // MIDI device control functions.
437
438 /**
439 * Creating a MIDI input device.
440 * CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>]
441 *
442 * @param pClient Pointer to client instance structure.
443 * @param pszMidiDriver MIDI driver type string (e.g. "ALSA").
444 * @param pParams Pointer to specific parameter list.
445 *
446 * @returns The new audio device number identifier on success,
447 * or -1 in case of failure.
448 */
449 int lscp_create_midi_device ( lscp_client_t *pClient, const char *pszMidiDriver, lscp_param_t *pParams )
450 {
451 int iMidiDevice = -1;
452
453 if (pClient == NULL)
454 return -1;
455 if (pszMidiDriver == NULL)
456 return -1;
457 if (pParams == NULL)
458 return -1;
459
460 return iMidiDevice;
461 }
462
463
464 /**
465 * Destroying a MIDI input device.
466 * DESTROY MIDI_INPUT_DEVICE <midi-device-id>
467 *
468 * @param pClient Pointer to client instance structure.
469 * @param iMidiDevice MIDI device number identifier.
470 *
471 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
472 */
473 lscp_status_t lscp_destroy_midi_device ( lscp_client_t *pClient, int iMidiDevice )
474 {
475 lscp_status_t ret = LSCP_FAILED;
476
477 if (pClient == NULL)
478 return ret;
479 if (iMidiDevice < 0)
480 return ret;
481
482 return ret;
483 }
484
485
486 /**
487 * Getting all created MIDI input devices.
488 * GET MIDI_INPUT_DEVICES
489 *
490 * @param pClient Pointer to client instance structure.
491 *
492 * @returns An array of MIDI device number identifiers,
493 * terminated with -1 on success, or NULL in case of failure.
494 */
495 int *lscp_get_midi_devices ( lscp_client_t *pClient )
496 {
497 int *piMidiDevices = NULL;
498
499 if (pClient == NULL)
500 return NULL;
501
502 return piMidiDevices;
503 }
504
505
506 /**
507 * Getting current settings of a MIDI input device.
508 * GET MIDI_INPUT_DEVICE INFO <midi-device-id>
509 *
510 * @param pClient Pointer to client instance structure.
511 * @param iMidiDevice MIDI device number identifier.
512 *
513 * @returns A pointer to a @ref lscp_device_info_t structure, with
514 * the given MIDI device information, or NULL in case of failure.
515 */
516 lscp_device_info_t* lscp_get_midi_device_info ( lscp_client_t *pClient, int iMidiDevice )
517 {
518 lscp_device_info_t *pDeviceInfo = NULL;
519
520 if (pClient == NULL)
521 return NULL;
522 if (iMidiDevice < 0)
523 return NULL;
524
525 return pDeviceInfo;
526 }
527
528
529 /**
530 * Changing settings of MIDI input devices.
531 * SET MIDI_INPUT_DEVICE_PARAMETER <midi-device-id> <param> <value>
532 *
533 * @param pClient Pointer to client instance structure.
534 * @param iMidiDevice MIDI device number identifier.
535 * @param pParam Pointer to a key-valued MIDI device parameter.
536 *
537 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
538 */
539 lscp_status_t lscp_set_midi_device_param ( lscp_client_t *pClient, int iMidiDevice, lscp_param_t *pParam )
540 {
541 lscp_status_t ret = LSCP_FAILED;
542
543 if (pClient == NULL)
544 return ret;
545 if (iMidiDevice < 0)
546 return ret;
547 if (pParam == NULL)
548 return ret;
549
550 return ret;
551 }
552
553
554 /**
555 * Getting informations about a MIDI port.
556 * GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port>
557 *
558 * @param pClient Pointer to client instance structure.
559 * @param iMidiDevice MIDI device number identifier.
560 * @param iMidiPort MIDI port number.
561 *
562 * @returns A pointer to a @ref lscp_device_channel_info_t structure,
563 * with the given MIDI port information, or NULL in case of failure.
564 */
565 lscp_device_channel_info_t* lscp_get_midi_port_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
566 {
567 lscp_device_channel_info_t *pDevChannelInfo = NULL;
568
569 if (pClient == NULL)
570 return NULL;
571 if (iMidiDevice < 0)
572 return NULL;
573 if (iMidiPort < 0)
574 return NULL;
575
576 return pDevChannelInfo;
577 }
578
579
580 /**
581 * Getting informations about specific MIDI port parameter.
582 * GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param>
583 *
584 * @param pClient Pointer to client instance structure.
585 * @param iMidiDevice MIDI device number identifier.
586 * @param iMidiPort MIDI port number.
587 * @param pszParam MIDI port parameter name.
588 *
589 * @returns A pointer to a @ref lscp_param_info_t structure, with
590 * the given MIDI port parameter information, or NULL in case of failure.
591 */
592 lscp_param_info_t* lscp_get_midi_port_param_info ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, const char *pszParam )
593 {
594 lscp_param_info_t *pParamInfo = NULL;
595
596 if (pClient == NULL)
597 return NULL;
598 if (iMidiDevice < 0)
599 return NULL;
600 if (iMidiPort < 0)
601 return NULL;
602 if (pszParam == NULL)
603 return NULL;
604
605 return pParamInfo;
606 }
607
608
609 /**
610 * Changing settings of MIDI input ports.
611 * SET MIDI_INPUT_PORT_PARAMETER <midi-device-id> <midi-port> <param> <value>
612 *
613 * @param pClient Pointer to client instance structure.
614 * @param iMidiDevice MIDI device number identifier.
615 * @param iMidiPort MIDI port number.
616 * @param pParam Pointer to a key-valued MIDI port parameter.
617 *
618 * @returns LSCP_OK on success, LSCP_FAILED otherwise.
619 */
620 lscp_status_t lscp_set_midi_port_param ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort, lscp_param_t *pParam )
621 {
622 lscp_status_t ret = LSCP_FAILED;
623
624 if (pClient == NULL)
625 return ret;
626 if (iMidiDevice < 0)
627 return ret;
628 if (iMidiPort < 0)
629 return ret;
630 if (pParam == NULL)
631 return ret;
632
633 return ret;
634 }
635
636 // end of device.c
637

  ViewVC Help
Powered by ViewVC