aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-21 14:10:07 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-21 14:10:07 +0200
commitb58b8220c1f3f20e97ca806cf8db0e334b920f4c (patch)
treef02c27b18499b95672bc6f316422de24885bcb38
parent425dd061bf64a8304ec96aec870b0e2e24fa44f4 (diff)
downloadMusicSampler-b58b8220c1f3f20e97ca806cf8db0e334b920f4c.tar.gz
MusicSampler-b58b8220c1f3f20e97ca806cf8db0e334b920f4c.tar.zst
MusicSampler-b58b8220c1f3f20e97ca806cf8db0e334b920f4c.zip
Reduce memory
-rw-r--r--config.yml43
-rw-r--r--helpers/music_file.py17
-rw-r--r--music_sampler.py6
3 files changed, 44 insertions, 22 deletions
diff --git a/config.yml b/config.yml
index a27f2e1..d5e6664 100644
--- a/config.yml
+++ b/config.yml
@@ -44,6 +44,9 @@ aliases:
44 paf: 44 paf:
45 file: "PIRATE_paf.mp3" 45 file: "PIRATE_paf.mp3"
46 name: Paf 46 name: Paf
47 coup:
48 file: "PIRATE_coup.wav"
49 name: Coup
47 ralenti: 50 ralenti:
48 file: "PIRATE_12-2-ralenti.mp3" 51 file: "PIRATE_12-2-ralenti.mp3"
49 name: Ralenti 52 name: Ralenti
@@ -58,7 +61,7 @@ key_properties:
58 description: 61 description:
59 - #Chloé 62 - #Chloé
60 - Jonglacro 63 - Jonglacro
61 - "2" 64 - 2
62 color: [73, 221, 226] 65 color: [73, 221, 226]
63 'e': 66 'e':
64 description: 67 description:
@@ -92,7 +95,7 @@ key_properties:
92 description: 95 description:
93 - #Chloé 96 - #Chloé
94 - Fin quête 97 - Fin quête
95 - Entrée ondine 98 - Grotte
96 color: [73, 221, 226] 99 color: [73, 221, 226]
97 'o': 100 'o':
98 description: 101 description:
@@ -104,7 +107,7 @@ key_properties:
104 description: 107 description:
105 - #Denise 108 - #Denise
106 - Fin 109 - Fin
107 - cour ondine 110 - Cour ondine
108 color: [190, 110, 236] 111 color: [190, 110, 236]
109 'q': 112 'q':
110 description: 113 description:
@@ -156,13 +159,13 @@ key_properties:
156 description: 159 description:
157 - #Jérôme 160 - #Jérôme
158 - Jeu à 161 - Jeu à
159 - "2 4" 162 - 2 et 4
160 color: [240, 158, 0] 163 color: [240, 158, 0]
161 'm': 164 'm':
162 description: 165 description:
163 - #Chloé 166 - #Chloé
164 - Fin jeu 167 - Fin jeu
165 - Début baston 168 - Baston
166 color: [73, 221, 226] 169 color: [73, 221, 226]
167 'w': 170 'w':
168 description: 171 description:
@@ -178,13 +181,28 @@ key_properties:
178 'c': 181 'c':
179 description: 182 description:
180 - #Christophe 183 - #Christophe
181 - Baston "2" 184 - Baston 2
182 color: [255, 255, 0] 185 color: [255, 255, 0]
183 'v': 186 'v':
184 description: 187 description:
185 - #Auréliane 188 - #Auréliane
186 - Fin baston "2" 189 - Fin baston 2
187 color: [0, 190, 27] 190 color: [0, 190, 27]
191 'ESC':
192 description:
193 -
194 - STOP !
195 color: [255, 0, 0]
196
197 'F1':
198 description:
199 -
200 - PAUSE
201
202 'F2':
203 description:
204 -
205 - REPRENDRE
188 206
189 207
190keys: 208keys:
@@ -276,8 +294,13 @@ keys:
276 - play: 294 - play:
277 include: trio_jalousie 295 include: trio_jalousie
278 'k': 296 'k':
297 - play:
298 include: coup
299 - wait:
300 duration: 0.2
279 - stop: 301 - stop:
280 include: trio_jalousie 302 include: trio_jalousie
303
281 'l': 304 'l':
282 - play: 305 - play:
283 include: piquage_2_4 306 include: piquage_2_4
@@ -312,3 +335,9 @@ keys:
312 - stop: ~ 335 - stop: ~
313 - stop_all_actions: ~ 336 - stop_all_actions: ~
314 337
338 'F1':
339 - pause: ~
340
341 'F2':
342 - unpause: ~
343
diff --git a/helpers/music_file.py b/helpers/music_file.py
index cdc9836..1078459 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -8,7 +8,6 @@ class MusicFile:
8 self.channel_id = channel_id 8 self.channel_id = channel_id
9 self.name = name or filename 9 self.name = name or filename
10 self.raw_data = None 10 self.raw_data = None
11 self.sound = None
12 11
13 self.loaded = False 12 self.loaded = False
14 self.flag_paused = False 13 self.flag_paused = False
@@ -17,8 +16,9 @@ class MusicFile:
17 def load_sound(self, lock): 16 def load_sound(self, lock):
18 lock.acquire() 17 lock.acquire()
19 print("Loading « {} »".format(self.name)) 18 print("Loading « {} »".format(self.name))
20 self.raw_data = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100).raw_data 19 audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100)
21 self.sound = pygame.mixer.Sound(self.raw_data) 20 self.sound_duration = audio_segment.duration_seconds
21 self.raw_data = audio_segment.raw_data
22 print("Loaded « {} »".format(self.name)) 22 print("Loaded « {} »".format(self.name))
23 self.loaded = True 23 self.loaded = True
24 lock.release() 24 lock.release()
@@ -35,15 +35,14 @@ class MusicFile:
35 self.set_volume(volume) 35 self.set_volume(volume)
36 36
37 if start_at > 0: 37 if start_at > 0:
38 song_duration = self.sound.get_length()
39 raw_data_length = len(self.raw_data) 38 raw_data_length = len(self.raw_data)
40 start_offset = int((raw_data_length / song_duration) * start_at) 39 start_offset = int((raw_data_length / self.sound_duration) * start_at)
41 start_offset = start_offset - (start_offset % 2) 40 start_offset = start_offset - (start_offset % 2)
42 self.sound = pygame.mixer.Sound(self.raw_data[start_offset:]) 41 sound = pygame.mixer.Sound(self.raw_data[start_offset:])
43 else: 42 else:
44 self.sound = pygame.mixer.Sound(self.raw_data) 43 sound = pygame.mixer.Sound(self.raw_data)
45 44
46 self.channel().play(self.sound, fade_ms = fade_in * 1000) 45 self.channel().play(sound, fade_ms = fade_in * 1000)
47 self.flag_paused = False 46 self.flag_paused = False
48 47
49 def pause(self): 48 def pause(self):
@@ -65,7 +64,7 @@ class MusicFile:
65 value = 0 64 value = 0
66 if value > 100: 65 if value > 100:
67 value = 100 66 value = 100
68 self.sound.set_volume(value / 100) 67 self.channel().set_volume(value / 100)
69 68
70 def wait_end(self): 69 def wait_end(self):
71 pass 70 pass
diff --git a/music_sampler.py b/music_sampler.py
index c17f7bf..6fed26b 100644
--- a/music_sampler.py
+++ b/music_sampler.py
@@ -78,9 +78,3 @@ while 1:
78 78
79 pygame.display.flip() 79 pygame.display.flip()
80 draw_lock.release() 80 draw_lock.release()
81
82#### In Ipython ####
83# for thread in threading.enumerate():
84# if thread.getName()[0:2] != "MS":
85# continue
86# thread.join()