# Can't get attack slider to work



## jesusginard (Dec 13, 2011)

I'm making a new instrument and I want to control the attack time with a slider on group 0 and 1. 

Here's what I have: 

on init
set_ui_height_px(350)
make_perfview
message("")
declare $count := 0
declare ui_slider $Attack(0,1000000)
make_persistent($Attack)
read_persistent_var($Attack)
move_control_px($Attack,146,55)
set_control_par(get_ui_id($Attack),$CONTROL_PAR_WIDTH,27)
set_control_par(get_ui_id($Attack),$CONTROL_PAR_HEIGHT,27)
end on
on ui_control($Attack)
set_engine_par($ENGINE_PAR_ATTACK,$Attack,0,-1,-1)
set_engine_par($ENGINE_PAR_ATTACK,$Attack,1,-1,-1)
end on

It doesn't work, don't know why.


----------



## ScoringFilm (Dec 13, 2011)

You have to be careful with the last three parameters:

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

<group> = group number or set to -1 at instrument level
<slot> = FX slot number (for all other applications, set this parameter to -1)
<generic> = 1 for insert or 0 for send (for all other applications, set this parameter to -1)

Don't forget group and slot are zero based:

*on ui_control* ($Attack) 
``_set_engine_par($ENGINE_PAR_ATTACK, $Attack, 0, 0, -1) 
``set_knob_label($Attack, _get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1)) 
``message("Attack=" & $Attack)
*end on*


----------



## jesusginard (Dec 13, 2011)

Thank you very much! I knew that, the problem was that in slot I put -1 and it has to be 0. Don't understand why... but now it works.


----------



## mk282 (Dec 13, 2011)

In fact, a MUCH safer way is approaching the envelopes and modulation intensities, using find_mod() and find_target() functions. This is how you do it if you want to approach to modulator controls (LFO, envelope, etc - *NOT* the modulation intensity!):

