from kivy.uix.relativelayout import RelativeLayout
-from kivy.properties import NumericProperty, ListProperty
+from kivy.properties import NumericProperty, ListProperty, StringProperty
from kivy.core.window import Window
from kivy.clock import Clock
'trigger': 'success',
'source': 'loading',
'dest': 'loaded'
+ },
+ {
+ 'trigger': 'reload',
+ 'source': 'loaded',
+ 'dest': 'configuring'
}
]
master_volume = NumericProperty(100)
ready_color = ListProperty([1, 165/255, 0, 1])
+ state = StringProperty("")
def __init__(self, **kwargs):
+ self.keys = []
+ self.running = []
+ self.wait_ids = {}
+ self.open_files = {}
+
+ Machine(model=self, states=self.STATES,
+ transitions=self.TRANSITIONS, initial='initial',
+ ignore_invalid_triggers=True, queued=True)
+ super(Mapping, self).__init__(**kwargs)
+ self.keyboard = Window.request_keyboard(self.on_keyboard_closed, self)
+ self.keyboard.bind(on_key_down=self.on_keyboard_down)
+
+ self.configure()
+
+ def on_enter_configuring(self):
if Config.builtin_mixing:
self.mixer = Mixer()
else:
error_print("Error while loading configuration: {}".format(e),
with_trace=True)
sys.exit()
+ else:
+ self.success()
- self.keys = []
- self.running = []
- self.wait_ids = {}
-
- super(Mapping, self).__init__(**kwargs)
- self.keyboard = Window.request_keyboard(self.on_keyboard_closed, self)
- self.keyboard.bind(on_key_down=self.on_keyboard_down)
+ def on_enter_loading(self):
+ for key in self.keys:
+ key.reload()
+ self.success()
# Kivy events
def add_widget(self, widget, index=0):
thread.join()
sys.exit()
+ elif 'ctrl' in modifiers and keycode[0] == 114:
+ threading.Thread(name="MSReload", target=self.reload).start()
return True
# Helpers
self.ready_color = [0, 1, 0, 1]
elif result == "partial":
self.ready_color = [1, 0, 0, 1]
+ else:
+ self.ready_color = [1, 165/255, 0, 1]
## Some global actions
def stop_all_running(self):
music_properties[filename],
filename)
- seen_files[filename] = MusicFile(
- filename, self, **music_property)
+ if filename in self.open_files:
+ self.open_files[filename]\
+ .reload_properties(**music_property)
+
+ seen_files[filename] = self.open_files[filename]
+ else:
+ seen_files[filename] = MusicFile(
+ filename, self, **music_property)
if filename not in key_properties[mapped_key]['files']:
key_properties[mapped_key]['files'] \
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: