From adbc93f1a413128b59bd1f6037098c56489a07cf Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 29 Jul 2003 13:19:19 +0000 Subject: [PATCH] More alisp extensions (card related functions, ctl_card_info). --- alsalisp/hctl.lisp | 35 ++++++--- include/control.h | 2 +- include/error.h | 1 + src/alisp/alisp.c | 2 +- src/alisp/alisp_snd.c | 161 ++++++++++++++++++++++++++++++++++++++++-- src/control/control.c | 32 ++++----- 6 files changed, 198 insertions(+), 35 deletions(-) diff --git a/alsalisp/hctl.lisp b/alsalisp/hctl.lisp index 67e36317..af136664 100644 --- a/alsalisp/hctl.lisp +++ b/alsalisp/hctl.lisp @@ -1,14 +1,23 @@ -(setq ctl (acall 'ctl_open ('default nil))) -(setq ctl (car (cdr ctl))) -(setq hctl (acall 'hctl_open_ctl ctl)) -(setq hctl (car (cdr hctl))) -(setq hctl (acall 'hctl_close hctl)) +(setq card (acall 'card_next -1)) +(setq card (aresult card)) +(while (>= card 0) + (progn + (princ "found card: " card "\n") + (princ " name : " (aresult (acall 'card_get_name card)) "\n") + (princ " longname: " (aresult (acall 'card_get_longname card)) "\n") + (setq card (acall 'card_next card)) + (setq card (aresult card)) + ) +) + +(princ "card_get_index test (SI7018): " (acall 'card_get_index "SI7018") "\n") +(princ "card_get_index test (ABCD): " (acall 'card_get_index "ABCD") "\n") (setq hctl (acall 'hctl_open ('default nil))) -(if (= (car hctl) 0) +(if (= (aerror hctl) 0) (progn (princ "open success: " hctl "\n") - (setq hctl (car (cdr hctl))) + (setq hctl (ahandle hctl)) (princ "open hctl: " hctl "\n") (setq hctl (acall 'hctl_close hctl)) (if (= hctl 0) @@ -22,15 +31,18 @@ ) (setq ctl (acall 'ctl_open ('default nil))) -(if (= (car ctl) 0) +(if (= (aerror ctl) 0) (progn (princ "ctl open success: " ctl "\n") - (setq ctl (car (cdr ctl))) + (setq ctl (ahandle ctl)) + (setq info (aresult (acall 'ctl_card_info ctl))) + (princ "ctl card info: " info "\n") + (princ "ctl card info (mixername): " (cdr (assq "mixername" info)) "\n") (setq hctl (acall 'hctl_open_ctl ctl)) - (if (= (car hctl) 0) + (if (= (aerror hctl) 0) (progn (princ "hctl open success: " hctl "\n") - (setq hctl (car (cdr hctl))) + (setq hctl (ahandle hctl)) (princ "open hctl: " hctl "\n") (setq hctl (acall 'hctl_close hctl)) (if (= hctl 0) @@ -40,6 +52,7 @@ ) (progn (princ "hctl open failed: " ctl "\n") + (acall 'ctl_close ctl) ) ) ) diff --git a/include/control.h b/include/control.h index a4f5e5b9..b26ab75c 100644 --- a/include/control.h +++ b/include/control.h @@ -232,7 +232,6 @@ int snd_ctl_wait(snd_ctl_t *ctl, int timeout); const char *snd_ctl_name(snd_ctl_t *ctl); snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl); -void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size); const char *snd_ctl_elem_type_name(snd_ctl_elem_type_t type); const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface); const char *snd_ctl_event_type_name(snd_ctl_event_type_t type); @@ -402,6 +401,7 @@ void snd_ctl_elem_value_set_integer(snd_ctl_elem_value_t *obj, unsigned int idx, void snd_ctl_elem_value_set_integer64(snd_ctl_elem_value_t *obj, unsigned int idx, long long val); void snd_ctl_elem_value_set_enumerated(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned int val); void snd_ctl_elem_value_set_byte(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned char val); +void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size); const void * snd_ctl_elem_value_get_bytes(const snd_ctl_elem_value_t *obj); void snd_ctl_elem_value_get_iec958(const snd_ctl_elem_value_t *obj, snd_aes_iec958_t *ptr); void snd_ctl_elem_value_set_iec958(snd_ctl_elem_value_t *obj, const snd_aes_iec958_t *ptr); diff --git a/include/error.h b/include/error.h index c1915bd1..b3413a16 100644 --- a/include/error.h +++ b/include/error.h @@ -40,6 +40,7 @@ extern "C" { #define SND_ERROR_BEGIN 500000 /**< Lower boundary of sound error codes. */ #define SND_ERROR_INCOMPATIBLE_VERSION (SND_ERROR_BEGIN+0) /**< Kernel/library protocols are not compatible. */ +#define SND_ERROR_ALISP_NIL (SND_ERROR_BEGIN+1) /**< Lisp encountered an error during acall. */ const char *snd_strerror(int errnum); diff --git a/src/alisp/alisp.c b/src/alisp/alisp.c index e11a76f3..6d3f15d7 100644 --- a/src/alisp/alisp.c +++ b/src/alisp/alisp.c @@ -1350,7 +1350,7 @@ static inline int eq(struct alisp_object * p1, struct alisp_object * p2) static int equal(struct alisp_object * p1, struct alisp_object * p2) { - if (eq(p1, p1)) + if (eq(p1, p2)) return 1; if (p1->type == ALISP_OBJ_CONS || p2->type == ALISP_OBJ_CONS) diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index 8bada801..414f4115 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -97,6 +97,46 @@ static const void *get_ptr(struct alisp_object * obj, const char *_ptr_id) return get_pointer(cdr(obj)); } +static struct alisp_object * new_lexpr(struct alisp_instance * instance, int err) +{ + struct alisp_object * lexpr; + + lexpr = new_object(instance, ALISP_OBJ_CONS); + if (lexpr == NULL) + return NULL; + lexpr->value.c.car = new_integer(instance, err); + if (lexpr->value.c.car == NULL) + return NULL; + lexpr->value.c.cdr = new_object(instance, ALISP_OBJ_CONS); + if (lexpr->value.c.cdr == NULL) + return NULL; + return lexpr; +} + +static struct alisp_object * add_cons(struct alisp_instance * instance, struct alisp_object *lexpr, int cdr, const char *id, struct alisp_object *obj) +{ + struct alisp_object * p1; + + if (lexpr == NULL || obj == NULL) + return NULL; + if (cdr) { + p1 = lexpr->value.c.cdr = new_object(instance, ALISP_OBJ_CONS); + } else { + p1 = lexpr->value.c.car = new_object(instance, ALISP_OBJ_CONS); + } + lexpr = p1; + if (p1 == NULL) + return NULL; + p1->value.c.car = new_object(instance, ALISP_OBJ_CONS); + if ((p1 = p1->value.c.car) == NULL) + return NULL; + p1->value.c.car = new_string(instance, id); + if (p1->value.c.car == NULL) + return NULL; + p1->value.c.cdr = obj; + return lexpr; +} + static inline struct alisp_object * new_result(struct alisp_instance * instance, int err) { return new_integer(instance, err); @@ -114,17 +154,40 @@ static struct alisp_object * new_result1(struct alisp_instance * instance, int e lexpr->value.c.car = new_integer(instance, err); if (lexpr->value.c.car == NULL) return NULL; - p1 = lexpr->value.c.cdr = new_object(instance, ALISP_OBJ_CONS); + p1 = add_cons(instance, lexpr, 1, ptr_id, new_pointer(instance, ptr)); if (p1 == NULL) return NULL; - p1->value.c.car = new_object(instance, ALISP_OBJ_CONS); - if ((p1 = p1->value.c.car) == NULL) + return lexpr; +} + +static struct alisp_object * new_result2(struct alisp_instance * instance, int err, int val) +{ + struct alisp_object * lexpr, * p1; + + if (err < 0) + val = 0; + lexpr = new_lexpr(instance, err); + if (lexpr == NULL) return NULL; - p1->value.c.car = new_string(instance, ptr_id); + p1 = lexpr->value.c.cdr; + p1->value.c.car = new_integer(instance, val); if (p1->value.c.car == NULL) return NULL; - p1->value.c.cdr = new_pointer(instance, ptr); - if (p1->value.c.cdr == NULL) + return lexpr; +} + +static struct alisp_object * new_result3(struct alisp_instance * instance, int err, const char *str) +{ + struct alisp_object * lexpr, * p1; + + if (err < 0) + str = ""; + lexpr = new_lexpr(instance, err); + if (lexpr == NULL) + return NULL; + p1 = lexpr->value.c.cdr; + p1->value.c.car = new_string(instance, str); + if (p1->value.c.car == NULL) return NULL; return lexpr; } @@ -140,6 +203,9 @@ static struct alisp_object * new_result1(struct alisp_instance * instance, int e typedef int (*snd_xxx_open_t)(void **rctl, const char *name, int mode); typedef int (*snd_xxx_open1_t)(void **rctl, void *handle); typedef int (*snd_xxx_close_t)(void **rctl); +typedef int (*snd_int_intp_t)(int *val); +typedef int (*snd_int_str_t)(const char *str); +typedef int (*snd_int_int_strp_t)(int val, char **str); static struct alisp_object * FA_xxx_open(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) { @@ -187,11 +253,78 @@ static struct alisp_object * FA_xxx_close(struct alisp_instance * instance, stru return new_result(instance, ((snd_xxx_close_t)item->xfunc)(handle)); } +static struct alisp_object * FA_int_intp(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) +{ + int val, err; + + args = eval(instance, args); + if (args->type != ALISP_OBJ_INTEGER) + return &alsa_lisp_nil; + val = args->value.i; + err = ((snd_int_intp_t)item->xfunc)(&val); + return new_result2(instance, err, val); +} + +static struct alisp_object * FA_int_str(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) +{ + int err; + + args = eval(instance, args); + if (args->type != ALISP_OBJ_STRING && args->type != ALISP_OBJ_IDENTIFIER) + return &alsa_lisp_nil; + err = ((snd_int_str_t)item->xfunc)(args->value.s); + return new_result(instance, err); +} + +static struct alisp_object * FA_int_int_strp(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) +{ + int err; + char *str; + + args = eval(instance, args); + if (args->type != ALISP_OBJ_INTEGER) + return &alsa_lisp_nil; + err = ((snd_int_int_strp_t)item->xfunc)(args->value.i, &str); + return new_result3(instance, err, str); +} + +static struct alisp_object * FA_card_info(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) +{ + snd_ctl_t *handle; + struct alisp_object * lexpr, * p1; + snd_ctl_card_info_t *info; + int err; + + args = eval(instance, args); + handle = (snd_ctl_t *)get_ptr(args, item->prefix); + if (handle == NULL) + return &alsa_lisp_nil; + snd_ctl_card_info_alloca(&info); + err = snd_ctl_card_info(handle, info); + lexpr = new_lexpr(instance, err); + if (err < 0) + return lexpr; + p1 = add_cons(instance, lexpr->value.c.cdr, 0, "id", new_string(instance, snd_ctl_card_info_get_id(info))); + p1 = add_cons(instance, p1, 1, "driver", new_string(instance, snd_ctl_card_info_get_driver(info))); + p1 = add_cons(instance, p1, 1, "name", new_string(instance, snd_ctl_card_info_get_name(info))); + p1 = add_cons(instance, p1, 1, "longname", new_string(instance, snd_ctl_card_info_get_longname(info))); + p1 = add_cons(instance, p1, 1, "mixername", new_string(instance, snd_ctl_card_info_get_mixername(info))); + p1 = add_cons(instance, p1, 1, "components", new_string(instance, snd_ctl_card_info_get_components(info))); + if (p1 == NULL) + return NULL; + return lexpr; +} + /* * main code */ static struct acall_table acall_table[] = { + { "card_get_index", &FA_int_str, (void *)snd_card_get_index, NULL }, + { "card_get_longname", &FA_int_int_strp, (void *)snd_card_get_longname, NULL }, + { "card_get_name", &FA_int_int_strp, (void *)snd_card_get_name, NULL }, + { "card_next", &FA_int_intp, (void *)&snd_card_next, NULL }, + { "ctl_card_info", &FA_card_info, NULL, "ctl" }, { "ctl_close", &FA_xxx_close, (void *)&snd_ctl_close, "ctl" }, { "ctl_open", &FA_xxx_open, (void *)&snd_ctl_open, "ctl" }, { "hctl_close", &FA_xxx_close, (void *)&snd_hctl_close, "hctl" }, @@ -223,6 +356,22 @@ static struct alisp_object * F_acall(struct alisp_instance *instance, struct ali return &alsa_lisp_nil; } +static struct alisp_object * F_ahandle(struct alisp_instance *instance ATTRIBUTE_UNUSED, struct alisp_object * args) +{ + return car(cdr(eval(instance, car(args)))); +} + +static struct alisp_object * F_aerror(struct alisp_instance *instance, struct alisp_object * args) +{ + args = car(eval(instance, car(args))); + if (args == &alsa_lisp_nil) + return new_integer(instance, SND_ERROR_ALISP_NIL); + return args; +} + static struct intrinsic snd_intrinsics[] = { { "acall", F_acall }, + { "aerror", F_aerror }, + { "ahandle", F_ahandle }, + { "aresult", F_ahandle }, }; diff --git a/src/control/control.c b/src/control/control.c index 7a144204..32f3e177 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -649,22 +649,6 @@ int snd_ctl_open_lconf(snd_ctl_t **ctlp, const char *name, return snd_ctl_open_noupdate(ctlp, lconf, name, mode); } -/** - * \brief Set CTL element #SND_CTL_ELEM_TYPE_BYTES value - * \param ctl CTL handle - * \param data Bytes value - * \param size Size in bytes - */ -void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size) -{ - assert(obj); - if (size >= sizeof(obj->value.bytes.data)) { - assert(0); - return; - } - memcpy(obj->value.bytes.data, data, size); -} - #ifndef DOC_HIDDEN #define TYPE(v) [SND_CTL_ELEM_TYPE_##v] = #v #define IFACE(v) [SND_CTL_ELEM_IFACE_##v] = #v @@ -2211,6 +2195,22 @@ void snd_ctl_elem_value_set_byte(snd_ctl_elem_value_t *obj, unsigned int idx, un obj->value.bytes.data[idx] = val; } +/** + * \brief Set CTL element #SND_CTL_ELEM_TYPE_BYTES value + * \param ctl CTL handle + * \param data Bytes value + * \param size Size in bytes + */ +void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size) +{ + assert(obj); + if (size >= sizeof(obj->value.bytes.data)) { + assert(0); + return; + } + memcpy(obj->value.bytes.data, data, size); +} + /** * \brief Get value for a #SND_CTL_ELEM_TYPE_BYTES CTL element id/value * \param obj CTL element id/value -- 2.47.1