1 ;; == Configuration Interface
2 ; https://alsa-project.org/alsa-doc/alsa-lib/group___config.html
5 ; This is an opaque internal struct for configuration nodes. The ALSA
6 ; library uses pointers to this structure as handles to configuration
7 ; nodes. Applications don't access contents directly.
9 ;; Type: snd_config_update_t
10 ; This is an opaque internal struct for configuration private update
11 ; objects. The ALSA library uses this structure to save private update
14 ;; Type: snd_config_iterator_t
15 ; This is a pointer to the opaque struct type used for configuration
16 ; compound iterators. The ALSA library uses these as handles for
17 ; configuration compound iterators. Applications don't access contents
20 ;; Enum: snd_config_type_t
22 'SND_CONFIG_TYPE_INTEGER 0
23 'SND_CONFIG_TYPE_INTEGER64 1
24 'SND_CONFIG_TYPE_REAL 2
25 'SND_CONFIG_TYPE_STRING 3
26 'SND_CONFIG_TYPE_POINTER 4
27 'SND_CONFIG_TYPE_COMPOUND 1024
31 (struct 'snd_devname_t
33 "char*" ; char * comment
34 "void*" ; snd_devname_t * next
37 ;; Variable: snd_config_t *snd_config
38 ; Holds the ALSA configuration tree.
39 (import LIB "snd_config")
41 ((unpack "Lu" (address snd_config)) 0))
43 ;; Function: int snd_config_update()
44 ; Updates variable snd_config by rereading the global configuration
46 (import LIB "snd_config_update" "int" "void")
47 (when (< (setf E (snd_config_update)))
48 (die 1 "** Cannot load the ALSA configuration tree: " E)
51 ;; Function: int snd_config_expand
52 ;; [in] snd_config_t *node = Handle to the expansion node
53 ;; [in] snd_config_t *root = Handle to the configuration root node
54 ;; [in] const char *args = Arguments string, can be NULL (last must be null)
55 ;; [in] snd_config_t *private_data = Handle to private data node for functions
56 ;; [out] snd_config_t **result
57 ; Expands a configuration node, applying arguments and functions. If
58 ; config has arguments (defined by a child with id @args), this
59 ; function replaces any string node beginning with $ with the
60 ; respective argument value, or the default argument value, or
61 ; nothing. Furthermore, any functions are evaluated (see
62 ; snd_config_evaluate). The resulting copy of config is returned in
65 ; Returns a non-negative value if successful, otherwise a negative
68 ; The import is wrapped to return the result pointer or (negative)
70 (import** LIB "snd_config_expand"
71 "int" ; int snd_config_expand
72 "void*" ; snd_config_t *config
73 "void*" ; snd_config_t *root
74 "void*" ; const char *args
75 "void*" ; snd_config_t *private_data
76 () ; snd_config_t **result
79 ;; Function: int snd_config_evaluate
80 ;; [in,out] snd_config_t *node = node in root to evaluate
81 ;; [in] snd_config_t *root = configuration root
82 ;; [in] snd_config_t *private_data
83 ;; [*] snd_config_t **result = must be null!
84 ; Evaluates a configuration node at runtime. This function evaluates
85 ; any functions (@func) in config and replaces those nodes with the
86 ; respective function results. Returns a non-negative value if
87 ; successful, otherwise a negative error code.
88 (import LIB "snd_config_evaluate"
89 "int" ; int snd_config_evaluate
90 "void*" ; snd_config_t *config
91 "void*" ; snd_config_t *root
92 "void*" ;snd_config_t *private_data
93 "void*" ;snd_config_t **result
97 ;; Term: (snd_config_get_id NODE)
98 ; Returns the id string for a configuration node.
100 ;; Function: int snd_config_get_id(char** id)
101 ;; [in] const snd_config_t *config - Handle to the configuration node.
102 ;; [out] config, const char **value - node id
103 ; Returns 0 if successful, otherwise a negative error code. The
104 ; returned string is owned by the configuration node; the application
105 ; must not modify or delete it, and the string becomes invalid when
106 ; the node's id changes or when the node is freed. If the node does
107 ; not have an id, *id is set to NULL.
109 ; The import is wrapped to return the id string or (negative) error
111 (import** LIB "snd_config_get_id"
112 "int" ;; int snd_config_get_id
113 "void*" ; [in] const snd_config_t *config,
114 (get-string-safe) ; [out] const char **id
117 ;; Function: int snd_config_get_integer(snd_config_t *node,int *value)
118 ; Returns the value of an integer ("lu") configuration node.
120 ; @param node - the configuration node concerned.
122 ; @param value - pointer for the return value.
124 ; The import is wrapped to return the integer as such, or (negative)
126 (import** LIB "snd_config_get_integer"
127 "int" ; int snd_config_get_integer
128 "void*" ; const snd_config_t *config,
132 ;; Function: int snd_config_get_integer64
133 ; [in] snd_config_t *config
134 ; [out] int64_t *value
136 ; Returns the value of a 64-bit-integer ("Lu") configuration node.
138 ; The import is wrapped to return the integer as such, or (negative)
140 (import** LIB "snd_config_get_integer64"
141 "int" ; int snd_config_get_integer64
142 "void*" ; const snd_config_t *config,
143 () ; long long *value
146 ;; Function: int snd_config_get_real
147 ;; [in] const snd_config_t *node
148 ;; [out] double *value
150 ; Returns the value of a real-number configuration node.
152 ; The import is wrapped to return the double as such, or (negative)
154 (import** LIB "snd_config_get_real"
155 "int" ; int snd_config_get_real
156 "void*" ; const snd_config_t *node,
157 ("lf") ; double *value
160 ; Returns the value of a real or integer configuration node as double. More...
161 ;; API function to return the double as such, or (negative) error code.
162 (import** LIB "snd_config_get_ireal"
163 "int" ; int snd_config_get_real
164 "void*" ; const snd_config_t *config,
165 ("lf") ; double *value)
168 ; Returns the value of a string configuration node. The returned
169 ; string is owned by the configuration node; the application must not
170 ; modify or delete it, and the string becomes invalid when the node's
171 ; value changes or when the node is freed.
173 ;; API function to return the string (copied), or (negative) error
175 (import** LIB "snd_config_get_string"
176 "int" ; int snd_config_get_string (
177 "void*" ; const snd_config_t *config,
178 (get-string) ; const char **value)
181 ;; int snd_config_get_ascii (const snd_config_t *config, char **value)
182 ; Returns the value of a configuration node as a string. This function
183 ; dynamically allocates the returned string. The application is
184 ; responsible for deleting it with free() when it is no longer used.
185 ; For a string node with NULL value, the returned string is NULL.
188 ; Returns the value of a pointer configuration node.
190 ;; API function to return the pointer (value), or (negative) error.
191 (import** LIB "snd_config_get_pointer"
192 "int" ; int snd_config_get_pointer (
193 "void*" ; const snd_config_t *config,
194 () ; const void **value)
197 ; Returns the type of a configuration node.
198 (import LIB "snd_config_get_type"
199 "unsigned int" ; snd_config_type_t snd_config_get_type
200 "void*" ; const snd_config_t *config
203 ; Returns count of items in array, zero when the compound is not an
204 ; array, otherwise a negative error code.
205 (import LIB "snd_config_is_array"
206 "int" ; int snd_config_is_array
207 "void*" ; const snd_config_t *config
210 ;; ------- iterator functions --------
212 ; Returns an iterator pointing to a node's first child. More...
213 (import LIB "snd_config_iterator_first"
214 "void*" ;; snd_config_iterator_t snd_config_iterator_first
215 "void*" ; const snd_config_t *node
218 ; Returns an iterator pointing to the next sibling. More...
219 (import LIB "snd_config_iterator_next"
220 "void*" ; snd_config_iterator_t snd_config_iterator_next
221 "void*" ; const snd_config_iterator_t iterator
224 ; Returns an iterator that ends a node's children list.
226 ; [in] config Handle to a configuration node.
228 ; Returns n iterator that indicates the end of config's children list.
229 ; config must be a compound node. The return value can be understood
230 ; as pointing past the last child of config.
231 (import LIB "snd_config_iterator_end"
232 "void*" ; snd_config_iterator_t snd_config_iterator_end
233 "void*" ; const snd_config_t *config
236 ; Returns the configuration node handle pointed to by an iterator.
237 (import LIB "snd_config_iterator_entry"
238 "void*" ; snd_config_t * snd_config_iterator_entry
239 "void*" ; const snd_config_iterator_t iterator
242 ;;======================================================================
245 ;; Term: (iterate NODE)
246 ; Make a list of a compound node's children by iterating over them.
247 (define (iterate NODE)
248 (let ((CUR (snd_config_iterator_first NODE))
249 (END (snd_config_iterator_end NODE))
252 (push (traverse (snd_config_iterator_entry CUR)) RES -1)
253 (setf CUR (snd_config_iterator_next CUR)))
254 (if (snd_config_is_array NODE)
255 (map list (sequence 0 (- (length RES) 1)) RES)
258 ;; Term: (traverse NODE)
259 ; Return the pair (ID value) for a node. The value of a compound node
260 ; is the list of its child nodes.
261 (define (traverse NODE)
262 (let ((TYPE (snd_config_get_type NODE))
263 (ID (snd_config_get_id NODE)))
266 (0 (snd_config_get_integer NODE))
267 (1 (snd_config_get_integer64 NODE))
268 (2 (snd_config_get_real NODE))
269 (3 (snd_config_get_string NODE))
270 (4 (snd_config_get_integer NODE))
271 (5 (sym (string ">" (snd_config_get_pointer NODE))))
272 (1024 (iterate NODE))
273 (true (list 'unknown NODE TYPE))))))
277 "libasound-config.lsp"