aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-15 09:34:47 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-15 09:35:21 +0200
commitd8ab67c745b78d0b2f5896cf6642004b3951433c (patch)
tree3ad10c636f68c3cd3bf63fe1f29decfded7c11c3
parent8f88a3e417d6eff7666571eccf0b6ad453c88ccd (diff)
downloadMusicSampler-d8ab67c745b78d0b2f5896cf6642004b3951433c.tar.gz
MusicSampler-d8ab67c745b78d0b2f5896cf6642004b3951433c.tar.zst
MusicSampler-d8ab67c745b78d0b2f5896cf6642004b3951433c.zip
Add stub commands
-rw-r--r--config.yml2
-rw-r--r--helpers.py45
-rw-r--r--run.py24
-rw-r--r--run.spec33
4 files changed, 91 insertions, 13 deletions
diff --git a/config.yml b/config.yml
index 1876e1e..1384c92 100644
--- a/config.yml
+++ b/config.yml
@@ -34,5 +34,5 @@ keys:
34 - volume: 34 - volume:
35 value: 90 35 value: 90
36 'p': 36 'p':
37 - run: 37 - command:
38 command: une_super_commande_de_feu_d'artifice 38 command: une_super_commande_de_feu_d'artifice
diff --git a/helpers.py b/helpers.py
index b4a0fe0..7fbfb99 100644
--- a/helpers.py
+++ b/helpers.py
@@ -3,9 +3,9 @@ from pygame import *
3 3
4class Action: 4class Action:
5 action_types = [ 5 action_types = [
6 'command',
6 'pause', 7 'pause',
7 'play', 8 'play',
8 'run',
9 'stop', 9 'stop',
10 'volume', 10 'volume',
11 'wait', 11 'wait',
@@ -22,10 +22,30 @@ class Action:
22 def run(self, callback): 22 def run(self, callback):
23 getattr(self, self.action)(callback, **self.arguments) 23 getattr(self, self.action)(callback, **self.arguments)
24 24
25 def stop(self, callback, musique = None, fade_out = 0): 25 def command(self, callback, command = "", **kwargs):
26 pass
27
28 def pause(self, callback, music = None, **kwargs):
29 pass
30
31 def play(self, callback,
32 music = None,
33 fade_in = 0,
34 restart_if_running = False,
35 volume = 100,
36 **kwargs):
37 pass
38
39 def stop(self, callback, music = None, fade_out = 0, **kwargs):
26 print('stopping') 40 print('stopping')
27 return callback() 41 return callback()
28 42
43 def volume(self, callback, music = None, value = 100, **kwargs):
44 pass
45
46 def wait(self, callback, time = 0, **kwargs):
47 pass
48
29class Key: 49class Key:
30 row_positions = { 50 row_positions = {
31 'first': 5, 51 'first': 5,
@@ -106,7 +126,22 @@ class Key:
106 if len(self.actions) > 0: 126 if len(self.actions) > 0:
107 self.actions[0].run(self.next_action) 127 self.actions[0].run(self.next_action)
108 128
109 def find_from_unicode(key_sym): 129 def list_actions(self, surface):
130 print("bouh", self.key_sym)
131 surface.fill((255, 0, 0))
132
133 def find_by_key_num(key_num):
134 if key_num in Mapping.KEYS:
135 return Mapping.KEYS[key_num]
136 return None
137
138 def find_by_collidepoint(position):
139 for key in Mapping.KEYS:
140 if Mapping.KEYS[key].collidepoint(position):
141 return Mapping.KEYS[key]
142 return None
143
144 def find_by_unicode(key_sym):
110 for key in Mapping.KEYS: 145 for key in Mapping.KEYS:
111 if Mapping.KEYS[key].key_sym == key_sym: 146 if Mapping.KEYS[key].key_sym == key_sym:
112 return Mapping.KEYS[key] 147 return Mapping.KEYS[key]
@@ -294,7 +329,7 @@ def parse_config():
294 seen_files = {} 329 seen_files = {}
295 330
296 for mapped_key in config['keys']: 331 for mapped_key in config['keys']:
297 key = Key.find_from_unicode(mapped_key) 332 key = Key.find_by_unicode(mapped_key)
298 if key is None: 333 if key is None:
299 continue 334 continue
300 335
@@ -317,7 +352,7 @@ def parse_config():
317 if filename not in seen_files: 352 if filename not in seen_files:
318 seen_files[filename] = MusicFile.new(filename) 353 seen_files[filename] = MusicFile.new(filename)
319 354
320 action_args['file'] = seen_files[filename] 355 action_args['music'] = seen_files[filename]
321 356
322 else: 357 else:
323 action_args[argument] = action[action_name][argument] 358 action_args[argument] = action[action_name][argument]
diff --git a/run.py b/run.py
index 69494d7..9797c91 100644
--- a/run.py
+++ b/run.py
@@ -1,6 +1,10 @@
1import sys
2
3if getattr(sys, 'frozen', False):
4 os.chdir(sys._MEIPASS)
5
1import pygame 6import pygame
2import pydub 7import pydub
3import sys
4import helpers 8import helpers
5 9
6pygame.mixer.pre_init(frequency = 44100) 10pygame.mixer.pre_init(frequency = 44100)
@@ -13,6 +17,8 @@ background = pygame.Surface(screen.get_size())
13background = background.convert() 17background = background.convert()
14background.fill((250, 250, 250)) 18background.fill((250, 250, 250))
15 19
20action_surface = pygame.Surface((600, 250)).convert()
21action_surface.fill((0,0,0))
16helpers.parse_config() 22helpers.parse_config()
17 23
18for key_name in helpers.Mapping.KEYS: 24for key_name in helpers.Mapping.KEYS:
@@ -20,6 +26,8 @@ for key_name in helpers.Mapping.KEYS:
20 key.draw(background) 26 key.draw(background)
21 27
22screen.blit(background, (0, 0)) 28screen.blit(background, (0, 0))
29screen.blit(action_surface, (10, 330))
30
23pygame.display.flip() 31pygame.display.flip()
24 32
25contexts = [ 33contexts = [
@@ -38,12 +46,14 @@ while 1:
38 sys.exit() 46 sys.exit()
39 47
40 if context == 'normal': 48 if context == 'normal':
41 if event.type == pygame.KEYDOWN and event.key in helpers.Mapping.KEYS: 49 if event.type == pygame.KEYDOWN:
42 helpers.Mapping.KEYS[event.key].do_actions() 50 key = helpers.Key.find_by_key_num(event.key)
43 if event.type == pygame.MOUSEBUTTONUP: 51 if key is not None:
44 for key in helpers.Mapping.KEYS: 52 key.do_actions()
45 if helpers.Mapping.KEYS[key].collidepoint(pygame.mouse.get_pos()): 53 elif event.type == pygame.MOUSEBUTTONUP:
46 helpers.Mapping.KEYS[key].do_actions() 54 key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos())
55 if key is not None:
56 key.list_actions(action_surface)
47 57
48 pygame.display.flip() 58 pygame.display.flip()
49 59
diff --git a/run.spec b/run.spec
new file mode 100644
index 0000000..ec27125
--- /dev/null
+++ b/run.spec
@@ -0,0 +1,33 @@
1# -*- mode: python -*-
2
3block_cipher = None
4
5a = Analysis(['run.py'],
6 pathex=['/home/immae/temp/soundplant_alternative'],
7 binaries=None,
8 datas=[('config.yml', '.')],
9 hiddenimports=[
10 'six',
11 'packaging',
12 'packaging.version',
13 'packaging.specifiers',
14 'packaging.requirements'
15 ],
16 hookspath=[],
17 runtime_hooks=[],
18 excludes=[],
19 win_no_prefer_redirects=False,
20 win_private_assemblies=False,
21 cipher=block_cipher)
22pyz = PYZ(a.pure, a.zipped_data,
23 cipher=block_cipher)
24exe = EXE(pyz,
25 a.scripts,
26 a.binaries,
27 a.zipfiles,
28 a.datas,
29 name='run',
30 debug=False,
31 strip=False,
32 upx=True,
33 console=True )