]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Added music name, currently playing musics, pause/unpause
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 20 Jun 2016 21:08:22 +0000 (23:08 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 20 Jun 2016 21:15:47 +0000 (23:15 +0200)
Symbola.ttf [new file with mode: 0644]
config.yml
helpers/__init__.py
helpers/action.py
helpers/key.py
helpers/music_file.py
music_sampler.py
music_sampler.spec

diff --git a/Symbola.ttf b/Symbola.ttf
new file mode 100644 (file)
index 0000000..51d9a88
Binary files /dev/null and b/Symbola.ttf differ
index bd674965761e0865f08811d374f2f95f22025051..a27f2e1a781204676c23d1c7fcc54d6dcc3829dd 100644 (file)
@@ -1,36 +1,52 @@
 aliases:
   intro_jonglacro:
     file: "PIRATE_01-1-intro_jonglacro.mp3"
+    name: Intro Jonglacro
   jonglacro_suite:
     file: "PIRATE_01-2-jonglacro_suite.mp3"
+    name: Jonglacro suite
   lancer_prisonniere:
     file: "PIRATE_02-lancers_de_prisonniere.mp3"
+    name: Lancer prisonnière
   quete:
     file: "PIRATE_03-quete.mp3"
+    name: Quête
   entree_ondine:
     file: "PIRATE_04-entree_ondine.mp3"
+    name: Entrée Ondine
   cour_ondine:
     file: "PIRATE_05-cour_a_londine.mp3"
+    name: Cour à l'Ondine
   fouille_jonglage:
     file: "PIRATE_07-fouille_jonglage.mp3"
+    name: Fouille jonglage
   liberation_prisonniere:
     file: "PIRATE_08-liberation_prisonniere.mp3"
+    name: Libération prisonnière
   duo_pirate_ondine:
     file: "PIRATE_09-duo_pirate_ondine.mp3"
+    name: Duo pirate Ondine
   trio_jalousie:
     file: "PIRATE_10-trios_jalousie.mp3"
+    name: Trio Jalousie
   piquage_2_4:
     file: "PIRATE_11-piquage_2_4.mp3"
+    name: Piquage 2-4
   baston:
     file: "PIRATE_12-1-baston.mp3"
+    name: Baston
   baston_ascension:
     file: "PIRATE_12-3-baston_ascension.mp3"
+    name: Baston ascension
   bruit:
     file: "PIRATE_bruit.wav"
+    name: Bruit
   paf:
     file: "PIRATE_paf.mp3"
+    name: Paf
   ralenti:
     file: "PIRATE_12-2-ralenti.mp3"
+    name: Ralenti
 
 key_properties:
   'a':
@@ -42,7 +58,7 @@ key_properties:
     description:
       -  #Chloé
       - Jonglacro
-      - 2
+      - "2"
     color: [73, 221, 226]
   'e':
     description:
@@ -140,7 +156,7 @@ key_properties:
     description:
       -   #Jérôme
       - Jeu à 
-      - 2 4
+      - "2 4"
     color: [240, 158, 0]
   'm':
     description:
@@ -162,12 +178,12 @@ 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]
 
 
index d0d3f46f5588d92677ecd7bc3e4a072fc103a9b3..b3ab1eba61d302a2cd249fd17c39fd4754a2c323 100644 (file)
@@ -41,7 +41,10 @@ def parse_config(mapping):
                 if argument == 'file':
                     filename = action[action_name]['file']
                     if filename not in seen_files:
-                        seen_files[filename] = MusicFile(filename, file_lock, channel_id)
+                        if 'name' in action[action_name]:
+                            seen_files[filename] = MusicFile(filename, file_lock, channel_id, name = action[action_name]['name'])
+                        else:
+                            seen_files[filename] = MusicFile(filename, file_lock, channel_id)
                         channel_id = channel_id + 1
 
                     action_args['music'] = seen_files[filename]
@@ -62,4 +65,4 @@ def parse_config(mapping):
             key.set_color(config['key_properties'][key_property]['color'])
 
     # Return the number of channels reserved
