aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/mapping.py
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler/mapping.py')
-rw-r--r--music_sampler/mapping.py50
1 files changed, 23 insertions, 27 deletions
diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py
index 9e40d40..a526ad2 100644
--- a/music_sampler/mapping.py
+++ b/music_sampler/mapping.py
@@ -22,8 +22,7 @@ class Mapping(RelativeLayout):
22 'configuring', 22 'configuring',
23 'configured', 23 'configured',
24 'loading', 24 'loading',
25 'loaded', 25 'loaded'
26 'failed'
27 ] 26 ]
28 27
29 TRANSITIONS = [ 28 TRANSITIONS = [
@@ -33,11 +32,6 @@ class Mapping(RelativeLayout):
33 'dest': 'configuring' 32 'dest': 'configuring'
34 }, 33 },
35 { 34 {
36 'trigger': 'fail',
37 'source': 'configuring',
38 'dest': 'failed'
39 },
40 {
41 'trigger': 'success', 35 'trigger': 'success',
42 'source': 'configuring', 36 'source': 'configuring',
43 'dest': 'configured', 37 'dest': 'configured',
@@ -49,11 +43,6 @@ class Mapping(RelativeLayout):
49 'dest': 'loading' 43 'dest': 'loading'
50 }, 44 },
51 { 45 {
52 'trigger': 'fail',
53 'source': 'loading',
54 'dest': 'failed'
55 },
56 {
57 'trigger': 'success', 46 'trigger': 'success',
58 'source': 'loading', 47 'source': 'loading',
59 'dest': 'loaded' 48 'dest': 'loaded'
@@ -74,17 +63,18 @@ class Mapping(RelativeLayout):
74 self.running = [] 63 self.running = []
75 self.wait_ids = {} 64 self.wait_ids = {}
76 self.open_files = {} 65 self.open_files = {}
66 self.is_leaving_application = False
77 67
78 Machine(model=self, states=self.STATES, 68 Machine(model=self, states=self.STATES,
79 transitions=self.TRANSITIONS, initial='initial', 69 transitions=self.TRANSITIONS, initial='initial',
80 ignore_invalid_triggers=True, queued=True) 70 auto_transitions=False, queued=True)
81 super(Mapping, self).__init__(**kwargs) 71 super(Mapping, self).__init__(**kwargs)
82 self.keyboard = Window.request_keyboard(self.on_keyboard_closed, self) 72 self.keyboard = Window.request_keyboard(self.on_keyboard_closed, self)
83 self.keyboard.bind(on_key_down=self.on_keyboard_down) 73 self.keyboard.bind(on_key_down=self.on_keyboard_down)
84 74
85 self.configure() 75 self.configure(initial=True)
86 76
87 def on_enter_configuring(self): 77 def on_enter_configuring(self, initial=True):
88 if Config.builtin_mixing: 78 if Config.builtin_mixing:
89 self.mixer = Mixer() 79 self.mixer = Mixer()
90 else: 80 else:
@@ -94,9 +84,9 @@ class Mapping(RelativeLayout):
94 self.key_config, self.open_files = self.parse_config() 84 self.key_config, self.open_files = self.parse_config()
95 except Exception as e: 85 except Exception as e:
96 error_print("Error while loading configuration: {}".format(e), 86 error_print("Error while loading configuration: {}".format(e),
97 with_trace=True, exit=True) 87 with_trace=False, exit=initial)
98 else: 88
99 self.success() 89 self.success()
100 90
101 def on_enter_loading(self): 91 def on_enter_loading(self):
102 for key in self.keys: 92 for key in self.keys:
@@ -127,13 +117,14 @@ class Mapping(RelativeLayout):
127 elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'): 117 elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'):
128 self.leave_application() 118 self.leave_application()
129 sys.exit() 119 sys.exit()
130 elif 'ctrl' in modifiers and keycode[0] == 114: 120 elif 'ctrl' in modifiers and keycode[0] == 114 and self.is_loaded():
131 threading.Thread(name="MSReload", target=self.reload).start() 121 self.reload(initial=False)
132 return True 122 return True
133 123
134 def leave_application(self): 124 def leave_application(self):
135 self.keyboard.unbind(on_key_down=self.on_keyboard_down) 125 self.keyboard.unbind(on_key_down=self.on_keyboard_down)
136 self.stop_all_running() 126 self.stop_all_running()
127 self.is_leaving_application = True
137 for music in self.open_files.values(): 128 for music in self.open_files.values():
138 music.stop() 129 music.stop()
139 for thread in threading.enumerate(): 130 for thread in threading.enumerate():
@@ -167,13 +158,20 @@ class Mapping(RelativeLayout):
167 158
168 # Callbacks 159 # Callbacks
169 def key_loaded_callback(self): 160 def key_loaded_callback(self):
161 if hasattr(self, 'finished_loading'):
162 return
163
164 opacity = int(Config.load_all_musics)
165
170 result = self.all_keys_ready() 166 result = self.all_keys_ready()
171 if result == "success": 167 if result == "success":
172 self.ready_color = [0, 1, 0, 1] 168 self.ready_color = [0, 1, 0, opacity]
169 self.finished_loading = True
173 elif result == "partial": 170 elif result == "partial":
174 self.ready_color = [1, 0, 0, 1] 171 self.ready_color = [1, 0, 0, opacity]
172 self.finished_loading = True
175 else: 173 else:
176 self.ready_color = [1, 165/255, 0, 1] 174 self.ready_color = [1, 165/255, 0, opacity]
177 175
178 ## Some global actions 176 ## Some global actions
179 def stop_all_running(self, except_key=None, key_start_time=0): 177 def stop_all_running(self, except_key=None, key_start_time=0):
@@ -350,13 +348,11 @@ class Mapping(RelativeLayout):
350 try: 348 try:
351 config = yaml.safe_load(stream) 349 config = yaml.safe_load(stream)
352 except Exception as e: 350 except Exception as e:
353 error_print("Error while loading config file: {}".format(e), 351 raise Exception("Error while loading config file: {}".format(e)) from e
354 exit=True)
355 stream.close() 352 stream.close()
356 353
357 if not isinstance(config, dict): 354 if not isinstance(config, dict):
358 error_print("Top level config is supposed to be a hash", 355 raise Exception("Top level config is supposed to be a hash")
359 exit=True)
360 356
361 if 'aliases' in config and isinstance(config['aliases'], dict): 357 if 'aliases' in config and isinstance(config['aliases'], dict):
362 aliases = config['aliases'] 358 aliases = config['aliases']