Skip to contentSkip to conversation

dummy: allow disabling mixer controls

GIT PULL Clemens Ladisch 3 participants 7 messages Oct 20, 2012 – Oct 24, 2012 Sound

lore
Share & tools
lore
#0 lore raw

The following changes since commit a0d271cbfed1dd50278c6b06bead3d00ba0a88f9:

Linux 3.6 (2012-09-30 16:47:46 -0700)

are available in the git repository at:
git://git.alsa-project.org/alsa-kprivate.git dummy-ctl-inactive

----------------------------------------------------------------
Quite a few mixer applications do not handle deactivated controls correctly. This patch adds such controls to snd-dummy to make crash^H^H^H^H^Htesting these apps easier.
----------------------------------------------------------------
Clemens Ladisch (1):
ALSA: dummy: allow disabling mixer controls

 sound/drivers/dummy.c |   73 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 2 deletions(-)
sound/drivers/dummy.c +71 -2
index 54bb664..4f522cf 100644
@@ -134,6 +134,9 @@ struct snd_dummy {
 	spinlock_t mixer_lock;
 	int mixer_volume[MIXER_ADDR_LAST+1][2];
 	int capture_source[MIXER_ADDR_LAST+1][2];
+	int iobox;
+	struct snd_kcontrol *cd_volume_ctl;
+	struct snd_kcontrol *cd_switch_ctl;
 	const struct dummy_timer_ops *timer_ops;
 };
 
@@ -817,6 +820,57 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
 	return change;
 }
 
+static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_info *info)
+{
+	const char *const names[] = { "None", "CD Player" };
+
+	return snd_ctl_enum_info(info, 1, 2, names);
+}
+
+static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_value *value)
+{
+	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+
+	value->value.enumerated.item[0] = dummy->iobox;
+	return 0;
+}
+
+static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_value *value)
+{
+	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+	int changed;
+
+	if (value->value.enumerated.item[0] > 1)
+		return -EINVAL;
+
+	changed = value->value.enumerated.item[0] != dummy->iobox;
+	if (changed) {
+		dummy->iobox = value->value.enumerated.item[0];
+
+		if (dummy->iobox) {
+			dummy->cd_volume_ctl->vd[0].access &=
+				~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+			dummy->cd_switch_ctl->vd[0].access &=
+				~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+		} else {
+			dummy->cd_volume_ctl->vd[0].access |=
+				SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+			dummy->cd_switch_ctl->vd[0].access |=
+				SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+		}
+
+		snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+			       &dummy->cd_volume_ctl->id);
+		snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+			       &dummy->cd_switch_ctl->id);
+	}
+
+	return changed;
+}
+
 static struct snd_kcontrol_new snd_dummy_controls[] = {
 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
@@ -827,22 +881,37 @@ DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),
 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
-DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
+DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD),
+{
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name  = "External I/O Box",
+	.info  = snd_dummy_iobox_info,
+	.get   = snd_dummy_iobox_get,
+	.put   = snd_dummy_iobox_put,
+},
 };
 
 static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
 {
 	struct snd_card *card = dummy->card;
+	struct snd_kcontrol *kcontrol;
 	unsigned int idx;
 	int err;
 
 	spin_lock_init(&dummy->mixer_lock);
 	strcpy(card->mixername, "Dummy Mixer");
+	dummy->iobox = 1;
 
 	for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
-		err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy));
+		kcontrol = snd_ctl_new1(&snd_dummy_controls[idx], dummy);
+		err = snd_ctl_add(card, kcontrol);
 		if (err < 0)
 			return err;
+		if (!strcmp(kcontrol->id.name, "CD Volume"))
+			dummy->cd_volume_ctl = kcontrol;
+		else if (!strcmp(kcontrol->id.name, "CD Capture Switch"))
+			dummy->cd_switch_ctl = kcontrol;
+
 	}
 	return 0;
 }
#1 lore raw

2012-10-21 上午6:11 於 "Clemens Ladisch" <[email protected]> 寫道:

Quoted 2 lines

The following changes since commit

a0d271cbfed1dd50278c6b06bead3d00ba0a88f9:

Quoted 11 lines

