# Does anyone know how a host application sets Kontakt tempo?



## brunodegazio (Jan 2, 2014)

Hi 

I'm writing a MIDI application that needs to set Kontakt 5's tempo for synchronization. I can't find anywhere in the KSP reference any mention of how to do this. 

I first assumed that K5 derived the current tempo from the rate of MIDI clock messages but that doesn't seem to be the case. 

Does anyone know which MIDI message a host application should use to set Kontakt's tempo?

thanks
Bruno


----------



## d.healey (Jan 3, 2014)

You need to use the on_listener callback - see manual. Inside it you need something like this


```
$host_temp := 60000000 / DURATION_QUARTER {BPM}
```

You'll need to declare $host_tempo in the on_init callback.

Once you have the host tempo you can use it to set things like Time Machine/Beat Machine or use it for other calculations within your script.


----------



## mk282 (Jan 3, 2014)

He's asking about what host needs to send as a BPM value to be received to Kontakt. Not how to deduce what BPM Kontakt is set to within KSP.


By the way, there is a bug with $DURATION_QUARTER in some versions of Kontakt, so the above formula is not good for certain BPMs (rounding errors occur due to integer division and incorrect value of $DURATION_QUARTER). Everybody should use this formula instead:


```
BPM := (60000000 + DURATION_QUARTER / 2) / DURATION_QUARTER
```

This was a problem in K5.2.1 vs K5.1.0, IIRC. You couldn't get BPM 110 with the original BPM formula because DURATION_QUARTER was wrongly reported (it was off by one microsecond - which is a huge deal when doing integer division, as rounding becomes more apparent and some BPMs are simply skipped).


----------



## d.healey (Jan 3, 2014)

mk282 @ Fri Jan 03 said:


> By the way, there is a bug with $DURATION_QUARTER in some versions of Kontakt, so the above formula is not good for certain BPMs (rounding errors occur due to integer division and incorrect value of $DURATION_QUARTER). Everybody should use this formula instead:
> 
> 
> ```
> ...



Oh I didn't know that, thanks! Where do you find out things like this?


----------



## mk282 (Jan 3, 2014)

Actually kb123 noticed it when scripting something for Sonokinetic, and it was raised as an issue in NI's bug tracker. And also I had a problem around BPM 154 or something, I don't remember. All works fine with this new formula (thanks Nils for sharing that with me!)


----------

