(me, showing off) Script to start the playback in Cubase from bar xyz

The video has sound and high dynamics. Be advised!

// if the widget with the ID 'misc_for_keypad' is value 1, then the value entered into the keypad will trigger the following lines.
if (get('misc_for_keypad') === 1) {

// delay origin
setTimeout(function(){ // execute these two lines at a 50ms delay (delay calculated from the delay origin/start)
send('midi:SessionKiano','/note', 7, 38,1) // move the cursor in Cubase to the start of the project (origin).
send('midi:SessionKiano','/note', 7, 41,1) // move the cursor 5 bars forward

setTimeout(function(){ // 180ms delay (delay calculated from the delay origin/start)
var obar = parseInt(`${get('digit_1')}` + `${get('digit_2')}` + `${get('digit_3')}`) // concatenate MCU (Mackie remote) bar number digits and convert the string to integer; obar = old bar

setTimeout(function(){ // 200ms delay (delay calculated from the delay origin/start)
var nbar = get('this') // entered bar number in the keypad (bar number where the cursor should go to); nbar stands for "new bar"
var diff = Math.abs(nbar-obar) // calculates by what amount one number is greater than the other and stores the value into a variable called "diff"

setTimeout(function(){ // 220ms delay
if (diff<5 && nbar<obar){ // if [the difference between nbar and obar is less than 5] and [nbar is smaller than obar] then execute the following "for" loop:
	for (var i = 0; i < diff; i++) { // if the above condition is met, the following lines will be executed a number equal to diff of times.
send('midi:SessionKiano','/note', 1, 73, 1) // cursor +1 (moves/locates the cursor in Cubase to the previous bar)

else if (diff<5 && nbar>obar){ // similar to the above condition, but this time the second part of it contains a "greater than" symbol.
	for (var i = 0; i < diff; i++) { // same "for" loop like the above one
send('midi:SessionKiano','/note', 1, 72, 1) // same action as the above one, but in the opposite direction (i.e. move the cursor one bar forward)

else if (diff>4 && nbar>obar){ // if [the difference between the two bar numbers is greater than 4] and [nbar is greater than obar], then execute the following:
	for (var i = 0; i < diff; i++) { // same loop
		send('midi:SessionKiano','/note', 1, 72, 1) // cursor +1

setTimeout(function(){ // 230ms delay

// sets the used buttons to a 0 value state
set('push_43',0, {send: false}) 
set('Backward one bar', 0, {send: false})
set('forward_one_bar', 0, {send: false})

// starts the playback

}, 230)	
}, 220)	
}, 200)
}, 180)
}, 50)

For this to work, a bar offset between 1 (lowest value) and 5 (highest value) must be set in:
Project/Project Setup...

Problems (that the user can live with):

  1. If the bar offset is bigger than 5, the cursor will start playing from an earlier bar than the one entered.
  2. If, on the other hand, it's smaller than 1, bars in the beginning will become inaccessible, meaning:
    at bar offset 0, entering "1" will be the same as entering "6". In other words, both 1 and 6 will trigger the playback from the sixth bar.
    at bar offset -1, entering "1" or "2" will be the same as entering "7".
    at bar offset -2, entering "1" or "2" or "3" will be the same as entering "8".
1 Like

Great! I shall be unashamedly stealing this!

1 Like

It was a lot of work... Though, I couldn't have done it without @jean-emmanuel's help (in delaying the used loops)...

1 Like