Linux 3.6 (2012-09-30 16:47:46 -0700)

are available in the git repository at:
git://git.alsa-project.org/alsa-kprivate.git dummy-ctl-inactive

----------------------------------------------------------------
Quite a few mixer applications do not handle deactivated controls correctly. This patch adds such controls to snd-dummy to make crash^H^H^H^H^Htesting these apps easier.
----------------------------------------------------------------

what is the meaning of deactivated control ?

amixer still can change the value of the deactivated cd volume control if write access is no disabled

Quoted 4 lines

Clemens Ladisch (1):
ALSA: dummy: allow disabling mixer controls

 sound/drivers/dummy.c |   73

+++++++++++++++++++++++++++++++++++++++++++++++-

sound/drivers/dummy.c static int snd_dummy_capsrc_put(struct snd_kcontrol

Quoted 17 lines
 1 files changed, 71 insertions(+), 2 deletions(-)
sound/drivers/dummy.c +3 -0
index 54bb664..4f522cf 100644
@@ -134,6 +134,9 @@ struct snd_dummy {
        spinlock_t mixer_lock;
        int mixer_volume[MIXER_ADDR_LAST+1][2];
        int capture_source[MIXER_ADDR_LAST+1][2];
+       int iobox;
+       struct snd_kcontrol *cd_volume_ctl;
+       struct snd_kcontrol *cd_switch_ctl;
        const struct dummy_timer_ops *timer_ops;
 };
 
@@ -817,6 +820,57 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol

*kcontrol, struct snd_ctl_el

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0,

Quoted 58 lines
sound/drivers/dummy.c +51 -0
        return change;
 }
 
+static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *info)
+{
+       const char *const names[] = { "None", "CD Player" };
+
+       return snd_ctl_enum_info(info, 1, 2, names);
+}
+
+static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+
+       value->value.enumerated.item[0] = dummy->iobox;
+       return 0;
+}
+
+static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+       int changed;
+
+       if (value->value.enumerated.item[0] > 1)
+               return -EINVAL;
+
+       changed = value->value.enumerated.item[0] != dummy->iobox;
+       if (changed) {
+               dummy->iobox = value->value.enumerated.item[0];
+
+               if (dummy->iobox) {
+                       dummy->cd_volume_ctl->vd[0].access &=
+                               ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+                       dummy->cd_switch_ctl->vd[0].access &=
+                               ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               } else {
+                       dummy->cd_volume_ctl->vd[0].access |=
+                               SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+                       dummy->cd_switch_ctl->vd[0].access |=
+                               SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               }
+
+               snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+                              &dummy->cd_volume_ctl->id);
+               snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+                              &dummy->cd_switch_ctl->id);
+       }
+
+       return changed;
+}
+
 static struct snd_kcontrol_new snd_dummy_controls[] = {
 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
@@ -827,22 +881,37 @@ DUMMY_CAPSRC("Line Capture Switch", 0,

MIXER_ADDR_LINE),

Quoted 17 lines
sound/drivers/dummy.c +8 -1
 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
-DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
+DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD),
+{
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name  = "External I/O Box",
+       .info  = snd_dummy_iobox_info,
+       .get   = snd_dummy_iobox_get,
+       .put   = snd_dummy_iobox_put,
+},
 };
 
 static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
 {
        struct snd_card *card = dummy->card;

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),

Quoted 10 lines
sound/drivers/dummy.c +2 -1
+       struct snd_kcontrol *kcontrol;
        unsigned int idx;
        int err;
 
        spin_lock_init(&dummy->mixer_lock);
        strcpy(card->mixername, "Dummy Mixer");
+       dummy->iobox = 1;
 
        for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
-               err = snd_ctl_add(card,

snd_ctl_new1(&snd_dummy_controls[idx], dummy));

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE), · line 917

Quoted 12 lines
sound/drivers/dummy.c +7 -0
+               kcontrol = snd_ctl_new1(&snd_dummy_controls[idx], dummy);
+               err = snd_ctl_add(card, kcontrol);
                if (err < 0)
                        return err;