* Let's say you have an envelope modulator that's named "ENV 1". To see the name of the envelope, you have to make sure you have Script Editor Edit mode open (but you can have the Script Editor itself closed - it's important that the white editing area is opened!), then right click on the envelope. Click on the displayed envelope name to rename the envelope to whatever you want. In this case, rename it to "ENV 1".

Now, use this code to set the Attack parameter:


```
set_engine_par($ENGINE_PAR_ATTACK,$Attack,<group>,find_mod(<group>,"ENV 1"),-1)
```

The last -1 is important here, because we're not approaching a modulation intensity slider! Also, <group> needs to be the same in both instances above.

* Let's say this ENV 1 is modulating pitch. Let's rename the modulator intensity slider! Go to Source section, press Mod to open the modulators there, and you should see your envelope modulating the pitch by default (if you set this modulation up - but for this example let's consider it already set up). Right-click the modulation intensity slider, and rename it to "ENV 1 -> PITCH". That's good. Now, from here you have two different methods of dealing with setting up modulation amount:

** First method:


```
set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY,$Amount,<group>,find_mod(<group>,"ENV 1"),find_target(<group>,find_mod(<group>,"ENV 1"),"ENV 1 -> PITCH"))
```

By using $ENGINE_PAR_MOD_TARGET_INTENSITY here, you're using ONLY the positive range of the modulation intensity slider (0.0% - 100%).

** Second method:


```
set_engine_par($ENGINE_PAR_INTMOD_INTENSITY,$Amount,<group>,find_mod(<group>,"ENV 1"),find_target(<group>,find_mod(<group>,"ENV 1"),"ENV 1 -> PITCH"))
```

INTMOD_INTENSITY is used basically just for LFO/env/step sequencer modulators, but it works on external modulator intensities as well (pitch bend, CC, aftertouch...). What it does is that it will allow you to change BOTH the positive AND negative range of the modulation intensity slider (-100.0 to 100.0%) by using just one line of code (instead of using if-else for toggling Invert button as in the example from KSP Reference - so inefficient!).


I recommend using second method if you need quick and easy bipolar modulation amount adjustments, and the first method if you need them to be just unipolar.


----------



## Mike Greene (Dec 13, 2011)

mk282 @ Tue Dec 13 said:


> In fact, a MUCH safer way is approaching the envelopes and modulation intensities, using find_mod() and find_target() functions.


I thought that people were having a problem with Kontakt renaming modulators on its own, mostly after adding a new modulator.

For that reason, I've been reluctant to use the names of a modulator, especially since I mostly just have one modulator (an ADSR envelope) per group anyway, so I can usually safely assume it's in slot zero. Although . . . I say "usually," because from time to time, either I or Kontakt somehow magically _adds_ a velocity modulator without me knowing it. And for some reason, that velocity modulator will take slot 0, moving the ADSR to slot one.

I'm tempted to use find_mod() and find_target() functions with the names of the ADSR envelopes, but with that "renaming bug," I worry I'd be jumping out of the pot and into the fire.


----------



## mk282 (Dec 13, 2011)

Kontakt 4 messes up modulator names ONLY if you use "Existing" option to use the same modulator on several targets. That's my only encounter of such weird renaming bugs. That bug is now fixed in K5.

Anyways, in K5 now you can also rename the same modulator across several groups (or all groups, if you have Edit All Groups enabled), which is a dream come true (and how it should have worked since Kontakt 3...)


----------



## Mike Greene (Dec 13, 2011)

The renaming bug is the one mentioned in this thread:
http://www.vi-control.net/forum/viewtopic.php?t=18496
<NOTE> - I see you edited your post, so that must be the one you're talking about.)

To be clear, I haven't experienced it myself. After reading that thread, it kinda scared me off because I was having enough problems as is. :mrgreen: 

I didn't know about the ability to rename modulators in all groups at once now! That's a big deal, and the fact that the renaming had to be done one group at a time was the other reason I never did it.

As usual, I'm learning very useful stuff even in threads I didn't think applied to me. 8)


----------



## mk282 (Dec 13, 2011)

Hmmm, right, what polypx said, yes. That's the bug I was mentioning above, I think. I encountered it ONLY if I used "Existing". Some weird crap happens. For example, I have an LFO modulating pan that I named "LFO 1" (and of course, Kontakt is STUPID so it doesn't rename LFO_SINE_VOLUME to LFO_SINE_PAN when you change the modulation destination!), so I rename it to "LFO 1 -> PAN" myself.

Then if I add that same LFO to modulate pitch. And what do I get? The LFO to pitch modulation amount gets named "_PITCH", the pan modulation amount gets named "(null)", and the LFO gets named "(null)", too!

That is horrid, and I hate NI for not retrogradely fixing this bug in Kontakt 4!


BTW; here's a hint for Kontakt 4: if you need to have the same modulators (and their names) across a lot of groups, create one group with all modulators, rename them, and then just copy that group as much as you need! THEN populate those groups with samples. Surely, not as fast as in K5 now, but it's the only workaround we have...


----------



## sonaht (Dec 14, 2011)

Hello,

There is a new "under the hood" feature in Kontakt 5.0.1 and if you right click in a modulator (with the Script Edit window open) you now can see the name as well as the group number, id, and generic value for both the modulator and modulation destination. This way you can avoid the find_mod, find_target sausage of a code 

Please see attached pictures:














I also uploaded the script and nki file that Evil Dragon had originally posted on this link(modified to show how to add these numbers in the command

```
set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY,$Amount,<group>,fi nd_mod(<group>,"ENV 1"),find_target(<group>,find_mod(<group>,"ENV 1"),"ENV 1 -> PITCH"))
```
 You can download it from here:
http://pinartoprak.com/KSP/Approaching_Modulators_5.0.1.zip (Approaching Modulators 5.0.1.zip) 

posted on this thread:

http://www.vi-control.net/forum/viewtopic.php?t=18496

Best,
Thanos


----------

