From 9bc123693e984f2d432dbf56221cabf43d8b3e17 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 29 Oct 2012 14:23:10 +0100 Subject: [PATCH] Make NAD mixer respond to interrupts during calibration --- docs/changes.rst | 7 +++++++ mopidy/audio/mixers/nad.py | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 025ed71e..c88027bd 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -60,6 +60,13 @@ backends: dummy/mocked lower layers easier than with the old variant, where dependencies where looked up in Pykka's actor registry. +**Changes** + +- Made the :mod:`NAD mixer ` responsive to interrupts + during amplifier calibration. It will now quit immediately, while previously + it completed the calibration first, and then quit, which could take more than + 15 seconds. + **Bug fixes** - :issue:`213`: Fix "streaming task paused, reason not-negotiated" errors diff --git a/mopidy/audio/mixers/nad.py b/mopidy/audio/mixers/nad.py index cb1266a1..1a807e39 100644 --- a/mopidy/audio/mixers/nad.py +++ b/mopidy/audio/mixers/nad.py @@ -179,7 +179,7 @@ class NadTalker(pykka.ThreadingActor): self._select_speakers() self._select_input_source() self.mute(False) - self._calibrate_volume() + self.calibrate_volume() def _get_device_model(self): model = self._ask_device('Main.Model') @@ -205,14 +205,21 @@ class NadTalker(pykka.ThreadingActor): else: self._check_and_set('Main.Mute', 'Off') - def _calibrate_volume(self): + def calibrate_volume(self, current_nad_volume=None): # The NAD C 355BEE amplifier has 40 different volume levels. We have no # way of asking on which level we are. Thus, we must calibrate the # mixer by decreasing the volume 39 times. - logger.info(u'NAD amplifier: Calibrating by setting volume to 0') - self._nad_volume = self.VOLUME_LEVELS - self.set_volume(0) - logger.info(u'NAD amplifier: Done calibrating') + if current_nad_volume is None: + current_nad_volume = self.VOLUME_LEVELS + if current_nad_volume == self.VOLUME_LEVELS: + logger.info(u'NAD amplifier: Calibrating by setting volume to 0') + self._nad_volume = current_nad_volume + if self._decrease_volume(): + current_nad_volume -= 1 + if current_nad_volume == 0: + logger.info(u'NAD amplifier: Done calibrating') + else: + self.actor_ref.proxy().calibrate_volume(current_nad_volume) def set_volume(self, volume): # Increase or decrease the amplifier volume until it matches the given