# Add semitone to tune control knob



## chopdub (Dec 9, 2017)

Hi Guys

I've seen many solutions to get a semitone tune knob but in my case I have a slider with custom image to make it a knob which is already linked to my tune knob but I can't manage to find a way of making the knob tune by semitones I'm using a macro to generate 9 knobs for my gui as I have 9 groups. 

Any help would be appreciated.

Thanks


----------



## EvilDragon (Dec 9, 2017)

Needs a bit of math. Kontakt's tune knob has linear scaling of values from -36.00 to +36.00 semitones in internal value range from 0 to 1000000, with 0 semitones being at 500000. So, divide 500000 by 36 and you get 13888.899999. Since engine parameters are only integer, we round this to 13889. Then it's a matter of:


```
set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)
```


----------



## chopdub (Dec 10, 2017)

EvilDragon said:


> Needs a bit of math. Kontakt's tune knob has linear scaling of values from -36.00 to +36.00 semitones in internal value range from 0 to 1000000, with 0 semitones being at 500000. So, divide 500000 by 36 and you get 13888.899999. Since engine parameters are only integer, we round this to 13889. Then it's a matter of:
> 
> 
> ```
> ...



Thanks for the reply ED

I think I actualy found a post where you helped someone with the exact same thing and maths I tried it from your other post I just can't find where I should input the info..


----------



## EvilDragon (Dec 10, 2017)

Please put code in CODE tags, this is getting pretty hard to follow.


----------



## chopdub (Dec 10, 2017)

EvilDragon said:


> Please put code in CODE tags, this is getting pretty hard to follow.



I'm very sorry I'm a newbie how do you do that?

Figured it again really sorry!


----------



## chopdub (Dec 10, 2017)

```
macro mixer_control_actions(#num#)

   ui.control_action($sli_vol_#num#, mdl.change_vol($sli_vol_#num#, #num#)) {Volume fader control action}
 
   ui.control_action($sli_tun_#num#, mdl.change_tune($sli_tun_#num#, #num#)) {Tune fader control action}
 
   ui.control_action($sli_bal_#num#, mdl.change_pan($sli_bal_#num#, #num#)) {Balance fader control action}
   set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)
 
   ui.control_action($swi_mute_#num#, mdl.toggle_switches(get_ui_id($swi_mute_#num#), get_ui_id($swi_solo_#num#))) {Mute button control action}
   ui.control_action($swi_solo_#num#, mdl.toggle_switches(get_ui_id($swi_solo_#num#), get_ui_id($swi_mute_#num#))) {Solo button control action}

end macro
Syntax error (line 1188)
set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)
```


----------



## chopdub (Dec 10, 2017)

```
taskfunc mdl.change_tune(value, channel_num)

declare i

for i := 0 to Sets.reps-1 {Each repetition group}
set_engine_par($ENGINE_PAR_TUNE, value, Sets.arts[channel_num]+i, -1, -1)
set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)

end for

end taskfunc

$Tune has not been declared. (line 61)
set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)

model.ksp:44
```


----------



## chopdub (Dec 10, 2017)

```
taskfunc mdl.change_tune(value, channel_num)

declare i

for i := 0 to Sets.reps-1 {Each repetition group}
set_engine_par($ENGINE_PAR_TUNE, value, Sets.arts[channel_num]+i, -1, -1)
set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)

end for

end taskfunc

$Tune has not been declared. (line 61)
set_engine_par($ENGINE_PAR_TUNE, 500000 + ($Tune * 13889), 0, -1, -1)

model.ksp:44
```


----------



## EvilDragon (Dec 10, 2017)

Obviously, don't copy my code literally. You didn't define a $Tune control, so of course it won't work?

Also, why are you using change_tune() if you actually wanna change group tuning?


This is getting more and more confusing. :D


----------



## chopdub (Dec 10, 2017)

EvilDragon said:


> Obviously, don't copy my code literally. You didn't define a $Tune control, so of course it won't work?
> 
> Also, why are you using change_tune() if you actually wanna change group tuning?
> 
> ...



I actually thought it was the tune control as in change_tune thats what the knobs are linked to connectiing it. The reason for me using that is I know of no other method of tuning per group. please bare with my newbiness!


```
{{Tune & Balanceknobs}
        ui.slider(tun_#num#, "Blackknob", 12 + $i, 69, 500000, 0, 1000000, 1) {create vertical slider}
        %ui_mix[0 + 9*#num#] := get_ui_id($sli_tun_#num#)
```

Thats the knob controlling it but it wont allow me to use that controller name or I'm not entering it right.


```
taskfunc mdl.change_tune(value, channel_num)

    declare i

    for i := 0 to Sets.reps-1 {Each repetition group}
        set_engine_par($ENGINE_PAR_TUNE, value, Sets.arts[channel_num]+i, -1, -1)
    end for

end taskfunc
```

with this in use each of my sliders/knobs tune each group so its acting as I would expect apart from being in semitones so I have 9 tune knobs that are changing the tune of of each individual group.


----------



## EvilDragon (Dec 10, 2017)

chopdub said:


> The reason for me using that is I know of no other method of tuning per group.



I gave you the code to adjust tuning per group (gotta use $ENGINE_PAR_TUNE instead). You just change 0 (group 1) to the number of group you want, which I see you've now figured it out  But your problem lies in the range of Tune sliders you're generating. They should be -36 to 36, not 0, 1000000 in order to utilize the math I did.

So, like this:


```
function mdl.change_tune(value, channel_num)

   declare i

   for i := 0 to Sets.reps-1 {Each repetition group}
       set_engine_par($ENGINE_PAR_TUNE, 500000 + (value * 13889), Sets.arts[channel_num]+i, -1, -1)
   end for

end function
```

"value" should go from -36 to 36. Or whatever other range you want (-12 to 12).


Also, there's no need to use taskfunc for these at all. You don't have wait() anywhere so no concurrency problems.


----------



## chopdub (Dec 11, 2017)

EvilDragon said:


> I gave you the code to adjust tuning per group (gotta use $ENGINE_PAR_TUNE instead). You just change 0 (group 1) to the number of group you want, which I see you've now figured it out  But your problem lies in the range of Tune sliders you're generating. They should be -36 to 36, not 0, 1000000 in order to utilize the math I did.
> 
> So, like this:
> 
> ...





That did the trick. You are a legend!

Thank you very much ED I don't think I'll be able to teach you anything about scripting apart from what not to do but if you need any extra drum sounds I got your back.


----------

