]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/music_file.py
Add debugger
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / music_file.py
index 7e5f978855c8b6c8dc4b4b47b9d22ef5ae3177d3..5b0d0dffdf2205d90e5c7fddbb3a2723860db659 100644 (file)
@@ -6,7 +6,7 @@ from transitions.extensions import HierarchicalMachine as Machine
 import os.path
 
 from .lock import Lock
-from . import Config, gain
+from . import Config, gain, debug_print, error_print
 from .mixer import Mixer
 
 file_lock = Lock("file")
@@ -32,8 +32,6 @@ class MusicFile(Machine):
 
         Machine.__init__(self, states=states, transitions=transitions, initial='initial')
 
-        # FIXME: catch error here
-        self.mixer = mapping.mixer or Mixer()
         self.volume = 100
         self.mapping = mapping
         self.filename = filename
@@ -49,18 +47,19 @@ class MusicFile(Machine):
     def on_enter_loading(self):
         with file_lock:
             try:
-                print("Loading « {} »".format(self.name))
+                debug_print("Loading « {} »".format(self.name))
+                self.mixer = self.mapping.mixer or Mixer()
                 db_gain = gain(self.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(db_gain)
                 self.audio_segment_frame_width = self.audio_segment.frame_width
                 self.sound_duration = self.audio_segment.duration_seconds
             except Exception as e:
-                print("failed to load « {} »: {}".format(self.name, e))
+                error_print("failed to load « {} »: {}".format(self.name, e))
                 self.loading_error = e
                 self.fail()
             else:
                 self.success()
-                print("Loaded « {} »".format(self.name))
+                debug_print("Loaded « {} »".format(self.name))
 
     def check_is_loaded(self):
         return self.state.startswith('loaded_')