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):
def on_keyboard_down(self, keyboard, keycode, text, modifiers):
key = self.find_by_key_code(keycode)
- if len(modifiers) == 0 and key is not None:
- threading.Thread(name="MSKeyAction", target=key.run).start()
+ if self.allowed_modifiers(modifiers) and key is not None:
+ modifiers.sort()
+ threading.Thread(name="MSKeyAction", target=key.run,
+ args=['-'.join(modifiers)]).start()
elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'):
self.stop_all_running()
for thread in threading.enumerate():
thread.join()
sys.exit()
+ elif 'ctrl' in modifiers and keycode[0] == 114:
+ threading.Thread(name="MSReload", target=self.reload).start()
return True
+ # Helpers
+ def allowed_modifiers(self, modifiers):
+ allowed = []
+ return len([a for a in modifiers if a not in allowed]) == 0
+
def find_by_key_code(self, key_code):
if "Key_" + str(key_code[0]) in self.ids:
return self.ids["Key_" + str(key_code[0])]
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'] \