Skip to content

Commit

Permalink
ALSA: dummy: allow disabling mixer controls
Browse files Browse the repository at this point in the history
To make the testing of deactivated mixer controls easier (and for people
with common hardware, possible), add a control that deactivates some
other controls.

Signed-off-by: Clemens Ladisch <[email protected]>
  • Loading branch information
cladisch committed Oct 20, 2012
1 parent a0d271c commit 16e4346
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions sound/drivers/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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),
Expand All @@ -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;
}
Expand Down

0 comments on commit 16e4346

Please sign in to comment.