]>
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, **kwargs
):
78 # FIXME: Make it stoppable
79 # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait
82 def command_print(self
, command
= "", **kwargs
):
83 return "running command {}".format(command
)
85 def pause_print(self
, music
= None, **kwargs
):
87 return "pausing {}".format(music
.filename
)
89 return "pausing all musics"
91 def play_print(self
, music
= None, fade_in
= 0, start_at
= 0,
92 restart_if_running
= False, volume
= 100, **kwargs
):
95 message
+= music
.filename
100 message
+= " at {}s".format(start_at
)
103 message
+= " with {}s fade_in".format(fade_in
)
105 message
+= " at volume {}%".format(volume
)
107 if restart_if_running
:
108 message
+= " (restarting if already running)"
112 def stop_print(self
, music
= None, fade_out
= 0, **kwargs
):
113 if music
is not None:
115 return "stopping music {}".format(music
.filename
)
117 return "stopping music {} with {}s fadeout".format(music
.filename
, fade_out
)
120 return "stopping all musics"
122 return "stopping all musics with {}s fadeout".format(fade_out
)
124 def stop_all_actions_print(self
, **kwargs
):
125 return "stopping all actions"
127 def volume_print(self
, music
= None, value
= 100, **kwargs
):
128 if music
is not None:
129 return "setting volume of {} to {}%".format(music
.filename
, value
)
131 return "setting volume to {}%".format(value
)
133 def wait_print(self
, duration
, **kwargs
):
134 return "waiting {}s".format(duration
)