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 an address – house number or place – to tell Kontakt what to control at all. For example the variable $ENGINE_PAR_VOLUME 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, or independent engine parameters 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 or other parameters outside these modules 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?

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!

Let us improve this post!

Tell us how we can improve this post?

7 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.

Leave a Reply

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

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

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