Add new setting MIXER_ALSA_CONTROL that overrides the control search in AlsaMixer

This commit is contained in:
Stein Magnus Jodal 2010-05-05 20:04:25 +02:00
parent 1660cccbea
commit 429caf51aa
2 changed files with 29 additions and 9 deletions

View File

@ -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]

View File

@ -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``.