json Encoding of tables containing MemoryBlocks #196
-
I'm not sure if anyone has saved panel data to json. json.encode is supposed to encode tables, but I'm wondering if this will also encode memoryBlocks containing sysex data, for example. It doesn't explicitly say whether it does or doesn't. What I'm trying to acheive. In my plugin I have a series of list boxes that list the patch names. patchBank is a table of patches patch.name (String) I want to be able to export patchbank and load it back in. The sysex dump for the synth does not support the name, author or category, so to be able to preserve that info, I need to export the entire patchBank. This will also be loaded back in, in conjunction with the normal state data (which does not save memoryBlocks). I'm looking for a structured way to save this, so json or xml is probably the preference. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 29 replies
-
Doing a bit of searching, json doesn't support binary data. It will either need to be encoded with toBase64 or toHexString |
Beta Was this translation helpful? Give feedback.
-
In my Juno Alpha panel there are two methods:
They might give clues as to how to create a record with a text file with your own custom extension. I create a lua table structure and save to file and just read it back in when loaded. I have my own file extension .JUMP Here is an example of the file contents:
You could just save the sysex as one string in the multi dimensional array. Reading it back into a MemoryBlock would be trivial! |
Beta Was this translation helpful? Give feedback.
-
I'm going to have to go through those functions and work out you cc_mapping_array and research what a StringArray() is. First time I've come across that. |
Beta Was this translation helpful? Give feedback.
-
Very interesting about json coding/decoding as, as you say, it is readable! I have handled this with memoryblocks and 2 files, one containing the actual sysex of the synth, the other one the metadata but in fact you could do it with just one single sysex file. If you use only one then for sure you cannot send that one without processing to the synth and it is the reason I used 2.
|
Beta Was this translation helpful? Give feedback.
-
I worked out how to do it and it wasn't easy! See attached: |
Beta Was this translation helpful? Give feedback.
-
Excellent! Just one note ⇒ "/n" should read "\n" This is going to be very useful. For example, you could save each modulator value panel:getModulatorByName("lfoRate"):getModulatorValue() i.e.
[{"mod":"lfoRate","value":"53},{"mod":"resonance","value":"31"} ]
either using Hex or Decimal for the values. Cool for panels that don't have banks of patch data as sysex etc. Just pull the current values from uiSlider etc. Saves looping through an ordered list of modulator names in a table and assigning each a value on file reload/save. |
Beta Was this translation helpful? Give feedback.
-
OK - The thread has got a bit messy. Here's the 4 final methods I ended up with. Encode Bank
Decode Bank
Save Library (export json)
Load Library (json)
You will also need the following declared in your initializePanel. This builds the patch class and the patchBank class.
|
Beta Was this translation helpful? Give feedback.
OK - The thread has got a bit messy. Here's the 4 final methods I ended up with.
Encode Bank