aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-19 21:31:54 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-19 21:31:54 +0200
commitb86db9f1679c855c2d39a0b116f846d271271a2c (patch)
tree3795bc88bd0fafda718248541d14b2529a1bd406
parentba9ea93a0f52178d24a606fddc2acc5dc85b7ff2 (diff)
downloadMusicSampler-b86db9f1679c855c2d39a0b116f846d271271a2c.tar.gz
MusicSampler-b86db9f1679c855c2d39a0b116f846d271271a2c.tar.zst
MusicSampler-b86db9f1679c855c2d39a0b116f846d271271a2c.zip
Add pirate example config.yml + description
-rw-r--r--config.yml294
-rw-r--r--helpers/__init__.py10
-rw-r--r--helpers/action.py8
-rw-r--r--helpers/key.py38
-rw-r--r--helpers/music_file.py2
5 files changed, 316 insertions, 36 deletions
diff --git a/config.yml b/config.yml
index ae87de5..ca6c399 100644
--- a/config.yml
+++ b/config.yml
@@ -1,46 +1,282 @@
1aliases: 1aliases:
2 jongle: 2 intro_jonglacro:
3 file: "/home/immae/temp/Pirates/PIRATE_01-1-intro_jonglacro.mp3" 3 file: "PIRATE_01-1-intro_jonglacro.mp3"
4 volume: 110 # pouvoir dire que "par défaut" la musique a un volume à 110% 4 jonglacro_suite:
5 acros: 5 file: "PIRATE_01-2-jonglacro_suite.mp3"
6 file: "../../temp/Pirates/PIRATE_01-2-jonglacro_suite.mp3" 6 lancer_prisonniere:
7 file: "PIRATE_02-lancers_de_prisonniere.mp3"
8 quete:
9 file: "PIRATE_03-quete.mp3"
10 entree_ondine:
11 file: "PIRATE_04-entree_ondine.mp3"
12 cour_ondine:
13 file: "PIRATE_05-cour_a_londine.mp3"
14 fouille_jonglage:
15 file: "PIRATE_07-fouille_jonglage.mp3"
16 liberation_prisonniere:
17 file: "PIRATE_08-liberation_prisonniere.mp3"
18 duo_pirate_ondine:
19 file: "PIRATE_09-duo_pirate_ondine.mp3"
20 trio_jalousie:
21 file: "PIRATE_10-trios_jalousie.mp3"
22 piquage_2_4:
23 file: "PIRATE_11-piquage_2_4.mp3"
24 baston:
25 file: "PIRATE_12-1-baston.mp3"
26 baston_ascension:
27 file: "PIRATE_12-3-baston_ascension.mp3"
28 bruit:
29 file: "PIRATE_bruit.wav"
30 paf:
31 file: "PIRATE_paf.mp3"
32 ralenti:
33 file: "PIRATE_12-2-ralenti.mp3"
34
35key_properties:
36 'a':
37 description:
38 - Chloé
39 - Jonglacro
40 color: [255, 0, 0]
41 'z':
42 description:
43 - Chloé
44 - Jonglacro 2
45 color: [255, 0, 0]
46 'e':
47 description:
48 - Chloé
49 - Stop jonglacro 2
50 color: [255, 0, 0]
51 'r':
52 description:
53 - Chloé
54 - Lancer prisonnière
55 color: [255, 0, 0]
56 't':
57 description:
58 - Chloé
59 - Stop lancer prisonnière
60 color: [255, 0, 0]
61 'y':
62 description:
63 - Chloé
64 - Quête
65 color: [255, 0, 0]
66 'u':
67 description:
68 - Chloé
69 - Grrr
70 color: [255, 0, 0]
71 'i':
72 description:
73 - Chloé
74 - Transition -> entrée ondine
75 color: [255, 0, 0]
76 'o':
77 description:
78 - Denise
79 - Cour ondine
80 color: [0, 255, 0]
81 'p':
82 description:
83 - Denise
84 - Stop cour ondine
85 color: [0, 255, 0]
86 'q':
87 description:
88 - Chloé
89 - Fouille jonglage
90 color: [255, 0, 0]
91 's':
92 description:
93 - Denise
94 - Stop fouille jonglage
95 color: [0, 255, 0]
96 'd':
97 description:
98 - Denise
99 - Libération prisonnière
100 color: [0, 255, 0]
101 'f':
102 description:
103 - Denise
104 - Paf + baisser musique
105 color: [0, 255, 0]
106 'g':
107 description:
108 - Denise
109 - Stop musique
110 color: [0, 255, 0]
111 'h':
112 description:
113 - Denise
114 - Duos
115 color: [0, 255, 0]
116 'j':
117 description:
118 - Jérôme
119 - Transition trios
120 color: [0, 0, 255]
121 'k':
122 description:
123 - Jérôme
124 - Stop trios
125 color: [0, 0, 255]
126 'l':
127 description:
128 - Jérôme
129 - Jeu à 2-4
130 color: [0, 0, 255]
131 'm':
132 description:
133 - Chloé
134 - Début baston
135 color: [255, 0, 0]
136 'w':
137 description:
138 - Christophe
139 - Transition ralenti
140 color: [255, 255, 0]
141 'x':
142 description:
143 - Christophe
144 - Stop ralenti
145 color: [255, 255, 0]
146 'c':
147 description:
148 - Christophe
149 - Début baston 2
150 color: [255, 255, 0]
151 'v':
152 description:
153 - Auréliane
154 - Stop baston 2
155 color: [0, 255, 255]
156
7 157
8keys: 158keys:
9 'a': 159 'a':
10 - play: 160 - play:
11 include: jongle 161 include: intro_jonglacro
12 fade_in: 5
13 restart_if_running: False
14 'z': 162 'z':
15 - stop: 163 - stop:
16 include: jongle 164 include: intro_jonglacro
165 fade_out: 5
17 - wait: 166 - wait:
18 duration: 3 167 duration: 7
168 - play:
169 include: jonglacro_suite
170 'e':
171 - stop:
172 include: jonglacro_suite
173 fade_out: 5
174 'r':
175 - play:
176 include: lancer_prisonniere
177 't':
178 - stop:
179 include: lancer_prisonniere
180 fade_out: 3
181 'y':
19 - play: 182 - play:
20 include: acros 183 include: quete
21 fade_in: 4 184 'u':
22 start_at: 40 185 - volume:
186 include: quete
187 value: 50
188 - play:
189 include: bruit
23 - wait: 190 - wait:
24 duration: 10 191 duration: 2
25 - volume: 192 - volume:
26 include: acros 193 include: quete
27 value: 50 194 value: 100
195 'i':
28 - stop: 196 - stop:
29 include: acros 197 include: quete
30 fade_out: 10 198 fade_out: 5
31 'e': 199 - wait:
200 duration: 20
32 - play: 201 - play:
33 include: acros 202 include: entree_ondine
34 restart_if_running: true 203 'o':
35 'r': 204 - stop:
205 include: entree_ondine
206 fade_out: 5
207 - wait:
208 duration: 5
36 - play: 209 - play:
37 include: acros 210 include: cour_ondine
211 'p':
212 - stop:
213 include: cour_ondine
214 fade_out: 5
215 'q':
216 - play:
217 include: fouille_jonglage
218 's':
219 - stop:
220 include: fouille_jonglage
221 fade_out: 2
222 'd':
223 - play:
224 include: liberation_prisonniere
225 'f':
226 - volume:
227 include: liberation_prisonniere
228 value: 20
229 - play:
230 include: paf
231 'g':
232 - stop:
233 include: liberation_prisonniere
234 fade_out: 3
235 'h':
236 - play:
237 include: duo_pirate_ondine
238 'j':
239 - stop:
240 include: duo_pirate_ondine
241 fade_out: 2
242 - wait:
243 duration: 2
244 - play:
245 include: trio_jalousie
246 'k':
247 - stop:
248 include: trio_jalousie
249 'l':
250 - play:
251 include: piquage_2_4
252 'm':
253 - stop:
254 include: piquage_2_4
255 fade_out: 5
256 - wait:
257 duration: 7
258 - play:
259 include: baston
260 'w':
261 - stop:
262 include: baston
263 fade_out: 1
264 - wait:
265 duration: 1
266 - play:
267 include: ralenti
268 'x':
269 - stop:
270 include: ralenti
271 fade_out: 2
272 'c':
273 - play:
274 include: baston_ascension
275 'v':
276 - stop:
277 include: baston_ascension
278 fade_out: 2
38 'ESC': 279 'ESC':
39 - stop: ~ 280 - stop: ~
40 - stop_all_actions: ~ 281 - stop_all_actions: ~
41 '-': 282
42 - volume:
43 value: 90
44 'p':
45 - command:
46 command: une_super_commande_de_feu_d'artifice
diff --git a/helpers/__init__.py b/helpers/__init__.py
index b1723ee..b7acbf5 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -47,3 +47,13 @@ def parse_config(mapping):
47 action_args[argument] = action[action_name][argument] 47 action_args[argument] = action[action_name][argument]
48 48
49 key.add_action(action_name, **action_args) 49 key.add_action(action_name, **action_args)
50
51 for key_property in config['key_properties']:
52 key = mapping.find_by_unicode(key_property)
53 if key is None:
54 continue
55
56 if 'description' in config['key_properties'][key_property]:
57 key.set_description(config['key_properties'][key_property]['description'])
58 if 'color' in config['key_properties'][key_property]:
59 key.set_color(config['key_properties'][key_property]['color'])
diff --git a/helpers/action.py b/helpers/action.py
index 97873a0..5afe437 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -74,10 +74,14 @@ class Action:
74 else: 74 else:
75 pass 75 pass
76 76
77 def wait(self, duration = 0, **kwargs): 77 def wait(self, duration = 0, music = None, **kwargs):
78 # FIXME: Make it stoppable 78 # FIXME: Make it stoppable
79 # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait 79 # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait
80 time.sleep(duration) 80 if music is None:
81 time.sleep(duration)
82 else:
83 # TODO
84 music.wait_end()
81 85
82 def command_print(self, command = "", **kwargs): 86 def command_print(self, command = "", **kwargs):
83 return "running command {}".format(command) 87 return "running command {}".format(command)
diff --git a/helpers/key.py b/helpers/key.py
index 6997e70..9a6cb3b 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -18,7 +18,8 @@ class Key:
18 lighter_outer_color = (200, 200, 200) 18 lighter_outer_color = (200, 200, 200)
19 default_inner_color = (255, 255, 255) 19 default_inner_color = (255, 255, 255)
20 mapped_inner_color = ( 0, 255, 0) 20 mapped_inner_color = ( 0, 255, 0)
21 mapped_unready_inner_color = (255, 165, 0) 21 mapped_unready_inner_color = ( 0, 255, 0, 100)
22 #mapped_unready_inner_color = (255, 165, 0)
22 23
23 def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False): 24 def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False):
24 self.draw_lock = draw_lock 25 self.draw_lock = draw_lock
@@ -50,13 +51,16 @@ class Key:
50 51
51 self.inner_color = self.default_inner_color 52 self.inner_color = self.default_inner_color
52 self.actions = [] 53 self.actions = []
54 self.description = []
55 self.custom_color = None
56 self.custom_unready_color = None
53 57
54 def square(self, all_actions_ready): 58 def square(self, all_actions_ready):
55 if self.has_actions(): 59 if self.has_actions():
56 if all_actions_ready: 60 if all_actions_ready:
57 self.inner_color = self.mapped_inner_color 61 self.inner_color = self.custom_color or self.mapped_inner_color
58 else: 62 else:
59 self.inner_color = self.mapped_unready_inner_color 63 self.inner_color = self.custom_unready_color or self.mapped_unready_inner_color
60 64
61 return RoundedRect((0, 0, self.width, self.height), 65 return RoundedRect((0, 0, self.width, self.height),
62 self.outer_color, self.inner_color, self.linewidth) 66 self.outer_color, self.inner_color, self.linewidth)
@@ -67,6 +71,14 @@ class Key:
67 position[1] - self.position[1] 71 position[1] - self.position[1]
68 ) 72 )
69 73
74 def set_description(self, description):
75 self.description = description
76
77 def set_color(self, color):
78 self.custom_color = tuple(color)
79 color.append(100)
80 self.custom_unready_color = tuple(color)
81
70 def draw(self, background_surface): 82 def draw(self, background_surface):
71 self.draw_lock.acquire() 83 self.draw_lock.acquire()
72 all_actions_ready = self.all_actions_ready() 84 all_actions_ready = self.all_actions_ready()
@@ -75,11 +87,27 @@ class Key:
75 87
76 if getattr(sys, 'frozen', False): 88 if getattr(sys, 'frozen', False):
77 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14) 89 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
90 text_police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 10)
78 else: 91 else:
79 police = pygame.font.Font("Ubuntu-Regular.ttf", 14) 92 police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
93 text_police = pygame.font.Font("Ubuntu-Regular.ttf", 10)
80 94
95 police.set_bold(True)
81 text = police.render(self.key_sym, True, (0,0,0)) 96 text = police.render(self.key_sym, True, (0,0,0))
82 self.surface.blit(text, (5,5)) 97 self.surface.blit(text, (5,5))
98
99 is_first_line = True
100 offset = 11 + text_police.get_linesize()
101 first_line_offset = 18
102 for description in self.description:
103 text = text_police.render(description, True, (0,0,0))
104 if is_first_line:
105 self.surface.blit(text, (first_line_offset, 9))
106 is_first_line = False
107 else:
108 self.surface.blit(text, (5, offset))
109 offset += text_police.get_linesize()
110
83 background_surface.blit(self.surface, self.position) 111 background_surface.blit(self.surface, self.position)
84 self.draw_lock.release() 112 self.draw_lock.release()
85 113
@@ -114,8 +142,8 @@ class Key:
114 142
115 def list_actions(self, screen): 143 def list_actions(self, screen):
116 action_descriptions = [action.description() for action in self.actions] 144 action_descriptions = [action.description() for action in self.actions]
117 print("actions linked to key {}:".format(self.key_sym)) 145 #print("actions linked to key {}:".format(self.key_sym))
118 print("\t" + "\n\t".join(action_descriptions)) 146 #print("\t" + "\n\t".join(action_descriptions))
119 self.draw_lock.acquire() 147 self.draw_lock.acquire()
120 surface = pygame.Surface((800, 250)).convert() 148 surface = pygame.Surface((800, 250)).convert()
121 surface.fill((250, 250, 250)) 149 surface.fill((250, 250, 250))
diff --git a/helpers/music_file.py b/helpers/music_file.py
index 36a7dd9..b834104 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -56,3 +56,5 @@ class MusicFile:
56 value = 100 56 value = 100
57 self.sound.set_volume(value / 100) 57 self.sound.set_volume(value / 100)
58 58
59 def wait_end(self):
60 pass