]>
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(getattr(self
, self
.action
+ "_print")(**self
.arguments
))
32 return getattr(self
, self
.action
)(**self
.arguments
)
34 def command(self
, command
= "", **kwargs
):
37 def pause(self
, music
= None, **kwargs
):
43 def play(self
, music
= None, fade_in
= 0, start_at
= 0,
44 restart_if_running
= False, volume
= 100, **kwargs
):
48 pygame
.mixer
.unpause()
50 def stop(self
, music
= None, fade_out
= 0, **kwargs
):
56 def stop_all_actions(self
, **kwargs
):
57 self
.key
.mapping
.stop_all_running()
59 def volume(self
, music
= None, value
= 100, **kwargs
):
62 def wait(self
, duration
= 0, **kwargs
):
65 def command_print(self
, command
= "", **kwargs
):
66 return "running command {}".format(command
)
68 def pause_print(self
, music
= None, **kwargs
):
70 return "pausing {}".format(music
.filename
)
72 return "pausing all musics"
74 def play_print(self
, music
= None, fade_in
= 0, start_at
= 0,
75 restart_if_running
= False, volume
= 100, **kwargs
):
78 message
+= music
.filename
83 message
+= " at {}s".format(start_at
)
86 message
+= " with {}s fade_in".format(fade_in
)
88 message
+= " at volume {}%".format(volume
)
90 if restart_if_running
:
91 message
+= " (restarting if already running)"
95 def stop_print(self
, music
= None, fade_out
= 0, **kwargs
):
98 return "stopping music {}".format(music
.filename
)
100 return "stopping music {} with {}s fadeout".format(music
.filename
, fade_out
)
103 return "stopping all musics"
105 return "stopping all musics with {}s fadeout".format(fade_out
)
107 def stop_all_actions_print(self
):
108 return "stopping all actions"
110 def volume_print(self
, music
= None, value
= 100, *kwargs
):
111 if music
is not None:
112 return "setting volume of {} to {}%".format(music
.filename
, value
)
114 return "setting volume to {}%".format(value
)
116 def wait_print(self
, duration
, **kwargs
):
117 return "waiting {}s".format(duration
)