How to attach Attack from the volume envelope to a knob in KSP?

artietrasshko
artietrasshko Member Posts: 7 Newcomer
edited October 2024 in Scripting Workshop

I have most of the code set up to achieve this but I believe I am just not understanding how to use set_engine_par to call upon the attack parameter. I believe since it is a modulator that there is something more to it but I have not been able to figure it out. I have included a screenshot of my current code. It lets me apply it but it doesn't actually affect the attack time.

Tagged:

Comments

  • corbo-billy
    corbo-billy Member Posts: 107 Helper
    edited June 2024

    An exemple in the KSP manual: verything lies in the last three digits corresponding to the group on a 0 basis.

    https://www.native-instruments.com/ni-tech-manuals/ksp-manual/en/engine-parameter-commands.html#get_mod_idx--

    It seems complicated at first but as you write and code, it improves in understanding.

  • artietrasshko
    artietrasshko Member Posts: 7 Newcomer

    I did find this example and tried following it, but then I started having problems with the "VOL_ENV" portion of the get_mod_idx command. I renamed it manually like it says in the manual but I get a warning saying that it is not recognized. I tried the same thing with the default name of the envelope and it still did not work. Can you look through my code and see if anything is off?

  • theodorech
    theodorech Member Posts: 73 Member

    This sticky thread is quite useful when it comes to modulators:



    As for the ENGINE_PAR_ATTACK, you can also do:

    on init
    declare $i
    declare ui_slider $attack(0,1000000)
    make_persistent($attack)
    end on on ui_control($attack)
    $i := 0
    while ($i<$NUM_GROUPS)
    set_engine_par($ENGINE_PAR_ATTACK,$attack,$i,0,0)
    inc($i)
    end while
    end on

  • artietrasshko
    artietrasshko Member Posts: 7 Newcomer

    Thank you so much for the code and the thread! Is it possible you can explain the while loop, specifically how it works with the $i<$NUM_GROUPS condition and the set_engine_par conditions? How does incrementing through different groups make it work?

  • theodorech
    theodorech Member Posts: 73 Member

    A while loop lets you apply the same command to different groups or slots without repeating the code.

    1. $i is the counter:
      • $i := 0 starts the loop at 0, but you can start at any number.
    2. The Loop Condition:
      • while ($i < $NUM_GROUPS) the loop runs as long as $i is less than $NUM_GROUPS
      • $NUM_GROUPS is a built-in KSP variable that tells you how many groups there are in a Kontakt instrument. The first group is always group index 0.
    3. Inside the Loop:
      • set_engine_par($ENGINE_PAR_ATTACK, $attack, $i, 0, 0) this sets the attack parameter for the current group $i
      • inc($i) this increases $i by 1, so the next loop works on the next group
    4. Ending the Loop:
      • end while the loop stops when $i is no longer less than $NUM_GROUPS


    Note that you can achieve the same result with less code if you use Sublime Text Editor to write your scripts. Example:


    for i:= 0 to NUM_GROUPS - 1 set_engine_par(ENGINE_PAR_ATTACK, attack, i, 0, 0) end for

  • artietrasshko
    artietrasshko Member Posts: 7 Newcomer

    Thanks for the breakdown, I am just still confused as to how you are able to target the volume envelope without mentioning it in the code. From the thread you had provided they had mentioned using get_mod_idx which makes sense but for whatever reason when I change the "ENV_ADHSR_VOLUME" name or just use that one it doesn't work.

    A better way to pose my initial question would be how does cycling through the different groups find the Attack parameter if my instrument is only in one group?

  • artietrasshko
    artietrasshko Member Posts: 7 Newcomer

    I had ended up removing the while loop to see if it would still work and it did. But now I understand that you had gotten the 0 values in your set_engine_par and get_engine_par from the (Group:0, Index:0,Generic:0) that is attached to ENV_AHDSR_VOLUME. I had been overcomplicating it with the whole get_mod_idx, so this does simplify it, thanks again for your help!

  • theodorech
    theodorech Member Posts: 73 Member

    Unless you need to control the modulator's intensity, there's no practical reason to target a specific modulator name just to adjust the ADSR values. The sticky thread covers almost everything about modulators, and I highly recommend checking it out and running some tests in a fresh .nki file.


    Note that my example using the while loop lets you control the attack levels of all your available groups.

This discussion has been closed.
Back To Top