# How do you properly display a group effect parameter value?



## argitoth (Jun 9, 2013)

Here's my code so far. As you can see my knob displays a number from 0 - 1000000db. I want it to display -18.0db to +18.0db exactly like the equalizer's gain knob displays values. How do you properly display the value in a GUI knob?


```
KSscript:
on init
  set_script_title("Equalization")
  make_perfview
  set_ui_height(8)
  
  make_knob(1,3, 0,1000000,0,1, Gain,1)
  set_knob_unit(knob1,$KNOB_UNIT_DB)
end on

on ui_control(knob1)
  set_engine_par($ENGINE_PAR_GAIN1,knob1,0,0,-1)
end on

macro make_knob(#x#,#y#, #min#,#max#,#default#,#scale#, #text#,#id#)
  declare ui_knob knob#id#(#min#,#max#,#scale#)
  set_text(knob#id#,"#text#")
  make_persistent(knob#id#)
  move_control(knob#id#, #x#,#y#)
  set_knob_defval (knob#id#,#default#)
end macro
```


----------



## Raptor4 (Jun 9, 2013)

Here is a simple example where the EQ is inserted in the 1st Insert slot.

```
on init
make_perfview
declare ui_knob $knob1(0,1000000,1)
make_persistent($knob1)
read_persistent_var($knob1)
set_knob_label($knob1,get_engine_par_disp($ENGINE_PAR_GAIN1,-1,0,0) & "dB")
end on

on ui_control($knob1)
set_engine_par($ENGINE_PAR_GAIN1,$knob1,-1,0,0)
set_knob_label($knob1,get_engine_par_disp($ENGINE_PAR_GAIN1,-1,0,0) & "dB")
end on
```
Regards
_________________________
www.audiogrocery.com


----------



## argitoth (Jun 9, 2013)

Thank you,

I improved the script now (KScript):


```
on ui_update {prevents users from changing the parameter directly from the instrument edit group  fx window}
  set_knob(GAIN1, 1, 0,0,-1)
end on

on ui_control(knob1)
  set_knob(GAIN1, 1, 0,0,-1)
end on

macro set_knob(#parameter#, #id#, #group#,#slot#,#generic#)
  set_engine_par($ENGINE_PAR_#parameter#,knob#id#,#group#,#slot#,#generic#
  set_knob_label(knob#id#,get_engine_par_disp($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#))
end macro
```

and instead of the "& dB", just use the unit variables

