]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/action.py
15 def __init__(self
, action
, key
, **kwargs
):
16 if action
in self
.action_types
:
19 raise Exception("Unknown action {}".format(action
))
22 self
.arguments
= kwargs
25 if 'music' in self
.arguments
:
26 return self
.arguments
['music'].loaded
31 print(self
.description())
32 return getattr(self
, self
.action
)(**self
.arguments
)
34 def description(self
):
35 return getattr(self
, self
.action
+ "_print")(**self
.arguments
)
37 def command(self
, command
= "", **kwargs
):
40 def pause(self
, music
= None, **kwargs
):
46 def play(self
, music
= None, fade_in
= 0, start_at
= 0,
47 restart_if_running
= False, volume
= 100, **kwargs
):
49 if restart_if_running
:
50 if music
.is_playing():
52 music
.play(volume
= volume
, fade_in
= fade_in
, start_at
= start_at
)
54 if not music
.is_playing():
55 music
.play(volume
= volume
, fade_in
= fade_in
, start_at
= start_at
)
57 pygame
.mixer
.unpause()
59 def stop(self
, music
= None, fade_out
= 0, **kwargs
):
61 music
.stop(fade_out
= fade_out
)
64 pygame
.fadeout(fade_out
* 1000)
68 def stop_all_actions(self
, **kwargs
):
69 self
.key
.mapping
.stop_all_running()
71 def volume(self
, music
= None, value
= 100, **kwargs
):
73 music
.set_volume(value
)
77 def wait(self
, duration
= 0, music
= None, **kwargs
):
78 # FIXME: Make it stoppable
79 # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait
86 def command_print(self
, command
= "", **kwargs
):
87 return "running command {}".format(command
)
89 def pause_print(self
, music
= None, **kwargs
):
91 return "pausing {}".format(music
.filename
)
93 return "pausing all musics"
95 def play_print(self
, music
= None, fade_in
= 0, start_at
= 0,
96 restart_if_running
= False, volume
= 100, **kwargs
):
99 message
+= music
.filename
104 message
+= " at {}s".format(start_at
)
107 message
+= " with {}s fade_in".format(fade_in
)
109 message
+= " at volume {}%".format(volume
)
111 if restart_if_running
:
112 message
+= " (restarting if already running)"
116 def stop_print(self
, music
= None, fade_out
= 0, **kwargs
):
117 if music
is not None:
119 return "stopping music {}".format(music
.filename
)
121 return "stopping music {} with {}s fadeout".format(music
.filename
, fade_out
)
124 return "stopping all musics"
126 return "stopping all musics with {}s fadeout".format(fade_out
)
128 def stop_all_actions_print(self
, **kwargs
):
129 return "stopping all actions"
131 def volume_print(self
, music
= None, value
= 100, **kwargs
):
132 if music
is not None:
133 return "setting volume of {} to {}%".format(music
.filename
, value
)
135 return "setting volume to {}%".format(value
)
137 def wait_print(self
, duration
, **kwargs
):
138 return "waiting {}s".format(duration
)