mopidy/mopidy/softwaremixer/mixer.py
Thomas Adamcik b8a0ca59cd audio: Refactor softwaremixer and audio interactions
This rips the mixer bits and pieces that have been hiding in the audio actor to
it's own class. The software mixer now only knows about this and nothing else
from audio.
2014-08-03 23:57:22 +02:00

65 lines
1.7 KiB
Python

from __future__ import unicode_literals
import logging
import pykka
from mopidy import mixer
logger = logging.getLogger(__name__)
class SoftwareMixer(pykka.ThreadingActor, mixer.Mixer):
name = 'software'
def __init__(self, config):
super(SoftwareMixer, self).__init__(config)
self._audio_mixer = None
self._initial_volume = None
self._initial_mute = None
# TODO: shouldn't this be logged by thing that choose us?
logger.info('Mixing using GStreamer software mixing')
def setup(self, mixer_ref):
self._audio_mixer = mixer_ref
# The Mopidy startup procedure will set the initial volume of a
# mixer, but this happens before the audio actor is injected into the
# software mixer and has no effect. Thus, we need to set the initial
# volume again.
if self._initial_volume is not None:
self.set_volume(self._initial_volume)
if self._initial_mute is not None:
self.set_mute(self._initial_mute)
def teardown(self):
self._audio_mixer = None
def get_volume(self):
if self._audio_mixer is None:
return None
return self._audio_mixer.get_volume().get()
def set_volume(self, volume):
if self._audio_mixer is None:
self._initial_volume = volume
return False
self._audio_mixer.set_volume(volume)
return True
def get_mute(self):
if self._audio_mixer is None:
return None
return self._audio_mixer.get_mute().get()
def set_mute(self, mute):
if self._audio_mixer is None:
self._initial_mute = mute
return False
self._audio_mixer.set_mute(mute)
return True