]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Add repeat_delay to key properties heads/mapping_cleanup
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 26 Jul 2016 23:17:42 +0000 (01:17 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 26 Jul 2016 23:17:42 +0000 (01:17 +0200)
helpers/key.py

index c21f9ae2a0bf8ffa60f927e5646a6f65528c8b50..3c98ce74617ef15a7940afdbf4214ad29ce9f796 100644 (file)
@@ -6,6 +6,7 @@ from kivy.uix.behaviors import ButtonBehavior
 from .action import Action
 from . import debug_print
 import time
+import threading
 from transitions.extensions import HierarchicalMachine as Machine
 
 class Key(ButtonBehavior, Widget):
@@ -17,7 +18,12 @@ class Key(ButtonBehavior, Widget):
         'failed',
         {
             'name': 'loaded',
-            'children': ['no_config', 'no_actions', 'running']
+            'children': [
+                'no_config',
+                'no_actions',
+                'running',
+                'protecting_repeat'
+            ]
         }
     ]
 
@@ -86,8 +92,13 @@ class Key(ButtonBehavior, Widget):
         {
             'trigger': 'finish',
             'source': 'loaded_running',
+            'dest': 'loaded_protecting_repeat'
+        },
+        {
+            'trigger': 'repeat_protection_finished',
+            'source': 'loaded_protecting_repeat',
             'dest': 'loaded'
-        }
+        },
     ]
 
     key_sym = StringProperty(None)
@@ -111,6 +122,8 @@ class Key(ButtonBehavior, Widget):
     def get_alias_color(self):
         if self.is_loaded_inactive():
             return [1, 1, 1, 1]
+        elif self.is_loaded_protecting_repeat():
+            return [*self.custom_color, 100/255]
         elif self.is_loaded(allow_substates=True):
             return [*self.custom_color, 1]
         elif self.is_failed():
@@ -183,6 +196,15 @@ class Key(ButtonBehavior, Widget):
 
         self.parent.finished_running(self, start_time)
 
+    def on_enter_loaded_protecting_repeat(self, modifiers):
+        if 'repeat_delay' in self.config['properties']:
+            self.protecting_repeat_timer = threading.Timer(
+                    self.config['properties']['repeat_delay'],
+                    self.repeat_protection_finished)
+            self.protecting_repeat_timer.start()
+        else:
+            self.repeat_protection_finished()
+
     # This one cannot be in the Machine state since it would be queued to run
     # *after* the loop is ended...
     def interrupt(self):