From b798117bb79038ae7495ea4fdb5254d15c7e4b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 26 Jun 2017 17:36:40 +0200 Subject: Change "keys" hash to "key_properties" in config.yml --- config.yml | 375 +++++++++++++++++++++-------------------------- documentation_en.md | 3 + documentation_fr.md | 3 + music_sampler/mapping.py | 100 +++++++------ 4 files changed, 228 insertions(+), 253 deletions(-) diff --git a/config.yml b/config.yml index 2e89a0f..56221d9 100644 --- a/config.yml +++ b/config.yml @@ -82,52 +82,83 @@ key_properties: - - Music 1 include: light_blue + actions: + - play: + include: music1 +# Play the songs 'z': description: - - Music 2 include: light_blue + actions: + - play: + include: music2 'e': description: - - Noise include: light_blue + actions: + - play: + include: noise +# Load the songs 'q': description: - - Load - Music 1 include: light_blue + actions: + - load_music: + include: music1 's': description: - - Load - Music 2 include: light_blue + actions: + - load_music: + include: music2 'd': description: - - Load - Noise include: light_blue + actions: + - load_music: + include: noise +# Unload the songs 'w': description: - - Unload - Music 1 include: light_blue + actions: + - unload_music: + include: music1 'x': description: - - Unload - Music 2 include: light_blue + actions: + - unload_music: + include: music2 'c': description: - - Unload - Noise include: light_blue + actions: + - unload_music: + include: noise +# Crossfade from any music to music 2 't': description: - @@ -135,27 +166,70 @@ key_properties: - music 2 include: green repeat_delay: 5 + actions: + - stop: + fade_out: 5 + - play: + include: music2 + fade_in: 5 +# Fade out, then wait and start music 2 'y': description: - - Stop wait - music 2 include: green + actions: + - wait: + include: music2 +# Play music 1, starting at 30 seconds then seeks at 60 after 5 seconds 'g': description: - - Music 1 - Seek 30/60 include: purple + actions: + - play: + include: music1 + start_at: 30 + - wait: + duration: 5 + - seek: + include: music1 + delta: false + value: 60 +# Lowers the volume of music 1 and 2 (if playing), during the duration of noise + 1 second 'i': description: - - Noise - +low vol include: green + actions: + - volume: + include: music1 + value: 50 + - volume: + include: music2 + value: 50 + - play: + include: noise + - wait: + include: noise + duration: 1 + - volume: + include: music1 + value: 100 + fade: 1 + - volume: + include: music2 + value: 100 + fade: 1 +# Stops all musics, then plays noise repeated twice (3 times) 'h': description: - @@ -163,48 +237,102 @@ key_properties: - 3 times include: purple repeat_delay: 2 + actions: + - stop: + fade_out: 0.5 + - play: + include: noise + loop: 2 +# Play music 1 and 2, after stopping all musics with a fade_out (and wait for this fade out) 'm': description: - - Musics - 1 & 2 include: purple + actions: + - stop: + fade_out: 2 + wait: true + - play: + include: music1 + - wait: + include: music1 + set_wait_id: m + - play: + include: music2 +# Lowers the volume of music 1 and 2 (if playing) down to 10% with a 5 seconds fade, then back to 100% 'n': description: - - Low vol - Up vol include: green + actions: + - volume: + include: music1 + value: 10 + fade: 5 + - volume: + include: music2 + value: 10 + fade: 5 + - wait: + duration: 5 + - volume: + include: music1 + value: 100 + fade: 5 + - volume: + include: music2 + value: 100 + fade: 5 +# skip waiting for the end of music1 'ù': description: - - stop - wait + actions: + - interrupt_wait: + wait_id: m 'home': description: - - vlc include: orange + actions: + - run_command: + command: vlc *.mp3 + wait: true ## Some general useful keys +# Emergency stop! 'ESC': description: - "!" - STOP! include: red repeat_delay: 0 + actions: + - stop_all_actions: + other_only: true + - stop: +# Pause and unpause 'F5': description: - "||" - PAUSE include: light_green repeat_delay: 0 + actions: + - pause: 'F6': description: @@ -212,7 +340,10 @@ key_properties: - UNPAUSE include: light_green repeat_delay: 0 + actions: + - unpause: +# Stopping all musics, with a short fade (sounds natural) 'F1': description: - @@ -220,7 +351,11 @@ key_properties: - fade include: orange repeat_delay: 0 + actions: + - stop: + fade_out: 1 +# Stopping all actions 'F2': description: - @@ -228,7 +363,10 @@ key_properties: - actions include: orange repeat_delay: 0 + actions: + - stop_all_actions: +# Skip wait 'F4': description: - @@ -236,29 +374,45 @@ key_properties: - wait include: pink repeat_delay: 0 + actions: + - interrupt_wait: 'F8': description: - - Pause - wait + actions: + - pause_wait: + 'F9': description: - - Unpause - wait + actions: + - unpause_wait: + 'F10': description: - - Reset - wait + actions: + - reset_wait: +# Changing volume 'F12': description: - - vol+ include: yellow repeat_delay: 0 + actions: + - volume: + delta: true + value: +10 + fade: 0.5 'F11': description: @@ -266,13 +420,23 @@ key_properties: - "vol-" include: yellow repeat_delay: 0 - + actions: + - volume: + delta: true + value: -10 + fade: 0.5 + +# Seek +- 10 seconds 'right': description: - - +10s include: blue repeat_delay: 0 + actions: + - seek: + value: 10 + delta: true 'left': description: @@ -280,208 +444,7 @@ key_properties: - -10s include: blue repeat_delay: 0 - -################################################################# -##### Keys: what do the key actually do when you press them ##### - -keys: -# Play the songs - 'a': - - play: - include: music1 - 'z': - - play: - include: music2 - 'e': - - play: - include: noise - -# Load the songs - 'q': - - load_music: - include: music1 - 's': - - load_music: - include: music2 - 'd': - - load_music: - include: noise - -# Unload the songs - 'w': - - unload_music: - include: music1 - 'x': - - unload_music: - include: music2 - 'c': - - unload_music: - include: noise - -# Crossfade from any music to music 2 - 't': - - stop: - fade_out: 5 - - play: - include: music2 - fade_in: 5 - -# Fade out, then wait and start music 2 - 'y': - - wait: - include: music2 - -# Play the noise, stop music 1, wait a bit then start music 2 - -# Play music 1, starting at 30 seconds then seeks at 60 after 5 seconds - 'g': - - play: - include: music1 - start_at: 30 - - wait: - duration: 5 - - seek: - include: music1 - delta: false - value: 60 - -# Play music 1 and 2, after stopping all musics with a fade_out (and wait for this fade out) - 'm': - - stop: - fade_out: 2 - wait: true - - play: - include: music1 - - wait: - include: music1 - set_wait_id: m - - play: - include: music2 - -# skip waiting for the end of music1 - 'ù': - - interrupt_wait: - wait_id: m - -# Lowers the volume of music 1 and 2 (if playing), during the duration of noise + 1 second - 'i': - - volume: - include: music1 - value: 50 - - volume: - include: music2 - value: 50 - - play: - include: noise - - wait: - include: noise - duration: 1 - - volume: - include: music1 - value: 100 - fade: 1 - - volume: - include: music2 - value: 100 - fade: 1 - -# Lowers the volume of music 1 and 2 (if playing) down to 10% with a 5 seconds fade, then back to 100% - 'n' : - - volume: - include: music1 - value: 10 - fade: 5 - - volume: - include: music2 - value: 10 - fade: 5 - - wait: - duration: 5 - - volume: - include: music1 - value: 100 - fade: 5 - - volume: - include: music2 - value: 100 - fade: 5 - -# Stops all musics, then plays noise repeated twice (3 times) - 'h': - - stop: - fade_out: 0.5 - - play: - include: noise - loop: 2 - - 'home': - - run_command: - command: vlc *.mp3 - wait: true - - -##### Useful keys (good to have them all the time) - -# Emergency stop! - 'ESC': - - stop_all_actions: - other_only: true - - stop: - - - -# Pause and unpause - 'F5': - - pause: - - 'F6': - - unpause: - -# Stopping all musics, with a short fade (sounds natural) - 'F1': - - stop: - fade_out: 1 - -# Stopping all actions - 'F2': - - stop_all_actions: - -# Skip wait - 'F4': - - interrupt_wait: - - 'F8': - - pause_wait: - - 'F9': - - unpause_wait: - - 'F10': - - reset_wait: - -# Changing volume - 'F12': - - volume: - delta: true - value: +10 - fade: 0.5 - - 'F11': - - volume: - delta: true - value: -10 - fade: 0.5 - - -# Seek +- 10 seconds - 'right': - - seek: - value: 10 - delta: true - - 'left': - - seek: - value: -10 - delta: true - - + actions: + - seek: + value: -10 + delta: true diff --git a/documentation_en.md b/documentation_en.md index e92b85c..ac12909 100644 --- a/documentation_en.md +++ b/documentation_en.md @@ -225,6 +225,7 @@ protected for 2 seconds after each stroke. - `repeat_delay: x` (default 0) : protection delay. Once all its actions are done, the key will remain disabled (semi-transparent and crossed) for that amount of time (in seconds). +- `actions: list`: List of actions to run with the key. #### `common` key property @@ -237,6 +238,8 @@ This section lets you describe for each key, the list of actions associated to it. Note that except for `wait` and some particular cases (see below), all the actions are almost instantaneous. +*This section is deprecated and replaced by an `actions` key containing a list +in `key_properties` section for each key.* #### Examples diff --git a/documentation_fr.md b/documentation_fr.md index cc2bf8f..d7d2f2c 100644 --- a/documentation_fr.md +++ b/documentation_fr.md @@ -247,6 +247,7 @@ secondes d'intervalle, le second appui est ignoré. - `repeat_delay: x` (par défaut : 0) : délai de "sécurité" en cas d'appuis 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. +- `actions: liste`: Liste des actions à effectuer en appuyant sur la touche. ### Propriété `common` @@ -259,6 +260,8 @@ Cette section sert à décrire, pour chaque touche, la liste des actions successives. Notez que la plupart des actions (hors `wait` et quelques cas particuliers, voir plus bas) sont quasi-instantanées. +*Cette section est obsolète et remplacée par une clé `actions` contenant une +liste dans la section `key_properties` pour chaque touche.* #### Exemples diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py index a526ad2..193f5e5 100644 --- a/music_sampler/mapping.py +++ b/music_sampler/mapping.py @@ -320,13 +320,60 @@ class Mapping(RelativeLayout): else: return {} - def check_mapped_key(mapped_keys, key): - if not isinstance(mapped_keys[key], list): + def check_mapped_key(actions, key): + if not isinstance(actions, list): warn_print("key config '{}' is not an array, ignored" .format(key)) return [] else: - return mapped_keys[key] + return actions + + def append_actions_to_key(mapped_key, actions, aliases, seen_files, music_properties, key_properties): + for index, action in enumerate(check_mapped_key(actions, mapped_key)): + if not isinstance(action, dict) or\ + not len(action) == 1 or\ + not isinstance(list(action.values())[0] or {}, dict): + warn_print("action number {} of key '{}' is invalid, " + "ignored".format(index + 1, mapped_key)) + continue + append_action_to_key(action, mapped_key, aliases, seen_files, music_properties, key_properties) + + def append_action_to_key(action, mapped_key, aliases, seen_files, music_properties, key_properties): + action_name = list(action)[0] + action_args = {} + if action[action_name] is None: + action[action_name] = {} + + include_aliases(action[action_name], aliases) + + for argument in action[action_name]: + if argument == 'file': + filename = str(action[action_name]['file']) + if filename not in seen_files: + music_property = check_music_property( + music_properties[filename], + filename) + + if filename in self.open_files: + self.open_files[filename]\ + .reload_properties(**music_property) + + seen_files[filename] =\ + self.open_files[filename] + else: + seen_files[filename] = MusicFile( + filename, self, **music_property) + + if filename not in key_properties[mapped_key]['files']: + key_properties[mapped_key]['files'] \ + .append(seen_files[filename]) + + action_args['music'] = seen_files[filename] + else: + action_args[argument] = action[action_name][argument] + + key_properties[mapped_key]['actions'] \ + .append([action_name, action_args]) def check_music_property(music_property, filename): if not isinstance(music_property, dict): @@ -400,52 +447,11 @@ class Mapping(RelativeLayout): check_key_property(key_prop, key) key_properties[key]["properties"].update(key_prop) + if 'actions' in key_prop: + append_actions_to_key(key, key_prop['actions'], aliases, seen_files, music_properties, key_properties) for mapped_key in check_mapped_keys(config): - for index, action in enumerate(check_mapped_key( - config['keys'], mapped_key)): - if not isinstance(action, dict) or\ - not len(action) == 1 or\ - not isinstance(list(action.values())[0] or {}, dict): - warn_print("action number {} of key '{}' is invalid, " - "ignored".format(index + 1, mapped_key)) - continue - - action_name = list(action)[0] - action_args = {} - if action[action_name] is None: - action[action_name] = {} - - include_aliases(action[action_name], aliases) - - for argument in action[action_name]: - if argument == 'file': - filename = str(action[action_name]['file']) - if filename not in seen_files: - music_property = check_music_property( - music_properties[filename], - filename) - - if filename in self.open_files: - self.open_files[filename]\ - .reload_properties(**music_property) - - seen_files[filename] =\ - self.open_files[filename] - else: - seen_files[filename] = MusicFile( - filename, self, **music_property) - - if filename not in key_properties[mapped_key]['files']: - key_properties[mapped_key]['files'] \ - .append(seen_files[filename]) - - action_args['music'] = seen_files[filename] - else: - action_args[argument] = action[action_name][argument] - - key_properties[mapped_key]['actions'] \ - .append([action_name, action_args]) + append_actions_to_key(mapped_key, config['keys'][mapped_key], aliases, seen_files, music_properties, key_properties) return (key_properties, seen_files) -- cgit v1.2.3