From b58b8220c1f3f20e97ca806cf8db0e334b920f4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 21 Jun 2016 14:10:07 +0200 Subject: [PATCH] Reduce memory --- config.yml | 43 ++++++++++++++++++++++++++++++++++++------- helpers/music_file.py | 17 ++++++++--------- music_sampler.py | 6 ------ 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: paf: file: "PIRATE_paf.mp3" name: Paf + coup: + file: "PIRATE_coup.wav" + name: Coup ralenti: file: "PIRATE_12-2-ralenti.mp3" name: Ralenti @@ -58,7 +61,7 @@ key_properties: description: - #Chloé - Jonglacro - - "2" + - 2 color: [73, 221, 226] 'e': description: @@ -92,7 +95,7 @@ key_properties: description: - #Chloé - Fin quête - - Entrée ondine + - Grotte color: [73, 221, 226] 'o': description: @@ -104,7 +107,7 @@ key_properties: description: - #Denise - Fin - - cour ondine + - Cour ondine color: [190, 110, 236] 'q': description: @@ -156,13 +159,13 @@ key_properties: description: - #Jérôme - Jeu à - - "2 4" + - 2 et 4 color: [240, 158, 0] 'm': description: - #Chloé - Fin jeu - - Début baston + - Baston color: [73, 221, 226] 'w': description: @@ -178,13 +181,28 @@ key_properties: 'c': description: - #Christophe - - Baston "2" + - Baston 2 color: [255, 255, 0] 'v': description: - #Auréliane - - Fin baston "2" + - Fin baston 2 color: [0, 190, 27] + 'ESC': + description: + - + - STOP ! + color: [255, 0, 0] + + 'F1': + description: + - + - PAUSE + + 'F2': + description: + - + - REPRENDRE keys: @@ -276,8 +294,13 @@ keys: - play: include: trio_jalousie 'k': + - play: + include: coup + - wait: + duration: 0.2 - stop: include: trio_jalousie + 'l': - play: include: piquage_2_4 @@ -312,3 +335,9 @@ keys: - stop: ~ - stop_all_actions: ~ + 'F1': + - pause: ~ + + 'F2': + - unpause: ~ + 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: self.channel_id = channel_id self.name = name or filename self.raw_data = None - self.sound = None self.loaded = False self.flag_paused = False @@ -17,8 +16,9 @@ class MusicFile: def load_sound(self, lock): lock.acquire() print("Loading « {} »".format(self.name)) - self.raw_data = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100).raw_data - self.sound = pygame.mixer.Sound(self.raw_data) + audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100) + self.sound_duration = audio_segment.duration_seconds + self.raw_data = audio_segment.raw_data print("Loaded « {} »".format(self.name)) self.loaded = True lock.release() @@ -35,15 +35,14 @@ class MusicFile: self.set_volume(volume) if start_at > 0: - song_duration = self.sound.get_length() raw_data_length = len(self.raw_data) - start_offset = int((raw_data_length / song_duration) * start_at) + start_offset = int((raw_data_length / self.sound_duration) * start_at) start_offset = start_offset - (start_offset % 2) - self.sound = pygame.mixer.Sound(self.raw_data[start_offset:]) + sound = pygame.mixer.Sound(self.raw_data[start_offset:]) else: - self.sound = pygame.mixer.Sound(self.raw_data) + sound = pygame.mixer.Sound(self.raw_data) - self.channel().play(self.sound, fade_ms = fade_in * 1000) + self.channel().play(sound, fade_ms = fade_in * 1000) self.flag_paused = False def pause(self): @@ -65,7 +64,7 @@ class MusicFile: value = 0 if value > 100: value = 100 - self.sound.set_volume(value / 100) + self.channel().set_volume(value / 100) def wait_end(self): 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: pygame.display.flip() draw_lock.release() - -#### In Ipython #### -# for thread in threading.enumerate(): -# if thread.getName()[0:2] != "MS": -# continue -# thread.join() -- 2.41.0