# Adding tune knob to GUI for controlling a few specific groups simultaneously?



## truelight (Mar 17, 2012)

Hi, I was wondering how I would accomplish adding a tune knob to my gui, but only have it affect specific groups within my instrument. Here's what I have so far...


```
on init
    set_ui_height_px(125)
	make_perfview

	declare $count

    declare ui_knob $Tune (0,10000000,10000)

    move_control ($Tune,1,3)

	$Tune := get_engine_par($ENGINE_PAR_TUNE, 0, find_mod(0,"ENV_AHDSR"), -1)

    make_persistent($Tune)

    read_persistent_var($Tune)

    set_knob_label($Tune, get_engine_par_disp($ENGINE_PAR_TUNE, 0, find_mod(0,"ENV_AHDSR"), -1))

	message("")
end on


on ui_control ($Tune)
	$count := 0
	while ($count < $NUM_GROUPS)
		set_engine_par($ENGINE_PAR_TUNE, $TUNE, $count, find_mod(0,"ENV_AHDSR"), -1)
		inc($count)
	end while

	set_knob_label($Tune, get_engine_par_disp($ENGINE_PAR_TUNE, 0, 0, -1))

end on
```


So I can see that I'm missing two important things ... the knob resolution itself jumps from -36 semitones up to +36 almost instantly (I need steps of 1 semitone with shift dragging adding fine control). The other thing is that I need it to only apply to six specific groups, how can I accomplish this?

Thank you so much for the help!


----------



## mk282 (Mar 18, 2012)

Ummm... why are you using find_mod() here? It is completely unrelated to $ENGINE_PAR_TUNE. You use find_mod() when you want to adjust LFO or envelope parameters...

Then, your knob range is completely wrong. It needs to be declare ui_knob $Tune (0,1000000,1) for this.

For changing to setting six specific groups, you need to change the boundaries of the while loop (change the starting number of the $count variable, and change the while ($count < $NUM_GROUPS) $NUM_GROUPS to a number that would end up 6 groups higher - but this is ONLY if your 6 groups are ordered consecutively in the Group Editor!).

As for the fine tune on Shift vs semitones regular, you have to do some math here. Let's say that you want to adjust the tuning of first six groups:


```
on ui_control ($Tune)
	$count := 0
	while ($count < 6)
		if (get_control_par(get_ui_id($Tune),$CONTROL_PAR_KEY_SHIFT) = 1)
			set_engine_par($ENGINE_PAR_TUNE,$Tune,$count,-1,-1)
		else
			set_engine_par($ENGINE_PAR_TUNE,13888 * ($Tune / 13888),$count,-1,-1)
		end if
		inc($count)
	end while

	set_knob_label($Tune,get_engine_par_disp($ENGINE_PAR_TUNE,0,-1, -1))
end on
```


----------



## truelight (Mar 18, 2012)

Thank you very much, that did the trick. I don't really know what I'm doing here, I had a script to make AHDSR controls on the GUI, and I just took that script and replaced bits with $ENGINE_PAR_TUNE to make a tuning knob, that's why that find mod bit was still there. :D 


Thank again!

edit: one more quick question ... how do I get it to reset to a default value of 0? Right now command clicking puts it at -36 semitones. I tried

set_knob_defval ($Tune,0)

but that doesn't seem to do the trick. Also, how can I get the fine control to be increments of 1 cent, like the main tuning knob of an instrument? Right now it's in increments of 3 cents. Here's the current code ...



```
on init 
    set_ui_height_px(125) 
   make_perfview 

   declare $count 

    declare ui_knob $Tune (0,1000000,1) 

    set_knob_defval ($Tune,0)

    move_control ($Tune,6,3) 

   $Tune := get_engine_par($ENGINE_PAR_TUNE, 0, find_mod(0,"ENV_AHDSR"), -1) 

    make_persistent($Tune) 

    read_persistent_var($Tune) 

    set_knob_label($Tune, get_engine_par_disp($ENGINE_PAR_TUNE, 0, find_mod(0,"ENV_AHDSR"), -1)) 

   message("") 
end on 


on ui_control ($Tune) 
   $count := 0 
   while ($count < 6) 
      if (get_control_par(get_ui_id($Tune),$CONTROL_PAR_KEY_SHIFT) = 1) 
         set_engine_par($ENGINE_PAR_TUNE,$Tune,$count,-1,-1) 
      else 
         set_engine_par($ENGINE_PAR_TUNE,13888 * ($Tune / 13888),$count,-1,-1) 
      end if 
      inc($count) 
   end while 

   set_knob_label($Tune,get_engine_par_disp($ENGINE_PAR_TUNE,0,-1, -1)) 
end on
```


----------



## mk282 (Mar 18, 2012)

The knob range is from 0 to 1000000, and Tune parameter is bipolar, so if you want it to reset to zero, then you need to set_knob_defval($Tune,500000).


Seems like you can't get finer resolution via scripted knob... Shift should've done it, but it doesn't seem to work well.


----------