+               if (!strcmp(kcontrol->id.name, "CD Volume"))
+                       dummy->cd_volume_ctl = kcontrol;
+               else if (!strcmp(kcontrol->id.name, "CD Capture Switch"))
+                       dummy->cd_switch_ctl = kcontrol;
+
        }
        return 0;
 }

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw

At Sun, 21 Oct 2012 15:24:56 +0800,

Quoted 17 lines · Raymond Yau

2012-10-21 上午6:11 於 "Clemens Ladisch" <[email protected]> 寫道:

Quoted 2 lines

The following changes since commit

a0d271cbfed1dd50278c6b06bead3d00ba0a88f9:

Quoted 11 lines

Linux 3.6 (2012-09-30 16:47:46 -0700)

are available in the git repository at:
git://git.alsa-project.org/alsa-kprivate.git dummy-ctl-inactive

----------------------------------------------------------------
Quite a few mixer applications do not handle deactivated controls correctly. This patch adds such controls to snd-dummy to make crash^H^H^H^H^Htesting these apps easier.
----------------------------------------------------------------

Quoted 4 lines

what is the meaning of deactivated control ?

amixer still can change the value of the deactivated cd volume control if write access is no disabled

If so, that should be checked rather in the core code...

Takashi

Quoted 103 lines
Quoted 4 lines

Clemens Ladisch (1):
ALSA: dummy: allow disabling mixer controls

 sound/drivers/dummy.c |   73

+++++++++++++++++++++++++++++++++++++++++++++++-

sound/drivers/dummy.c static int snd_dummy_capsrc_put(struct snd_kcontrol

Quoted 17 lines
 1 files changed, 71 insertions(+), 2 deletions(-)
sound/drivers/dummy.c +3 -0
index 54bb664..4f522cf 100644
@@ -134,6 +134,9 @@ struct snd_dummy {
        spinlock_t mixer_lock;
        int mixer_volume[MIXER_ADDR_LAST+1][2];
        int capture_source[MIXER_ADDR_LAST+1][2];
+       int iobox;
+       struct snd_kcontrol *cd_volume_ctl;
+       struct snd_kcontrol *cd_switch_ctl;
        const struct dummy_timer_ops *timer_ops;
 };
 
@@ -817,6 +820,57 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol

*kcontrol, struct snd_ctl_el

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0,

Quoted 58 lines
sound/drivers/dummy.c +51 -0
        return change;
 }
 
+static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *info)
+{
+       const char *const names[] = { "None", "CD Player" };
+
+       return snd_ctl_enum_info(info, 1, 2, names);
+}
+
+static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+
+       value->value.enumerated.item[0] = dummy->iobox;
+       return 0;
+}
+
+static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+       int changed;
+
+       if (value->value.enumerated.item[0] > 1)
+               return -EINVAL;
+
+       changed = value->value.enumerated.item[0] != dummy->iobox;
+       if (changed) {
+               dummy->iobox = value->value.enumerated.item[0];
+
+               if (dummy->iobox) {
+                       dummy->cd_volume_ctl->vd[0].access &=
+                               ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+                       dummy->cd_switch_ctl->vd[0].access &=
+                               ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               } else {
+                       dummy->cd_volume_ctl->vd[0].access |=
+                               SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+                       dummy->cd_switch_ctl->vd[0].access |=
+                               SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               }
+
+               snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+                              &dummy->cd_volume_ctl->id);
+               snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+                              &dummy->cd_switch_ctl->id);
+       }
+
+       return changed;
+}
+
 static struct snd_kcontrol_new snd_dummy_controls[] = {
 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
@@ -827,22 +881,37 @@ DUMMY_CAPSRC("Line Capture Switch", 0,

MIXER_ADDR_LINE),

Quoted 21 lines
sound/drivers/dummy.c +9 -1
 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
-DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
+DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD),
+{
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name  = "External I/O Box",
+       .info  = snd_dummy_iobox_info,
+       .get   = snd_dummy_iobox_get,
+       .put   = snd_dummy_iobox_put,
+},
 };
 
 static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
 {
        struct snd_card *card = dummy->card;
+       struct snd_kcontrol *kcontrol;
        unsigned int idx;
        int err;
 
Quoted 19 lines

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),

Quoted 6 lines
sound/drivers/dummy.c +1 -1
        spin_lock_init(&dummy->mixer_lock);
        strcpy(card->mixername, "Dummy Mixer");
+       dummy->iobox = 1;
 
        for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
-               err = snd_ctl_add(card,

snd_ctl_new1(&snd_dummy_controls[idx], dummy));

Quoted 12 lines
sound/drivers/dummy.c +7 -0
+               kcontrol = snd_ctl_new1(&snd_dummy_controls[idx], dummy);
+               err = snd_ctl_add(card, kcontrol);
                if (err < 0)
                        return err;
+               if (!strcmp(kcontrol->id.name, "CD Volume"))
+                       dummy->cd_volume_ctl = kcontrol;
+               else if (!strcmp(kcontrol->id.name, "CD Capture Switch"))
+                       dummy->cd_switch_ctl = kcontrol;
+
        }
        return 0;
 }

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw

2012-10-21 下午4:22 於 "Takashi Iwai" <[email protected]> 寫道:

Quoted 23 lines

At Sun, 21 Oct 2012 15:24:56 +0800,

Quoted 20 lines · Raymond Yau

2012-10-21 上午6:11 於 "Clemens Ladisch" <[email protected]> 寫道:

Quoted 2 lines

The following changes since commit

a0d271cbfed1dd50278c6b06bead3d00ba0a88f9:

Quoted 11 lines

Linux 3.6 (2012-09-30 16:47:46 -0700)

are available in the git repository at:
git://git.alsa-project.org/alsa-kprivate.git dummy-ctl-inactive

----------------------------------------------------------------
Quite a few mixer applications do not handle deactivated controls correctly. This patch adds such controls to snd-dummy to make crash^H^H^H^H^Htesting these apps easier.
----------------------------------------------------------------

what is the meaning of deactivated control ?

amixer still can change the value of the deactivated cd volume control

if

Quoted 3 lines
Quoted 1 line

write access is no disabled

If so, that should be checked rather in the core code...

the other problem is that the simple mixer api does not provide any function to know whether the cd playback volume control or the cd playback switch control is active or inactive so alsamixer disable both controls

Quoted 25 lines

Takashi

Quoted 21 lines
Quoted 4 lines

Clemens Ladisch (1):
ALSA: dummy: allow disabling mixer controls

 sound/drivers/dummy.c |   73

+++++++++++++++++++++++++++++++++++++++++++++++-

Quoted 16 lines
 1 files changed, 71 insertions(+), 2 deletions(-)
sound/drivers/dummy.c +3 -0
index 54bb664..4f522cf 100644
@@ -134,6 +134,9 @@ struct snd_dummy {
        spinlock_t mixer_lock;
        int mixer_volume[MIXER_ADDR_LAST+1][2];
        int capture_source[MIXER_ADDR_LAST+1][2];
+       int iobox;
+       struct snd_kcontrol *cd_volume_ctl;
+       struct snd_kcontrol *cd_switch_ctl;
        const struct dummy_timer_ops *timer_ops;
 };
 
Quoted 1 line
Quoted 1 line

sound/drivers/dummy.c static int snd_dummy_capsrc_put(struct

Quoted 1 line
sound/drivers/dummy.c +0 -0
@@ -817,6 +820,57 @@ static int snd_dummy_capsrc_put(struct

snd_kcontrol

Quoted 74 lines
Quoted 74 lines

*kcontrol, struct snd_ctl_el

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0,

Quoted 58 lines
sound/drivers/dummy.c +51 -0
        return change;
 }
 
+static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *info)
+{
+       const char *const names[] = { "None", "CD Player" };
+
+       return snd_ctl_enum_info(info, 1, 2, names);
+}
+
+static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+
+       value->value.enumerated.item[0] = dummy->iobox;
+       return 0;
+}
+
+static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *value)
+{
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+       int changed;
+
+       if (value->value.enumerated.item[0] > 1)
+               return -EINVAL;
+
+       changed = value->value.enumerated.item[0] != dummy->iobox;
+       if (changed) {
+               dummy->iobox = value->value.enumerated.item[0];
+
+               if (dummy->iobox) {
+                       dummy->cd_volume_ctl->vd[0].access &=
+                               ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+                       dummy->cd_switch_ctl->vd[0].access &=
+                               ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               } else {
+                       dummy->cd_volume_ctl->vd[0].access |=
+                               SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+                       dummy->cd_switch_ctl->vd[0].access |=
+                               SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+               }
+
+               snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+                              &dummy->cd_volume_ctl->id);
+               snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+                              &dummy->cd_switch_ctl->id);
+       }
+
+       return changed;
+}
+
 static struct snd_kcontrol_new snd_dummy_controls[] = {
 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
@@ -827,22 +881,37 @@ DUMMY_CAPSRC("Line Capture Switch", 0,

MIXER_ADDR_LINE),

Quoted 14 lines
sound/drivers/dummy.c +8 -1
 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
-DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
+DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD),
+{
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name  = "External I/O Box",
+       .info  = snd_dummy_iobox_info,
+       .get   = snd_dummy_iobox_get,
+       .put   = snd_dummy_iobox_put,
+},
 };
 
