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.
This commit is contained in:
parent
06ae86b9f8
commit
2e1971af89
@ -544,6 +544,8 @@ class Audio(pykka.ThreadingActor):
|
|||||||
"""Convert value between scales."""
|
"""Convert value between scales."""
|
||||||
new_min, new_max = new
|
new_min, new_max = new
|
||||||
old_min, old_max = old
|
old_min, old_max = old
|
||||||
|
if old_min == old_max:
|
||||||
|
return old_max
|
||||||
scaling = float(new_max - new_min) / (old_max - old_min)
|
scaling = float(new_max - new_min) / (old_max - old_min)
|
||||||
return int(round(scaling * (value - old_min) + new_min))
|
return int(round(scaling * (value - old_min) + new_min))
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import pygst
|
|||||||
pygst.require('0.10')
|
pygst.require('0.10')
|
||||||
import gst
|
import gst
|
||||||
|
|
||||||
|
import gobject
|
||||||
|
gobject.threads_init()
|
||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import audio
|
from mopidy import audio
|
||||||
@ -80,6 +83,18 @@ class AudioTest(unittest.TestCase):
|
|||||||
self.assertTrue(self.audio.set_volume(value).get())
|
self.assertTrue(self.audio.set_volume(value).get())
|
||||||
self.assertEqual(value, self.audio.get_volume().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
|
@unittest.SkipTest
|
||||||
def test_set_state_encapsulation(self):
|
def test_set_state_encapsulation(self):
|
||||||
pass # TODO
|
pass # TODO
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user