I dumped an LUT that I generated to a JSON: how do I access its contents after importing it back in?
-
I made an LUT for things I want pre-computed.
I dumped the LUT to a JSON and I can see the data is in there.
When I import the JSON back in to work with it, it comes up as "undefined".const PCS_LUT = Engine.loadFromJSON("PCS_LUT.json");
How do I "unpack" the contents to use the LUT?
-
@VirtualVirgin Use the File/FileSystem APIs to load the JSON as an object.
-
@d-healey said in I dumped an LUT that I generated to a JSON: how do I access its contents after importing it back in?:
@VirtualVirgin Use the File/FileSystem APIs to load the JSON as an object.
Thanks :)
What kind of syntax do I use here?
I'm not quite getting it:
Am I supposed to point to the file in the directory somehow?
-
Yeah so if the file is on your desktop for example you would do this.
const f = FileSystem.getFolder(FileSystem.Desktop).getChildFile("PCS_LUT.json"); const pcsLut = f.loadAsObject();
Now if this json data is something you want to embed in your plugin then instead of loading it as an outside file you should put the contents into a
.js
file and include it like a regular script. -
@d-healey Thanks again :)
A couple more questions:
-
I have a hashtag in a folder name in the directory. How do I handle that?
-
Instead of dumping my LUT to JSON, importing it and converting to a .js, is there a way to convert my generated LUT directly to a .js file?
-
-
@VirtualVirgin said in I dumped an LUT that I generated to a JSON: how do I access its contents after importing it back in?:
I have a hashtag in a folder name in the directory. How do I handle that?
I would change the folder name, special characters in folder names can be problematic - especially if you work with the commandline. But if you want to keep it I don't think HISE would have a problem with it, I haven't tested though.
@VirtualVirgin said in I dumped an LUT that I generated to a JSON: how do I access its contents after importing it back in?:
Instead of dumping my LUT to JSON, importing it and converting to a .js, is there a way to convert my generated LUT directly to a .js file?
What format does it use? Is it just an array?
-
@d-healey It is an array with filled with objects that contain arrays. The lower-level arrays just contain integers.
-
Just rename the file with a .js extension and assign the array to a variable.
For example if your file is this kind of thing
[ {someKey:[{anotherKey: data}]}, {someKey:[{anotherKey: data}]}, {someKey:[{anotherKey: data}]}, {someKey:[{anotherKey: data}]}, ... ]
Do this
namespace Lut { const pcs = [ {someKey:[{anotherKey: data}]}, {someKey:[{anotherKey: data}]}, {someKey:[{anotherKey: data}]}, {someKey:[{anotherKey: data}]}, ... ] }
Then you can access it using
Lut.pcs