-    return channel_id + 1
+    return (channel_id + 1, seen_files)
index 5afe43763c2f303ca8f6351ff14cf44e51287619..1cb168650c765301039a48132f34eb2684119c26 100644 (file)
@@ -8,6 +8,7 @@ class Action:
         'play',
         'stop',
         'stop_all_actions',
+        'unpause',
         'volume',
         'wait',
     ]
@@ -29,7 +30,8 @@ class Action:
 
     def run(self):
         print(self.description())
-        return getattr(self, self.action)(**self.arguments)
+        getattr(self, self.action)(**self.arguments)
+        pygame.event.post(pygame.event.Event(pygame.USEREVENT))
 
     def description(self):
         return getattr(self, self.action + "_print")(**self.arguments)
@@ -43,6 +45,12 @@ class Action:
         else:
             pygame.mixer.pause()
 
+    def unpause(self, music = None, **kwargs):
+        if music is not None:
+            music.unpause()
+        else:
+            pygame.mixer.unpause()
+
     def play(self, music = None, fade_in = 0, start_at = 0,
             restart_if_running = False, volume = 100, **kwargs):
         if music is not None:
@@ -88,15 +96,21 @@ class Action:
 
     def pause_print(self, music = None, **kwargs):
         if music is not None:
-            return "pausing {}".format(music.filename)
+            return "pausing « {} »".format(music.name)
         else:
             return "pausing all musics"
 
+    def unpause_print(self, music = None, **kwargs):
+        if music is not None:
+            return "unpausing « {} »".format(music.name)
+        else:
+            return "unpausing all musics"
+
     def play_print(self, music = None, fade_in = 0, start_at = 0,
             restart_if_running = False, volume = 100, **kwargs):
         message = "starting "
         if music is not None:
-            message += music.filename
+            message += "« {} »".format(music.name)
         else:
             message += "music"
 
@@ -116,9 +130,9 @@ class Action:
     def stop_print(self, music = None, fade_out = 0, **kwargs):
         if music is not None:
             if fade_out == 0:
-                return "stopping music {}".format(music.filename)
+                return "stopping music « {} »".format(music.name)
             else:
-                return "stopping music {} with {}s fadeout".format(music.filename, fade_out)
+                return "stopping music « {} » with {}s fadeout".format(music.name, fade_out)
         else:
             if fade_out == 0:
                 return "stopping all musics"
@@ -130,7 +144,7 @@ class Action:
 
     def volume_print(self, music = None, value = 100, **kwargs):
         if music is not None:
-            return "setting volume of {} to {}%".format(music.filename, value)
+            return "setting volume of « {} » to {}%".format(music.name, value)
         else:
             return "setting volume to {}%".format(value)
 
index 7b8051eca028ea049b0c0c8daa889c99cc1b9722..57fdef1d5616eb9df83ddf0bf0c18d9fb592d2dc 100644 (file)
@@ -149,7 +149,7 @@ class Key:
         #print("actions linked to key {}:".format(self.key_sym))
         #print("\t" + "\n\t".join(action_descriptions))
         self.draw_lock.acquire()
-        surface = pygame.Surface((800, 250)).convert()
+        surface = pygame.Surface((690, 250)).convert()
         surface.fill((250, 250, 250))
         if getattr(sys, 'frozen', False):
             police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
@@ -168,7 +168,7 @@ class Key:
             surface.blit(text, (0, offset))
             offset += police.get_linesize()
 
-        screen.blit(surface, (10, 330))
+        screen.blit(surface, (5, 308))
         pygame.display.flip()
         self.draw_lock.release()
 
index f6b0117d1f1bf71f67d6d9973c1e9b80b7ecf226..d40a13262c51dc78657ea351b0833b43326a530f 100644 (file)
@@ -3,28 +3,35 @@ import pydub
 import pygame
 
 class MusicFile:
-    def __init__(self, filename, lock, channel_id):
+    def __init__(self, filename, lock, channel_id, name = None):
         self.filename = filename
         self.channel_id = channel_id
+        self.name = name or filename
         self.raw_data = None
         self.sound = None
 
         self.loaded = False
