Generating many mappings with python and json #564
Replies: 3 comments 22 replies
-
Cool stuff, thanks for this writeup. BTW, even if you prefer Python over Lua, you might benefit from the new data format that came up with the introduction of ReaLearn Script (Lua). This new data format is just a plain data structure really, there's nothing Lua-specific in there! So you could easily use Python to generate a JSON that conforms to that new data format, ReaLearn will accept it. ReaLearn's integrated Lua import does more or less the same. Here are some advantages of using the new format (directly written in JSON or generated by Python, Python, JavaScript or any language really):
The advantage of specifically using Lua to generate data in this new format (optional, on top of that):
|
Beta Was this translation helpful? Give feedback.
-
I can confirm that generation with Lua is very easy, as is the language itself. |
Beta Was this translation helpful? Give feedback.
-
Please could anyone make a Youtube tutorial or a written tutorial for a noob explaining how to make |
Beta Was this translation helpful? Give feedback.
-
Generating many mappings with python and json
Just adding this here for posterity, I haven't tried the new LUA mappings but for now, this is how I've been generating hundreds of mappings for TouchOSC.
Step 1. Creating a reference mapping in Realearn so source and target are configured as you want all the mappings to be set:
In this particular case, I am creating aliases for my FX Parameters and letting Realearn find the "Channel" alias FX and then the "LPF", "HPF"... etc aliases for FX Parameters. These are all the aliases I would use for whatever channelstrip I load:
I don't want to do it all by hand so:
Step 2. Copy the reference mapping and save it as .json:
Do it for as many variants you want to have, so if you are sending a float value, then a string formatted as {{target.text_value}} and another string formatted as {{target.fx_parameter.name}} you would need 3 different references because the there would be too many changes to the JSON file and it's easier to set it once on Realearn and then not touching the JSON much on the script.
You could do it without a reference but that's just to much JSON shenanigans so it's easier to start from a reference mapping.
Step 3. This is how the mapping would look, this example has the formatted string {{target.fx_parameter.name}}:
Then you save all the references as something like "value.json", "name.json" etc, then config and run the following python script:
CODE HERE:
What you want to change is the Attributes of your "mappings" instance as:
If you want to change how the JSON is addressed, just change the keys at modifyJson():
You can customize whatever target you want even after having created the reference mappings. As I said, I am using aliases for my FX and FX Param but you could use the real param names or whatever is your pleasure.
Step 4. The result will be in "output.json" and you can copy the contents of the file and then paste it into a new group in Realearn:
You can tweak and re-generate the output.json and replace all mappings in the group if you need to.
Then the TouchOSC side of things is another story but it works great:
Hope this made sense, haven't seen much of these shenanigans around.
This really works great with TouchOSC because the mappings are "infinite" so no matter what you want to control you can create hundreds of mappings and Realearn can handle it all really well. Make sure to enable/disble groups through Realearn parameters so you don't have thousands of mappings active at a time, but rather they get enabled as you page through your controller.
If y'all got any other ideas or ways of automating more of this stuff feel free to share them!
Thanks. Realearn is cool.
Beta Was this translation helpful? Give feedback.
All reactions