1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Solved Keeping controls hidden after reloading instrument?

Discussion in 'Scripting Workshop' started by rossc, Sep 26, 2021.

  1. rossc

    rossc New Member

    Messages:
    9
    Hi guys,

    I'm creating multiple menus by hiding the currently displayed controls when another menu option is selected. However, when I save the NKI, then load it back up, all of the hidden controls become visible again, cluttering the GUI. All of my controls have been made persistent.

    Is there a way to retain the fact that controls are hidden, even after reopening the instrument?

    Thanks for your help! :)
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Making the control persistent only saves its value, not the display state.

    You should do your hide/showing in a function, then call that function in "on persistence_changed" callback. Protip: any tabs that you have should be make_instr_persistent() not make_persistent().
     
    • Like Like x 1
    • Informative Informative x 1
  3. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Hi _

    I take this opportunity to ask for the utility of the "read_var_persistent" command; i can't understand out the difference with make_persistent.
    It's quite vague even if I understood correctly for "make_persistent" _
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    read_persistent_var() reads the value of a persistent value within init callback, after applying that command you can use that value to do stuff. Simple test:

    Code:
    on init
        declare ui_knob $Test (0, 127, 1)
        $Test := 64
        make_persistent($Test)
        { read_persistent_var($Test) }
        message($Test)
    end on
    In the above case, with read_persistent_var() commented out, message() will always print out 64, even if you set the knob to a different value. If you uncomment that one line, it will use the persistent value (the one you've last set it to).

    It's largely deprecated since "on persistence_changed" callback was introduced.
     
  5. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Thank you for these explanations; I had actually understood nothing.

    The interest of this "read_persistent_var" is therefore to transmit the last value of a control, of a parameter so that it is used (value, modulation or other chosen). It's ambiguous when you don't speak the English language, I get the impression.
    Thanks again _ :thumbsup:
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yes - but it only ever makes sense in init callback. Here's another example:

    Code:
    on init
        declare $page
        declare ui_button $Tab1
        declare ui_button $Tab2
    
        make_persistent($page)
        {read_persistent_var($page)}
    
        $Tab1 := 1 - $page
        $Tab2 := $page
    end on
    
    on ui_control ($Tab1)
        $page := 0
        $Tab1 := 1 - $page
        $Tab2 := $page
    end on
    
    on ui_control ($Tab2)
        $page := 1
        $Tab1 := 1 - $page
        $Tab2 := $page
    end on
    If you don't use read_persistent_var() in this case, even if you select Tab2, after reloading the NKI or resetting the audio engine it will have Tab1 selected.

    So it's only needed if you have to do something based on the last known (and internally stored) value of a variable, in the init callback. However, as I mentioned, this is really very rarely needed now that we have "on persistence_changed" callback, where we can do anything we want directly after init (including calling functions).
     
  7. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Yes, this second example is more "talking" and demonstrative. And so, in the absence of "read_persistent_var ($ page)", it would be necessary to add:


    Code:
    on persistence_changed
        $Tab1 := 1 - $page
        $Tab2 := $page
    end on
     
  8. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah. Or you make it a function, and call it from persistence_changed, and each button's UI callbacks. :)
     
  9. WocherMusic

    WocherMusic NI Product Owner

    Messages:
    35
    May I just hook into this topic here – I have gotten a little bit confused about the persistence functionality in Kontakt.

    In the instrument I've been working on I made a lot of control elements like switches and sliders where I only wrote make_persistent and the display states (switch off vs. switch on, slider values and positions) get saved. For the sliders, though, I assigned get_engine_par to them, so that seems to be a different way of getting persistency. (Right?) But really, the switches seem to be saved only by make_persistent and

    On the other hand, I wasn't able to make a certain slider persistent, and that was the Pitch Bend range (intensity) slider. I had to write an if-statement into the on persistence_changed callback, otherwise my hide_control states wouldn't be saved. Does the display state's getting saved – or not getting saved – only apply to functions like hide_control but not to switch graphic states? It seems like it!
     
  10. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    get_engine_par() doesn't have anything to do with the sliders themselves - it only gives the current engine parameter value of the parameter you're getting.

    Persistence in Kontakt is only about value. Any display states are supposed to be handled separately (and yes, best in persistence_changed callback).
     
    • Informative Informative x 1
  11. WocherMusic

    WocherMusic NI Product Owner

    Messages:
    35
    Yes, so what I did was I assigned that engine parameter's value to each respective slider in the init callback. I assume though that this isn't such a good idea if I want to share my instrument and a new user will just get arbitrary values...? Not sure yet, I will have to test this.

    Ok, thank you! :thumbsup: