]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/__init__.py
Added music name, currently playing musics, pause/unpause
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / __init__.py
1 # -*- coding: utf-8 -*-
2 from .music_file import *
3 from .mapping import *
4 from .lock import *
5 import yaml
6
7 def parse_config(mapping):
8 stream = open("config.yml", "r")
9 config = yaml.load(stream)
10 stream.close()
11
12 aliases = config['aliases']
13 seen_files = {}
14
15 file_lock = Lock("file")
16
17 channel_id = 0
18
19 for mapped_key in config['keys']:
20 key = mapping.find_by_unicode(mapped_key)
21 if key is None:
22 continue
23
24 for action in config['keys'][mapped_key]:
25 action_name = list(action)[0]
26 action_args = {}
27 if action[action_name] is None:
28 action[action_name] = []
29
30 if 'include' in action[action_name]:
31 included = action[action_name]['include']
32 del(action[action_name]['include'])
33
34 if isinstance(included, str):
35 action[action_name].update(aliases[included], **action[action_name])
36 else:
37 for included_ in included:
38 action[action_name].update(aliases[included_], **action[action_name])
39
40 for argument in action[action_name]:
41 if argument == 'file':
42 filename = action[action_name]['file']
43 if filename not in seen_files:
44 if 'name' in action[action_name]:
45 seen_files[filename] = MusicFile(filename, file_lock, channel_id, name = action[action_name]['name'])
46 else:
47 seen_files[filename] = MusicFile(filename, file_lock, channel_id)
48 channel_id = channel_id + 1
49
50 action_args['music'] = seen_files[filename]
51
52 else:
53 action_args[argument] = action[action_name][argument]
54
55 key.add_action(action_name, **action_args)
56
57 for key_property in config['key_properties']:
58 key = mapping.find_by_unicode(key_property)
59 if key is None:
60 continue
61
62 if 'description' in config['key_properties'][key_property]:
63 key.set_description(config['key_properties'][key_property]['description'])
64 if 'color' in config['key_properties'][key_property]:
65 key.set_color(config['key_properties'][key_property]['color'])
66
67 # Return the number of channels reserved
68 return (channel_id + 1, seen_files)