From 2e1971af89361d15e283f8ad49ad36762f25f6cc Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 6 Oct 2013 22:24:32 +0200 Subject: [PATCH] audio: Handle min=max when scaling volumes (fixes: #525) Also add gobject.threads_init() so we can run the audio actor test on its own. --- mopidy/audio/actor.py | 2 ++ tests/audio/actor_test.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/mopidy/audio/actor.py b/mopidy/audio/actor.py index 6f539707..747c2a00 100644 --- a/mopidy/audio/actor.py +++ b/mopidy/audio/actor.py @@ -544,6 +544,8 @@ class Audio(pykka.ThreadingActor): """Convert value between scales.""" new_min, new_max = new old_min, old_max = old + if old_min == old_max: + return old_max scaling = float(new_max - new_min) / (old_max - old_min) return int(round(scaling * (value - old_min) + new_min)) diff --git a/tests/audio/actor_test.py b/tests/audio/actor_test.py index 617131cc..e44c5e12 100644 --- a/tests/audio/actor_test.py +++ b/tests/audio/actor_test.py @@ -6,6 +6,9 @@ import pygst pygst.require('0.10') import gst +import gobject +gobject.threads_init() + import pykka from mopidy import audio @@ -80,6 +83,18 @@ class AudioTest(unittest.TestCase): self.assertTrue(self.audio.set_volume(value).get()) self.assertEqual(value, self.audio.get_volume().get()) + def test_set_volume_with_mixer_min_equal_max(self): + config = { + 'audio': { + 'mixer': 'fakemixer track_max_volume=0', + 'mixer_track': None, + 'output': 'fakesink', + 'visualizer': None, + } + } + self.audio = audio.Audio.start(config=config).proxy() + self.assertEqual(0, self.audio.get_volume().get()) + @unittest.SkipTest def test_set_state_encapsulation(self): pass # TODO