Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduced mixer control id #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The following configuration values are available:
Other typical values includes ``PCM``. Run the command ``amixer scontrols``
to list available controls on your system.

- ``alsamixer/mixerid``: the id of the mixer control. Default is 0.

- ``alsamixer/min_volume`` and ``alsamixer/max_volume``: Map the Mopidy volume
control range to a different range. Values are in the range 0-100. Use this
if the default range (0-100) is too wide, resulting in a small usable range
Expand All @@ -67,6 +69,7 @@ Example ``alsamixer`` section from the Mopidy configuration file::
[alsamixer]
card = 1
control = PCM
mixerid = 0
min_volume = 0
max_volume = 100
volume_scale = cubic
Expand Down
1 change: 1 addition & 0 deletions mopidy_alsamixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_config_schema(self):
schema = super(Extension, self).get_config_schema()
schema['card'] = config.Integer(minimum=0)
schema['control'] = config.String()
schema['mixerid'] = config.Integer(minimum=0)
schema['min_volume'] = config.Integer(minimum=0, maximum=100)
schema['max_volume'] = config.Integer(minimum=0, maximum=100)
schema['volume_scale'] = config.String(
Expand Down
1 change: 1 addition & 0 deletions mopidy_alsamixer/ext.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
enabled = true
card = 0
control = Master
mixerid = 0
min_volume = 0
max_volume = 100
volume_scale = cubic
13 changes: 7 additions & 6 deletions mopidy_alsamixer/mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, config):
self.config = config
self.cardindex = self.config['alsamixer']['card']
self.control = self.config['alsamixer']['control']
self.mixerid = self.config['alsamixer']['mixerid']
self.min_volume = self.config['alsamixer']['min_volume']
self.max_volume = self.config['alsamixer']['max_volume']
self.volume_scale = self.config['alsamixer']['volume_scale']
Expand Down Expand Up @@ -58,20 +59,20 @@ def __init__(self, config):
self._last_mute = None

logger.info(
'Mixing using ALSA, card %d, mixer control "%s".',
self.cardindex, self.control)
'Mixing using ALSA, card %d, mixer control "%s", mixerid %d.',
self.cardindex, self.control, self.mixerid)

def on_start(self):
self._observer = AlsaMixerObserver(
cardindex=self.cardindex, control=self.control,
cardindex=self.cardindex, mixerid=self.mixerid, control=self.control,
callback=self.actor_ref.proxy().trigger_events_for_changed_values)
self._observer.start()

@property
def _mixer(self):
# The mixer must be recreated every time it is used to be able to
# observe volume/mute changes done by other applications.
return alsaaudio.Mixer(cardindex=self.cardindex, control=self.control)
return alsaaudio.Mixer(cardindex=self.cardindex, id=self.mixerid, control=self.control)

def get_volume(self):
channels = self._mixer.getvolume()
Expand Down Expand Up @@ -159,12 +160,12 @@ class AlsaMixerObserver(threading.Thread):
daemon = True
name = 'AlsaMixerObserver'

def __init__(self, cardindex, control, callback=None):
def __init__(self, cardindex, mixerid, control, callback=None):
super(AlsaMixerObserver, self).__init__()
self.running = True

# Keep the mixer instance alive for the descriptors to work
self.mixer = alsaaudio.Mixer(cardindex=cardindex, control=control)
self.mixer = alsaaudio.Mixer(cardindex=cardindex, id=mixerid, control=control)
descriptors = self.mixer.polldescriptors()
assert len(descriptors) == 1
self.fd = descriptors[0][0]
Expand Down