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.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py
index 9e40d40..5c61f8a 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,10 +63,11 @@ 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)
@@ -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()
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):