]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/__init__.py
1 # -*- coding: utf-8 -*-
2 from .music_file
import *
7 def parse_config(mapping
):
8 stream
= open("config.yml", "r")
9 config
= yaml
.load(stream
)
12 aliases
= config
['aliases']
15 file_lock
= Lock("file")
19 for mapped_key
in config
['keys']:
20 key
= mapping
.find_by_unicode(mapped_key
)
24 for action
in config
['keys'][mapped_key
]:
25 action_name
= list(action
)[0]
27 if action
[action_name
] is None:
28 action
[action_name
] = []
30 if 'include' in action
[action_name
]:
31 included
= action
[action_name
]['include']
32 del(action
[action_name
]['include'])
34 if isinstance(included
, str):
35 action
[action_name
].update(aliases
[included
], **action
[action_name
])
37 for included_
in included
:
38 action
[action_name
].update(aliases
[included_
], **action
[action_name
])
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'])
47 seen_files
[filename
] = MusicFile(filename
, file_lock
, channel_id
)
48 channel_id
= channel_id
+ 1
50 action_args
['music'] = seen_files
[filename
]
53 action_args
[argument
] = action
[action_name
][argument
]
55 key
.add_action(action_name
, **action_args
)
57 for key_property
in config
['key_properties']:
58 key
= mapping
.find_by_unicode(key_property
)
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'])
67 # Return the number of channels reserved
68 return (channel_id
+ 1, seen_files
)