From 429caf51aa75c275c3cba570e2ebd6c5404db384 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 5 May 2010 20:04:25 +0200 Subject: [PATCH] Add new setting MIXER_ALSA_CONTROL that overrides the control search in AlsaMixer --- mopidy/mixers/alsa.py | 32 +++++++++++++++++++++++--------- mopidy/settings.py | 6 ++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/mopidy/mixers/alsa.py b/mopidy/mixers/alsa.py index 9bcd8b6f..4fd84fd2 100644 --- a/mopidy/mixers/alsa.py +++ b/mopidy/mixers/alsa.py @@ -1,6 +1,7 @@ import alsaaudio import logging +from mopidy import settings from mopidy.mixers import BaseMixer logger = logging.getLogger('mopidy.mixers.alsa') @@ -13,17 +14,30 @@ class AlsaMixer(BaseMixer): def __init__(self, *args, **kwargs): super(AlsaMixer, self).__init__(*args, **kwargs) - # A mixer named 'Master' does not always exist, so we fall back to - # using 'PCM'. If this turns out to be a bad solution, we should make - # it possible to override with a setting. - self._mixer = None - for mixer_name in (u'Master', u'PCM'): - if mixer_name in alsaaudio.mixers(): - logger.info(u'Mixer in use: %s', mixer_name) - self._mixer = alsaaudio.Mixer(mixer_name) - break + self._mixer = alsaaudio.Mixer(self._get_mixer_control()) assert self._mixer is not None + def _get_mixer_control(self): + """Returns the first mixer control candidate that is known to ALSA""" + candidates = self._get_mixer_control_candidates() + for control in candidates: + if control in alsaaudio.mixers(): + logger.info(u'Mixer control in use: %s', control) + return control + else: + logger.debug(u'Mixer control not found, skipping: %s', control) + logger.warning(u'No working mixer controls found. Tried: %s', candidates) + + def _get_mixer_control_candidates(self): + """ + A mixer named 'Master' does not always exist, so we fall back to using + 'PCM'. If this does not work for you, you may set + :attr:`mopidy.settings.MIXER_ALSA_CONTROL`. + """ + if settings.MIXER_ALSA_CONTROL: + return [settings.MIXER_ALSA_CONTROL] + return [u'Master', u'PCM'] + def _get_volume(self): return self._mixer.getvolume()[0] diff --git a/mopidy/settings.py b/mopidy/settings.py index b1e2e7b2..a2ba88e5 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -61,6 +61,12 @@ if sys.platform == 'linux2': elif sys.platform == 'darwin': MIXER = u'mopidy.mixers.osa.OsaMixer' +#: ALSA mixer only. What mixer control to use. If set to :class:`False`, first +#: ``Master`` and then ``PCM`` will be tried. +#: +#: Example: ``Master Front``. *Default:* :class:`False` +MIXER_ALSA_CONTROL = False + #: External mixers only. Which port the mixer is connected to. #: #: This must point to the device port like ``/dev/ttyUSB0``.