# Simple ADSR script



## damstraversaz (Feb 10, 2011)

Hi

I just try to use a basic ADSR with kontakt . I had this script ( I forgot who made this, sorry...),but it seems to be an error when I try to apply it ERROR (line3): 'end on' expected . so If somebony can help me to resolve this issue, or annother alternative, it will be great !

thanks for reading

Damien




> on init
> 
> ``declare ui_knob $Atk_Curve (0,1000000,1)
> ``set_text($Atk_Curve, "Curve")
> ...


----------



## Yuroun (Feb 10, 2011)

It works here. 

*on init* 
````make_perfview
*declare* ui_knob $Atk_Curve (0,1000000,1) 
set_text($Atk_Curve, "Curve") 
set_knob_unit($Atk_Curve, $KNOB_UNIT_NONE) 
_set_engine_par($ENGINE_PAR_ATK_CURVE, $Atk_Curve, 0, 0, -1) 
set_knob_label($Atk_Curve, _get_engine_par_disp($ENGINE_PAR_ATK_CURVE, 0, 0, -1)) 

*declare* ui_knob $Atk (0,1000000,1) 
set_text($Atk, "Attack") 
set_knob_unit($Atk, $KNOB_UNIT_HZ) 
_set_engine_par($ENGINE_PAR_ATTACK, $Atk, 0, 0, -1) 
set_knob_label($Atk, _get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1)) 

*declare* ui_knob $Hold (0,1000000,1) 
set_text($Hold, "Hold") 
set_knob_unit($Hold, $KNOB_UNIT_MS) 
_set_engine_par($ENGINE_PAR_HOLD, $Hold, 0, 0, -1) 
set_knob_label($Hold, _get_engine_par_disp($ENGINE_PAR_HOLD, 0, 0, -1)) 

*declare* ui_knob $Decay (0,1000000,1) 
set_text($Decay, "Decay") 
set_knob_unit($Decay, $KNOB_UNIT_MS) 
_set_engine_par($ENGINE_PAR_DECAY, $Decay, 0, 0, -1) 
set_knob_label($Decay, _get_engine_par_disp($ENGINE_PAR_DECAY, 0, 0, -1)) 

*declare* ui_knob $Sus (0,1000000,1) 
set_text($Sus, "Sustain") 
set_knob_unit($Sus, $KNOB_UNIT_MS) 
_set_engine_par($ENGINE_PAR_SUSTAIN, $Sus, 0, 0, -1) 
set_knob_label($Sus, _get_engine_par_disp($ENGINE_PAR_SUSTAIN, 0, 0, -1)) 

*declare* ui_knob $Rel (0,1000000,1) 
set_text($Rel, "Release") 
set_knob_unit($Rel, $KNOB_UNIT_MS) 
_set_engine_par($ENGINE_PAR_RELEASE, $Rel, 0, 0, -1) 
set_knob_label($Rel, _get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1)) 
*end on* 

*on ui_control* ($Atk_Curve) 
_set_engine_par($ENGINE_PAR_ATK_CURVE, $Atk_Curve, 0, 0, -1) 
set_knob_label($Atk_Curve, _get_engine_par_disp($ENGINE_PAR_ATK_CURVE, 0, 0, -1)) 
*end on* 

*on ui_control* ($Atk) 
_set_engine_par($ENGINE_PAR_ATTACK, $Atk, 0, 0, -1) 
set_knob_label($Atk, _get_engine_par_disp($ENGINE_PAR_ATTACK, 0, 0, -1)) 
*end on*ò u   â×d u   âÙŸ u   âÚi u   âÜú u   âÝ
 u   âÝ: u   âÝR u   âÞ u   âÞŒ u   âà~ u   âá* u   âáÅ u   âáá u   âãž u   âã´ u   âå u   âå& u   âåK u   âåL u   âå¿ u   âæ u   âæ u   âæ' u   âæa u   âæ€ u   âæ™ u   âæë u   âéÆ u   âéú u   âì“ u   âì¶ u   âîÆ u   âï u   âðk u   âð˜ u   âñ0 u   âñœ u   âõ† u   âö u   âø? u   âø u   âù u   âùF u   âùR u   âù‹ u   âú2 u   âú@ u   âúã u   âû^ u   âü: u   âüV u   âý¤ u   âýÄ u   ãu   ã À u   ã È u   ã^ u   ãs u   ã, u   ã_ u   ãQ u   ã u   ã u   ã4 u   ãÌ u   ã u   ã+ u   ãT u   ãÄ u   ãû u   ãú u   ã t u   ã × u   ã ø u   ã– u   ãî u   ã¬ u   ãè u   ã* u   ãn u   ãí u   ã’ u   ãk u   ã³ u   ãÜ u   ãc u   ã– u   ãÅ u   ãÆ u   ãÕ u   ã  u   ãr u   ã¢ u   ãË u   ãã u   ãü u   ãß u   ãL u   ãå u   ã u   ã¤ u   ã¿ u   ãÈ u   ãî u   ã é u   ã!‚ u   ã$z u   ã$Ç u   ã(2 u   ã(œ u   ã) u   ã)ª              ò u   ã*v u   ã-Q u   ã-~ u   ã-Ñ u   ã-ß u   ã/ u   ã/p u   ã/¢ u   ã/Ü u   ã0[ u   ã0n u   ã0• u   ã0ª u   ã1¹ u   ã1ê u   ã2S u   ã2w u   ã3 u   ã3¤ u   ã3Þ u   ã3ò u   ã48 u   ã4‹ u   ã5 u   ã5% u   ã5’ u   ã6 u


