# Preset loading from nka array



## joanhadeau (Jan 11, 2018)

Hi Everyone, 

I want to have a next and prev button to "cycle" through presets that load from an .nka file in the Data folder.

But I have no idea what command to use.

So I save a preset as "preset0.nka" save another one as "preset1.nka" , "preset2.nka"
and so on. through the browser and thats fine. 

Now to Load with the next/prev button 
I thought I could do something like this :

```
$load_arr_id := load_array(%preset & $PresetCounter,0)
```
So I could iterate the name of the array preset0,preset1,preset2 etc
but that doesn't work. :(

I'm sure there is a simple way.

Examples or pseudo code would help a lot since Im still learning

Thank you so much for taking a look! 


```
on init
    message ("")
    declare $count
    declare ui_button $Load
    declare ui_button $Save
    declare ui_button $NextPreset
    declare ui_button $PrevPreset
    
    declare ui_table %table[8] (2,2,100)
    make_persistent(%table)
    
    declare $PresetCounter:=0
    
    declare %preset0[8]
    declare %preset1[8]
    declare %preset2[8]
    
    declare $load_arr_id
    $load_arr_id := -1
    declare $save_arr_id
    $save_arr_id := -1
    
    
    
end on

on ui_control (%table)
    
    $count := 0
    
    while($count < 8)
        %preset0[$count] := %table[$count]
        inc($count)
    end while
    
end on

on ui_control ($Load) {with browser}
    
    $load_arr_id := load_array(%preset0,0)
    
end on

on ui_control ($Save) {with browser}
    
    $save_arr_id := save_array(%preset0,0)
    
end on
{*** Load next Preset**}
on ui_control ($NextPreset){no browser}
    {??}
    $load_arr_id := load_array(%preset0,1) {If i could iterate the 0 perhaps that could work? :s}
    
end on

on ui_control ($PrevPreset) {no browser}
    
    $save_arr_id := save_array(%preset0,1)
    
end on

on async_complete
    
    if ($NI_ASYNC_ID = $load_arr_id)
        $load_arr_id := -1
        $Load := 0
        
        if ($NI_ASYNC_EXIT_STATUS = 1)
            $count := 0
            while($count < 8)
                %table[$count] := %preset0[$count] {set the newly loaded array into table}
                inc($count)
            end while
        end if
        
    end if
    
    if ($NI_ASYNC_ID = $save_arr_id)
        $save_arr_id := -1
        $Save := 0
    end if
    
end on
```


----------



## Ecliptiq Audio (Jan 11, 2018)

Hi,

Your initial idea about the $PresetCounter is not bad. What you can do is increase it (on the next preset button) or decrease it (on the previous button) and after that do a select statement like this:

```
on ui_control ($NextPreset)
    inc($PresetCounter)
    select $PresetCounter
    case 0
        $load_arr_id :=load_array(%preset0, 1)
    case 1
        $load_arr_id :=load_array(%preset1, 1)
    case 2
        $load_arr_id :=load_array(%preset2, 1)
    end select 
end on
```

This is quite ugly especially if you have a lot of presets, but I can't think of anything better now.

Regards,
Peter


----------



## EvilDragon (Jan 11, 2018)

A better solution would be to use load_array_str() instead. All the stored NKAs would use the same preset array (no need to change the array name), then all you need is use get_folder($GET_FOLDER_PATCH_DIR) then go back to Data folder relatively, to get to your NKAs. And then just load them.


----------



## joanhadeau (Jan 11, 2018)

Ahh!! okay I will try some tests! thanks so much guys!!


----------



## Maxheadroom (Nov 5, 2018)

EvilDragon said:


> A better solution would be to use load_array_str() instead. All the stored NKAs would use the same preset array (no need to change the array name), then all you need is use get_folder($GET_FOLDER_PATCH_DIR) then go back to Data folder relatively, to get to your NKAs. And then just load them.



I am currently also trying to figure out an efficient NKA-loading script for a large number of NKA files. Did I get this right? You are suggesting to have a "Master"-NKA-file which holds all the single NKA-file-name strings. Then to use "load_array_str()" on the UI Control to get the "Master", and in the next step get the needed .NKA with the correct array index by a "counter variable"?


----------



## raidmarji (Feb 3, 2019)

Hi all
is there an auto load array command for MAC, I mean that I have my .nka resides inside:
users/Raid/Library/Logs/test.nka
Note: Library folder (Hidden Folder) can be shown on pressing option key +go


----------



## EvilDragon (Feb 3, 2019)

You would need to use load_array_str(), but you should be aware that the path you're talking about wouldn't be the same on Windows. You should ideally base your path on $GET_FOLDER_PATCH_DIR, relatively.


----------