on init
set_knob_unit(knob#id#,$KNOB_UNIT_#unit#)
end on

#id# = name of knob
#unit# = DB, OCT, PERCENT, etc. (these are specific built-in variables)


----------



## argitoth (Jun 9, 2013)

:roll: omg what the heck

*Raptor4*, I followed the exact formula you made for the gain knob (except I'm using group fx, not insert/instrument) and I can't get the bandwidth knob to function. What's up with that?

Edit: Ok something is wrong with my code... your formula is working.
Edit: OHHHH figured it out. :oops: 

I had on_ui_control(knob1) contain the code for both knob1 and knob2 when I actually needed a separate on_ui_control(knob2) for controlling knob2.

Edit: that being said, is there a way to avoid making a "on_ui_control" for every single thing?


----------



## Raptor4 (Jun 10, 2013)

argitoth @ Sun Jun 09 said:


> I can't get the bandwidth knob to function. What's up with that?


Here it is:

```
set_engine_par($ENGINE_PAR_BW1,$knob1,0,0,-1)
set_knob_label($knob1,get_engine_par_disp($ENGINE_PAR_BW1,0,0,-1) & "oc")
```
It is set for the EQ which is inserted into the 1st group -> 1st slot.
There are up to 3 Bandwidth extensions BW1, BW2, BW3.
_____________________
www.audiogrocery.com


----------



## mk282 (Jun 10, 2013)

argitoth @ 9.6.2013 said:


> Edit: that being said, is there a way to avoid making a "on_ui_control" for every single thing?



No, you have to have it. ui_control callback defines everything that needs to happen when you actually tweak the knob. That's how it works in KSP.


----------



## argitoth (Jun 10, 2013)

Awesome, making good progress here.

Question: Can you set a label to be hidden and in the background so that when you use the non pixel X Y positions to set controls, the label doesn't take up space? My goal is to make a label that has a large area, completely hidden, sits in the background of an area of the GUI, and then set the help text, so that wherever the mouse is WITHIN AN AREA the correct help text is displayed.

Possible?


----------



## Lindon (Jun 11, 2013)

Er I think I understand what you are trying to do. There is no on-over event to use in this hidden label, there's only the std on-click(which KSP calls on ui_control), so your label wont get to show anything until it is clicked. 

But why are you not using the $CONTROL_PAR_HELP to set help text?


set_control_par_str(get_ui_id($yourControl),$CONTROL_PAR_HELP,"your help text here...")

This gets the outcome I think you are after...

LP


----------



## Lindon (Jun 11, 2013)

actually re-reading this may be what you are proposing with the label....you just need to be aware that the display order is based on declaration order AND widget type....and where the widget (say a button) is higher in the z-order than the label then the help text might not display...


----------



## mk282 (Jun 11, 2013)

ui_labels don't have ui_control callbacks.


----------



## Lindon (Jun 11, 2013)

Oops silly me. true, I just use single-image buttons instead. Still all that stuff about z-order still applies I think.


----------



## argitoth (Jun 11, 2013)

great, thanks!

Question: I'm trying to set the default value for an equalizer. I am able to set default values for compressor parameters, volume, panning, but the equalizer always defaults to 0... is this a Kontakt bug or is my code to blame?

EDIT: Ok... it works now... nevermind. :? 


```
make_knob(1,4,  0,1000000,1, 500000, 0,0,-1, GAIN1,DB,Gain,1)
  make_knob(1,6,  0,1000000,1, 500000, 0,0,-1, BW1,OCT,Bandwidth,2)
  make_knob(1,8,  0,1000000,1, 500000, 0,0,-1, FREQ1,HZ,Frequency,3)
  make_knob(1,11, 0,1000000,1, 500000, 0,0,-1, GAIN2,DB,Gain,4)
  make_knob(1,13, 0,1000000,1, 500000, 0,0,-1, BW2,OCT,Bandwidth,5)
  make_knob(1,15, 0,1000000,1, 500000, 0,0,-1, FREQ2,HZ,Frequency,6)
  make_knob(2,6,  0,1000000,1, 500000, 0,0,-1, PAN,NONE,Panning,8)
  make_knob(2,9,  0,1000000,1, 1000000, 0,1,-1, THRESHOLD,DB,Threshold,9)
  make_knob(2,11, 0,1000000,1, 0, 0,1,-1, RATIO,NONE,Ratio,10)
  make_knob(2,13, 0,1000000,1, 0, 0,1,-1, COMP_ATTACK,MS,Attack,11)
  make_knob(2,15, 0,1000000,1, 0, 0,1,-1, COMP_DECAY,MS,Decay,12)

macro make_knob(#x#,#y#, #min#,#max#,#scale#, #default#, #group#,#slot#,#generic#, #parameter#,#unit#, #text#,#id#)
  declare ui_knob knob#id#(#min#,#max#,#scale#)
  move_control(knob#id#, #x#,#y#)
  set_text(knob#id#,"#text#")
  make_persistent(knob#id#)
  read_persistent_var(knob#id#)
  set_knob_unit(knob#id#,$KNOB_UNIT_#unit#)
  set_knob_label(knob#id#,get_engine_par_disp($ENGINE_PAR_#parameter#, #group#,#slot#,#generic#))
  set_knob_defval (knob#id#,#default#)
end macro
```


----------



## argitoth (Jun 11, 2013)

Where do you put the txt file to describe the image? Right now I have the txt file right next the the png file. Is this correct? The image shows up in kontakt, but the height (and possibly width) is all wrong. When pressing the button, the height of the image becomes its full height (showing all states at once). Anyway, basically it doesn't work even though I have 6 images vertically and the text file says 6 animations.

So far this is my code

```
on init
  set_script_title("Effects (global)")
  make_perfview
  set_ui_height(8)

declare ui_button $button1
set_control_par_str(get_ui_id($button1),$CONTROL_PAR_TEXT,"")
set_control_par_str(get_ui_id($button1),$CONTROL_PAR_PICTURE,"button_bypass")
end on
```
image file: button_bypass.png
text file: button_bypass.txt
Has Alpha Channel: yes
Number of Animations: 6
Horizontal Animation: no
Vertical Resizable: no
Horizontal Resizable: no
Fixed Top: 0
Fixed Bottom: 0
Fixed Left: 0
Fixed Right: 0


----------



## argitoth (Jun 11, 2013)

Alright, here's the problem!

you MUST have a breakline at the end of the last character at the last line of the text document

so your cursor should be
text
text
text<hit ENTER here!>
|

| = where your cursor should be.


----------



## argitoth (Jun 12, 2013)

UGH NEW PROBLEM!!! :x 

I am trying to get two-way communication with a bypass button gui element <-> engine parameter so that when you click the bypass button in the instrument edit window, it will update the bypass state in the gui performace view. I got this two-way communication to work with all my knobs, sliders, and labels, but why not buttons?

```
make_button(1, 68,46, button_bypass)

macro make_button(#id#, #x#,#y#, #image#)
  declare ui_button button#id#
  set_text(button#id#,"")
  move_control_px(button#id#, #x#,#y#)
  make_persistent(button#id#)
  read_persistent_var(button#id#)
  set_control_par_str(get_ui_id(button#id#),$CONTROL_PAR_PICTURE,"#image#")
end macro

get_button(1, 0,0,-1, EFFECT_BYPASS)

macro get_button(#id#, #group#,#slot#,#generic#, #parameter#)
  button#id# := get_engine_par($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#)
end macro
```

What am I missing? The code doesn't give an error, it simply doesn't work.


----------



## Big Bob (Jun 12, 2013)

Is this all the code you are using?

Seems like you need both a ui_control callback handler plus a on ui_update handler to do what you want (ie if I understood what you are trying to do :lol: )

Rejoice,

Bob


----------



## argitoth (Jun 12, 2013)

oh right right, ok here's more of my code.


```
on init
  make_button(1, 68,46, button_bypass)
end on

on ui_update
    get_button(1, 0,0,-1, EFFECT_BYPASS)
end on

set_button(1, 0,0,-1, EFFECT_BYPASS) {includes on ui_control() in the macro}

{MACRO BUTTON: make, get, set}
macro make_button(#id#, #x#,#y#, #image#)
  declare ui_button button#id#
  set_text(button#id#,"")
  set_control_par_str(get_ui_id(button#id#),$CONTROL_PAR_PICTURE,"#image#")
  move_control_px(button#id#, #x#,#y#)
  make_persistent(button#id#)
  read_persistent_var(button#id#)
end macro
macro get_button(#id#, #group#,#slot#,#generic#, #parameter#)
  button#id# := get_engine_par($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#)
end macro
macro set_button(#id#, #group#,#slot#,#generic#, #parameter#)
  on ui_control(button#id#)
    set_engine_par($ENGINE_PAR_#parameter#,button#id#,#group#,#slot#,#generic#)
    message(button#id#)
  end on
end macro
```


----------



## Big Bob (Jun 12, 2013)

Well, now that you've added the callback handlers, it looks like it should work OK.

Are you saying that it still doesn't work? :?

Or was this just your way of saying, OK I now got it working and this is my code? :lol:

EDIT: Maybe I should mention that you may have to use a set_ui_height_px command in order to position your button within the visible panel area (ie otherwise it may be below the default panel height) but I presume you have done that and just didn't want to post the entire script.


----------



## argitoth (Jun 12, 2013)

lol, oh yeah, forgot about that code. Yeah, I'm just trying to post the important code for easy debugging. Thanks for your help! But, yes, SADLY IT DOES NOT WORK!

Actually, here's what I think is going on. I think it *is* working, but it's simply not updating the GUI / button animation.

Finally, here's the full code just to be SURE.

```
on init
  set_script_title("Mixing")
  make_perfview
  set_ui_height(8)

  declare @resonance_help 
  resonance_help := "Frequency of this EQ is carefully set to control the resonance of the instrument."

  {SLIDERS: id, group,slot,generic, x,y, mix,max, default}
  make_slider(1, 0,0,-1, 1,2, 0,1000000, 500000, TUNE,"Tune: ")
  make_slider(2, 1,0,-1, 3,2, 0,1000000, 500000, TUNE,"Tune: ")
  make_slider(3, 2,0,-1, 5,2, 0,1000000, 500000, TUNE,"Tune: ")
  
  {BUTTONS: id, x,y, image}
  make_button(1, 68,46, button_bypass)
  make_button(2, 68,193, button_bypass)
  make_button(3, 160,151, button_bypass) 
  
  {KNOBS: id, group,slot,generic, x,y, min,max,scale, default, unit,parameter,text}
  make_knob(1,  0,0,-1, 1,4,  0,1000000,1, 500000,  DB,GAIN1,"Gain")
  make_knob(2,  0,0,-1, 1,6,  0,1000000,1, 0,       OCT,BW1,"Bandwidth")
  make_knob(3,  0,0,-1, 1,8,  0,1000000,1, 500000,  HZ,FREQ1,"Frequency")
  make_knob(4,  0,1,-1, 1,11, 0,1000000,1, 500000,  DB,GAIN1,"Gain")
  make_knob(5,  0,1,-1, 1,13, 0,1000000,1, 61000,   OCT,BW1,"Bandwidth")
  make_knob(6,  0,1,-1, 1,15, 0,1000000,1, 500000,  HZ,FREQ1,"Frequency")
  make_knob(7,  0,0,-1, 2,4,  0,1000000,1, 630000,  DB,VOLUME,"Volume")
  make_knob(8,  0,0,-1, 2,6,  0,1000000,1, 500000,  NONE,PAN,"Panning")
  make_knob(9,  0,2,-1, 2,9,  0,1000000,1, 1000000, DB,THRESHOLD,"Threshold")
  make_knob(10, 0,2,-1, 2,11, 0,1000000,1, 0,       NONE,RATIO,"Ratio")
  make_knob(11, 0,2,-1, 2,13, 0,1000000,1, 0,       MS,COMP_ATTACK,"Attack")
  make_knob(12, 0,2,-1, 2,15, 0,1000000,1, 0,       MS,COMP_DECAY,"Decay")
  
  {Help Text}
  set_control_help(knob1,resonance_help)
  set_control_help(knob2,resonance_help)
  set_control_help(knob3,resonance_help)
end on

{UI UPDATES get/set: id, group,slot,generic, parameter, text}
on ui_update
  get_slider(1, 0,0,-1, TUNE, "Tune: ")
  get_slider(2, 1,0,-1, TUNE, "Tune: ")
  get_slider(3, 2,0,-1, TUNE, "Tune: ")
  get_button(1, 0,0,-1, EFFECT_BYPASS)
  get_button(2, 0,1,-1, EFFECT_BYPASS)
  get_button(3, 0,2,-1, EFFECT_BYPASS)
  get_knob(1,   0,0,-1, GAIN1)
  get_knob(2,   0,0,-1, BW1)
  get_knob(3,   0,0,-1, FREQ1)
  get_knob(4,   0,1,-1, GAIN1)
  get_knob(5,   0,1,-1, BW1)
  get_knob(6,   0,1,-1, FREQ1)
  get_knob(7,   0,0,-1, VOLUME)
  get_knob(8,   0,0,-1, PAN)
  get_knob(9,   0,2,-1, THRESHOLD)
  get_knob(10,  0,2,-1, RATIO)
  get_knob(11,  0,2,-1, COMP_ATTACK)
  get_knob(12,  0,2,-1, COMP_DECAY)
end on
{on ui_control}
  set_slider(1, 0,0,-1, TUNE,"Tune: ")
  set_slider(2, 1,0,-1, TUNE,"Tune: ")
  set_slider(3, 2,0,-1, TUNE,"Tune: ")
  set_button(1, 0,0,-1, EFFECT_BYPASS)
  set_button(2, 0,1,-1, EFFECT_BYPASS)
  set_button(3, 0,2,-1, EFFECT_BYPASS)
  set_knob(1,  0,0,-1, GAIN1)
  set_knob(2,  0,0,-1, BW1)
  set_knob(3,  0,0,-1, FREQ1)
  set_knob(4,  0,0,-1, GAIN2)
  set_knob(5,  0,0,-1, BW2)
  set_knob(6,  0,0,-1, FREQ2)
  set_knob(7,  0,0,-1, VOLUME)
  set_knob(8,  0,0,-1, PAN)
  set_knob(9,  0,2,-1, THRESHOLD)
  set_knob(10, 0,2,-1, RATIO)
  set_knob(11, 0,2,-1, COMP_ATTACK)
  set_knob(12, 0,2,-1, COMP_DECAY)
{end on}

{MACRO SLIDER: make, get, set}
macro make_slider(#id#, #group#,#slot#,#generic#, #x#,#y#, #min#,#max#, #default#, #parameter#,#text#)
  declare ui_label label#id#(1,1)
  move_control(label#id#, #x#+1,#y#)
  hide_part(label#id#,$HIDE_PART_BG)
  set_text(label#id#,#text# & get_engine_par_disp($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#))
  declare ui_slider slider#id#(#min#,#max#)
  move_control(slider#id#, #x#,#y#)
  set_knob_defval(slider#id#,#default#)
  make_persistent(slider#id#)
  read_persistent_var(slider#id#)
end macro
macro get_slider(#id#, #group#,#slot#,#generic#, #parameter#, #text#)
  slider#id# := get_engine_par($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#)
  set_text(label#id#,#text# & get_engine_par_disp($ENGINE_PAR_TUNE,#group#,#slot#,#generic#))
end macro
macro set_slider(#id#, #group#,#slot#,#generic#, #parameter#,#text#)
  on ui_control(slider#id#)
    set_engine_par($ENGINE_PAR_#parameter#,slider#id#,#group#,#slot#,#generic#)
    set_text(label#id#,#text# & _get_engine_par_disp($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#))  
  end on
end macro

{MACRO BUTTON: make, get, set}
macro make_button(#id#, #x#,#y#, #image#)
  declare ui_button button#id#
  set_text(button#id#,"")
  set_control_par_str(get_ui_id(button#id#),$CONTROL_PAR_PICTURE,"#image#")
  move_control_px(button#id#, #x#,#y#)
  make_persistent(button#id#)
  read_persistent_var(button#id#)
end macro
macro get_button(#id#, #group#,#slot#,#generic#, #parameter#)
  button#id# := get_engine_par($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#)
end macro
macro set_button(#id#, #group#,#slot#,#generic#, #parameter#)
  on ui_control(button#id#)
    set_engine_par($ENGINE_PAR_#parameter#,button#id#,#group#,#slot#,#generic#)
    message(button#id#)
  end on
end macro

{MACRO KNOB: make, get, set}
macro make_knob(#id#, #group#,#slot#,#generic#, #x#,#y#, #min#,#max#,#scale#, #default#, #unit#,#parameter#,#text#)
  declare ui_knob knob#id#(#min#,#max#,#scale#)
  set_text(knob#id#,#text#)
  set_knob_defval (knob#id#,#default#)
  move_control(knob#id#, #x#,#y#)
  make_persistent(knob#id#)
  read_persistent_var(knob#id#)
  set_knob_unit(knob#id#,$KNOB_UNIT_#unit#)
  set_knob_label(knob#id#,get_engine_par_disp($ENGINE_PAR_#parameter#, #group#,#slot#,#generic#))
end macro
macro get_knob(#id#, #group#,#slot#,#generic#, #parameter#)
  knob#id# := get_engine_par($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#)
  set_knob_label(knob#id#,get_engine_par_disp($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#))
end macro
macro set_knob(#id#, #group#,#slot#,#generic#, #parameter#)
  on ui_control(knob#id#)
    set_knob_label(knob#id#,get_engine_par_disp($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#))
    set_engine_par($ENGINE_PAR_#parameter#,knob#id#,#group#,#slot#,#generic#)
    message(knob#id#)
  end on
end macro
```


----------



## Big Bob (Jun 13, 2013)

Now you've gone the other extreme :lol: I really don't want to study all your code since you originally said that just the button bypass thingy wasn't working bi-directionally.

Why don't you simply post the code relevant to the button bypass issue (but don't leave anything out that is needed to demo the problem). And then state very clearly just what doesn't work correctly. So, far your posts have been rather like moving targets. :lol: 

Rejoice,

Bob


----------



## argitoth (Jun 13, 2013)

-I can use the ui button to bypass the effect in group1 slot1
-I can use engine parameter button in the instrument edit window to bypass the effect
-Problem: the ui button does not update due to changing the engine parameter bypass button


```
on init 
  set_script_title("Mixing") 
  make_perfview 
  set_ui_height(8) 
  
  {BUTTONS: id, x,y, image} 
  make_button(1, 68,46, button_bypass) 
end on 

{UI UPDATES get/set: id, group,slot,generic, parameter, text} 
on ui_update 
  get_button(1, 0,0,-1, EFFECT_BYPASS) 
end on 
{on ui_control} 
  set_button(1, 0,0,-1, EFFECT_BYPASS) 
{end on} 

{MACRO BUTTON: make, get, set} 
macro make_button(#id#, #x#,#y#, #image#) 
  declare ui_button button#id# 
  set_text(button#id#,"") 
  set_control_par_str(get_ui_id(button#id#),$CONTROL_PAR_PICTURE,"#image#") 
  move_control_px(button#id#, #x#,#y#) 
  make_persistent(button#id#) 
  read_persistent_var(button#id#) 
end macro 
macro get_button(#id#, #group#,#slot#,#generic#, #parameter#) 
  button#id# := get_engine_par($ENGINE_PAR_#parameter#,#group#,#slot#,#generic#) 
end macro 
macro set_button(#id#, #group#,#slot#,#generic#, #parameter#) 
  on ui_control(button#id#) 
    set_engine_par($ENGINE_PAR_#parameter#,button#id#,#group#,#slot#,#generic#) 
    message(button#id#) 
  end on 
end macro
```


----------



## Raptor4 (Jun 13, 2013)

argitoth @ Thu Jun 13 said:


> -Problem: the ui button does not update due to changing the engine parameter bypass button


I just revised you example above and it works as expected!
*Note*: Some plugins require to tweak the main plugin "Byp." button to have an UI update (not the small red "B" one" - for example the EQ). Some others (for example the Compressor) can update from both buttons "Byp." plugin one and the small "B" shown on the Group. 

Regards
____________________
www.audiogrocery.com


----------



## argitoth (Jun 13, 2013)

Yep, my code is fine. Kontakt is the culprit. "Byp." works "B" doesn't, so I'm just going to completely remove that two-way communication with the bypass buttons.

*Raptor4*, thanks for the astute observation.


----------

