Tap tempo BPM displayed as widget label text

Hey guys! I am trying to find a way to have a big text label update in real time based on the global tempo of the project. Im not really a programmer, but I thought I would give it a try rather than just asking for help right away:

Obviously my script doesnt work, and I dont know if its the right approach anyways for updating the text label in real time based on the project bpm.

Any help would be great!

Welcome to the forum!

Give this a try:

Var
   TempoLabel : Widget
   intialbeats : double
// Sets intial BPM
Initialization
   intialbeats = GetBPM()
   SetWidgetLabel(TempoLabel,intialbeats)
end

//Changes TempoLabel when BPM changes
On TempoChanged (beats : double)
    SetWidgetLabel(TempoLabel,beats)
end
1 Like

That works great, thanks! Only one small issue (which I dont know if it can be fixed), is when I use tap tempo with midi:
tap
I get large decimal values. Is there a way to limit the text output to round to the nearest 0.1 (tenths place)? Seeing 123.6, 85.4, or 120.0 looks a lot cleaner than large values.

A quick ‘fix’ is to adjust the size of the label and text size so that only a few digits after the decimal point will display.

764

1 Like

I looked through some of the documentation and found the Round() function (rounds a floating point number to nearest integer). Added that into your script, and it outputs a result with no decimals.

Here’s the full script with tap tempo included if anyone also wants it:

Var
   Tapper : Widget
   TempoLabel : Widget
   intialbeats : double
// Sets intial BPM
Initialization
   intialbeats = GetBPM()
   SetWidgetLabel(TempoLabel,intialbeats)
end

//Changes TempoLabel when BPM changes
On TempoChanged (beats : double)
    SetWidgetLabel(TempoLabel,Round(beats))
end



//tap tempo
On WidgetValueChanged(newValue : double) from Tapper

    Tap()
    
End

Thanks for the help!

1 Like

Yes, you can round to an integer if you don’t need any decimal values.
Well done with the research and script!

1 Like

There is a DoubleToString that lets you define the number of places

https://gigperformer.com/docs/GPScript36/content/reference/list-of-functions.html#DoubleToString

:grinning:

3 Likes

Ah, there you go. I knew it was there somewhere but couldn’t remember the function.

Right on! Updated script with DoubleToString() for whoever wants it:

Var
   Tapper : Widget
   TempoLabel : Widget
   intialbeats : double
   rounded : string
// Sets intial BPM
Initialization
   intialbeats = GetBPM()
   SetWidgetLabel(TempoLabel,intialbeats)

end

//Changes TempoLabel when BPM changes
On TempoChanged (beats : double)
    rounded = DoubleToString(beats, 1)
    SetWidgetLabel(TempoLabel, rounded)
    
end

//tap tempo
On WidgetValueChanged(newValue : double) from Tapper

    Tap()
    
End
4 Likes