aboutsummaryrefslogtreecommitdiff
path: root/helpers/action.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 13:26:39 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 13:26:39 +0200
commit29597680758e4924aa71fc021465189e153f2016 (patch)
treef86b35983958ed5d82d8d4c3dd47dd3cd6ca1815 /helpers/action.py
parent9b9dd12a0253f2e65c5934068d91b544f7679f12 (diff)
downloadMusicSampler-29597680758e4924aa71fc021465189e153f2016.tar.gz
MusicSampler-29597680758e4924aa71fc021465189e153f2016.tar.zst
MusicSampler-29597680758e4924aa71fc021465189e153f2016.zip
Move from pygame to sounddevice for sound handling
Move lock files to files Add with statement to lock
Diffstat (limited to 'helpers/action.py')
-rw-r--r--helpers/action.py39
1 files changed, 17 insertions, 22 deletions
diff --git a/helpers/action.py b/helpers/action.py
index b921fbf..69ae96f 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -38,43 +38,37 @@ class Action:
38 def command(self, command = "", **kwargs): 38 def command(self, command = "", **kwargs):
39 pass 39 pass
40 40
41 def pause(self, music = None, **kwargs): 41 def music_list(self, music):
42 if music is not None: 42 if music is not None:
43 music.pause() 43 return [music]
44 else: 44 else:
45 for music in self.key.parent.open_files.values(): 45 return self.key.parent.open_files.values()
46 if music.is_playing() and not music.is_paused(): 46
47 music.pause() 47 def pause(self, music = None, **kwargs):
48 for music in self.music_list(music):
49 if music.is_loaded_playing():
50 music.pause()
48 51
49 def unpause(self, music = None, **kwargs): 52 def unpause(self, music = None, **kwargs):
50 if music is not None: 53 for music in self.music_list(music):
51 music.unpause() 54 if music.is_loaded_paused():
52 else: 55 music.unpause()
53 for music in self.key.parent.open_files.values():
54 if music.is_playing() and music.is_paused():
55 music.unpause()
56 56
57 def play(self, music = None, fade_in = 0, start_at = 0, 57 def play(self, music = None, fade_in = 0, start_at = 0,
58 restart_if_running = False, volume = 100, **kwargs): 58 restart_if_running = False, volume = 100, **kwargs):
59 if music is not None: 59 if music is not None:
60 if restart_if_running: 60 if restart_if_running:
61 if music.is_playing(): 61 if music.is_not_stopped():
62 music.stop() 62 music.stop()
63 music.play(volume = volume, fade_in = fade_in, start_at = start_at) 63 music.play(volume = volume, fade_in = fade_in, start_at = start_at)
64 else: 64 else:
65 if not music.is_playing(): 65 if not music.is_not_stopped():
66 music.play(volume = volume, fade_in = fade_in, start_at = start_at) 66 music.play(volume = volume, fade_in = fade_in, start_at = start_at)
67 else:
68 pygame.mixer.unpause()
69 67
70 def stop(self, music = None, fade_out = 0, **kwargs): 68 def stop(self, music = None, fade_out = 0, **kwargs):
71 if music is not None: 69 for music in self.music_list(music):
72 music.stop(fade_out = fade_out) 70 if music.is_loaded_paused() or music.is_loaded_playing():
73 else: 71 music.stop(fade_out = fade_out)
74 if fade_out > 0:
75 pygame.mixer.fadeout(int(fade_out * 1000))
76 else:
77 pygame.mixer.stop()
78 72
79 def stop_all_actions(self, **kwargs): 73 def stop_all_actions(self, **kwargs):
80 self.key.parent.stop_all_running() 74 self.key.parent.stop_all_running()
@@ -83,6 +77,7 @@ class Action:
83 if music is not None: 77 if music is not None:
84 music.set_volume(value) 78 music.set_volume(value)
85 else: 79 else:
80 # FIXME: todo
86 pass 81 pass
87 82
88 def wait(self, duration = 0, music = None, **kwargs): 83 def wait(self, duration = 0, music = None, **kwargs):