----------



## Mike Greene (Feb 10, 2011)

I'm confused by why a "set_knob_label" is in each of the callbacks. Like this one:


```
on ui_control ($Rel) 
_set_engine_par($ENGINE_PAR_RELEASE, $Rel, 0, 0, -1) 
set_knob_label($Rel, _get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1)) 
end on
```

In other words, isn't:

```
set_knob_label($Rel, _get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1))
```
the same as:

```
set_knob_label($Rel,$Rel)
```

And if that's the case, doesn't the label *already* show a value of $Rel, without us needing to tell it to?

Also, since I'm asking remedial questions :mrgreen: , is there a reason why there is an underscore before each of the "_set_engine_par" lines? Is that just to make it easier (visually) to find the set_parameter commands, or does it actually do something different than without the underscore?


----------



## polypx (Feb 10, 2011)

Mike, the underscore prefix is leftover from K3, you no longer need it in K4.

cheers, Dan


----------



## EvilDragon (Feb 11, 2011)

Mike Greene @ 11.2.2011 said:


> I'm confused by why a "set_knob_label" is in each of the callbacks. Like this one:
> 
> 
> 
> ...



It's not the same. $Rel is a knob with value range from 0 to 1000000. So, if its value was 500000, set_knob_label($Rel,$Rel) won't do anything, it will just say 500000. BUT, when you add get_engine_par_disp, it actually fetches the displayed value on the Release knob, after you set that knob to the value of $Rel. That's why you need to do it.



Oh, and people, please use

```
tags!
```


----------



## gazdadash (Mar 4, 2011)

alright, i've got a newbie question. this script regulates ahdsr values for the group 1 only. i tried to change the group parametar in set_engine_par to -1 to make it work for the whole instrument, but it doesn't. why?


----------



## germancomponist (Mar 4, 2011)

ADSR and AHDSR are so antiquated. 
Is there any script with what I can set 8 or more steps, and between two of them the sustain point?


----------



## Tod (Mar 4, 2011)

gazdadash @ Fri Mar 04 said:


> alright, i've got a newbie question. this script regulates ahdsr values for the group 1 only. i tried to change the group parametar in set_engine_par to -1 to make it work for the whole instrument, but it doesn't. why?



Each group will have it's own envelope so you have to include code for each group. In the "$Atk, 0, 0, -1)" the first "0" is the first group (the groups indexs start at 0). In other words if you have 2 groups then you could set the $Atk_Curve up like this:


```
on ui_control ($Atk_Curve) 
     _set_engine_par($ENGINE_PAR_ATK_CURVE, $Atk_Curve, 0, 0, -1) 
     set_knob_label($Atk_Curve, _get_engine_par_disp($ENGINE_PAR_ATK_CURVE, 0, 0, -1)) 

     _set_engine_par($ENGINE_PAR_ATK_CURVE, $Atk_Curve, 1, 0, -1) 
end on
```

You only need the one "set_knob_label" because the knob can only reflect one group at a time.

Heh heh, at least I think it's the way it works.


----------



## polypx (Mar 4, 2011)

> alright, i've got a newbie question. this script regulates ahdsr values for the group 1 only. i tried to change the group parametar in set_engine_par to -1 to make it work for the whole instrument, but it doesn't. why?



To set all the groups you can use a while statement like this (declare $count in the init):


```
on ui_control ($Rel)
$count := 0
while ($count <$NUM_GROUPS)
_set_engine_par($ENGINE_PAR_RELEASE, $Rel, $count, 0, -1)
inc($count)
end while
set_knob_label($Rel, _get_engine_par_disp($ENGINE_PAR_RELEASE, 0, 0, -1))
end on
```


----------



## gazdadash (Mar 4, 2011)

thanx, it works!
but please tell me, why the group parameter (in this case 0 and 1) can't be set to -1 to fetch all the groups like in $ENGINE_PAR_VOLUME function?


----------



## polypx (Mar 4, 2011)

Volume at the -1 designation is different from Volume with a 0 designation ... the -1 designation will change the Instrument volume, not the Group volume.

Envelopes ONLY exist at the group level, not at the instrument level, so there is no overall Instrument parameter to change.

EDIT
Similarly, insert effects are at the Instrument level, not the group level, therefore have the -1.


----------



## gazdadash (Mar 5, 2011)

thank you ppl!


----------

