]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Fix initial volume factor
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 18 Jul 2016 19:17:02 +0000 (21:17 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 18 Jul 2016 19:17:02 +0000 (21:17 +0200)
helpers/music_file.py

index 54a3fdcbb65614187f5ff5c75b399bbbca239944..3053008c0a281adedf65761ab205b5de8bb01d84 100644 (file)
@@ -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):