Quoted 1 line
Quoted 1 line

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, · line 894

Quoted 1 line
sound/drivers/dummy.c +0 -0
 static int __devinit snd_card_dummy_new_mixer(struct snd_dummy

*dummy)

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
sound/drivers/dummy.c +1 -0
 {
        struct snd_card *card = dummy->card;
+       struct snd_kcontrol *kcontrol;
        unsigned int idx;
        int err;
 
Quoted 8 lines
Quoted 8 lines

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),

Quoted 6 lines
sound/drivers/dummy.c +1 -1
        spin_lock_init(&dummy->mixer_lock);
        strcpy(card->mixername, "Dummy Mixer");
+       dummy->iobox = 1;
 
        for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
-               err = snd_ctl_add(card,

snd_ctl_new1(&snd_dummy_controls[idx], dummy));

Quoted 1 line
sound/drivers/dummy.c +1 -0
+               kcontrol = snd_ctl_new1(&snd_dummy_controls[idx],

dummy);

Quoted 6 lines
Quoted 6 lines

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),

Quoted 6 lines
sound/drivers/dummy.c +4 -0
+               err = snd_ctl_add(card, kcontrol);
                if (err < 0)
                        return err;
+               if (!strcmp(kcontrol->id.name, "CD Volume"))
+                       dummy->cd_volume_ctl = kcontrol;
+               else if (!strcmp(kcontrol->id.name, "CD Capture

Switch"))

Quoted 5 lines
Quoted 5 lines

sound/drivers/dummy.c DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE), · line 917

Quoted 5 lines
sound/drivers/dummy.c +2 -0
+                       dummy->cd_switch_ctl = kcontrol;
+
        }
        return 0;
 }

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw
In reply to Raymond Yau
Quoted 5 lines · Raymond Yau

2012-10-21 上午6:11 於 "Clemens Ladisch" <[email protected]> 寫道:

Quoted 2 lines

Quite a few mixer applications do not handle deactivated controls correctly.

what is the meaning of deactivated control ?

A control where writes do not have an (immediate) effect.

Quoted 2 lines

amixer still can change the value of the deactivated cd volume control if write access is no disabled

Yes, when write access is enabled, the control can be written to. This is necessary for "alsactl (re)store".

Alsamixer displays such controls as gray and read-only because changing them would not make sense at the moment, but allowing changes would actually be possible (if confusing).

Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw

2012-10-21 下午7:13 於 "Clemens Ladisch" <[email protected]> 寫道:

Quoted 9 lines
Quoted 5 lines · Raymond Yau

2012-10-21 上午6:11 於 "Clemens Ladisch" <[email protected]> 寫道:

Quoted 2 lines

Quite a few mixer applications do not handle deactivated controls correctly.

what is the meaning of deactivated control ?

A control where writes do not have an (immediate) effect.

why do you not implement this kind of control by disable/enable the write access ?

Quoted 2 lines
Quoted 2 lines

amixer still can change the value of the deactivated cd volume control

if

Quoted 4 lines
Quoted 1 line

write access is no disabled

Yes, when write access is enabled, the control can be written to. This is necessary for "alsactl (re)store".

