From e02f9a96501449292e307eb68c7742b7a4e08ca2 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 13 Feb 2001 14:07:28 +0000 Subject: [PATCH] Definitely fixed the sorting/find problems for hcontrol & mixer. --- include/mixer.h | 2 +- src/control/hcontrol.c | 19 +++++++++---------- src/mixer/mixer.c | 8 ++++---- src/mixer/simple.c | 15 ++++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/mixer.h b/include/mixer.h index fc47c986..0ce702d6 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -50,7 +50,7 @@ int snd_mixer_wait(snd_mixer_t *mixer, int timeout); int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort); snd_mixer_elem_t *snd_mixer_elem_next(snd_mixer_elem_t *elem); -snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *helem); +snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *elem); int snd_mixer_class_unregister(snd_mixer_class_t *clss); diff --git a/src/control/hcontrol.c b/src/control/hcontrol.c index 7b24ccd7..f16ce8dd 100644 --- a/src/control/hcontrol.c +++ b/src/control/hcontrol.c @@ -99,9 +99,9 @@ static int _snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id, in while (l < u) { idx = (l + u) / 2; c = hctl->compare((snd_hctl_elem_t *) id, hctl->pelems[idx]); - if (c > 0) + if (c < 0) u = idx; - else if (c < 0) + else if (c > 0) l = idx + 1; else break; @@ -148,9 +148,9 @@ static int snd_hctl_elem_add(snd_hctl_t *hctl, snd_hctl_elem_t *elem) assert(dir != 0); if (dir > 0) { list_add(&elem->list, &hctl->pelems[idx]->list); + idx++; } else { list_add_tail(&elem->list, &hctl->pelems[idx]->list); - idx++; } memmove(hctl->pelems + idx + 1, hctl->pelems + idx, @@ -221,7 +221,7 @@ static int snd_hctl_compare_mixer_priority_lookup(char **name, char * const *nam *name += strlen(*names); if (**name == ' ') (*name)++; - return res; + return res+1; } } return NOT_FOUND; @@ -231,16 +231,11 @@ static int snd_hctl_compare_mixer_priority(const char *name) { static char *names[] = { "Master", - "Master Digital", - "Master Mono", "Hardware Master", "Headphone", "Tone Control", "3D Control", "PCM", - "PCM Front", - "PCM Rear", - "PCM Pan", "Synth", "FM", "Wave", @@ -254,7 +249,6 @@ static int snd_hctl_compare_mixer_priority(const char *name) "PC Speaker", "Aux", "Mono", - "Mono Output", "ADC", "Capture Source", "Capture", @@ -272,6 +266,11 @@ static int snd_hctl_compare_mixer_priority(const char *name) "Playback", "Capture", "Bypass", + "Mono", + "Front", + "Rear", + "Pan", + "Output", NULL }; static char *names2[] = { diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index ea58ab3c..576d350c 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -233,9 +233,9 @@ static int _snd_mixer_find_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem, int while (l < u) { idx = (l + u) / 2; c = mixer->compare(elem, mixer->pelems[idx]); - if (c > 0) + if (c < 0) u = idx; - else if (c < 0) + else if (c > 0) l = idx + 1; else break; @@ -268,9 +268,9 @@ int snd_mixer_elem_add(snd_mixer_elem_t *elem, snd_mixer_class_t *class) assert(dir != 0); if (dir > 0) { list_add(&elem->list, &mixer->pelems[idx]->list); + idx++; } else { list_add_tail(&elem->list, &mixer->pelems[idx]->list); - idx++; } memmove(mixer->pelems + idx + 1, mixer->pelems + idx, @@ -431,7 +431,7 @@ static int snd_mixer_sort(snd_mixer_t *mixer) assert(mixer); assert(mixer->compare); INIT_LIST_HEAD(&mixer->elems); - qsort(mixer->pelems, mixer->count, sizeof(snd_mixer_elem_t), compar); + qsort(mixer->pelems, mixer->count, sizeof(snd_mixer_elem_t*), compar); for (k = 0; k < mixer->count; k++) list_add_tail(&mixer->pelems[k]->list, &mixer->elems); return 0; diff --git a/src/mixer/simple.c b/src/mixer/simple.c index 889cad04..ce906fa4 100644 --- a/src/mixer/simple.c +++ b/src/mixer/simple.c @@ -97,13 +97,11 @@ static const char *get_short_name(const char *lname) static int get_compare_weight(const char *name, int index) { static char *names[] = { + "Master", "Master Mono", "Master Digital", - "Master", - "Tone Control - Bass", - "Tone Control - Treble", - "Synth Tone Control - Bass", - "Synth Tone Control - Treble", + "Bass", + "Treble", "PCM", "Surround", "Synth", @@ -692,6 +690,7 @@ int simple_add1(snd_mixer_class_t *class, const char *name, melem->private_data = simple; melem->private_free = selem_free; INIT_LIST_HEAD(&melem->helems); + melem->compare_weight = get_compare_weight(simple->id.name, simple->id.index); new = 1; } else { simple = melem->private_data; @@ -712,7 +711,6 @@ int simple_add1(snd_mixer_class_t *class, const char *name, err = snd_mixer_elem_attach(melem, helem); if (err < 0) return err; - melem->compare_weight = get_compare_weight(simple->id.name, simple->id.index); err = simple_update(melem); assert(err >= 0); if (new) @@ -812,7 +810,10 @@ static int simple_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2 { selem_t *s1 = c1->private_data; selem_t *s2 = c2->private_data; - return strcmp(s1->id.name, s2->id.name); + int res = strcmp(s1->id.name, s2->id.name); + if (res) + return res; + return s1->id.index - s2->id.index; } int snd_mixer_selem_register(snd_mixer_t *mixer, snd_mixer_class_t **classp) -- 2.47.1