From 2e1971af89361d15e283f8ad49ad36762f25f6cc Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 6 Oct 2013 22:24:32 +0200 Subject: [PATCH 1/2] 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 From 8c8fdb0b0134af83228d0be9a8839e4eb785dc01 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 6 Oct 2013 22:30:16 +0200 Subject: [PATCH 2/2] docs: Add bug fix to changelog --- docs/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 24656add..b37b24c5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,10 @@ v0.16.0 (UNRELEASED) Currently we support M3U, PLS, XSPF and ASX files, also note that we can currently only play the first stream in the playlist. +- We now handle the rare case where an audio track has max volume equal to min. + This was causing divide by zero errors when scaling volumes to a zero to + hundred scale. (Fixes: :issue:`525`) + v0.15.0 (2013-09-19) ====================