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