Last modifiedby & filed under KSP Scripting (NI Kontakt) - Tutorials, KSP: Basics.

The set_engine_par() command is used to control or set almost any engine parameters like volume, pan, tune, fx, lfo’s, envelopes and more. It is mostly used in combination with the on ui_control callback whenever we use custom knobs or buttons to control Kontakt’s FX, Modulators or any other engine parameter.

Mechanics

set_engine_par(<parameter>,<value>,<group>,<slot>,<generic>)

 

<parameter>

here goes the engine parameter variable. All engine parameter variables start with the prefix “$ENGINE_PAR_”

Basically you can consider the engine parameter variable like a full address with name, street, house number and place – to tell Kontakt what to control at all. For example we use “names” – which are given variables – as an identifier to adress specific engine parts. The variable $ENGINE_PAR_VOLUME for example addresses all volumes (see image). Via group, slot, generic you define exactly which volume you like to address of which more below.

There are many many engine parameter variables and you find them all listed in your KSP reference guide under  “Engine Parameter Variables”.

 

<value>

here goes the value you “send” to the engine. In most cases it’s any integer between 0 to 1000000. Kontakt translates this value into any engine specific value. So 0 would set the Volume to -inf and 1000000 sets the volume to +12.0 dB any other value can in this case also produce decimals like 6.3 dB.
Another example: with $ENGINE_PAR_PAN, 0 would be the very left and 1000000 the very right

 

<group>

this can also be considered as an address. This time it tells Kontakt on which level to look for the engine parameter.

Any value >= 0 addresses a group you have created (inside the groups tab). It’s also any brownish area inside the edit mode. LFOs or envelopes are also on a group level

.group level

-1 addresses an Instrument FX or any Bus parameter. It’s all white or light-gray areas. (see image below).

<slot>

addresses the slot in which an FX resides. It can also address a modulator.

When a slot is not needed we set it to -1 e.g. with any engine parameters on an instrument level like the Volume

“0 – 7”  to address an FX slot. There are always 8 slots on each level (group, bus or instrument level), starting with zero. So if we want to set a parameter in the first FX slot, the slot value would be “0”.

find_mod() if we want to address LFOs, Envelopes  or other modulators.

-1 for any other application like the Volume which is not in any FX slot.

<generic>

this final parameter is rather generic. It is used to help addressing the Send FX module, Insert FX modules, modulators, any parameter inside buses.

Set it to -1 for any other parameters outside fx, modules or buses like vol, pan, tune..

1 for insert FX

0 for send FX

$NI_BUS_OFFSET + [0-15] to address the paramters inside buses. $NI_BUS_OFFSET is a variable given by Kontakt. You simply need to add the bus number then. Like “$NI_BUS_OFFSET + 0” addresses the first bus.

find_mod(<group-idx>,<mod-name>) If we want to address LFO’s or Envelopes or other modulators we need the find_mod() command which will fin the right generic mod index for us by the mod name you have given.

-1 for any other applications like Volume or Pan (outside buses)

Examples

Bypass Button

this button bypasses all instrument insert FX in any slot.

on init
    declare ui_switch $bypass
    declare $count
    make_perfview
end on

on ui_control($bypass)
    $count := 0
    while ($count < 8)
        set_engine_par($ENGINE_PAR_EFFECT_BYPASS,$bypass,-1,$count,-1)
        inc($count)
    end while
end on

Volume Knob (all groups)

this knob changes the volume of all groups simultaneously

on init 	 	 
    declare ui_knob $volume(0, 1000000,10000)
    declare $count	  
    make_perfview	 	 
end on	 	 

on ui_control($volume)	 	 
    $count := 0	 	 
    while ($count &lt; $NUM_GROUPS)	 	 
        set_engine_par($ENGINE_PAR_VOLUME,$volume,$count,-1,-1)	 	 
        inc($count)	 	 
    end while	 	 
end on

Volume Knob (main Volume)

this knob changes the main volume of our instrument

