diff options
-rw-r--r-- | helpers/action.py | 17 | ||||
-rw-r--r-- | helpers/music_file.py | 7 |
2 files changed, 24 insertions, 0 deletions
diff --git a/helpers/action.py b/helpers/action.py index 2f294a0..3dc1b8d 100644 --- a/helpers/action.py +++ b/helpers/action.py | |||
@@ -6,6 +6,7 @@ class Action: | |||
6 | 'command', | 6 | 'command', |
7 | 'pause', | 7 | 'pause', |
8 | 'play', | 8 | 'play', |
9 | 'seek', | ||
9 | 'stop', | 10 | 'stop', |
10 | 'stop_all_actions', | 11 | 'stop_all_actions', |
11 | 'unpause', | 12 | 'unpause', |
@@ -73,6 +74,10 @@ class Action: | |||
73 | if not music.is_not_stopped(): | 74 | if not music.is_not_stopped(): |
74 | music.play(volume = volume, fade_in = fade_in, start_at = start_at) | 75 | music.play(volume = volume, fade_in = fade_in, start_at = start_at) |
75 | 76 | ||
77 | def seek(self, music = None, value = 0, delta = False, **kwargs): | ||
78 | for music in self.music_list(music): | ||
79 | music.seek(value = value, delta = delta) | ||
80 | |||
76 | def stop(self, music = None, fade_out = 0, wait = False, **kwargs): | 81 | def stop(self, music = None, fade_out = 0, wait = False, **kwargs): |
77 | previous = None | 82 | previous = None |
78 | for music in self.music_list(music): | 83 | for music in self.music_list(music): |
@@ -156,6 +161,18 @@ class Action: | |||
156 | def stop_all_actions_print(self, **kwargs): | 161 | def stop_all_actions_print(self, **kwargs): |
157 | return "stopping all actions" | 162 | return "stopping all actions" |
158 | 163 | ||
164 | def seek_print(self, music = None, value = 0, delta = False, **kwargs): | ||
165 | if delta: | ||
166 | if music is not None: | ||
167 | return "moving music « {} » by {:+d}s".format(music.name, value) | ||
168 | else: | ||
169 | return "moving all musics by {:+d}s".format(value) | ||
170 | else: | ||
171 | if music is not None: | ||
172 | return "moving music « {} » to position {}s".format(music.name, value) | ||
173 | else: | ||
174 | return "moving all musics to position {}s".format(value) | ||
175 | |||
159 | def volume_print(self, music = None, value = 100, delta = False, **kwargs): | 176 | def volume_print(self, music = None, value = 100, delta = False, **kwargs): |
160 | if delta: | 177 | if delta: |
161 | if music is not None: | 178 | if music is not None: |
diff --git a/helpers/music_file.py b/helpers/music_file.py index b926c64..32869b6 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py | |||
@@ -129,6 +129,13 @@ class MusicFile(Machine): | |||
129 | 129 | ||
130 | out_data[:] = audio_segment.ljust(len(out_data), b'\0') | 130 | out_data[:] = audio_segment.ljust(len(out_data), b'\0') |
131 | 131 | ||
132 | def seek(self, value = 0, delta = False): | ||
133 | # We don't want to do that while stopping | ||
134 | if not (self.is_loaded_playing() or self.is_loaded_paused()): | ||
135 | return | ||
136 | with self.music_lock: | ||
137 | self.current_frame = max(0, int(delta) * self.current_frame + int(value * self.audio_segment.frame_rate)) | ||
138 | |||
132 | def stop(self, fade_out = 0, wait = False): | 139 | def stop(self, fade_out = 0, wait = False): |
133 | if self.is_loaded_playing(): | 140 | if self.is_loaded_playing(): |
134 | ms = int(self.sound_position * 1000) | 141 | ms = int(self.sound_position * 1000) |