aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helpers/action.py43
-rw-r--r--helpers/mapping.py14
-rw-r--r--helpers/music_file.py4
3 files changed, 51 insertions, 10 deletions
diff --git a/helpers/action.py b/helpers/action.py
index eaa419b..99cd399 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -6,6 +6,7 @@ from . import debug_print
6class Action: 6class Action:
7 action_types = [ 7 action_types = [
8 'command', 8 'command',
9 'interrupt_wait',
9 'pause', 10 'pause',
10 'play', 11 'play',
11 'seek', 12 'seek',
@@ -88,7 +89,11 @@ class Action:
88 for music in self.music_list(music): 89 for music in self.music_list(music):
89 music.seek(value=value, delta=delta) 90 music.seek(value=value, delta=delta)
90 91
91 def stop(self, music=None, fade_out=0, wait=False, **kwargs): 92 def interrupt_wait(self, wait_id=None):
93 self.mapping.interrupt_wait(wait_id)
94
95 def stop(self, music=None, fade_out=0, wait=False,
96 set_wait_id=None, **kwargs):
92 previous = None 97 previous = None
93 for music in self.music_list(music): 98 for music in self.music_list(music):
94 if music.is_loaded_paused() or music.is_loaded_playing(): 99 if music.is_loaded_paused() or music.is_loaded_playing():
@@ -99,7 +104,10 @@ class Action:
99 music.stop(fade_out=fade_out) 104 music.stop(fade_out=fade_out)
100 105
101 if previous is not None: 106 if previous is not None:
102 previous.stop(fade_out=fade_out, wait=wait) 107 previous.stop(
108 fade_out=fade_out,
109 wait=wait,
110 set_wait_id=set_wait_id)
103 111
104 def stop_all_actions(self, **kwargs): 112 def stop_all_actions(self, **kwargs):
105 self.mapping.stop_all_running() 113 self.mapping.stop_all_running()
@@ -110,7 +118,10 @@ class Action:
110 else: 118 else:
111 self.mapping.set_master_volume(value, delta=delta, fade=fade) 119 self.mapping.set_master_volume(value, delta=delta, fade=fade)
112 120
113 def wait(self, duration=0, music=None, **kwargs): 121 def wait(self, duration=0, music=None, set_wait_id=None, **kwargs):
122 if set_wait_id is not None:
123 self.mapping.add_wait_id(set_wait_id, self)
124
114 self.sleep_event = threading.Event() 125 self.sleep_event = threading.Event()
115 126
116 if music is not None: 127 if music is not None:
@@ -123,6 +134,9 @@ class Action:
123 def command_print(self, command="", **kwargs): 134 def command_print(self, command="", **kwargs):
124 return "running command {}".format(command) 135 return "running command {}".format(command)
125 136
137 def interrupt_wait_print(self, wait_id=None, **kwargs):
138 return "interrupt wait with id {}".format(wait_id)
139
126 def pause_print(self, music=None, **kwargs): 140 def pause_print(self, music=None, **kwargs):
127 if music is not None: 141 if music is not None:
128 return "pausing « {} »".format(music.name) 142 return "pausing « {} »".format(music.name)
@@ -161,7 +175,9 @@ class Action:
161 175
162 return message 176 return message
163 177
164 def stop_print(self, music=None, fade_out=0, wait=False, **kwargs): 178 def stop_print(self, music=None, fade_out=0, wait=False,
179 set_wait_id=None, **kwargs):
180
165 message = "stopping " 181 message = "stopping "
166 if music is not None: 182 if music is not None:
167 message += "music « {} »".format(music.name) 183 message += "music « {} »".format(music.name)
@@ -171,7 +187,11 @@ class Action:
171 if fade_out > 0: 187 if fade_out > 0:
172 message += " with {}s fadeout".format(fade_out) 188 message += " with {}s fadeout".format(fade_out)
173 if wait: 189 if wait:
174 message += " (waiting the end of fadeout)" 190 if set_wait_id is not None:
191 message += " (waiting the end of fadeout, with id {})"\
192 .format(set_wait_id)
193 else:
194 message += " (waiting the end of fadeout)"
175 195
176 return message 196 return message
177 197
@@ -217,17 +237,22 @@ class Action:
217 237
218 return message 238 return message
219 239
220 def wait_print(self, duration=0, music=None, **kwargs): 240 def wait_print(self, duration=0, music=None, set_wait_id=None, **kwargs):
241 message = ""
221 if music is None: 242 if music is None:
222 return "waiting {}s" \ 243 message += "waiting {}s" \
223 .format(duration) 244 .format(duration)
224 elif duration == 0: 245 elif duration == 0:
225 return "waiting the end of « {} »" \ 246 message += "waiting the end of « {} »" \
226 .format(music.name) 247 .format(music.name)
227 else: 248 else:
228 return "waiting the end of « {} » + {}s" \ 249 message += "waiting the end of « {} » + {}s" \
229 .format(music.name, duration) 250 .format(music.name, duration)
230 251
252 if set_wait_id is not None:
253 message += " (setting id = {})".format(set_wait_id)
254
255 return message
231 256
232 # Interruptions 257 # Interruptions
233 def wait_interrupt(self, duration=0, music=None, **kwargs): 258 def wait_interrupt(self, duration=0, music=None, **kwargs):
diff --git a/helpers/mapping.py b/helpers/mapping.py
index 43cacf2..0c81af4 100644
--- a/helpers/mapping.py
+++ b/helpers/mapping.py
@@ -11,6 +11,7 @@ from .music_file import *
11from .mixer import Mixer 11from .mixer import Mixer
12from . import Config, gain, error_print 12from . import Config, gain, error_print
13from .music_effect import GainEffect 13from .music_effect import GainEffect
14from .action import Action
14 15
15class Mapping(RelativeLayout): 16class Mapping(RelativeLayout):
16 expected_keys = NumericProperty(0) 17 expected_keys = NumericProperty(0)
@@ -27,6 +28,7 @@ class Mapping(RelativeLayout):
27 self._keyboard = Window.request_keyboard(self._keyboard_closed, self) 28 self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
28 self._keyboard.bind(on_key_down=self._on_keyboard_down) 29 self._keyboard.bind(on_key_down=self._on_keyboard_down)
29 self.running = [] 30 self.running = []
31 self.wait_ids = {}
30 Clock.schedule_interval(self.not_all_keys_ready, 1) 32 Clock.schedule_interval(self.not_all_keys_ready, 1)
31 33
32 @property 34 @property
@@ -53,6 +55,18 @@ class Mapping(RelativeLayout):
53 else: 55 else:
54 music.set_gain(db_gain) 56 music.set_gain(db_gain)
55 57
58 def add_wait_id(self, wait_id, action_or_wait):
59 self.wait_ids[wait_id] = action_or_wait
60
61 def interrupt_wait(self, wait_id):
62 if wait_id in self.wait_ids:
63 action_or_wait = self.wait_ids[wait_id]
64 del(self.wait_ids[wait_id])
65 if isinstance(action_or_wait, Action):
66 action_or_wait.interrupt()
67 else:
68 action_or_wait.set()
69
56 def _keyboard_closed(self): 70 def _keyboard_closed(self):
57 self._keyboard.unbind(on_key_down=self._on_keyboard_down) 71 self._keyboard.unbind(on_key_down=self._on_keyboard_down)
58 self._keyboard = None 72 self._keyboard = None
diff --git a/helpers/music_file.py b/helpers/music_file.py
index 5f4fe76..b0e218f 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -259,7 +259,7 @@ class MusicFile(Machine):
259 self.gain_effects = [] 259 self.gain_effects = []
260 self.set_gain(db_gain) 260 self.set_gain(db_gain)
261 261
262 def stop(self, fade_out=0, wait=False): 262 def stop(self, fade_out=0, wait=False, set_wait_id=None):
263 if self.is_loaded_playing(): 263 if self.is_loaded_playing():
264 ms = int(self.sound_position * 1000) 264 ms = int(self.sound_position * 1000)
265 ms_fo = max(1, int(fade_out * 1000)) 265 ms_fo = max(1, int(fade_out * 1000))
@@ -270,6 +270,8 @@ class MusicFile(Machine):
270 self.current_audio_segment = new_audio_segment 270 self.current_audio_segment = new_audio_segment
271 self.stop_playing() 271 self.stop_playing()
272 if wait: 272 if wait:
273 if set_wait_id is not None:
274 self.mapping.add_wait_id(set_wait_id, self.wait_event)
273 self.wait_end() 275 self.wait_end()
274 else: 276 else:
275 self.stop_playing() 277 self.stop_playing()