3 * \ingroup Configuration
4 * \brief Configuration helper functions
5 * \author Abramo Bagnara <abramo@alsa-project.org>
6 * \author Jaroslav Kysela <perex@perex.cz>
9 * Configuration helper functions.
11 * See the \ref conffunc page for more details.
14 * Miscellaneous configuration helper functions
15 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>,
16 * Jaroslav Kysela <perex@perex.cz>
19 * This library is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as
21 * published by the Free Software Foundation; either version 2.1 of
22 * the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 \section conffunc_ref Function reference
40 <LI>The getenv function - snd_func_getenv() - obtains
41 an environment value. The result is a string.
42 <LI>The igetenv function - snd_func_igetenv() - obtains
43 an environment value. The result is an integer.
44 <LI>The concat function - snd_func_concat() - merges all specified
45 strings. The result is a string.
46 <LI>The iadd function - snd_func_iadd() - sum all specified integers.
47 The result is an integer.
48 <LI>The imul function - snd_func_imul() - multiply all specified integers.
49 The result is an integer.
50 <LI>The datadir function - snd_func_datadir() - returns the
51 ALSA data directory. The result is a string.
52 <LI>The refer function - snd_func_refer() - copies the referred
53 configuration. The result has the same type as the referred node.
54 <LI>The card_inum function - snd_func_card_inum() - returns
55 a card number (integers).
56 <LI>The card_driver function - snd_func_card_driver() - returns
57 a driver identification. The result is a string.
58 <LI>The card_id function - snd_func_card_id() - returns
59 a card identification. The result is a string.
60 <LI>The card_name function - snd_func_card_name() - returns
61 a card's name. The result is a string.
62 <LI>The pcm_id function - snd_func_pcm_id() - returns
63 a pcm identification. The result is a string.
64 <LI>The private_string function - snd_func_private_string() - returns the
65 string from the private_data node.
66 <LI>The private_card_driver function - snd_func_private_card_driver() -
67 returns the driver identification from the private_data node.
68 The result is a string.
69 <LI>The private_pcm_subdevice function - snd_func_private_pcm_subdevice() -
70 returns the PCM subdevice number from the private_data node.
71 The result is a string.
85 * \brief Gets the boolean value from the given ASCII string.
86 * \param ascii The string to be parsed.
87 * \return 0 or 1 if successful, otherwise a negative error code.
89 int snd_config_get_bool_ascii(const char *ascii)
105 for (k = 0; k < sizeof(b) / sizeof(*b); k++) {
106 if (strcasecmp(b[k].str, ascii) == 0)
113 * \brief Gets the boolean value from a configuration node.
114 * \param conf Handle to the configuration node to be parsed.
115 * \return 0 or 1 if successful, otherwise a negative error code.
117 int snd_config_get_bool(const snd_config_t *conf)
120 const char *str, *id;
123 err = snd_config_get_id(conf, &id);
126 err = snd_config_get_integer(conf, &v);
128 if (v < 0 || v > 1) {
130 SNDERR("Invalid value for %s", id);
135 err = snd_config_get_string(conf, &str);
137 SNDERR("Invalid type for %s", id);
140 err = snd_config_get_bool_ascii(str);
147 * \brief Gets the card number from a configuration node.
148 * \param conf Handle to the configuration node to be parsed.
149 * \return The card number if successful, otherwise a negative error code.
151 int snd_config_get_card(const snd_config_t *conf)
153 const char *str, *id;
157 if ((err = snd_config_get_integer(conf, &v)) < 0) {
158 if ((err = snd_config_get_string(conf, &str)) < 0) {
159 snd_config_get_id(conf, &id);
160 SNDERR("Invalid field %s", id);
163 err = snd_card_get_index(str);
165 SNDERR("Cannot get card index for %s", str);
170 if (v < 0 || v > INT_MAX)
176 * \brief Gets the control interface index from the given ASCII string.
177 * \param ascii The string to be parsed.
178 * \return The control interface index if successful, otherwise a negative error code.
180 int snd_config_get_ctl_iface_ascii(const char *ascii)
183 snd_ctl_elem_iface_t idx;
184 if (isdigit(ascii[0])) {
185 if (safe_strtol(ascii, &v) >= 0) {
186 if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST)
191 for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++) {
192 if (strcasecmp(snd_ctl_elem_iface_name(idx), ascii) == 0)
199 * \brief Gets the control interface index from a configuration node.
200 * \param conf Handle to the configuration node to be parsed.
201 * \return The control interface index if successful, otherwise a negative error code.
203 int snd_config_get_ctl_iface(const snd_config_t *conf)
206 const char *str, *id;
209 err = snd_config_get_id(conf, &id);
212 err = snd_config_get_integer(conf, &v);
214 if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST) {
216 SNDERR("Invalid value for %s", id);
221 err = snd_config_get_string(conf, &str);
223 SNDERR("Invalid type for %s", id);
226 err = snd_config_get_ctl_iface_ascii(str);
233 * Helper functions for the configuration file
237 * \brief Returns an environment value.
238 * \param dst The function puts the handle to the result configuration node
239 * (with type string) at the address specified by \p dst.
240 * \param root Handle to the root source node.
241 * \param src Handle to the source node, with definitions for \c vars and
243 * \param private_data Handle to the \c private_data node.
244 * \return Zero if successful, otherwise a negative error code.
250 vars [ MY_CARD CARD C ]
255 int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
256 snd_config_t *private_data)
259 snd_config_iterator_t i, next;
260 const char *res, *id;
262 int idx = 0, err, hit;
264 err = snd_config_search(src, "vars", &n);
266 SNDERR("field vars not found");
269 err = snd_config_evaluate(n, root, private_data, NULL);
271 SNDERR("error evaluating vars");
274 err = snd_config_search(src, "default", &d);
276 SNDERR("field default not found");
279 err = snd_config_evaluate(d, root, private_data, NULL);
281 SNDERR("error evaluating default");
284 err = snd_config_get_ascii(d, &def);
286 SNDERR("error getting field default");
291 snd_config_for_each(i, next, n) {
292 snd_config_t *n = snd_config_iterator_entry(i);
295 if (snd_config_get_id(n, &id) < 0)
297 if (snd_config_get_type(n) != SND_CONFIG_TYPE_STRING) {
298 SNDERR("field %s is not a string", id);
302 err = safe_strtol(id, &i);
304 SNDERR("id of field %s is not an integer", id);
310 err = snd_config_get_string(n, &ptr);
312 SNDERR("invalid string for id %s", id);
317 if (res != NULL && *res != '\0')
325 err = snd_config_get_id(src, &id);
327 err = snd_config_imake_string(dst, id, res);
333 SND_DLSYM_BUILD_VERSION(snd_func_getenv, SND_CONFIG_DLSYM_VERSION_EVALUATE);
337 * \brief Returns an integer environment value.
338 * \param dst The function puts the handle to the result configuration node
339 * (with type integer) at the address specified by \p dst.
340 * \param root Handle to the root source node.
341 * \param src Handle to the source node, with definitions for \c vars and
343 * \param private_data Handle to the \c private_data node.
344 * \return Zero if successful, otherwise a negative error code.
350 vars [ MY_DEVICE DEVICE D ]
355 int snd_func_igetenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
356 snd_config_t *private_data)
359 const char *str, *id;
363 err = snd_func_getenv(&d, root, src, private_data);
366 err = snd_config_get_string(d, &str);
368 snd_config_delete(d);
371 err = safe_strtol(str, &v);
373 snd_config_delete(d);
376 snd_config_delete(d);
377 err = snd_config_get_id(src, &id);
380 err = snd_config_imake_integer(dst, id, v);
386 SND_DLSYM_BUILD_VERSION(snd_func_igetenv, SND_CONFIG_DLSYM_VERSION_EVALUATE);
390 * \brief Merges the given strings.
391 * \param dst The function puts the handle to the result configuration node
392 * (with type string) at the address specified by \p dst.
393 * \param root Handle to the root source node.
394 * \param src Handle to the source node, with a definition for \c strings.
395 * \param private_data Handle to the \c private_data node.
396 * \return A non-negative value if successful, otherwise a negative error code.
398 * Example (result is "a1b2c3"):
402 strings [ "a1" "b2" "c3" ]
406 int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
407 snd_config_t *private_data)
410 snd_config_iterator_t i, next;
412 char *res = NULL, *tmp;
413 int idx = 0, len = 0, len1, err, hit;
415 err = snd_config_search(src, "strings", &n);
417 SNDERR("field strings not found");
420 err = snd_config_evaluate(n, root, private_data, NULL);
422 SNDERR("error evaluating strings");
427 snd_config_for_each(i, next, n) {
428 snd_config_t *n = snd_config_iterator_entry(i);
432 if (snd_config_get_id(n, &id) < 0)
434 err = safe_strtol(id, &i);
436 SNDERR("id of field %s is not an integer", id);
442 err = snd_config_get_ascii(n, &ptr);
444 SNDERR("invalid ascii string for id %s", id);
449 tmp = realloc(res, len + len1 + 1);
455 memcpy(tmp + len, ptr, len1);
465 SNDERR("empty string is not accepted");
469 err = snd_config_get_id(src, &id);
471 err = snd_config_imake_string(dst, id, res);
477 SND_DLSYM_BUILD_VERSION(snd_func_concat, SND_CONFIG_DLSYM_VERSION_EVALUATE);
481 static int snd_func_iops(snd_config_t **dst,
484 snd_config_t *private_data,
488 snd_config_iterator_t i, next;
491 long result = 0, val;
492 int idx = 0, err, hit;
494 err = snd_config_search(src, "integers", &n);
496 SNDERR("field integers not found");
499 err = snd_config_evaluate(n, root, private_data, NULL);
501 SNDERR("error evaluating integers");
506 snd_config_for_each(i, next, n) {
507 snd_config_t *n = snd_config_iterator_entry(i);
510 if (snd_config_get_id(n, &id) < 0)
512 err = safe_strtol(id, &i);
514 SNDERR("id of field %s is not an integer", id);
520 err = snd_config_get_integer(n, &val);
522 SNDERR("invalid integer for id %s", id);
527 case 0: result += val; break;
528 case 1: result *= val; break;
534 err = snd_config_get_id(src, &id);
536 err = snd_config_imake_integer(dst, id, result);
544 * \brief Sum the given integers.
545 * \param dst The function puts the handle to the result configuration node
546 * (with type integer) at the address specified by \p dst.
547 * \param root Handle to the root source node.
548 * \param src Handle to the source node, with a definition for \c integers.
549 * \param private_data Handle to the \c private_data node.
550 * \return A non-negative value if successful, otherwise a negative error code.
552 * Example (result is 10):
560 int snd_func_iadd(snd_config_t **dst, snd_config_t *root,
561 snd_config_t *src, snd_config_t *private_data)
563 return snd_func_iops(dst, root, src, private_data, 0);
566 SND_DLSYM_BUILD_VERSION(snd_func_iadd, SND_CONFIG_DLSYM_VERSION_EVALUATE);
570 * \brief Multiply the given integers.
571 * \param dst The function puts the handle to the result configuration node
572 * (with type integer) at the address specified by \p dst.
573 * \param root Handle to the root source node.
574 * \param src Handle to the source node, with a definition for \c integers.
575 * \param private_data Handle to the \c private_data node.
576 * \return A non-negative value if successful, otherwise a negative error code.
578 * Example (result is 12):
586 int snd_func_imul(snd_config_t **dst, snd_config_t *root,
587 snd_config_t *src, snd_config_t *private_data)
589 return snd_func_iops(dst, root, src, private_data, 1);
592 SND_DLSYM_BUILD_VERSION(snd_func_imul, SND_CONFIG_DLSYM_VERSION_EVALUATE);
596 * \brief Returns the ALSA data directory.
597 * \param dst The function puts the handle to the result configuration node
598 * (with type string) at the address specified by \p dst.
599 * \param root Handle to the root source node.
600 * \param src Handle to the source node.
601 * \param private_data Handle to the \c private_data node. Not used.
602 * \return A non-negative value if successful, otherwise a negative error code.
604 * Example (result is "/usr/share/alsa" using the default paths):
611 int snd_func_datadir(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
612 snd_config_t *src, snd_config_t *private_data ATTRIBUTE_UNUSED)
617 err = snd_config_get_id(src, &id);
620 return snd_config_imake_string(dst, id, snd_config_topdir());
623 SND_DLSYM_BUILD_VERSION(snd_func_datadir, SND_CONFIG_DLSYM_VERSION_EVALUATE);
626 static int open_ctl(long card, snd_ctl_t **ctl)
629 snprintf(name, sizeof(name), "hw:%li", card);
630 name[sizeof(name)-1] = '\0';
631 return snd_ctl_open(ctl, name, 0);
635 static int string_from_integer(char **dst, long v)
639 sprintf(str, "%li", v);
648 int _snd_func_private_data(snd_config_t **dst, snd_config_t *src,
649 snd_config_t **private_data, const char *id)
653 if (*private_data == NULL)
654 return snd_config_copy(dst, src);
655 if (snd_config_get_type(*private_data) == SND_CONFIG_TYPE_COMPOUND) {
656 err = snd_config_search(*private_data, id, private_data);
660 err = snd_config_test_id(*private_data, id);
663 SNDERR("field %s not found", id);
671 * \brief Returns the string from \c private_data.
672 * \param dst The function puts the handle to the result configuration node
673 * (with type string) at the address specified by \p dst.
674 * \param root Handle to the root source node.
675 * \param src Handle to the source node.
676 * \param private_data Handle to the \c private_data node (type string,
678 * \return A non-negative value if successful, otherwise a negative error code.
687 int snd_func_private_string(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
688 snd_config_t *src, snd_config_t *private_data)
691 const char *str, *id;
693 err = _snd_func_private_data(dst, src, &private_data, "string");
696 err = snd_config_get_string(private_data, &str);
698 SNDERR("field string is not a string");
701 err = snd_config_get_id(src, &id);
703 err = snd_config_imake_string(dst, id, str);
707 SND_DLSYM_BUILD_VERSION(snd_func_private_string, SND_CONFIG_DLSYM_VERSION_EVALUATE);
711 * \brief Returns the integer from \c private_data.
712 * \param dst The function puts the handle to the result configuration node
713 * (with type integer) at the address specified by \p dst.
714 * \param root Handle to the root source node.
715 * \param src Handle to the source node.
716 * \param private_data Handle to the \c private_data node (type integer,
718 * \return A non-negative value if successful, otherwise a negative error code.
723 @func private_integer
727 int snd_func_private_integer(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
728 snd_config_t *src, snd_config_t *private_data)
734 err = _snd_func_private_data(dst, src, &private_data, "integer");
737 err = snd_config_get_integer(private_data, &val);
739 SNDERR("field integer is not a string");
742 err = snd_config_get_id(src, &id);
744 err = snd_config_imake_integer(dst, id, val);
748 SND_DLSYM_BUILD_VERSION(snd_func_private_integer, SND_CONFIG_DLSYM_VERSION_EVALUATE);
752 int snd_determine_driver(int card, char **driver)
754 snd_ctl_t *ctl = NULL;
755 snd_ctl_card_info_t info = {0};
759 assert(card >= 0 && card <= SND_MAX_CARDS);
760 err = open_ctl(card, &ctl);
762 SNDERR("could not open control for card %i", card);
765 err = snd_ctl_card_info(ctl, &info);
767 SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
770 res = strdup(snd_ctl_card_info_get_driver(&info));
785 * \brief Returns the driver identification from \c private_data.
786 * \param dst The function puts the handle to the result configuration node
787 * (with type string) at the address specified by \p dst.
788 * \param root Handle to the root source node.
789 * \param src Handle to the source node.
790 * \param private_data Handle to the \c private_data node (type integer,
792 * \return A non-negative value if successful, otherwise a negative error code.
797 @func private_card_driver
801 int snd_func_private_card_driver(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *src,
802 snd_config_t *private_data)
809 err = snd_config_test_id(private_data, "card");
811 SNDERR("field card not found");
814 err = snd_config_get_integer(private_data, &card);
816 SNDERR("field card is not an integer");
819 if ((err = snd_determine_driver(card, &driver)) < 0)
821 err = snd_config_get_id(src, &id);
823 err = snd_config_imake_string(dst, id, driver);
828 SND_DLSYM_BUILD_VERSION(snd_func_private_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE);
831 static int parse_card(snd_config_t *root, snd_config_t *src,
832 snd_config_t *private_data)
838 err = snd_config_search(src, "card", &n);
840 SNDERR("field card not found");
843 err = snd_config_evaluate(n, root, private_data, NULL);
845 SNDERR("error evaluating card");
848 err = snd_config_get_ascii(n, &str);
850 SNDERR("field card is not an integer or a string");
853 card = snd_card_get_index(str);
855 SNDERR("cannot find card '%s'", str);
861 * \brief Returns the card number as integer.
862 * \param dst The function puts the handle to the result configuration node
863 * (with type string) at the address specified by \p dst.
864 * \param root Handle to the root source node.
865 * \param src Handle to the source node, with a \c card definition.
866 * \param private_data Handle to the \c private_data node.
867 * \return A non-negative value if successful, otherwise a negative error code.
877 int snd_func_card_inum(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
878 snd_config_t *private_data)
883 card = parse_card(root, src, private_data);
886 err = snd_config_get_id(src, &id);
888 err = snd_config_imake_integer(dst, id, card);
892 SND_DLSYM_BUILD_VERSION(snd_func_card_inum, SND_CONFIG_DLSYM_VERSION_EVALUATE);
896 * \brief Returns the driver identification for a card.
897 * \param dst The function puts the handle to the result configuration node
898 * (with type string) at the address specified by \p dst.
899 * \param root Handle to the root source node.
900 * \param src Handle to the source node, with a \c card definition.
901 * \param private_data Handle to the \c private_data node.
902 * \return A non-negative value if successful, otherwise a negative error code.
912 int snd_func_card_driver(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
913 snd_config_t *private_data)
918 card = parse_card(root, src, private_data);
921 err = snd_config_imake_integer(&val, "card", card);
924 err = snd_func_private_card_driver(dst, root, src, val);
925 snd_config_delete(val);
929 SND_DLSYM_BUILD_VERSION(snd_func_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE);
933 * \brief Returns the identification of a card.
934 * \param dst The function puts the handle to the result configuration node
935 * (with type string) at the address specified by \p dst.
936 * \param root Handle to the root source node.
937 * \param src Handle to the source node, with a \c card definition.
938 * \param private_data Handle to the \c private_data node.
939 * \return A non-negative value if successful, otherwise a negative error code.
949 int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
950 snd_config_t *private_data)
952 snd_ctl_t *ctl = NULL;
953 snd_ctl_card_info_t info = {0};
957 card = parse_card(root, src, private_data);
960 err = open_ctl(card, &ctl);
962 SNDERR("could not open control for card %i", card);
965 err = snd_ctl_card_info(ctl, &info);
967 SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
970 err = snd_config_get_id(src, &id);
972 err = snd_config_imake_string(dst, id,
973 snd_ctl_card_info_get_id(&info));
980 SND_DLSYM_BUILD_VERSION(snd_func_card_id, SND_CONFIG_DLSYM_VERSION_EVALUATE);
984 * \brief Returns the name of a card.
985 * \param dst The function puts the handle to the result configuration node
986 * (with type string) at the address specified by \p dst.
987 * \param root Handle to the root source node.
988 * \param src Handle to the source node, with a \c card definition.
989 * \param private_data Handle to the \c private_data node.
990 * \return A non-negative value if successful, otherwise a negative error code.
1000 int snd_func_card_name(snd_config_t **dst, snd_config_t *root,
1001 snd_config_t *src, snd_config_t *private_data)
1003 snd_ctl_t *ctl = NULL;
1004 snd_ctl_card_info_t info = {0};
1008 card = parse_card(root, src, private_data);
1011 err = open_ctl(card, &ctl);
1013 SNDERR("could not open control for card %i", card);
1016 err = snd_ctl_card_info(ctl, &info);
1018 SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
1021 err = snd_config_get_id(src, &id);
1023 err = snd_config_imake_safe_string(dst, id,
1024 snd_ctl_card_info_get_name(&info));
1031 SND_DLSYM_BUILD_VERSION(snd_func_card_name, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1037 * \brief Returns the pcm identification of a device.
1038 * \param dst The function puts the handle to the result configuration node
1039 * (with type string) at the address specified by \p dst.
1040 * \param root Handle to the root source node.
1041 * \param src Handle to the source node, with definitions for \c card,
1042 * \c device and (optionally) \c subdevice.
1043 * \param private_data Handle to the \c private_data node.
1044 * \return A non-negative value if successful, otherwise a negative error code.
1052 subdevice 0 # optional
1056 int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
1059 snd_ctl_t *ctl = NULL;
1060 snd_pcm_info_t info = {0};
1062 long card, device, subdevice = 0;
1065 card = parse_card(root, src, private_data);
1068 err = snd_config_search(src, "device", &n);
1070 SNDERR("field device not found");
1073 err = snd_config_evaluate(n, root, private_data, NULL);
1075 SNDERR("error evaluating device");
1078 err = snd_config_get_integer(n, &device);
1080 SNDERR("field device is not an integer");
1083 if (snd_config_search(src, "subdevice", &n) >= 0) {
1084 err = snd_config_evaluate(n, root, private_data, NULL);
1086 SNDERR("error evaluating subdevice");
1089 err = snd_config_get_integer(n, &subdevice);
1091 SNDERR("field subdevice is not an integer");
1095 err = open_ctl(card, &ctl);
1097 SNDERR("could not open control for card %li", card);
1100 snd_pcm_info_set_device(&info, device);
1101 snd_pcm_info_set_subdevice(&info, subdevice);
1102 err = snd_ctl_pcm_info(ctl, &info);
1104 SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
1107 err = snd_config_get_id(src, &id);
1109 err = snd_config_imake_string(dst, id,
1110 snd_pcm_info_get_id(&info));
1117 SND_DLSYM_BUILD_VERSION(snd_func_pcm_id, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1121 * \brief Returns the pcm card and device arguments (in form CARD=N,DEV=M)
1122 * for pcm specified by class and index.
1123 * \param dst The function puts the handle to the result configuration node
1124 * (with type string) at the address specified by \p dst.
1125 * \param root Handle to the root source node.
1126 * \param src Handle to the source node, with definitions for \c class
1128 * \param private_data Handle to the \c private_data node.
1129 * \return A non-negative value if successful, otherwise a negative error code.
1134 @func pcm_args_by_class
1140 int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
1143 snd_ctl_t *ctl = NULL;
1144 snd_pcm_info_t info = {0};
1151 err = snd_config_search(src, "class", &n);
1153 SNDERR("field class not found");
1156 err = snd_config_evaluate(n, root, private_data, NULL);
1158 SNDERR("error evaluating class");
1161 err = snd_config_get_integer(n, &class);
1163 SNDERR("field class is not an integer");
1166 err = snd_config_search(src, "index", &n);
1168 SNDERR("field index not found");
1171 err = snd_config_evaluate(n, root, private_data, NULL);
1173 SNDERR("error evaluating index");
1176 err = snd_config_get_integer(n, &index);
1178 SNDERR("field index is not an integer");
1183 err = snd_card_next(&card);
1185 SNDERR("could not get next card");
1190 err = open_ctl(card, &ctl);
1192 SNDERR("could not open control for card %i", card);
1197 err = snd_ctl_pcm_next_device(ctl, &dev);
1199 SNDERR("could not get next pcm for card %i", card);
1204 snd_pcm_info_set_device(&info, dev);
1205 err = snd_ctl_pcm_info(ctl, &info);
1208 if (snd_pcm_info_get_class(&info) == (snd_pcm_class_t)class &&
1222 if((err = snd_config_get_id(src, &id)) >= 0) {
1224 snprintf(name, sizeof(name), "CARD=%i,DEV=%i", card, dev);
1225 err = snd_config_imake_string(dst, id, name);
1230 SND_DLSYM_BUILD_VERSION(snd_func_pcm_args_by_class, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1234 * \brief Returns the PCM subdevice from \c private_data.
1235 * \param dst The function puts the handle to the result configuration node
1236 * (with type integer) at the address specified by \p dst.
1237 * \param root Handle to the root source node.
1238 * \param src Handle to the source node.
1239 * \param private_data Handle to the \c private_data node (type pointer,
1241 * \return A non-negative value if successful, otherwise a negative error code.
1246 @func private_pcm_subdevice
1250 int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
1251 snd_config_t *src, snd_config_t *private_data)
1253 snd_pcm_info_t info = {0};
1259 if (private_data == NULL)
1260 return snd_config_copy(dst, src);
1261 err = snd_config_test_id(private_data, "pcm_handle");
1263 SNDERR("field pcm_handle not found");
1266 err = snd_config_get_pointer(private_data, &data);
1267 pcm = (snd_pcm_t *)data;
1269 SNDERR("field pcm_handle is not a pointer");
1272 err = snd_pcm_info(pcm, &info);
1274 SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
1277 err = snd_config_get_id(src, &id);
1279 err = snd_config_imake_integer(dst, id,
1280 snd_pcm_info_get_subdevice(&info));
1284 SND_DLSYM_BUILD_VERSION(snd_func_private_pcm_subdevice, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1287 #endif /* BUILD_PCM */
1290 * \brief Copies the specified configuration node.
1291 * \param dst The function puts the handle to the result configuration node
1292 * (with the same type as the specified node) at the address
1293 * specified by \p dst.
1294 * \param root Handle to the root source node.
1295 * \param src Handle to the source node, with definitions for \c name and
1296 * (optionally) \c file.
1297 * \param private_data Handle to the \c private_data node.
1298 * \return A non-negative value if successful, otherwise a negative error code.
1299 * \note The root source node can be modified!
1305 file "/etc/myconf.conf" # optional
1310 int snd_func_refer(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
1311 snd_config_t *private_data)
1314 const char *file = NULL, *name = NULL;
1317 err = snd_config_search(src, "file", &n);
1319 err = snd_config_evaluate(n, root, private_data, NULL);
1321 SNDERR("error evaluating file");
1324 err = snd_config_get_string(n, &file);
1326 SNDERR("file is not a string");
1330 err = snd_config_search(src, "name", &n);
1332 err = snd_config_evaluate(n, root, private_data, NULL);
1334 SNDERR("error evaluating name");
1337 err = snd_config_get_string(n, &name);
1339 SNDERR("name is not a string");
1345 SNDERR("name is not specified");
1350 err = snd_input_stdio_open(&input, file, "r");
1352 SNDERR("Unable to open file %s: %s", file, snd_strerror(err));
1355 err = snd_config_load(root, input);
1356 snd_input_close(input);
1360 err = snd_config_search_definition(root, NULL, name, dst);
1363 err = snd_config_get_id(src, &id);
1365 err = snd_config_set_id(*dst, id);
1367 err = snd_config_search(src, "default", &n);
1369 SNDERR("Unable to find definition '%s'", name);
1372 err = snd_config_evaluate(n, root, private_data, NULL);
1375 if ((err = snd_config_copy(dst, n)) >= 0) {
1376 if ((err = snd_config_get_id(src, &id)) < 0 ||
1377 (err = snd_config_set_id(*dst, id)) < 0)
1378 snd_config_delete(*dst);
1386 SND_DLSYM_BUILD_VERSION(snd_func_refer, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1390 int _snd_conf_generic_id(const char *id)
1392 static const char ids[3][8] = { "comment", "type", "hint" };
1394 for (k = 0; k < sizeof(ids) / sizeof(ids[0]); ++k) {
1395 if (strcmp(id, ids[k]) == 0)