aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helpers/music_file.py10
1 files changed, 7 insertions, 3 deletions
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):
81 self.music_lock = Lock("music__" + filename) 81 self.music_lock = Lock("music__" + filename)
82 self.wait_event = threading.Event() 82 self.wait_event = threading.Event()
83 self.db_gain = 0 83 self.db_gain = 0
84 self.volume_factor = 1
84 85
85 threading.Thread(name="MSMusicLoad", target=self.load).start() 86 threading.Thread(name="MSMusicLoad", target=self.load).start()
86 87
@@ -123,7 +124,7 @@ class MusicFile(Machine):
123 return 0 124 return 0
124 125
125 def play(self, fade_in=0, volume=100, loop=0, start_at=0): 126 def play(self, fade_in=0, volume=100, loop=0, start_at=0):
126 self.db_gain = gain(volume) + self.mapping.master_gain 127 self.set_gain(gain(volume) + self.mapping.master_gain, absolute=True)
127 self.volume = volume 128 self.volume = volume
128 self.loop = loop 129 self.loop = loop
129 130
@@ -244,8 +245,11 @@ class MusicFile(Machine):
244 self.stop_playing() 245 self.stop_playing()
245 self.stopped() 246 self.stopped()
246 247
247 def set_gain(self, db_gain): 248 def set_gain(self, db_gain, absolute=False):
248 self.db_gain += db_gain 249 if absolute:
250 self.db_gain = db_gain
251 else:
252 self.db_gain += db_gain
249 self.volume_factor = 10 ** (self.db_gain / 20) 253 self.volume_factor = 10 ** (self.db_gain / 20)
250 254
251 def set_volume(self, value, delta=False): 255 def set_volume(self, value, delta=False):