aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-25 23:20:34 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-25 23:24:19 +0200
commit8612c5f8bb0fc9529bc489a6719654d4474db6d5 (patch)
treed335fa08bd49f155d1f9159a96904905e9b01777 /helpers
parent9d505ec9accd9a84bc6f22f4118bed9669c32fc8 (diff)
downloadMusicSampler-8612c5f8bb0fc9529bc489a6719654d4474db6d5.tar.gz
MusicSampler-8612c5f8bb0fc9529bc489a6719654d4474db6d5.tar.zst
MusicSampler-8612c5f8bb0fc9529bc489a6719654d4474db6d5.zip
Use kivy instead of pygame
Diffstat (limited to 'helpers')
-rw-r--r--helpers/__init__.py76
-rw-r--r--helpers/action.py4
2 files changed, 77 insertions, 3 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py
index 7fe9c35..eb948f2 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -5,6 +5,80 @@ from .lock import *
5from .font import * 5from .font import *
6import yaml 6import yaml
7 7
8def parse_config2():
9 stream = open("config.yml", "r")
10 config = yaml.load(stream)
11 stream.close()
12
13 aliases = config['aliases']
14 seen_files = {}
15
16 file_lock = Lock("file")
17
18 channel_id = 0
19
20 key_properties = {}
21
22 for key in config['key_properties']:
23 if key not in key_properties:
24 key_properties[key] = {
25 "actions": [],
26 "properties": config['key_properties'][key],
27 "files": []
28 }
29
30 for mapped_key in config['keys']:
31 if mapped_key not in key_properties:
32 key_properties[mapped_key] = {
33 "actions": [],
34 "properties": {},
35 "files": []
36 }
37 for action in config['keys'][mapped_key]:
38 action_name = list(action)[0]
39 action_args = {}
40 if action[action_name] is None:
41 action[action_name] = []
42
43 if 'include' in action[action_name]:
44 included = action[action_name]['include']
45 del(action[action_name]['include'])
46
47 if isinstance(included, str):
48 action[action_name].update(aliases[included], **action[action_name])
49 else:
50 for included_ in included:
51 action[action_name].update(aliases[included_], **action[action_name])
52
53 for argument in action[action_name]:
54 if argument == 'file':
55 filename = action[action_name]['file']
56 if filename not in seen_files:
57 if filename in config['music_properties']:
58 seen_files[filename] = MusicFile(
59 filename,
60 file_lock,
61 channel_id,
62 **config['music_properties'][filename])
63 else:
64 seen_files[filename] = MusicFile(
65 filename,
66 file_lock,
67 channel_id)
68 channel_id = channel_id + 1
69
70 if filename not in key_properties[mapped_key]['files']:
71 key_properties[mapped_key]['files'].append(seen_files[filename])
72
73 action_args['music'] = seen_files[filename]
74
75 else:
76 action_args[argument] = action[action_name][argument]
77
78 key_properties[mapped_key]['actions'].append([action_name, action_args])
79
80 return (key_properties, channel_id + 1, seen_files)
81
8def parse_config(mapping): 82def parse_config(mapping):
9 stream = open("config.yml", "r") 83 stream = open("config.yml", "r")
10 config = yaml.load(stream) 84 config = yaml.load(stream)
@@ -46,7 +120,7 @@ def parse_config(mapping):
46 seen_files[filename] = MusicFile( 120 seen_files[filename] = MusicFile(
47 filename, 121 filename,
48 file_lock, 122 file_lock,
49 channel_id, 123 channel_id,
50 **config['music_properties'][filename]) 124 **config['music_properties'][filename])
51 else: 125 else:
52 seen_files[filename] = MusicFile( 126 seen_files[filename] = MusicFile(
diff --git a/helpers/action.py b/helpers/action.py
index d4c6252..aff61e7 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -31,7 +31,7 @@ class Action:
31 def run(self): 31 def run(self):
32 print(self.description()) 32 print(self.description())
33 getattr(self, self.action)(**self.arguments) 33 getattr(self, self.action)(**self.arguments)
34 pygame.event.post(pygame.event.Event(pygame.USEREVENT)) 34 #pygame.event.post(pygame.event.Event(pygame.USEREVENT))
35 35
36 def description(self): 36 def description(self):
37 return getattr(self, self.action + "_print")(**self.arguments) 37 return getattr(self, self.action + "_print")(**self.arguments)
@@ -74,7 +74,7 @@ class Action:
74 pygame.mixer.stop() 74 pygame.mixer.stop()
75 75
76 def stop_all_actions(self, **kwargs): 76 def stop_all_actions(self, **kwargs):
77 self.key.mapping.stop_all_running() 77 self.key.parent.stop_all_running()
78 78
79 def volume(self, music = None, value = 100, **kwargs): 79 def volume(self, music = None, value = 100, **kwargs):
80 if music is not None: 80 if music is not None: