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) ==================== 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