if the control can be write when the driver is loaded, the write access of the control can be disable/enable instead of using active/inactive

Quoted 4 lines

Alsamixer displays such controls as gray and read-only because changing them would not make sense at the moment, but allowing changes would actually be possible (if confusing).

alsamixer can also display non writable control in different color
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw
In reply to Clemens Ladisch

At Sun, 21 Oct 2012 00:09:40 +0200,

Quoted 5 lines · Clemens Ladisch

The following changes since commit a0d271cbfed1dd50278c6b06bead3d00ba0a88f9:

Linux 3.6 (2012-09-30 16:47:46 -0700)

Quoted 7 lines

are available in the git repository at:
git://git.alsa-project.org/alsa-kprivate.git dummy-ctl-inactive

----------------------------------------------------------------
Quite a few mixer applications do not handle deactivated controls correctly. This patch adds such controls to snd-dummy to make crash^H^H^H^H^Htesting these apps easier.

Pulled now. Thanks.

Takashi

Quoted 120 lines

----------------------------------------------------------------
Clemens Ladisch (1):
ALSA: dummy: allow disabling mixer controls

 sound/drivers/dummy.c |   73 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 2 deletions(-)
sound/drivers/dummy.c +71 -2
index 54bb664..4f522cf 100644
@@ -134,6 +134,9 @@ struct snd_dummy {
 	spinlock_t mixer_lock;
 	int mixer_volume[MIXER_ADDR_LAST+1][2];
 	int capture_source[MIXER_ADDR_LAST+1][2];
+	int iobox;
+	struct snd_kcontrol *cd_volume_ctl;
+	struct snd_kcontrol *cd_switch_ctl;
 	const struct dummy_timer_ops *timer_ops;
 };
 
@@ -817,6 +820,57 @@ static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
 	return change;
 }
 
+static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_info *info)
+{
+	const char *const names[] = { "None", "CD Player" };
+
+	return snd_ctl_enum_info(info, 1, 2, names);
+}
+
+static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_value *value)
+{
+	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+
+	value->value.enumerated.item[0] = dummy->iobox;
+	return 0;
+}
+
+static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_value *value)
+{
+	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
+	int changed;
+
+	if (value->value.enumerated.item[0] > 1)
+		return -EINVAL;
+
+	changed = value->value.enumerated.item[0] != dummy->iobox;
+	if (changed) {
+		dummy->iobox = value->value.enumerated.item[0];
+
+		if (dummy->iobox) {
+			dummy->cd_volume_ctl->vd[0].access &=
+				~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+			dummy->cd_switch_ctl->vd[0].access &=
+				~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+		} else {
+			dummy->cd_volume_ctl->vd[0].access |=
+				SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+			dummy->cd_switch_ctl->vd[0].access |=
+				SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+		}
+
+		snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+			       &dummy->cd_volume_ctl->id);
+		snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
+			       &dummy->cd_switch_ctl->id);
+	}
+
+	return changed;
+}
+
 static struct snd_kcontrol_new snd_dummy_controls[] = {
 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
@@ -827,22 +881,37 @@ DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),
 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
-DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
+DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD),
+{
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name  = "External I/O Box",
+	.info  = snd_dummy_iobox_info,
+	.get   = snd_dummy_iobox_get,
+	.put   = snd_dummy_iobox_put,
+},
 };
 
 static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
 {
 	struct snd_card *card = dummy->card;
+	struct snd_kcontrol *kcontrol;
 	unsigned int idx;
 	int err;
 
 	spin_lock_init(&dummy->mixer_lock);
 	strcpy(card->mixername, "Dummy Mixer");
+	dummy->iobox = 1;
 
 	for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
-		err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy));
+		kcontrol = snd_ctl_new1(&snd_dummy_controls[idx], dummy);
+		err = snd_ctl_add(card, kcontrol);
 		if (err < 0)
 			return err;
+		if (!strcmp(kcontrol->id.name, "CD Volume"))
+			dummy->cd_volume_ctl = kcontrol;
+		else if (!strcmp(kcontrol->id.name, "CD Capture Switch"))
+			dummy->cd_switch_ctl = kcontrol;
+
 	}
 	return 0;
 }