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")
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
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_')