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

Allow user to select device of soundcard #12

Open
wants to merge 7 commits 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 @@ -61,6 +61,8 @@ The following configuration values are available:
- ``alsamixer/volume_scale``: Either ``linear``, ``cubic``, or ``log``. The
cubic scale is the default as it is closer to how the human ear percieves
volume, and matches the volume scale used in the ``alsamixer`` program.

- ``alsamixer/device``: select what device number you want to use. Numbered from 0 and up. 0 is the default.

Example ``alsamixer`` section from the Mopidy configuration file::

Expand All @@ -70,6 +72,7 @@ Example ``alsamixer`` section from the Mopidy configuration file::
min_volume = 0
max_volume = 100
volume_scale = cubic
device = 1

Project resources
=================
Expand Down
1 change: 1 addition & 0 deletions mopidy_alsamixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_default_config(self):
def get_config_schema(self):
schema = super(Extension, self).get_config_schema()
schema['card'] = config.Integer(minimum=0)
schema['device'] = config.String()
schema['control'] = config.String()
schema['min_volume'] = config.Integer(minimum=0, maximum=100)
schema['max_volume'] = config.Integer(minimum=0, maximum=100)
Expand Down
1 change: 1 addition & 0 deletions mopidy_alsamixer/ext.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[alsamixer]
enabled = true
card = 0
device = default
control = Master
min_volume = 0
max_volume = 100
Expand Down
12 changes: 7 additions & 5 deletions mopidy_alsamixer/mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, config):
super(AlsaMixer, self).__init__()
self.config = config
self.cardindex = self.config['alsamixer']['card']
self.device = self.config['alsamixer']['device']
self.control = self.config['alsamixer']['control']
self.min_volume = self.config['alsamixer']['min_volume']
self.max_volume = self.config['alsamixer']['max_volume']
Expand Down Expand Up @@ -56,12 +57,12 @@ 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", device "%s".',
self.cardindex, self.control, self.device)

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

Expand Down Expand Up @@ -157,12 +158,13 @@ class AlsaMixerObserver(threading.Thread):
daemon = True
name = 'AlsaMixerObserver'

def __init__(self, cardindex, control, callback=None):
def __init__(self, cardindex, control, device, 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, control=control,
device=device)
descriptors = self.mixer.polldescriptors()
assert len(descriptors) == 1
self.fd = descriptors[0][0]
Expand Down