aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 01:17:42 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 01:17:42 +0200
commit343822904ee26955e622e325539c64aee1c2112e (patch)
tree5878db371dc567ddfeaae4c3e83cac5d21407cf4 /helpers
parentb17aed6aba689f484a4932d99b30aff1bdee7176 (diff)
downloadMusicSampler-343822904ee26955e622e325539c64aee1c2112e.tar.gz
MusicSampler-343822904ee26955e622e325539c64aee1c2112e.tar.zst
MusicSampler-343822904ee26955e622e325539c64aee1c2112e.zip
Add repeat_delay to key properties
Diffstat (limited to 'helpers')
-rw-r--r--helpers/key.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/helpers/key.py b/helpers/key.py
index c21f9ae..3c98ce7 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -6,6 +6,7 @@ from kivy.uix.behaviors import ButtonBehavior
6from .action import Action 6from .action import Action
7from . import debug_print 7from . import debug_print
8import time 8import time
9import threading
9from transitions.extensions import HierarchicalMachine as Machine 10from transitions.extensions import HierarchicalMachine as Machine
10 11
11class Key(ButtonBehavior, Widget): 12class Key(ButtonBehavior, Widget):
@@ -17,7 +18,12 @@ class Key(ButtonBehavior, Widget):
17 'failed', 18 'failed',
18 { 19 {
19 'name': 'loaded', 20 'name': 'loaded',
20 'children': ['no_config', 'no_actions', 'running'] 21 'children': [
22 'no_config',
23 'no_actions',
24 'running',
25 'protecting_repeat'
26 ]
21 } 27 }
22 ] 28 ]
23 29
@@ -86,8 +92,13 @@ class Key(ButtonBehavior, Widget):
86 { 92 {
87 'trigger': 'finish', 93 'trigger': 'finish',
88 'source': 'loaded_running', 94 'source': 'loaded_running',
95 'dest': 'loaded_protecting_repeat'
96 },
97 {
98 'trigger': 'repeat_protection_finished',
99 'source': 'loaded_protecting_repeat',
89 'dest': 'loaded' 100 'dest': 'loaded'
90 } 101 },
91 ] 102 ]
92 103
93 key_sym = StringProperty(None) 104 key_sym = StringProperty(None)
@@ -111,6 +122,8 @@ class Key(ButtonBehavior, Widget):
111 def get_alias_color(self): 122 def get_alias_color(self):
112 if self.is_loaded_inactive(): 123 if self.is_loaded_inactive():
113 return [1, 1, 1, 1] 124 return [1, 1, 1, 1]
125 elif self.is_loaded_protecting_repeat():
126 return [*self.custom_color, 100/255]
114 elif self.is_loaded(allow_substates=True): 127 elif self.is_loaded(allow_substates=True):
115 return [*self.custom_color, 1] 128 return [*self.custom_color, 1]
116 elif self.is_failed(): 129 elif self.is_failed():
@@ -183,6 +196,15 @@ class Key(ButtonBehavior, Widget):
183 196
184 self.parent.finished_running(self, start_time) 197 self.parent.finished_running(self, start_time)
185 198
199 def on_enter_loaded_protecting_repeat(self, modifiers):
200 if 'repeat_delay' in self.config['properties']:
201 self.protecting_repeat_timer = threading.Timer(
202 self.config['properties']['repeat_delay'],
203 self.repeat_protection_finished)
204 self.protecting_repeat_timer.start()
205 else:
206 self.repeat_protection_finished()
207
186 # This one cannot be in the Machine state since it would be queued to run 208 # This one cannot be in the Machine state since it would be queued to run
187 # *after* the loop is ended... 209 # *after* the loop is ended...
188 def interrupt(self): 210 def interrupt(self):