+        self.flag_paused = False
         threading.Thread(name = "MSMusicLoad", target = self.load_sound, args = [lock]).start()
 
     def load_sound(self, lock):
         lock.acquire()
-        print("Loading {}".format(self.filename))
+        print("Loading « {} »".format(self.name))
         self.raw_data = pydub.AudioSegment.from_file(self.filename).raw_data
         self.sound = pygame.mixer.Sound(self.raw_data)
-        print("Loaded {}".format(self.filename))
+        print("Loaded « {} »".format(self.name))
         self.loaded = True
         lock.release()
 
     def is_playing(self):
         return self.channel().get_busy()
 
+    def is_paused(self):
+        return self.flag_paused
+
     def play(self, fade_in = 0, volume = 100, start_at = 0):
+        self.channel().set_endevent()
+        self.channel().set_endevent(pygame.USEREVENT)
         self.set_volume(volume)
 
         if start_at > 0:
@@ -37,9 +44,15 @@ class MusicFile:
             self.sound = pygame.mixer.Sound(self.raw_data)
 
         self.channel().play(self.sound, fade_ms = fade_in * 1000)
+        self.flag_paused = False
 
     def pause(self):
         self.channel().pause()
+        self.flag_paused = True
+
+    def unpause(self):
+        self.channel().unpause()
+        self.flag_paused = False
 
     def stop(self, fade_out = 0):
         if fade_out > 0:
index 8dbbc28de8e35a9e10e3ba08f08a1a2a96a89c1c..ff04fd1e42d2d1d62c559cbbd5a9929b353d381b 100644 (file)
@@ -6,14 +6,14 @@ import threading
 pygame.mixer.pre_init(frequency = 44100)
 pygame.init()
 
-size = width, height = 1024, 600
+size = width, height = 913, 563
 screen = pygame.display.set_mode(size)
-screen.fill((250, 250, 250))
+screen.fill((229, 228, 226))
 
 draw_lock = helpers.Lock("draw")
 
 mapping = helpers.Mapping(screen, draw_lock)
-channel_number = helpers.parse_config(mapping)
+channel_number, open_files = helpers.parse_config(mapping)
 pygame.mixer.set_num_channels(channel_number)
 
 mapping.draw()
@@ -49,12 +49,37 @@ while 1:
             key = mapping.find_by_key_num(event.key)
             if key is not None:
                 threading.Thread(name = "MSKeyAction", target=key.do_actions).start()
+                threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
         elif event.type == pygame.MOUSEBUTTONUP:
             key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
             if key is not None:
                 threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
 
     draw_lock.acquire()
+    if getattr(sys, 'frozen', False):
+        icon_police = pygame.font.Font(sys._MEIPASS + "/Symbola.ttf", 19)
+        police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
+    else:
+        icon_police = pygame.font.Font("Symbola.ttf", 19)
+        police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
+
+    surface = pygame.Surface((208, 250)).convert()
+    surface.fill((250, 250, 250))
+    offset = 0
+    for music_file in open_files.values():
+        police.set_bold(False)
+        if music_file.is_playing():
+            icon = icon_police.render("⏵", True, (0,0,0))
+            if music_file.is_paused():
+                icon = icon_police.render("⏸", True, (0,0,0))
+            else:
+                police.set_bold(True)
+            text = police.render(music_file.name, True, (0,0,0))
+            surface.blit(icon, (0, offset))
+            surface.blit(text, (20, offset))
+            offset += police.get_linesize()
+    screen.blit(surface, (700, 308))
+
     pygame.display.flip()
     draw_lock.release()
 
index 3c85a2ac298e9155d8cfbbb6c82607c8e949eb12..a60c546c2dd7cfc5c9987e5adbeabddf1b358ff3 100644 (file)
@@ -4,7 +4,11 @@ block_cipher = None
 
 a = Analysis(['music_sampler.py'],
              binaries=None,
-             datas=[('config.yml', '.'), ('Ubuntu-Regular.ttf', '.')],
+             datas=[
+              ('config.yml', '.'),
+              ('Ubuntu-Regular.ttf', '.'),
+              ('Symbola.ttf', '.')
+             ],
              hiddenimports=[
                'six',
                'packaging',