]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Add stub commands
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 15 Jun 2016 07:34:47 +0000 (09:34 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 15 Jun 2016 07:35:21 +0000 (09:35 +0200)
config.yml
helpers.py
run.py
run.spec [new file with mode: 0644]

index 1876e1e88a735373e2ee5c247ef8cc971b75eb43..1384c925d0d9f5d4dc951be94522f610a1c96010 100644 (file)
@@ -34,5 +34,5 @@ keys:
     - volume:
         value: 90
   'p':
-    - run:
+    - command:
         command: une_super_commande_de_feu_d'artifice
index b4a0fe00da53e8c2bb4f04f9ae9080f40247b4f4..7fbfb99b59bb665db42fa533df9e807641f81295 100644 (file)
@@ -3,9 +3,9 @@ from pygame import *
 
 class Action:
     action_types = [
+        'command',
         'pause',
         'play',
-        'run',
         'stop',
         'volume',
         'wait',
@@ -22,10 +22,30 @@ class Action:
     def run(self, callback):
         getattr(self, self.action)(callback, **self.arguments)
 
-    def stop(self, callback, musique = None, fade_out = 0):
+    def command(self, callback, command = "", **kwargs):
+        pass
+
+    def pause(self, callback, music = None, **kwargs):
+        pass
+
+    def play(self, callback,
+            music = None,
+            fade_in = 0,
+            restart_if_running = False,
+            volume = 100,
+            **kwargs):
+        pass
+
+    def stop(self, callback, music = None, fade_out = 0, **kwargs):
         print('stopping')
         return callback()
 
+    def volume(self, callback, music = None, value = 100, **kwargs):
+        pass
+
+    def wait(self, callback, time = 0, **kwargs):
+        pass
+
 class Key:
     row_positions = {
         'first':    5,
@@ -106,7 +126,22 @@ class Key:
         if len(self.actions) > 0:
             self.actions[0].run(self.next_action)
 
-    def find_from_unicode(key_sym):
+    def list_actions(self, surface):
+        print("bouh", self.key_sym)
+        surface.fill((255, 0, 0))
+
+    def find_by_key_num(key_num):
+        if key_num in Mapping.KEYS:
+            return Mapping.KEYS[key_num]
+        return None
+
+    def find_by_collidepoint(position):
+        for key in Mapping.KEYS:
+            if Mapping.KEYS[key].collidepoint(position):
+                return Mapping.KEYS[key]
+        return None
+
+    def find_by_unicode(key_sym):
         for key in Mapping.KEYS:
             if Mapping.KEYS[key].key_sym == key_sym:
                 return Mapping.KEYS[key]
@@ -294,7 +329,7 @@ def parse_config():
     seen_files = {}
 
     for mapped_key in config['keys']:
-        key = Key.find_from_unicode(mapped_key)
+        key = Key.find_by_unicode(mapped_key)
         if key is None:
             continue
 
@@ -317,7 +352,7 @@ def parse_config():
                     if filename not in seen_files:
                         seen_files[filename] = MusicFile.new(filename)
 
-                    action_args['file'] = seen_files[filename]
+                    action_args['music'] = seen_files[filename]
 
                 else:
                     action_args[argument] = action[action_name][argument]
diff --git a/run.py b/run.py
index 69494d76a793de54d68e7f3d19ccdd6fc44b9b96..9797c918073f4baa8033f85634b9c5163efc34e9 100644 (file)
--- a/run.py
+++ b/run.py
@@ -1,6 +1,10 @@
+import sys
+
+if getattr(sys, 'frozen', False):
+    os.chdir(sys._MEIPASS)
+
 import pygame
 import pydub
-import sys
 import helpers
 
 pygame.mixer.pre_init(frequency = 44100)
@@ -13,6 +17,8 @@ background = pygame.Surface(screen.get_size())
 background = background.convert()
 background.fill((250, 250, 250))
 
+action_surface = pygame.Surface((600, 250)).convert()
+action_surface.fill((0,0,0))
 helpers.parse_config()
 
 for key_name in helpers.Mapping.KEYS:
@@ -20,6 +26,8 @@ for key_name in helpers.Mapping.KEYS:
     key.draw(background)
 
 screen.blit(background, (0, 0))
+screen.blit(action_surface, (10, 330))
+
 pygame.display.flip()
 
 contexts = [
@@ -38,12 +46,14 @@ while 1:
         sys.exit()
 
     if context == 'normal':
-        if event.type == pygame.KEYDOWN and event.key in helpers.Mapping.KEYS:
-            helpers.Mapping.KEYS[event.key].do_actions()
-        if event.type == pygame.MOUSEBUTTONUP:
-            for key in helpers.Mapping.KEYS:
-                if helpers.Mapping.KEYS[key].collidepoint(pygame.mouse.get_pos()): 
-                    helpers.Mapping.KEYS[key].do_actions()
+        if event.type == pygame.KEYDOWN:
+            key = helpers.Key.find_by_key_num(event.key)
+            if key is not None:
+                key.do_actions()
+        elif event.type == pygame.MOUSEBUTTONUP:
+            key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos())
+            if key is not None:
+                key.list_actions(action_surface)
 
     pygame.display.flip()
 
diff --git a/run.spec b/run.spec
new file mode 100644 (file)
index 0000000..ec27125
--- /dev/null
+++ b/run.spec
@@ -0,0 +1,33 @@
+# -*- mode: python -*-
+
+block_cipher = None
+
+a = Analysis(['run.py'],
+             pathex=['/home/immae/temp/soundplant_alternative'],
+             binaries=None,
+             datas=[('config.yml', '.')],
+             hiddenimports=[
+               'six',
+               'packaging',
+               'packaging.version',
+               'packaging.specifiers',
+               'packaging.requirements'
+             ],
+             hookspath=[],
+             runtime_hooks=[],
+             excludes=[],
+             win_no_prefer_redirects=False,
+             win_private_assemblies=False,
+             cipher=block_cipher)
+pyz = PYZ(a.pure, a.zipped_data,
+             cipher=block_cipher)
+exe = EXE(pyz,
+          a.scripts,
+          a.binaries,
+          a.zipfiles,
+          a.datas,
+          name='run',
+          debug=False,
+          strip=False,
+          upx=True,
+          console=True )