on init 
    declare ui_knob $volume(0, 1000000,10000)
    declare $count
    make_perfview
end on
on ui_control($volume)
    set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,-1)
end on

Volume Knob (Bus 1)

this knob changes the volume of bus 1

on init 
    declare ui_knob $volume(0, 1000000,10000)
    declare $count
    make_perfview
end on
on ui_control($volume)
    set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,$NI_BUS_OFFSET + 0)
end on

Attack Rate – AEG

this knob controls the Attack rate of the default AEG of the first group (with index 0).

on init 
 declare ui_knob $Attack (0,1000000,100)
end on

on ui_control ($Attack)
 set_engine_par($ENGINE_PAR_ATTACK,$Attack,0,find_mod(0,"ENV_AHDSR"),-1)
end on

How useful was this article?

something you didn't like? Please tell us before you rate!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

NOTE: highly negative votes may be removed without any reasonable given feedback!

Tell us how we can improve this post?

25 Responses to “Kontakt Scripting (KSP) :: BASICS :: commands – set_engine_par()”

  1. john

    The last one regarding the attack assumes you have already named the mod Envelope AHDSR to "ENV_AHDSR" otherwise you will get error Object "blah blah" not found - Index will be invalid This part of kontakt scripting is the biggest headache when dealing with the "mod" section so badley designed

    • YummyBeats

      When you create a blank new isntrument the default AHDSR (for the group amplifier volume) is already called "ENV_AHDSR".
      So to test this little code you actually don't need to change anything (just wanted to keep it very simple here)

      But yes you are right. If you do a project with more Modulators you should always think of a systematic naming and also rename the default EG again - in case you are using it.

      Yes, it often really is a headache. Sometimes you even need to work with the direct id's/indices of the modulators .. highly error-prone.

      • John

        Hiya YB Thanks for the reply :) Im still getting this very annoying error right now even though I renamed the AHDSR from the default value, now "ENV_1" Object "ENV_1" not found - Index will be invalid I find adding effects into slots easy enough - this can be dont via the on init for example: If I wanted to load a "Ladder LP4" into the first "Insert FX" slot on init set_engine_par($ENGINE_PAR_EFFECT_TYPE,$EFFECT_TYPE_FILTER,-1,0,1) set_engine_par($ENGINE_PAR_EFFECT_SUBTYPE, $FILTER_TYPE_LDR_LP4,-1,0,1) end on This works like a charm but trying the same with a mod is some what troublesome since (as far as I can tell) there is no way to assign the mod slot a name.. You can do this... on init set_engine_par($ENGINE_PAR_INTMOD_TYPE,$INTMOD_TYPE_ENVELOPE,1,0,0) set_engine_par($ENGINE_PAR_INTMOD_SUBTYPE,$ENV_TYPE_AHDSR,1,0,0) end on Which does create the Env AHDSR in slot 1 BUT you cant assign it a name which to me is just bad design! If there is a way maybe I missed it or as you said it can be done with IDs then I would love to know more :) Cheers

        • John

          on init
          set_engine_par($ENGINE_PAR_INTMOD_TYPE,$INTMOD_TYPE_ENVELOPE,1,0,0)
          set_engine_par($ENGINE_PAR_INTMOD_SUBTYPE,$ENV_TYPE_AHDSR,1,0,0)
          end on
          
          Ok so trying to set the mod in "on init" does not actually work as I previously stated Its now giving me an error as "Not supported" (boo!)

          Still getting this really annoying error though "Object ENV_1 not found - Index will be invalid"

          Its really stange though because appart from this the scritp actually works as I want, which is one set of AHDSR knobs to control ALL zone samples

          Here is the part of the code maybe someone else can see what im doing wrong
          on init
          
          declare $group_idx
          declare $slot_idx
          $group_idx := 1
          $slot_idx := find_mod(1,"ENV_1")
          
          declare ui_knob $knobAttack(0, 1000000, 1)
          move_control($knobAttack,1,2)
          set_text($knobAttack,"Attack")
          set_knob_unit($knobAttack, $KNOB_UNIT_MS)
          set_knob_defval($knobAttack,500000)
          
          $knobAttack := get_engine_par($ENGINE_PAR_ATTACK,$group_idx,$slot_idx,0)
          set_knob_label($knobAttack, get_engine_par_disp($ENGINE_PAR_ATTACK,$group_idx,$slot_idx,0))
          make_persistent($knobAttack)
          
          end on
          
          { Attack Knob - START }
          on ui_control($knobAttack)
              $group_idx := 0
              while($group_idx < $NUM_GROUPS)   
              set_engine_par($ENGINE_PAR_ATTACK, $knobAttack, $group_idx, $slot_idx,0)
              inc($group_idx)
              end while
              set_knob_label($knobAttack, get_engine_par_disp($ENGINE_PAR_ATTACK, 0, $slot_idx,0))
          end on
          { Attack Knob - END }
          
          


          Like I said this works as a global Attack for all zones / groups but really dont understand the error "Object "ENV_1" not found - Index will be invalid" since I have added the Env and renamed it "ENV_1" from its default value

          So frustrating!

          • John

            Ok sorry to spam this post again lol - I've just found out that there MUST be a bug with this side on Kontakt. Now, Im actually using version 5.8.0 of Kontakt If you rename the Envolope AHDSR mod to "ENV_AHDSR" from its default value of "ENV_AHDSR_VOLUME" the error will be no more! I have no idea why this happens it appears to be a bug of some kind since you should be able to rename them what ever you want really

          • YummyBeats

            No Problem with the "spam" :)
            Yeah that's weird. Actually you can name the mods as you like. For me it worked with Kontakt 6 as well as 5.8.1 without any errors?! However I could only manage to change the subtype not the INTMOD_TYPE?!

            This is what I did (I used the default namings of the default volume envelope)
            on init
            	declare $mod_idx
            	declare $target_idx
            	declare $group_idx := 1
            	$mod_idx := find_mod($group_idx,"ENV_AHDSR") {mod name}
            	$target_idx := find_target($group_idx,$mod_idx,"ENV_AHDSR_VOLUME") {intensity slider's name}
            
            	set_engine_par($ENGINE_PAR_INTMOD_SUBTYPE,$ENV_TYPE_AHDSR,$group_idx,$mod_idx,$target_idx)
            end on
            

            EDIT: Have you added the mod to the correct group? Sometimes this accidently happens if you are hanging around in the wrong group.

          • YummyBeats

            I tried your code now and also didn't get any errors with Kontakt 5.8.1?! Maybe there was an old error left in your satus bar? At best always add message("") at the end of your on init to clear all former error reports. But don't forget to remove message("") again for debugging.

          • John

            Hi YB Thank you so much for your help and checking my code I will try the message thing on init and see how that goes The error normally appears when you hit the apply button on the script window thanks so much man your a legand!

          • YummyBeats

            Hey I was just about to edit my reply. I now think you didn't name the intensity slider and tried to adress the modulator module (below), right?!

            To change the subtype you need to adress the intensity slider. That's why "ENV_AHDSR_VOLUME" worked, becasue the volume intensity slider is named like this by default.

            To name the intensitry slider do the same as with the module below: open scipt editor -> right click somewheere on an empty area in the intensity slider (left to the invert button)

            I still couldn't figure out how to change the INTMOD_TYPE, though.

          • John

            Hi ya

            I tried to right click on the slider and it comes up with a learn midi cc and if its slightly off it just shows the mod name "ENV_AHDSR_VOLUME"

            Anyway, I tried your code which actually did rename the env mod... code

            declare $mod_idx
            declare $target_idx
            $mod_idx := find_mod($group_idx,"ENV_AHDSR") {mod name}
            $target_idx := find_target($group_idx,$mod_idx,"ENV_AHDSR_VOLUME") {intensity slider's name}
            set_engine_par($ENGINE_PAR_INTMOD_SUBTYPE,$ENV_TYPE_AHDSR,$group_idx,$mod_idx,$target_idx)
            
            

            So in my version of kontakt the default name for Env AHDSR is "ENV_AHDSR" so because I already had this mod in the first slot it did infact remane it to "ENV_AHDSR_VOLUME" - Which is cool... HOWEVER!!!! This is where I feel NI have got lazy.. As you know you can assign an effect to a slot via the on init by doing this:

            on init
            
            set_engine_par($ENGINE_PAR_EFFECT_TYPE,$EFFECT_TYPE_FILTER,-1,0,1)
            set_engine_par($ENGINE_PAR_EFFECT_SUBTYPE, $FILTER_TYPE_LDR_LP4,-1,0,1)
            set_engine_par($ENGINE_PAR_EFFECT_TYPE, $EFFECT_TYPE_TRANS_MASTER,-1,1,1)
            set_engine_par($ENGINE_PAR_SEND_EFFECT_TYPE,$EFFECT_TYPE_REVERB, -1,0,0)
            set_engine_par($ENGINE_PAR_SEND_EFFECT_TYPE,$EFFECT_TYPE_DELAY, -1,1,0)
            
            end on
            

            Going down the list, This would put the effects in:


            "Filter Ladder LP4" into "InsertFX Slot 1"
            "Transient Master" into "InsertFX Slot 2"
            "Reverb" into "SendFX Slot 1"
            "Delay" into "SendFX Slot 2"

            Again this works like a charm! adding this in your on init automatically puts these effect into the slots ready for tweeking lol BUT from what I can tell so far, this does not work with the mod section

            You have to already have the ENV AHDSR placed manually before you can do anything with it which sucks :(

            Now because "AHDSR" is a subtype of "Envelope" you would thing that this code would infact do what the above effects do
            on inti
            
            set_engine_par($ENGINE_PAR_INTMOD_TYPE,$INTMOD_TYPE_ENVELOPE,1,0,0) 
            set_engine_par($ENGINE_PAR_INTMOD_SUBTYPE,$ENV_TYPE_AHDSR,1,0,0)
            
            end on
            
            

            This gives the error "set_engine_par: Parameter tag not suported"

            What they should have done is to allow you to call up these mods and name them in the on inti call but it just does not appear to be an option. You have to manually add it first (booooooo!)

          • YummyBeats

            Yes exactly, that's what I'm also struggling with right now. I don't get any errors but using $ENGINE_PAR_INTMOD_TYPE just doesn't do anyithing. I mean to my understaning that's exactly what $ENGINE_PAR_INTMOD_TYPE is meant for?!

            Is it important to be able to change the modulator types dynamically e.g. via on control?

            I always set multiple modulators manually and work with the bypass. Well depends on how many modulators you are using in total becasue the bummer is the performance of course.

            EDIT: "

            What they should have done is to allow you to call up these mods and name them in the on inti call but it just does not appear to be an option. You have to manually add it first (booooooo!)

            "

            Yes true, I mean the manual naming would be ok. Since it's like an ID and you don't wanna change it anymore once it is all set.
            But yeah, being able to set all your modulators in the on init and change them dynamically would be really helpful and sometimes more perfromant!

          • John

            Oh and as for checking the groups I did try many things but.. When you manually add a mod, lets say "Envelope (AHDSR)" as we are talking about it, if you right click this by the text "Envelope (AHDSR)" it tells you the locations. Example: ENV_AHDSR_VOLUME (group: 1, idx: 0, gen: 0)

          • John

            Hi Mr YB This is perplexing to me too - i am new to KSP but OMG give me php any day lol Im a php coder at heart and al least the php manual is helpful The kontakt KSP sucks big time its clearly written by someone who already knows the code inside and out and they can be bothered to break things down to the gen pop lol Im currently have a love hate relationship with it at the moment tbh the manual for coding is just a joke! Via scripting would you happen to know if there is a way to stop a sample looping like a kill switch Ive created these AHDSR knobs with a switch so you can turn them on or off but one of the samples im using is looped and when you switch the AHDSR button the sample carries on looping Ive tried note_off($ALL_EVENTS) on both switch states (on/off) but still loops cheers again dude your so helpful

          • John

            Figured out the other little problem regarding the looped sample just added the following code for each switch state fade_out($ALL_EVENTS,10,1) { $ALL_EVENTS means all pressed notes. 10 is the time in ms to fade out. 1 means voice is stopped after the fade out } hope this helps someone else :)

          • YummyBeats

            Yeah as a beginner you feel pretty lost with the reference guide. I felt the same. But when you are using it for a while it gets better. NI doesn't explain complex stuff or offering any tutorials, though. Therefore the ksp community is always very helpful .. well hopefully :)

            That's weird again. The note_off($ALL_EVENTS) should actually work as you wanted it to. It's like if you are releasing all keys, so it also triggers the release phase of your volume envelope.

            If the release time is set very long it takes a while until the sound fades out.
            Whereas fade_out($ALL_EVENTS,10,1) works on the voice level before all modulators, if that's ok for you?

            BTW, that's my motto with KSP: "if it works .. it works" :) From my experience you don't need to prettify your code as much or make it super fancy performant as with other languages.

          • John

            Hi Mr YB Thank you so much for your help you have been awesome! I do keep trying with the KSP ref guide even though its like pulling teeth hehehe The note_off($ALL_EVENTS) does stop the notes if your holding the keys but if a sample is set to loop it would not stop it when I switched the button from AHDSR on/off. the fade_out($ALL_EVENTS,10,1) does do the job though so I will stick with it However Im still getting this stupid errors, i thought id fix it but when you move one of the knobs, say attack, the error appears again. I am right in assuming that mods work on group level so the group setting should be equal or more then 0 Since im using samples assigned to zones I have to use a while loop to go through the groups but this error is a nightmare. Even tried the on init message("") as you said but still appears when I move a knob

          • YummyBeats

            Sure, you're welcome!

            Ok, I see

            Yes, the modulators all work on the group level (only). Hmm, what type of error do you still get?

          • John

            Hiya! The error is Object "ENV_AHDSR_VOLUME" not found - Index will be invalid What a suprise lol What do you use to code its really annoying that Kontakt does not display line numbers but yet insist on giving errors on line numbers lol

          • YummyBeats

            Haha, thought u got a different error now.

            yes, debugging is a PITA!

            I still don't get any error when using your code, so maybe there is another issue?!
            Sometimes Kontakt is messung up the naming and/or the mod positions if you disable "edit all groups" and change any modulator setting for one group.
            So maybe double check all your groups if all the volume intensity sliders are really named "ENV_AHDSR_VOLUME".

            If you got too many groups you could also start from scratch:

            1. enable "edit all groups"
            2. delete all modulators
            3. add all modulators again
            4. still keep "edit all groups" enabled and rename the modulator for one group (all other modulators will be renamed as well)

          • John

            I've just installed Sublime just so i can get to the lines where the errors appear Here is a short example
            
            on init
            
            declare $group_idx
            declare $slot_idx
            declare $target_idx
            
            $group_idx := 0
            $slot_idx := find_mod($group_idx,"ENV_AHDSR") {Old Mod Name}
            $target_idx := find_target($group_idx,$slot_idx,"ENV_AHDSR_VOLUME") {Rename Mod}
            
            { Attack Knob - START }
            declare ui_knob $AttackKnob(0, 1000000, 1)
            set_text($AttackKnob,"Attack")
            set_knob_unit($AttackKnob, $KNOB_UNIT_MS)
            set_knob_defval($AttackKnob,46000)
            $AttackKnob := get_engine_par($ENGINE_PAR_ATTACK,$group_idx,$slot_idx,0)
            set_knob_label($AttackKnob, get_engine_par_disp($ENGINE_PAR_ATTACK,$group_idx,$slot_idx,0))
            make_persistent($AttackKnob)
            { Attack Knob - END }
            
            end on
            
            
            { Attack Knob - START }
            on ui_control($AttackKnob)
                $group_idx := 0
                while($group_idx < $NUM_GROUPS)   
                set_engine_par($ENGINE_PAR_ATTACK, $AttackKnob, $group_idx, $slot_idx, find_mod($group_idx,"ENV_AHDSR_VOLUME"))   
                inc($group_idx)
                end while
                set_knob_label($AttackKnob,get_engine_par_disp($ENGINE_PAR_ATTACK,0,$slot_idx,0))
            end on
            { Attack Knob - END }
            
            
            So the error id located at set_engine_par($ENGINE_PAR_ATTACK, $AttackKnob, $group_idx, $slot_idx, find_mod($group_idx,"ENV_AHDSR_VOLUME")) if I change find_mod($group_idx,"ENV_AHDSR_VOLUME") back to find_mod($group_idx,"ENV_AHDSR") the error does not show anymore even though the actual mod is called "ENV_AHDSR_VOLUME" This is just crazy stupid shizznizzal!!!

          • YummyBeats

            Ah I see. Is your modulator really called "ENV_AHDSR_VOLUME" or just the intensity slider?

            If I cahnge the modulator name (below) to ENV_AHDSR_VOLUME, I don't get any error with your code. With the default naming "ENV_AHDSR" I also get the error.

            find_mod and $ENGINE_PAR_ATTACK adreseses the modulator itself, not the intensity slider level. But yes, this whole adressing system can be very confusing.

            So I recommend to use an own naming system which helps a lot

          • John

            This is so infuriating! Which part of the script page should i be looking at for the names, man i feel im loosing the will to live lol Should I be getting the name from the brown mod area just below amplifier or the mod right at the bottom the one in the brown area is called "ENV_AHDSR_VOLUME" Is this were im going wrong?

          • John

            OK So do you what works best for my needs lol Absoluly nothing at all - meaning i have stripped all the find_mods out and other functions that appeared to be causing issues. The bottom line is these for me where not needed hense the errors was not dont looking to add a velocity slider for attack or anything else for that matter - all I wanted was a global AHDSR for all groups and for this I do not need to use find_mod or find_target() Since you HAVE to manually add the "Envolope (AHDSR)" where it actually says "Envolope (AHDSR)" right click and just make a not of the Group, Slot & Generic values For me for this mod they are all 0 so...
            
            on init
            
            declare $group_idx
            declare $slot_idx
            declare $generic_idx
            
            $group_idx := 0
            $slot_idx := 0
            $generic_idx := 0
            
            { Attack Knob - START }
            declare ui_knob $AttackKnob(0, 1000000, 1)
            set_text($AttackKnob,"Attack")
            set_knob_unit($AttackKnob, $KNOB_UNIT_MS)
            set_knob_defval($AttackKnob,46000)
            $AttackKnob := get_engine_par($ENGINE_PAR_ATTACK,$group_idx,$slot_idx,$generic_idx)
            set_knob_label($AttackKnob, get_engine_par_disp($ENGINE_PAR_ATTACK,$group_idx,$slot_idx,$generic_idx))
            make_persistent($AttackKnob)
            { Attack Knob - END }
            
            end on
            
            { Attack Knob - START }
            on ui_control($AttackKnob)
                $group_idx := 0 
                while($group_idx < $NUM_GROUPS)   
                set_engine_par($ENGINE_PAR_ATTACK, $AttackKnob, $group_idx, $slot_idx, $generic_idx)   
                inc($group_idx)
                end while
                set_knob_label($AttackKnob,get_engine_par_disp($ENGINE_PAR_ATTACK,0,$slot_idx,$generic_idx))
            end on
            { Attack Knob - END }
            
            
            This attack knob will now effect all sample in groups and zones - all I wanted lol No need to pass names = no errors lol problem solved Cheers YB for your help owe you big time

Leave a Reply

use <pre> </pre> to wrap code blocks

use <code> </code> to wrap small code snippets

use basic html to style your comment

Your email address will not be published. Required fields are marked *