]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/action.py
69ae96fb8581b5f0bc0006d7841394e37ec87500
16 def __init__(self
, action
, key
, **kwargs
):
17 if action
in self
.action_types
:
20 raise Exception("Unknown action {}".format(action
))
23 self
.arguments
= kwargs
26 if 'music' in self
.arguments
:
27 return self
.arguments
['music'].check_is_loaded()
32 print(self
.description())
33 getattr(self
, self
.action
)(**self
.arguments
)
35 def description(self
):
36 return getattr(self
, self
.action
+ "_print")(**self
.arguments
)
38 def command(self
, command
= "", **kwargs
):
41 def music_list(self
, music
):
45 return self
.key
.parent
.open_files
.values()
47 def pause(self
, music
= None, **kwargs
):
48 for music
in self
.music_list(music
):
49 if music
.is_loaded_playing():
52 def unpause(self
, music
= None, **kwargs
):
53 for music
in self
.music_list(music
):
54 if music
.is_loaded_paused():
57 def play(self
, music
= None, fade_in
= 0, start_at
= 0,
58 restart_if_running
= False, volume
= 100, **kwargs
):
60 if restart_if_running
:
61 if music
.is_not_stopped():
63 music
.play(volume
= volume
, fade_in
= fade_in
, start_at
= start_at
)
65 if not music
.is_not_stopped():
66 music
.play(volume
= volume
, fade_in
= fade_in
, start_at
= start_at
)
68 def stop(self
, music
= None, fade_out
= 0, **kwargs
):
69 for music
in self
.music_list(music
):
70 if music
.is_loaded_paused() or music
.is_loaded_playing():
71 music
.stop(fade_out
= fade_out
)
73 def stop_all_actions(self
, **kwargs
):
74 self
.key
.parent
.stop_all_running()
76 def volume(self
, music
= None, value
= 100, **kwargs
):
78 music
.set_volume(value
)
83 def wait(self
, duration
= 0, music
= None, **kwargs
):
84 # FIXME: Make it stoppable
85 # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait
92 def command_print(self
, command
= "", **kwargs
):
93 return "running command {}".format(command
)
95 def pause_print(self
, music
= None, **kwargs
):
97 return "pausing « {} »".format(music
.name
)
99 return "pausing all musics"
101 def unpause_print(self
, music
= None, **kwargs
):
102 if music
is not None:
103 return "unpausing « {} »".format(music
.name
)
105 return "unpausing all musics"
107 def play_print(self
, music
= None, fade_in
= 0, start_at
= 0,
108 restart_if_running
= False, volume
= 100, **kwargs
):
109 message
= "starting "
110 if music
is not None:
111 message
+= "« {} »".format(music
.name
)
116 message
+= " at {}s".format(start_at
)
119 message
+= " with {}s fade_in".format(fade_in
)
121 message
+= " at volume {}%".format(volume
)
123 if restart_if_running
:
124 message
+= " (restarting if already running)"
128 def stop_print(self
, music
= None, fade_out
= 0, **kwargs
):
129 if music
is not None:
131 return "stopping music « {} »".format(music
.name
)
133 return "stopping music « {} » with {}s fadeout".format(music
.name
, fade_out
)
136 return "stopping all musics"
138 return "stopping all musics with {}s fadeout".format(fade_out
)
140 def stop_all_actions_print(self
, **kwargs
):
141 return "stopping all actions"
143 def volume_print(self
, music
= None, value
= 100, **kwargs
):
144 if music
is not None:
145 return "setting volume of « {} » to {}%".format(music
.name
, value
)
147 return "setting volume to {}%".format(value
)
149 def wait_print(self
, duration
, **kwargs
):
150 return "waiting {}s".format(duration
)