aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 00:51:48 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 00:51:48 +0200
commitb17aed6aba689f484a4932d99b30aff1bdee7176 (patch)
tree1e45363eea8cb76580092e38447374d5cae02854
parent1094ab1ac48313b0c1caec15bc4fb6c584efa047 (diff)
downloadMusicSampler-b17aed6aba689f484a4932d99b30aff1bdee7176.tar.gz
MusicSampler-b17aed6aba689f484a4932d99b30aff1bdee7176.tar.zst
MusicSampler-b17aed6aba689f484a4932d99b30aff1bdee7176.zip
Improve actions listing
-rw-r--r--helpers/key.py35
-rw-r--r--music_sampler.py13
2 files changed, 31 insertions, 17 deletions
diff --git a/helpers/key.py b/helpers/key.py
index 9099f00..c21f9ae 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -78,7 +78,7 @@ class Key(ButtonBehavior, Widget):
78 'trigger': 'run', 78 'trigger': 'run',
79 'source': 'loaded', 79 'source': 'loaded',
80 'dest': 'loaded_running', 80 'dest': 'loaded_running',
81 'after': 'finish', 81 'after': ['run_actions', 'finish'],
82 # if a child, like loaded_no_actions, has no transitions, then it is 82 # if a child, like loaded_no_actions, has no transitions, then it is
83 # bubbled to the parent, and we don't want that. 83 # bubbled to the parent, and we don't want that.
84 'conditions': ['is_loaded'] 84 'conditions': ['is_loaded']
@@ -125,6 +125,8 @@ class Key(ButtonBehavior, Widget):
125 125
126 def __init__(self, **kwargs): 126 def __init__(self, **kwargs):
127 self.actions = [] 127 self.actions = []
128 self.current_action = None
129
128 Machine(model=self, states=self.STATES, 130 Machine(model=self, states=self.STATES,
129 transitions=self.TRANSITIONS, initial='initial', 131 transitions=self.TRANSITIONS, initial='initial',
130 ignore_invalid_triggers=True, queued=True) 132 ignore_invalid_triggers=True, queued=True)
@@ -168,18 +170,16 @@ class Key(ButtonBehavior, Widget):
168 else: 170 else:
169 self.no_actions() 171 self.no_actions()
170 172
171 def on_enter_loaded_running(self, modifiers): 173 def run_actions(self, modifiers):
172 self.parent.parent.ids['KeyList'].append(self.key_sym) 174 self.parent.parent.ids['KeyList'].append(self.key_sym)
173 debug_print("running actions for {}".format(self.key_sym)) 175 debug_print("running actions for {}".format(self.key_sym))
174 start_time = time.time() 176 start_time = time.time()
175 self.parent.start_running(self, start_time) 177 self.parent.start_running(self, start_time)
176 action_number = 0
177 for self.current_action in self.actions: 178 for self.current_action in self.actions:
178 if self.parent.keep_running(self, start_time): 179 if self.parent.keep_running(self, start_time):
179 self.list_actions(action_number=action_number + 0.5) 180 self.list_actions()
180 self.current_action.run() 181 self.current_action.run()
181 action_number += 1 182 self.list_actions(last_action_finished=True)
182 self.list_actions(action_number=action_number)
183 183
184 self.parent.finished_running(self, start_time) 184 self.parent.finished_running(self, start_time)
185 185
@@ -217,6 +217,23 @@ class Key(ButtonBehavior, Widget):
217 def add_action(self, action_name, **arguments): 217 def add_action(self, action_name, **arguments):
218 self.actions.append(Action(action_name, self, **arguments)) 218 self.actions.append(Action(action_name, self, **arguments))
219 219
220 def list_actions(self, action_number=0): 220 def list_actions(self, last_action_finished=False):
221 self.parent.parent.ids['ActionList'].update_list(self, action_number) 221 not_running = (not self.is_loaded_running())
222 222 current_action_seen = False
223 action_descriptions = []
224 for action in self.actions:
225 if not_running:
226 state = "inactive"
227 elif last_action_finished:
228 state = "done"
229 elif current_action_seen:
230 state = "pending"
231 elif action == self.current_action:
232 current_action_seen = True
233 state = "current"
234 else:
235 state = "done"
236 action_descriptions.append([action.description(), state])
237 self.parent.parent.ids['ActionList'].update_list(
238 self,
239 action_descriptions)
diff --git a/music_sampler.py b/music_sampler.py
index 41b71be..c10b634 100644
--- a/music_sampler.py
+++ b/music_sampler.py
@@ -62,21 +62,18 @@ class ActionList(RelativeLayout):
62 action_title = StringProperty("") 62 action_title = StringProperty("")
63 action_list = ListProperty([]) 63 action_list = ListProperty([])
64 64
65 def update_list(self, key, action_number = 0): 65 def update_list(self, key, action_descriptions):
66 self.action_title = "actions linked to key {}:".format(key.key_sym) 66 self.action_title = "actions linked to key {}:".format(key.key_sym)
67 self.action_list = [] 67 self.action_list = []
68 68
69 action_descriptions = [action.description() for action in key.actions] 69 for [action, status] in action_descriptions:
70 70 if status == "done":
71 for index, description in enumerate(action_descriptions):
72 if index < int(action_number):
73 icon = "✓" 71 icon = "✓"
74 elif index + 0.5 == action_number: 72 elif status == "current":
75 icon = "✅" 73 icon = "✅"
76 else: 74 else:
77 icon = " " 75 icon = " "
78 76 self.action_list.append([icon, action])
79 self.action_list.append([icon, description])
80 77
81class Screen(FloatLayout): 78class Screen(FloatLayout):
82 pass 79 pass