]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Reduce memory
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 21 Jun 2016 12:10:07 +0000 (14:10 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 21 Jun 2016 12:10:07 +0000 (14:10 +0200)
config.yml
helpers/music_file.py
music_sampler.py

index a27f2e1a781204676c23d1c7fcc54d6dcc3829dd..d5e6664d80811ecb8b689c59c0a952e4aea50375 100644 (file)
@@ -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: ~
+
index cdc9836c19a299b82b2ba2fcca17495ea5f53cd9..10784596a38db66cbde3594aab0adcac3b2231fb 100644 (file)
@@ -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
index c17f7bff98d1764704ee542ef9a1004aa1151f8b..6fed26b05e8ddb5406c465b052a70eb9a5624f44 100644 (file)
@@ -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()