# Gaussian Random Script Function For Micro tuning



## jfino (Mar 8, 2017)

Hi Everyone, 

I came across the Gaussian Random Script Function on a post here developed by the Great Nils and the Epic Big Bob.

I very new to ksp and I dont know how to use it.

How would i use it for micro tuning? so every note played is slightly different in pitch.
From what I gather and I could be wrong , with the above script it would be random but
still more likely to tune around the main pitch. 

And example would be amazing!

Thank you so much!!

Jimmy


----------



## polypx (Mar 8, 2017)

In the "on note" section, you would need to add a change_tune command after the randg function, and scale the -100,100 properly for the amount of tuning deviation you want. Maybe put that on a knob to adjust the random tuning depth? It's a good challenge for a first KSP project!


----------



## jfino (Mar 8, 2017)

Done ! Thanks for pointing me in the right direction polypx! 

Anyone interested here is the code:
dont forget it has to be compiled in sublime or nils ksp editor


```
function randg(a, b, result)
    result := (random(0, b-a) + random(0, b-a) + random(0, b-a) + random(0, b-a) + ...
            random(0, b-a) + random(0, b-a) + random(0, b-a) + random(0, b-a) + ...
                   random(0, b-a) + random(0, b-a) + random(0, b-a) + random(0, b-a)) / 12 + a
end function



on init
    declare $microtuning_result
end on

on note 
    randg(-100000,100000, $microtuning_result){randomly detune each note by ± 100 cent }{exaggerated for demonstration purposes}
    change_tune ($EVENT_ID,$microtuning_result,1)
    message('random tuning number = ' & $microtuning_result)
end on
```


----------



## polypx (Mar 8, 2017)

Cool. And you could add variable depth. ie.

```
declare ui_knob $Depth (0, 200000, 1)

randg(-$Depth, $Depth, $microtuning_result)
```


----------



## Ultra (Mar 8, 2017)

@jfino: thanks for sharing this !

couple of follow up questions, first time Kontakt script user here as well:

(1) why did you not use Bob's improved script ? did you find anything problematic with it ?

(2) absolute noob: how would I invoke the script via CC on a Kontakt instrument or a variety of instruments hosted in multiple Kontakt instances in VEPro ?

create a UI knob in Kontakt (as per polypx suggestion), then control that via CC, and then use that to trigger the tuning ? or can it be done directly via CC ?

Thanks !


----------



## Lindon (Mar 9, 2017)

Ultra said:


> @jfino:
> .... create a UI knob in Kontakt (as per polypx suggestion), then control that via CC, and then use that to trigger the tuning ? or can it be done directly via CC ?
> 
> Thanks !


look in the manual for the on controller call back


----------



## polypx (Mar 9, 2017)

Bob's version is not actually "improved", it's just different. It has a higher Q by default (48 samples averaged rather than 12), although you could set them the same if you like. The main difference in Bob's is that the local jumps from one value to the next tend to be smaller, so it has a different real time feel than Nils more general Gaussian implementation. Over time the results are statistically the same, but in the short term they behave differently.


----------

