From dac64df84b0ed14199f41ac163d12ec20e497213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 12 Aug 2016 13:30:08 +0200 Subject: 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 --- documentation_en.md | 5 +++++ documentation_fr.md | 5 +++++ music_sampler/mapping.py | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) 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. done, the key will remain disabled (semi-transparent and crossed) for that amount of time (in seconds). +#### `common` key property + +A special entry `common` has its properties applying to all the keys. They can +be overriden individually. + ### `keys` : actions related to keys This 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é. successifs sur la touche. La touche est désactivée (grisée et barrée) pendant toute la durée des actions puis le délai de x secondes. +### Propriété `common` + +Une entrée spéciale `common` s'applique à toutes les touches. Les propriétés +définies dans cette entrée peuvent être modifiées individuellement. + ### `keys` : actions sur les touches Cette 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): def parse_config(self): def update_alias(prop_hash, aliases, key): if isinstance(aliases[key], dict): - prop_hash.update(aliases[key], **prop_hash) + for alias in aliases[key]: + prop_hash.setdefault(alias, aliases[key][alias]) else: warn_print("Alias {} is not a hash, ignored".format(key)) @@ -336,6 +337,14 @@ class Mapping(RelativeLayout): seen_files = {} + common_key_properties = {} + if 'common' in config['key_properties'] and\ + isinstance(config['key_properties'], dict): + common_key_properties = config['key_properties']['common'] + include_aliases(common_key_properties, aliases) + elif 'common' in config['key_properties']: + warn_print("'common' key in key_properties is not a hash, ignored") + key_properties = defaultdict(lambda: { "actions": [], "properties": {}, @@ -343,6 +352,9 @@ class Mapping(RelativeLayout): }) for key in check_key_properties(config): + if key == 'common': + continue + key_prop = config['key_properties'][key] if not isinstance(key_prop, dict): @@ -351,6 +363,9 @@ class Mapping(RelativeLayout): continue include_aliases(key_prop, aliases) + for _key in common_key_properties: + key_prop.setdefault(_key, common_key_properties[_key]) + check_key_property(key_prop, key) key_properties[key]["properties"] = key_prop -- cgit v1.2.3