X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git;a=blobdiff_plain;f=helpers%2Fmusic_file.py;h=ba8614204e030423c2aa71baca8b3f084143e759;hp=9976306bcd254436f4dc030c5c51408de377b0ae;hb=ab47d2a1269c20d70f42942c4295c056544491f4;hpb=4b6d1836f3cc6e063bca3f4011ce5d17f733baa6 diff --git a/helpers/music_file.py b/helpers/music_file.py index 9976306..ba86142 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -92,6 +92,31 @@ class MusicFile: threading.Thread(name="MSMusicLoad", target=self.load).start() + def reload_properties(self, name=None, gain=1): + self.name = name or self.filename + if gain != self.initial_volume_factor: + self.initial_volume_factor = gain + self.reload_music_file() + + def reload_music_file(self): + with file_lock: + try: + debug_print("Reloading « {} »".format(self.name)) + initial_db_gain = gain(self.initial_volume_factor * 100) + self.audio_segment = pydub.AudioSegment \ + .from_file(self.filename) \ + .set_frame_rate(Config.frame_rate) \ + .set_channels(Config.channels) \ + .set_sample_width(Config.sample_width) \ + .apply_gain(initial_db_gain) + except Exception as e: + error_print("failed to reload « {} »: {}"\ + .format(self.name, e)) + self.loading_error = e + self.to_failed() + else: + debug_print("Reloaded « {} »".format(self.name)) + # Machine related events def on_enter_loading(self): with file_lock: