# Need Help with NKA Preset File Browser



## DarylWise (Jun 27, 2019)

I have a large library that I want to add a NKA Preset File Browser. I know very little about scripting and I was wondering I could possibly pay someone on here to create one for me. Please PM me and we can talk further. Thanks!


----------



## P.N. (Jun 27, 2019)

Hello.
Have you considered snapshots? If you don't know enough about scripting, these are the perfect solution.
You can even organize them into folders in order to create nested menus in the snapshot browser.
Cheers.


----------



## DarylWise (Jun 27, 2019)

P.N. said:


> Hello.
> Have you considered snapshots? If you don't know enough about scripting, these are the perfect solution.
> You can even organize them into folders in order to create nested menus in the snapshot browser.
> Cheers.



Yes I have. And my issue with that is 3rd Party Libraries cannot embed snapshots into the NKI or the Resource Container. So my customers would have to install the Snapshots in the Documents folder I believe. EvilDragon can confirm this as I found out from him.

And I also have done NKI presets but my main issue is that this library is large with groups (275), that each NKI is around 2.5MB. Making initial loading times 5-10 minutes.

Having a NKA preset browser would fix all of this.


----------



## P.N. (Jun 27, 2019)

Yes, the snapshots need to be manually copied which is an inconvenience.

There are a lot of preset browsers around. Some make use of the internal filebrowser.
Others use specialized solutions that allow the user to also create and rename new user presets.
This last solution is not very easy to do when scrolling and out of order saving/deletion is involved.

If you only require preset loading, i'd suggest a file browser as the best solution (menus are not too suited for the job anymore).

Best regards.


----------



## DarylWise (Jun 27, 2019)

P.N. said:


> Yes, the snapshots need to be manually copied which is an inconvenience.
> 
> There are a lot of preset browsers around. Some make use of the internal filebrowser.
> Others use specialized solutions that allow the user to also create and rename new user presets.
> ...



I would really love to have a loading and saving feature. Even if it’s a preset browser with just factory presets if you will without the loading and saving features I would let the users just make their own presets by saving the NKI.

If you or someone could still script a preset browser for me I would appreciate it. I know it will still be quite a job because all the controls need to go into an array I believe. And this library is pretty much a full blown synth with 4 independent Oscillators each with their own controls.

I am willing to pay as well. Can anyone help?


----------



## Fredeke (Jun 29, 2019)

I'd like to make one for my own lib. Only thing... I don't know how to do that yet. @DarylWise : you seem to know more than I about the theory of it - I, on the other hand, lack the theory but am not afraid of coding. Maybe we can help each other? Can you (or anybody) point me to documentation about what nka presets are and how they work? I'm sure I could code something once I know the basic principles.


----------



## P.N. (Jun 29, 2019)

The base theory is pretty much the same no matter which method is used.
If you have a load/save button, it would work as follow:

On save, write the values of the relevant controls into an array, preferably in a loop.
At this stage there may be situations where a 2D array is useful in order to stack different groups of controls in predermined array elements.

On load, the reverse happens, with the expection that the functions for each control need to be recalled, so that the preset actually works and doesn't just change the control values.
You could just use a global function for this.

You know, it's hard to say exactly what works better, and where, because this depends a lot on your instrument sctructure (how you set up control arrays, control functions (if you made functions for every control, etc).

But yeah, it's write values, save array... then, load values to controls, apply functions (or set whichever paramenters you defined for the controls).

If you use load_array mode 0, then it's pretty much all there is to it. (you use the dialog box).
The thing is... almost everyone hates mode 0. :D, that's why solutions with menus, buttons, filebrowsers are normally used and require a lot more scripting (specially a custom scrolling solution with buttons).
Even the menu solution is tricky if you try to hide/show the menu entries, while also renaming them based on a ui_text save option...

If you just use a menu with fixed items and names, that could work, but menus are really not the best way to do this, IMHO. If you have a few dozen presets it starts to get clumsy.

PS: Make sure the array has finished loading (async check) before updating controls and recalling functions.


----------



## Fredeke (Jun 29, 2019)

@P.N.: I understand, thanks.
Btw, can't you just make an array persistent?


----------



## P.N. (Jun 29, 2019)

Fredeke said:


> Oh, actually, I have one already: can't you just make an array persistent?



You can (int and, if i'm not mistaken, real arrays too). String arrays cannot.

Still, if your idea is having a bunch of persistent arrays around, consider this:

- Preset arrays can grow to huge sizes;
- You'd need to store a lot of these persistent arrays (depending on the number of presets, you'd have a lot of data floating around - imagine 100-500 persistent arrays. It would prove tricky to manage and doesn't seem efficient.)
- No ability to share presets via nkas.


----------



## Fredeke (Jun 29, 2019)

P.N. said:


> You can (int and, if i'm not mistaken, real arrays too). String arrays cannot.
> 
> Still, if your idea is having a bunch of persistent arrays around, consider this:
> 
> ...


Right. How silly of me


----------



## P.N. (Jul 2, 2019)

Fredeke said:


> Right. How silly of me


Nah, not silly. It really depends on your script and your needs.
If you had just a couple of "factory" presets, maybe it wouldn't be worth it using external arrays.


----------



## Fredeke (Jul 2, 2019)

I just implemented an nka preset manager in my instr. 
It way super easy - thanks.


----------



## DarylWise (Jul 7, 2019)

Fredeke said:


> I just implemented an nka preset manager in my instr.
> It way super easy - thanks.



I have a feeling for my library this wouldn't be so easy...


----------



## Fredeke (Jul 8, 2019)

I didn't actually make a preset manager. I just made Reset, Compare, Copy and Paste buttons, to allow the user to copy settings from one instrument to the other (because mine is a multi-nki library), etc. One single nka file serving as the clipboard, so there is no browser.

It was tedious to have to copy all controls' names several times over, but besides that it's the easiest thing I've ever done.

From what I understood, if you want to make a preset manager you must still save everything in a single array, and a single nka file (otherwise, I'm afraid rigid array names become impossible to deal with) and then provide a browser menu parsing the array, which should be partitioned into a definite number of "memory slots". SublimeKSP's multidimensional arrays may give a little help in that.

Oh, and I don't even know where the file is saved. Since there's only one, I trust Kontakt to find it where it left it. That might mean that factory presets should rather be imbeded in a script - anyway that's how I store the default settings associated with my Reset button.


----------



## EvilDragon (Jul 8, 2019)

Fredeke said:


> Oh, and I don't even know where the file is saved.



Depends on which array load/save mode you use. See KSP reference. In case of mode 0, it opens up a dialog for saving/loading, by default pointing to the Data folder (relative to the NKR path) or Documents folder (in case of Kontakt Player libraries). In mode 1 it's the same paths, just no dialog.

If you want to be in control of the path where the NKA is stored, use load/save_array_str(), and put it relative to $GET_FOLDER_PATCH_DIR (or $GET_FOLDER_LIBRARY_DIR in case of Player libraries).


----------



## Fredeke (Jul 8, 2019)

EvilDragon said:


> Depends on which array load/save mode you use. See KSP reference.


I did, but it wasn't where the ref said it would be. I use the mode without file browser, which doesn't allow me to pick the location.


----------



## EvilDragon (Jul 8, 2019)

Fredeke said:


> I did, but it wasn't where the ref said it would.



Paths are the same in mode 1 as by default in mode 0, IIRC.


----------



## Fredeke (Jul 8, 2019)

Ah, that could help.
and this too:


EvilDragon said:


> $GET_FOLDER_PATCH_DIR (or $GET_FOLDER_LIBRARY_DIR in case of Player libraries)


----------



## EvilDragon (Jul 8, 2019)

Note that $GET_FOLDER_PATCH_DIR might work a bit tricky in multis, not sure if your lib is based around multis or not.


----------



## Fredeke (Jul 8, 2019)

EvilDragon said:


> Note that $GET_FOLDER_PATCH_DIR might work a bit tricky in multis, not sure if your lib is based around multis or not.


I don't think it will be. Thanks.


----------



## P.N. (Jul 8, 2019)

Fredeke said:


> From what I understood, if you want to make a preset manager you must still save everything in a single array, and a single nka file (otherwise, I'm afraid rigid array names become impossible to deal with) and then provide a browser menu parsing the array, which should be partitioned into a definite number of "memory slots". SublimeKSP's multidimensional arrays may give a little help in that.



You can save in multiple arrays and still allow for user deletion.
But this is where things increase in complexity, though.
You have "preset slots" (maybe similar to your "memory slots"?) - basically individual preset arrays -, with an easy to follow iterative naming approach.
(you don't need to create them manually, you can let the script do it as it needs them).
You'd then use the save_array_str() command to allow users to delete/overwrite presets.
Another string array (as big as the maximum number of presets) would then be used to store the preset names.
You'd also need a preset status array (0,1) to let the UI know if that preset is active or was erased.
(with this method you don't need to actually erase the array data, you simply flag it).

This approach would allow you to delete, copy and paste presets from the UI, out of order, without comparing data everytime you do preset operation and without creating a messy data folder, full of presets that you already erased (with the preset status flagging array).

It would also allow for single preset sharing via nka, although i... it would still need a dedicated import/export function as we cannot reliably know which preset is which from the data folder directly.


----------

