Controlling the metronome volume remotely


#1

Over the past week I have really gotten to dig in with GPScript and I am loving it. One of the things that I wanted to be able to do was to control the metronome volume using a knob, and turn it off and on using a button. GPScript gives the needed access to the metronome and the playhead.

Enabling the metronome starts the playhead at the same time so that the beat starts when I hit the button – useful when the band gets off the click and you need to reset it.

// Declare global variables
var dialMetro : Widget // Assumes there is a widget with a script name of dialMetro
buttonMetro : widget // Assumes there is a widget with a script name of buttonMetro

// Set the metronome volume according to the initial widget value
Initialization
SetMetronomeVolume(GetWidgetValue(dialMetro))
End

// Respond any time the metronome volume widget changes
On WidgetValueChanged(newValue : double) from dialMetro
SetMetronomeVolume(newValue)
End

// Respond any time the metronome enable button is changed
On WidgetValueChanged(newValue : double) from buttonMetro
var boolEnable : boolean

boolEnable = newValue != 0.0
EnableMetronome(boolEnable)
EnablePlayhead(boolEnable)
End

PS - My script lost its whitespace / indentation in the translation to HTML! If anyone knows how to post with indentation please let me know!


#2

Great use of GP Script here. May I offer one suggestion. Instead of

boolEnable = newValue != 0.0

consider writing

boolEnable = newValue > 0.5

If someone wants to use a physical device like a pedal, the values may not go completely to 0 and so you’d end up with the metronome always being enabled.

Never thought I’d see Hungarian Notation being used with GP Script though :slight_smile:
By the way, to deal with the indentation stuff, just select your code and click on the </> icon in the editor menu.

// Declare global variables
var 
   dialMetro : Widget // Assumes there is a widget with a script name of dialMetro   
   buttonMetro : widget // Assumes there is a widget with a script name of buttonMetro

// Set the metronome volume according to the initial widget value
Initialization
   SetMetronomeVolume(GetWidgetValue(dialMetro))
End

// Respond any time the metronome volume widget changes
On WidgetValueChanged(newValue : double) from dialMetro
   SetMetronomeVolume(newValue)
End

// Respond any time the metronome enable button is changed
On WidgetValueChanged(newValue : double) from buttonMetro
   var boolEnable : boolean

   boolEnable = newValue > 0.5
   EnableMetronome(boolEnable)
   EnablePlayhead(boolEnable)
End