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
96 ;; Function: int snd_config_search
97 ;; [in] snd_config_t *config = root of the configuration (sub)tree to search
98 ;; [in] const char *key = one or more node ids, separated with dots
99 ;; [out] snd_config_t **result
100 ; This function searches for a child node of config that is identified
101 ; by key, which contains either the id of a direct child node of
102 ; config, or a series of ids, separated with dots, where each id
103 ; specifies a node that is contained in the previous compound node.
104 ;; Returns 0 on success.
105 (import LIB "snd_config_search"
106 "int" ; int snd_config_search
107 "void*" ; snd_config_t *config
108 "char*" ; const char *key
109 "void*" ; snd_config_t **result
112 ;; Term: (snd_config_get_id NODE)
113 ; Returns the id string for a configuration node.
115 ;; Function: int snd_config_get_id(char** id)
116 ;; [in] const snd_config_t *config - Handle to the configuration node.
117 ;; [out] config, const char **value - node id
118 ; Returns 0 if successful, otherwise a negative error code. The
119 ; returned string is owned by the configuration node; the application
120 ; must not modify or delete it, and the string becomes invalid when
121 ; the node's id changes or when the node is freed. If the node does
122 ; not have an id, *id is set to NULL.
124 ; The import is wrapped to return the id string or (negative) error
126 (import** LIB "snd_config_get_id"
127 "int" ;; int snd_config_get_id
128 "void*" ; [in] const snd_config_t *config,
129 (get-string-safe) ; [out] const char **id
132 ;; Function: int snd_config_get_integer(snd_config_t *node,int *value)
133 ; Returns the value of an integer ("lu") configuration node.
135 ; @param node - the configuration node concerned.
137 ; @param value - pointer for the return value.
139 ; The import is wrapped to return the integer as such, or (negative)
141 (import** LIB "snd_config_get_integer"
142 "int" ; int snd_config_get_integer
143 "void*" ; const snd_config_t *config,
147 ;; Function: int snd_config_get_integer64
148 ; [in] snd_config_t *config
149 ; [out] int64_t *value
151 ; Returns the value of a 64-bit-integer ("Lu") configuration node.
153 ; The import is wrapped to return the integer as such, or (negative)
155 (import** LIB "snd_config_get_integer64"
156 "int" ; int snd_config_get_integer64
157 "void*" ; const snd_config_t *config,
158 () ; long long *value
161 ;; Function: int snd_config_get_real
162 ;; [in] const snd_config_t *node
163 ;; [out] double *value
165 ; Returns the value of a real-number configuration node.
167 ; The import is wrapped to return the double as such, or (negative)
169 (import** LIB "snd_config_get_real"
170 "int" ; int snd_config_get_real
171 "void*" ; const snd_config_t *node,
172 ("lf") ; double *value
175 ; Returns the value of a real or integer configuration node as double.
176 ; API function to return the double as such, or (negative) error code.
177 (import** LIB "snd_config_get_ireal"
178 "int" ; int snd_config_get_real
179 "void*" ; const snd_config_t *config,
180 ("lf") ; double *value)
183 ; Returns the value of a string configuration node. The returned
184 ; string is owned by the configuration node; the application must not
185 ; modify or delete it, and the string becomes invalid when the node's
186 ; value changes or when the node is freed.
188 ;; API function to return the string (copied), or (negative) error
190 (import** LIB "snd_config_get_string"
191 "int" ; int snd_config_get_string (
192 "void*" ; const snd_config_t *config,
193 (get-string) ; const char **value)
196 ; Changes the value of a string configuration node. function deletes
197 ; the old string in the node and stores a copy of value string in the
198 ; node. Returns 0 if successful, otherwise a negative error code.
199 (import LIB "snd_config_set_string"
200 "int" ; int snd_config_set_string(
201 "void*" ; snd_config_t *config,
202 "char*" ; const char *value )
205 ;; int snd_config_get_ascii (const snd_config_t *config, char **value)
206 ; Returns the value of a configuration node as a string. This function
207 ; dynamically allocates the returned string. The application is
208 ; responsible for deleting it with free() when it is no longer used.
209 ; For a string node with NULL value, the returned string is NULL.
211 ; Returns the value of a pointer configuration node.
213 ;; API function to return the pointer (value), or (negative) error.
214 (import** LIB "snd_config_get_pointer"
215 "int" ; int snd_config_get_pointer (
216 "void*" ; const snd_config_t *config,
217 () ; const void **value)
220 ; Returns the type of a configuration node.
221 (import LIB "snd_config_get_type"
222 "unsigned int" ; snd_config_type_t snd_config_get_type
223 "void*" ; const snd_config_t *config
226 ; Returns count of items in array, zero when the compound is not an
227 ; array, otherwise a negative error code.
228 (import LIB "snd_config_is_array"
229 "int" ; int snd_config_is_array
230 "void*" ; const snd_config_t *config
233 ;; ------- iterator functions --------
235 ; Returns an iterator pointing to a node's first child. More...
236 (import LIB "snd_config_iterator_first"
237 "void*" ;; snd_config_iterator_t snd_config_iterator_first
238 "void*" ; const snd_config_t *node
241 ; Returns an iterator pointing to the next sibling. More...
242 (import LIB "snd_config_iterator_next"
243 "void*" ; snd_config_iterator_t snd_config_iterator_next
244 "void*" ; const snd_config_iterator_t iterator
247 ; Returns an iterator that ends a node's children list.
249 ; [in] config Handle to a configuration node.
251 ; Returns n iterator that indicates the end of config's children list.
252 ; config must be a compound node. The return value can be understood
253 ; as pointing past the last child of config.
254 (import LIB "snd_config_iterator_end"
255 "void*" ; snd_config_iterator_t snd_config_iterator_end
256 "void*" ; const snd_config_t *config
259 ; Returns the configuration node handle pointed to by an iterator.
260 (import LIB "snd_config_iterator_entry"
261 "void*" ; snd_config_t * snd_config_iterator_entry
262 "void*" ; const snd_config_iterator_t iterator
267 ;;======================================================================
270 ;; Term: (iterate NODE)
271 ; Make a list of a compound node's children by iterating over them.
272 (define (iterate NODE)
273 (let ((CUR (snd_config_iterator_first NODE))
274 (END (snd_config_iterator_end NODE))
277 (push (traverse (snd_config_iterator_entry CUR)) RES -1)
278 (setf CUR (snd_config_iterator_next CUR)))
279 (if (snd_config_is_array NODE)
280 (map list (sequence 0 (- (length RES) 1)) RES)
283 ;; Term: (traverse NODE)
284 ; Return the pair (ID value) for a node. The value of a compound node
285 ; is the list of its child nodes.
286 (define (traverse NODE)
287 (let ((TYPE (snd_config_get_type NODE))
288 (ID (snd_config_get_id NODE)))
291 (0 (snd_config_get_integer NODE))
292 (1 (snd_config_get_integer64 NODE))
293 (2 (snd_config_get_real NODE))
294 (3 (snd_config_get_string NODE))
295 (4 (snd_config_get_integer NODE))
296 (5 (sym (string ">" (snd_config_get_pointer NODE))))
297 (1024 (iterate NODE))
298 (true (list 'unknown NODE TYPE))))))
300 "libasound-config.lsp"