aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-08-12 13:30:08 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-08-12 13:34:07 +0200
commitdac64df84b0ed14199f41ac163d12ec20e497213 (patch)
tree4fddf98221d1e88eccabcdb4753954128fef9772
parent3a488f9facff1f0d3a9b943d7da318424bc35efb (diff)
downloadMusicSampler-dac64df84b0ed14199f41ac163d12ec20e497213.tar.gz
MusicSampler-dac64df84b0ed14199f41ac163d12ec20e497213.tar.zst
MusicSampler-dac64df84b0ed14199f41ac163d12ec20e497213.zip
Add a 'common' section in key properties
Any option defined here applies to all keys (they can be overriden individualy) Fixes https://git.immae.eu/mantisbt/view.php?id=5
-rw-r--r--documentation_en.md5
-rw-r--r--documentation_fr.md5
-rw-r--r--music_sampler/mapping.py17
3 files changed, 26 insertions, 1 deletions
diff --git a/documentation_en.md b/documentation_en.md
index 1cf5cfd..d65e7ad 100644
--- a/documentation_en.md
+++ b/documentation_en.md
@@ -226,6 +226,11 @@ protected for 2 seconds after each stroke.
226 done, the key will remain disabled (semi-transparent and crossed) for that 226 done, the key will remain disabled (semi-transparent and crossed) for that
227 amount of time (in seconds). 227 amount of time (in seconds).
228 228
229#### `common` key property
230
231A special entry `common` has its properties applying to all the keys. They can
232be overriden individually.
233
229### `keys` : actions related to keys 234### `keys` : actions related to keys
230 235
231This section lets you describe for each key, the list of actions associated to 236This section lets you describe for each key, the list of actions associated to
diff --git a/documentation_fr.md b/documentation_fr.md
index b739aa2..64e3a4f 100644
--- a/documentation_fr.md
+++ b/documentation_fr.md
@@ -248,6 +248,11 @@ secondes d'intervalle, le second appui est ignoré.
248 successifs sur la touche. La touche est désactivée (grisée et barrée) pendant 248 successifs sur la touche. La touche est désactivée (grisée et barrée) pendant
249 toute la durée des actions puis le délai de x secondes. 249 toute la durée des actions puis le délai de x secondes.
250 250
251### Propriété `common`
252
253Une entrée spéciale `common` s'applique à toutes les touches. Les propriétés
254définies dans cette entrée peuvent être modifiées individuellement.
255
251### `keys` : actions sur les touches 256### `keys` : actions sur les touches
252 257
253Cette section sert à décrire, pour chaque touche, la liste des actions 258Cette section sert à décrire, pour chaque touche, la liste des actions
diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py
index e589ac0..50b68a9 100644
--- a/music_sampler/mapping.py
+++ b/music_sampler/mapping.py
@@ -224,7 +224,8 @@ class Mapping(RelativeLayout):
224 def parse_config(self): 224 def parse_config(self):
225 def update_alias(prop_hash, aliases, key): 225 def update_alias(prop_hash, aliases, key):
226 if isinstance(aliases[key], dict): 226 if isinstance(aliases[key], dict):
227 prop_hash.update(aliases[key], **prop_hash) 227 for alias in aliases[key]:
228 prop_hash.setdefault(alias, aliases[key][alias])
228 else: 229 else:
229 warn_print("Alias {} is not a hash, ignored".format(key)) 230 warn_print("Alias {} is not a hash, ignored".format(key))
230 231
@@ -336,6 +337,14 @@ class Mapping(RelativeLayout):
336 337
337 seen_files = {} 338 seen_files = {}
338 339
340 common_key_properties = {}
341 if 'common' in config['key_properties'] and\
342 isinstance(config['key_properties'], dict):
343 common_key_properties = config['key_properties']['common']
344 include_aliases(common_key_properties, aliases)
345 elif 'common' in config['key_properties']:
346 warn_print("'common' key in key_properties is not a hash, ignored")
347
339 key_properties = defaultdict(lambda: { 348 key_properties = defaultdict(lambda: {
340 "actions": [], 349 "actions": [],
341 "properties": {}, 350 "properties": {},
@@ -343,6 +352,9 @@ class Mapping(RelativeLayout):
343 }) 352 })
344 353
345 for key in check_key_properties(config): 354 for key in check_key_properties(config):
355 if key == 'common':
356 continue
357
346 key_prop = config['key_properties'][key] 358 key_prop = config['key_properties'][key]
347 359
348 if not isinstance(key_prop, dict): 360 if not isinstance(key_prop, dict):
@@ -351,6 +363,9 @@ class Mapping(RelativeLayout):
351 continue 363 continue
352 364
353 include_aliases(key_prop, aliases) 365 include_aliases(key_prop, aliases)
366 for _key in common_key_properties:
367 key_prop.setdefault(_key, common_key_properties[_key])
368
354 check_key_property(key_prop, key) 369 check_key_property(key_prop, key)
355 370
356 key_properties[key]["properties"] = key_prop 371 key_properties[key]["properties"] = key_prop