]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/__init__.py
1 # -*- coding: utf-8 -*-
2 from .music_file
import *
9 stream
= open("config.yml", "r")
10 config
= yaml
.load(stream
)
13 aliases
= config
['aliases']
16 file_lock
= Lock("file")
22 for key
in config
['key_properties']:
23 if key
not in key_properties
:
24 key_properties
[key
] = {
26 "properties": config
['key_properties'][key
],
30 for mapped_key
in config
['keys']:
31 if mapped_key
not in key_properties
:
32 key_properties
[mapped_key
] = {
37 for action
in config
['keys'][mapped_key
]:
38 action_name
= list(action
)[0]
40 if action
[action_name
] is None:
41 action
[action_name
] = []
43 if 'include' in action
[action_name
]:
44 included
= action
[action_name
]['include']
45 del(action
[action_name
]['include'])
47 if isinstance(included
, str):
48 action
[action_name
].update(aliases
[included
], **action
[action_name
])
50 for included_
in included
:
51 action
[action_name
].update(aliases
[included_
], **action
[action_name
])
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(
62 **config
['music_properties'][filename
])
64 seen_files
[filename
] = MusicFile(
68 channel_id
= channel_id
+ 1
70 if filename
not in key_properties
[mapped_key
]['files']:
71 key_properties
[mapped_key
]['files'].append(seen_files
[filename
])
73 action_args
['music'] = seen_files
[filename
]
76 action_args
[argument
] = action
[action_name
][argument
]
78 key_properties
[mapped_key
]['actions'].append([action_name
, action_args
])
80 return (key_properties
, channel_id
+ 1, seen_files
)
82 def parse_config(mapping
):
83 stream
= open("config.yml", "r")
84 config
= yaml
.load(stream
)
87 aliases
= config
['aliases']
90 file_lock
= Lock("file")
94 for mapped_key
in config
['keys']:
95 key
= mapping
.find_by_unicode(mapped_key
)
99 for action
in config
['keys'][mapped_key
]:
100 action_name
= list(action
)[0]
102 if action
[action_name
] is None:
103 action
[action_name
] = []
105 if 'include' in action
[action_name
]:
106 included
= action
[action_name
]['include']
107 del(action
[action_name
]['include'])
109 if isinstance(included
, str):
110 action
[action_name
].update(aliases
[included
], **action
[action_name
])
112 for included_
in included
:
113 action
[action_name
].update(aliases
[included_
], **action
[action_name
])
115 for argument
in action
[action_name
]:
116 if argument
== 'file':
117 filename
= action
[action_name
]['file']
118 if filename
not in seen_files
:
119 if filename
in config
['music_properties']:
120 seen_files
[filename
] = MusicFile(
124 **config
['music_properties'][filename
])
126 seen_files
[filename
] = MusicFile(
130 channel_id
= channel_id
+ 1
132 action_args
['music'] = seen_files
[filename
]
135 action_args
[argument
] = action
[action_name
][argument
]
137 key
.add_action(action_name
, **action_args
)
139 for key_property
in config
['key_properties']:
140 key
= mapping
.find_by_unicode(key_property
)
144 if 'description' in config
['key_properties'][key_property
]:
145 key
.set_description(config
['key_properties'][key_property
]['description'])
146 if 'color' in config
['key_properties'][key_property
]:
147 key
.set_color(config
['key_properties'][key_property
]['color'])
149 # Return the number of channels reserved
150 return (channel_id
+ 1, seen_files
)