From b37c72a236806f02e5538ba7e607f6add0cc6fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 18 Jul 2016 21:17:02 +0200 Subject: Fix initial volume factor --- helpers/music_file.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'helpers') diff --git a/helpers/music_file.py b/helpers/music_file.py index 54a3fdc..3053008 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -81,6 +81,7 @@ class MusicFile(Machine): self.music_lock = Lock("music__" + filename) self.wait_event = threading.Event() self.db_gain = 0 + self.volume_factor = 1 threading.Thread(name="MSMusicLoad", target=self.load).start() @@ -123,7 +124,7 @@ class MusicFile(Machine): return 0 def play(self, fade_in=0, volume=100, loop=0, start_at=0): - self.db_gain = gain(volume) + self.mapping.master_gain + self.set_gain(gain(volume) + self.mapping.master_gain, absolute=True) self.volume = volume self.loop = loop @@ -244,8 +245,11 @@ class MusicFile(Machine): self.stop_playing() self.stopped() - def set_gain(self, db_gain): - self.db_gain += db_gain + def set_gain(self, db_gain, absolute=False): + if absolute: + self.db_gain = db_gain + else: + self.db_gain += db_gain self.volume_factor = 10 ** (self.db_gain / 20) def set_volume(self, value, delta=False): -- cgit v1.2.3