aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-18 21:17:02 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-18 21:17:02 +0200
commitb37c72a236806f02e5538ba7e607f6add0cc6fb6 (patch)
treef3a9eb298709190dc7b5a72426e4b0d2c5701f0a /helpers
parent6c44b2313c8c115ee05ffe9106ccd8517ec5c66b (diff)
downloadMusicSampler-b37c72a236806f02e5538ba7e607f6add0cc6fb6.tar.gz
MusicSampler-b37c72a236806f02e5538ba7e607f6add0cc6fb6.tar.zst
MusicSampler-b37c72a236806f02e5538ba7e607f6add0cc6fb6.zip
Fix initial volume factor
Diffstat (limited to 'helpers')
-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):