]>
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
):
46 if restart_if_running
:
47 if music
.is_playing():
49 music
.play(volume
= volume
, fade_in
= fade_in
, start_at
= start_at
)
51 if not music
.is_playing():
52 music
.play(volume
= volume
, fade_in
= fade_in
, start_at
= start_at
)
54 pygame
.mixer
.unpause()
56 def stop(self
, music
= None, fade_out
= 0, **kwargs
):
58 music
.stop(fade_out
= fade_out
)
61 pygame
.fadeout(fade_out
* 1000)
65 def stop_all_actions(self
, **kwargs
):
66 self
.key
.mapping
.stop_all_running()
68 def volume(self
, music
= None, value
= 100, **kwargs
):
70 music
.set_volume(value
)
74 def wait(self
, duration
= 0, **kwargs
):
75 # FIXME: Make it stoppable
76 # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait
79 def command_print(self
, command
= "", **kwargs
):
80 return "running command {}".format(command
)
82 def pause_print(self
, music
= None, **kwargs
):
84 return "pausing {}".format(music
.filename
)
86 return "pausing all musics"
88 def play_print(self
, music
= None, fade_in
= 0, start_at
= 0,
89 restart_if_running
= False, volume
= 100, **kwargs
):
92 message
+= music
.filename
97 message
+= " at {}s".format(start_at
)
100 message
+= " with {}s fade_in".format(fade_in
)
102 message
+= " at volume {}%".format(volume
)
104 if restart_if_running
:
105 message
+= " (restarting if already running)"
109 def stop_print(self
, music
= None, fade_out
= 0, **kwargs
):
110 if music
is not None:
112 return "stopping music {}".format(music
.filename
)
114 return "stopping music {} with {}s fadeout".format(music
.filename
, fade_out
)
117 return "stopping all musics"
119 return "stopping all musics with {}s fadeout".format(fade_out
)
121 def stop_all_actions_print(self
, **kwargs
):
122 return "stopping all actions"
124 def volume_print(self
, music
= None, value
= 100, **kwargs
):
125 if music
is not None:
126 return "setting volume of {} to {}%".format(music
.filename
, value
)
128 return "setting volume to {}%".format(value
)
130 def wait_print(self
, duration
, **kwargs
):
131 return "waiting {}s".format(duration
)