Added INTEGER64 support by Paul Davis

This commit is contained in:
Jaroslav Kysela 2002-05-13 09:54:24 +00:00
parent 133c82b4d9
commit bd2c771ca9
2 changed files with 122 additions and 0 deletions

View file

@ -105,6 +105,26 @@ static int snd_config_integer_add(snd_config_t *father, char *id, long integer)
return 0; return 0;
} }
static int snd_config_integer64_add(snd_config_t *father, char *id, long long integer)
{
int err;
snd_config_t *leaf;
err = snd_config_make_integer64(&leaf, id);
if (err < 0)
return err;
err = snd_config_add(father, leaf);
if (err < 0) {
snd_config_delete(leaf);
return err;
}
err = snd_config_set_integer64(leaf, integer);
if (err < 0) {
snd_config_delete(leaf);
return err;
}
return 0;
}
static int snd_config_string_add(snd_config_t *father, const char *id, const char *string) static int snd_config_string_add(snd_config_t *father, const char *id, const char *string)
{ {
int err; int err;
@ -236,6 +256,22 @@ static int get_control(snd_ctl_t *handle, snd_ctl_elem_id_t *id, snd_config_t *t
} }
break; break;
} }
case SND_CTL_ELEM_TYPE_INTEGER64:
{
long long min = snd_ctl_elem_info_get_min64(info);
long long max = snd_ctl_elem_info_get_max64(info);
long long step = snd_ctl_elem_info_get_step64(info);
if (step)
sprintf(buf, "%Li - %Li (step %Li)", min, max, step);
else
sprintf(buf, "%Li - %Li", min, max);
err = snd_config_string_add(comment, "range", buf);
if (err < 0) {
error("snd_config_string_add: %s", snd_strerror(err));
return err;
}
break;
}
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
{ {
unsigned int items; unsigned int items;
@ -339,6 +375,13 @@ static int get_control(snd_ctl_t *handle, snd_ctl_elem_id_t *id, snd_config_t *t
return err; return err;
} }
return 0; return 0;
case SND_CTL_ELEM_TYPE_INTEGER64:
err = snd_config_integer64_add(control, "value", snd_ctl_elem_value_get_integer64(ctl, 0));
if (err < 0) {
error("snd_config_integer64_add: %s", snd_strerror(err));
return err;
}
return 0;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
{ {
unsigned int v = snd_ctl_elem_value_get_enumerated(ctl, 0); unsigned int v = snd_ctl_elem_value_get_enumerated(ctl, 0);
@ -386,6 +429,15 @@ static int get_control(snd_ctl_t *handle, snd_ctl_elem_id_t *id, snd_config_t *t
} }
} }
break; break;
case SND_CTL_ELEM_TYPE_INTEGER64:
for (idx = 0; idx < count; idx++) {
err = snd_config_integer64_add(value, num_str(idx), snd_ctl_elem_value_get_integer64(ctl, idx));
if (err < 0) {
error("snd_config_integer64_add: %s", snd_strerror(err));
return err;
}
}
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
for (idx = 0; idx < count; idx++) { for (idx = 0; idx < count; idx++) {
unsigned int v = snd_ctl_elem_value_get_enumerated(ctl, idx); unsigned int v = snd_ctl_elem_value_get_enumerated(ctl, idx);
@ -519,12 +571,16 @@ static int get_controls(int cardno, snd_config_t *top)
static int config_iface(snd_config_t *n) static int config_iface(snd_config_t *n)
{ {
unsigned long i; unsigned long i;
unsigned long long li;
snd_ctl_elem_iface_t idx; snd_ctl_elem_iface_t idx;
const char *str; const char *str;
switch (snd_config_get_type(n)) { switch (snd_config_get_type(n)) {
case SND_CONFIG_TYPE_INTEGER: case SND_CONFIG_TYPE_INTEGER:
snd_config_get_integer(n, &i); snd_config_get_integer(n, &i);
return i; return i;
case SND_CONFIG_TYPE_INTEGER64:
snd_config_get_integer64(n, &li);
return i;
case SND_CONFIG_TYPE_STRING: case SND_CONFIG_TYPE_STRING:
snd_config_get_string(n, &str); snd_config_get_string(n, &str);
break; break;
@ -542,12 +598,18 @@ static int config_bool(snd_config_t *n)
{ {
const char *str; const char *str;
long val; long val;
long long lval;
switch (snd_config_get_type(n)) { switch (snd_config_get_type(n)) {
case SND_CONFIG_TYPE_INTEGER: case SND_CONFIG_TYPE_INTEGER:
snd_config_get_integer(n, &val); snd_config_get_integer(n, &val);
if (val < 0 || val > 1) if (val < 0 || val > 1)
return -1; return -1;
return val; return val;
case SND_CONFIG_TYPE_INTEGER64:
snd_config_get_integer64(n, &lval);
if (lval < 0 || lval > 1)
return -1;
return (int) lval;
case SND_CONFIG_TYPE_STRING: case SND_CONFIG_TYPE_STRING:
snd_config_get_string(n, &str); snd_config_get_string(n, &str);
break; break;
@ -566,11 +628,15 @@ static int config_enumerated(snd_config_t *n, snd_ctl_t *handle,
{ {
const char *str; const char *str;
long val; long val;
long long lval;
unsigned int idx, items; unsigned int idx, items;
switch (snd_config_get_type(n)) { switch (snd_config_get_type(n)) {
case SND_CONFIG_TYPE_INTEGER: case SND_CONFIG_TYPE_INTEGER:
snd_config_get_integer(n, &val); snd_config_get_integer(n, &val);
return val; return val;
case SND_CONFIG_TYPE_INTEGER64:
snd_config_get_integer64(n, &lval);
return (int) lval;
case SND_CONFIG_TYPE_STRING: case SND_CONFIG_TYPE_STRING:
snd_config_get_string(n, &str); snd_config_get_string(n, &str);
break; break;
@ -609,6 +675,7 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
long index = -1; long index = -1;
snd_config_t *value = NULL; snd_config_t *value = NULL;
long val; long val;
long long lval;
unsigned int idx; unsigned int idx;
int err; int err;
char *set; char *set;
@ -748,6 +815,13 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
goto _ok; goto _ok;
} }
break; break;
case SND_CTL_ELEM_TYPE_INTEGER64:
err = snd_config_get_integer64(value, &lval);
if (err == 0) {
snd_ctl_elem_value_set_integer64(ctl, 0, lval);
goto _ok;
}
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
val = config_enumerated(value, handle, info); val = config_enumerated(value, handle, info);
if (val >= 0) { if (val >= 0) {
@ -838,6 +912,14 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
} }
snd_ctl_elem_value_set_integer(ctl, idx, val); snd_ctl_elem_value_set_integer(ctl, idx, val);
break; break;
case SND_CTL_ELEM_TYPE_INTEGER64:
err = snd_config_get_integer64(n, &lval);
if (err < 0) {
error("bad control.%d.value.%d content", numid, idx);
return -EINVAL;
}
snd_ctl_elem_value_set_integer64(ctl, idx, lval);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
val = config_enumerated(n, handle, info); val = config_enumerated(n, handle, info);
if (val < 0) { if (val < 0) {

View file

@ -266,6 +266,31 @@ static long get_integer(char **ptr, long min, long max)
return tmp1; return tmp1;
} }
static long get_integer64(char **ptr, long long min, long long max)
{
long long tmp, tmp1, tmp2;
if (**ptr == ':')
(*ptr)++;
if (**ptr == '\0' || (!isdigit(**ptr) && **ptr != '-'))
return min;
tmp = strtol(*ptr, ptr, 10);
tmp1 = tmp;
tmp2 = 0;
if (**ptr == '.') {
(*ptr)++;
tmp2 = strtol(*ptr, ptr, 10);
}
if (**ptr == '%') {
tmp1 = convert_prange1(tmp, min, max);
(*ptr)++;
}
tmp1 = check_range(tmp1, min, max);
if (**ptr == ',')
(*ptr)++;
return tmp1;
}
static int get_volume_simple(char **ptr, int min, int max, int orig) static int get_volume_simple(char **ptr, int min, int max, int orig)
{ {
int tmp, tmp1, tmp2; int tmp, tmp1, tmp2;
@ -384,6 +409,12 @@ static int show_control(const char *space, snd_hctl_elem_t *elem,
snd_ctl_elem_info_get_max(info), snd_ctl_elem_info_get_max(info),
snd_ctl_elem_info_get_step(info)); snd_ctl_elem_info_get_step(info));
break; break;
case SND_CTL_ELEM_TYPE_INTEGER64:
printf(",min=%Li,max=%Li,step=%Li\n",
snd_ctl_elem_info_get_min64(info),
snd_ctl_elem_info_get_max64(info),
snd_ctl_elem_info_get_step64(info));
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
{ {
unsigned int items = snd_ctl_elem_info_get_items(info); unsigned int items = snd_ctl_elem_info_get_items(info);
@ -418,6 +449,9 @@ static int show_control(const char *space, snd_hctl_elem_t *elem,
case SND_CTL_ELEM_TYPE_INTEGER: case SND_CTL_ELEM_TYPE_INTEGER:
printf("%li", snd_ctl_elem_value_get_integer(control, idx)); printf("%li", snd_ctl_elem_value_get_integer(control, idx));
break; break;
case SND_CTL_ELEM_TYPE_INTEGER64:
printf("%Li", snd_ctl_elem_value_get_integer64(control, idx));
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
printf("%u", snd_ctl_elem_value_get_enumerated(control, idx)); printf("%u", snd_ctl_elem_value_get_enumerated(control, idx));
break; break;
@ -969,6 +1003,12 @@ static int cset(int argc, char *argv[], int roflag)
snd_ctl_elem_info_get_max(info)); snd_ctl_elem_info_get_max(info));
snd_ctl_elem_value_set_integer(control, idx, tmp); snd_ctl_elem_value_set_integer(control, idx, tmp);
break; break;
case SND_CTL_ELEM_TYPE_INTEGER64:
tmp = get_integer64(&ptr,
snd_ctl_elem_info_get_min64(info),
snd_ctl_elem_info_get_max64(info));
snd_ctl_elem_value_set_integer64(control, idx, tmp);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
tmp = get_integer(&ptr, 0, snd_ctl_elem_info_get_items(info) - 1); tmp = get_integer(&ptr, 0, snd_ctl_elem_info_get_items(info) - 1);
snd_ctl_elem_value_set_enumerated(control, idx, tmp); snd_ctl_elem_value_set_enumerated(control, idx, tmp);