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. So wiht this command we actually control Kontakt via our custom UI. So set_engine_par() 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.
SYNTAX
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_”
We use the $ENGINE_PAR variables like an address to tell Kontakt what to control at all. The variable $ENGINE_PAR_VOLUME for example addresses all volumes (see image). Via group, slot, generic we define which specific volume we like to address .. read 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 we “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 produce decimals like 6.3 dB.
Or another example: with $ENGINE_PAR_PAN, 0 would be the very left and 1000000 the very right
<group>
this is also part of the addressing. This time it tells Kontakt at which level the engine parameter should be addressed.
Any value >= 0 addresses a group we have created (inside the groups tab). It’s also any brownish area inside the edit mode. Whereas the value represents the group’s index. So “3” would be group idx 3 (which is actually our 4th group since the index starts at 0: group 1 = idx 0; group 2 = idx 1; group 3 = idx 2 ….).
LFOs or Envelopes are also on a group level
-1 addresses an Instrument FX or the Busses. 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 or Pan
“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.
<generic>
this final parameter really 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
2 for main FX
Alternatively also these constants can be used:
$NI_SEND_BUS for Send FX
$NI_INSERT_BUS for Insert FX
$NI_MAIN_BUS for Main 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 < $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
Sofía
Hi! I have a question. How can I make a knob that works like the tone knob of a fender stratocaster?YummyBeats
if you just need the volume knob this article here explains it already
However for the tone knobs - especially the humbucker knob - it gets way more complex. Too complex for the comments here and for me as well ;), sorry.
Most important part for the humbucker knob is the sampling itself I'd say. I never worked on an e-guitar but I would kind of blend over the single samples then. This can cause heavy phasing so it is most likely not just a simple (volume based) cross fade I guess?!
The filter tone knob is a little easier. You just need to control a filter like the Solid EQ. But I don't know how the filter on a Strat actually works. Is it just a simple high shelf?
In this case put a Solid EQ into Slot 1 of the insert FX Section. Adjust the High Shelf freq, to bring it closely enough to the real sounding.
Then you can control the HF gain like this:
Of course you can put the filter/EQ into any fx slot you want. Simply adjust the set_engine_par then like described in this article.
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 designedYummyBeats
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 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... 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 :) CheersJohn
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
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 reallyYummyBeats
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)
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 yaI 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
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:
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 doThis 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 helpfulJohn
Figured out the other little problem regarding the looped sample just added the following code for each switch statefade_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 knobYummyBeats
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 lolYummyBeats
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:
John
I've just installed Sublime just so i can get to the lines where the errors appear Here is a short example So the error id located atset_engine_par($ENGINE_PAR_ATTACK, $AttackKnob, $group_idx, $slot_idx, find_mod($group_idx,"ENV_AHDSR_VOLUME"))
if I changefind_mod($group_idx,"ENV_AHDSR_VOLUME")
back tofind_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
I wish I could put screen shots up here lolYummyBeats
Yeah, good point, I've just sent u an email :)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... 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