Anybody know how to bind to multiple button presses in the Javascript API?
I thought about using a Custom Variable to store the state of the first button press…
Some example code would be amazing…
Anybody know how to bind to multiple button presses in the Javascript API?
I thought about using a Custom Variable to store the state of the first button press…
Some example code would be amazing…
Hi,
Yes, using the Custom Variable is the way to go.
function makePageA() {
var page = makePageWithDefaults('A')
var selectedTrackChannel = page.mHostAccess.mTrackSelection.mMixerChannel
var dummyVolume = surface.makeCustomValueVariable('dummyVolume')
page.makeValueBinding(dummyVolume, selectedTrackChannel.mValue.mVolume)
var dummyPan = surface.makeCustomValueVariable('dummyPan')
page.makeValueBinding(dummyPan, selectedTrackChannel.mValue.mPan)
// Same direction of both controls
surfaceElements.knobA.mSurfaceValue.mOnProcessValueChange = function (activeDevice, value) {
dummyVolume.setProcessValue(activeDevice, value)
dummyPan.setProcessValue(activeDevice, value)
}
// Oposite direction of the controls
surfaceElements.knobB.mSurfaceValue.mOnProcessValueChange = function (activeDevice, value) {
dummyVolume.setProcessValue(activeDevice, value)
var reverseValue = 1 - value
dummyPan.setProcessValue(activeDevice, reverseValue)
}
return page
}
That’s great info @Martin.Jirsak -
What I’m actually trying to do here is buttons- specifically I want to catch the STOP and REW transport buttons simultaneously to do a RTZ “return to project start” command. So like press STOP, then REW and it returns to zero. It seems to get tricky, because I’d need to override the standard REW button for rewind when STOP is active. Any ideas there? Thank you
Just figured out the issue… my “stop” var binding needed to use .setValueTakeOverModePickup() and it works!
var hostTransportRewind = page.mHostAccess.mTransport.mValue.mRewind
var hostTransportStop = page.mHostAccess.mTransport.mValue.mStop
page.makeValueBinding(var_stopPressed, hostTransportStop).setValueTakeOverModePickup()
page.makeValueBinding(var_rewPressed, hostTransportRewind)
btnStop.mSurfaceValue.mOnProcessValueChange =
function(context, newValue, diff) {
var_stopPressed.setProcessValue(context, newValue)
}
btnRewind.mSurfaceValue.mOnProcessValueChange =
function(context, newValue, diff) {
var stopPressed = var_stopPressed.getProcessValue(context)
if (stopPressed) {
var_RTZPressed.setProcessValue(context, 1.0)
} else {
var_rewPressed.setProcessValue(context, newValue)
}
}
page.makeCommandBinding(var_RTZPressed, "Transport", "Return to Zero")
I have a separate question now, not related to this code, but normal Stop behavior…
When I press STOP button, it jumps back to the last playback position… However if I press Stop in Cubase, it stops normally right where the playhead is.
How do I send the normal Cubase “stop” command, and not the one that jumps backward? “page.mHostAccess.mTransport.mValue.mStop” seems to jump back.
You can use
page.makeCommandBinding(var_stopPressed,'Transport', 'Stop')
I suspect that the mStop internally by the API is handed twice, not sure if there’s a reason or it’s a miss.
This is not the real reason for not working, though it may workaround things.
Your issue is here:
You shouldn’t read the var_stopPressed but rather the original btnStop.mSurfaceValue which will really hold the state of the stop button. The var_stopPressed will be always set to either 1 when playback is stopped, or 0 when we’re in playback. This means, that it doesn’t really represent the action of hitting the stop button.
var stopPressed = btnStop.mSurfaceValue.getProcessValue(context)
@m.c to the rescue again…
The “transport”, “stop” commandbinding worked! No more jumping back. It would seem at that point, I don’t even need the stop variable, because this simpler code works:
btnRewind.mSurfaceValue.mOnProcessValueChange =
function(context, newValue, diff) {
var stopPressed = btnStop.mSurfaceValue.getProcessValue(context)
if (stopPressed) {
var_RTZPressed.setProcessValue(context, 1.0)
} else {
var_rewPressed.setProcessValue(context, newValue)
}
}
page.makeValueBinding(var_rewPressed, hostTransportRewind)
page.makeCommandBinding(btnStop.mSurfaceValue, "Transport", "Stop")
page.makeCommandBinding(var_RTZPressed, "Transport", "Return to Zero")
Thanks! Final note… I had been attempting to finagle something around this from the API, but never got it to change the stop. (Though I did get cubase to show me a yellow box telling me it saw the command). Perhaps mStop is being sent twice, that’s diabolical of you to realize that, sir
page.makeCommandBinding(var_TransportStopMode, "Transport", "Activate Return to Start Position" )
function initCustomHostVars(context) {
// 0 or 1 values neither worked
var_TransportStopMode.setProcessValue(context, 0)
}
Gotta have that RTZ baby