From: Ismaƫl Bouya Date: Mon, 18 Jul 2016 19:17:02 +0000 (+0200) Subject: Fix initial volume factor X-Git-Tag: 1.0.0~42 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=b37c72a236806f02e5538ba7e607f6add0cc6fb6;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git Fix initial volume factor --- 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):