Skip to content

Variable substitution in Actions' string parameters #15

@michd

Description

@michd

Allow using a %-surrounded syntax within strings to substitute other values, be it data from the event that triggered the action, or data retrieved from the state keeper.

The syntax is already described in docs/config.md (Link to version of the document at the latest commit on main at the time of writing), but I propose a few additions to the format.

Normal syntax: "My string here %varname%" if varname evaluates to a value of "MYVALUE" this results in the string "My string here MYVALUE". If there is no value available for the variable named varname, it is substituted with empty string, resulting in "My string here "

Specifying a fallback value: include a | character after the variable name and specify the fallback text. Example: "My string here %varname|MYFALLBACK%". In case varname exists and contains "MYVALUE", this results, as before, in "My string here MYVALUE". If varname does not evaluate to any value, this variant will result in "My string here MYFALLBACK".

Further diverging from the current config documentation, to insert a literal % in the string (and don't have it evaluated for variable replacement), use \%.

Variable naming

Variables can consist of multiple .-separated segments for namespacing. Within each segment name / variable name, the characters a-z, A-Z, 0-9, _ are valid.

Fallback values

In fallback values, you can use any character, but if you need a literal %, you must escape it: \%.


Data sources

Event data

Any field from the data object of the event that lead to this action being run may be used:

In case of a MIDI note_on event: event.channel, event.key, event.velocity. Note that values will be returned in their normal format, so if you specified an event matcher with a key of C3, that will return the number 48 here instead.

State data

Any known state data, such as state.midi.channels.3.notes_on.12 Exactly how these should be resolved is to be worked out. Perhaps even a * to match "any" could be helpful here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions