Cubase 12 Midi Remote API Simple JS Example

Hi,

Trying to mess with a simple button example with the midi remote API using JS. However, I’m having no success actually getting the command to execute. Is the example below correct? Just trying to send midi message ex: “16, 64” to open file > save as. I can see in cubase that midi messages are coming in but nothing happens.

//-----------------------------------------------------------------------------
// 1. DRIVER SETUP - create driver object, midi ports and detection information
//-----------------------------------------------------------------------------

// get the api's entry point
var midiremote_api = require("midiremote_api_v1")

// create the device driver main object
var deviceDriver = midiremote_api.makeDeviceDriver(
  "test Studios",
  "OSC_Template",
  "test Studios OSC Template"
)

// create objects representing the hardware's MIDI ports
var midiInput = deviceDriver.mPorts.makeMidiInput()
var midiOutput = deviceDriver.mPorts.makeMidiOutput()

// define all possible namings the devices MIDI ports could have
deviceDriver
  .makeDetectionUnit()
  .detectPortPair(midiInput, midiOutput)
  .expectInputNameEquals("OSC_OUT")
  .expectOutputNameEquals("OSC_IN")

//-----------------------------------------------------------------------------
// 2. SURFACE LAYOUT - create control elements and midi bindings
//-----------------------------------------------------------------------------

var button = deviceDriver.mSurface.makeButton(2, 8, 2, 1)
button.mSurfaceValue.mMidiBinding.setInputPort(midiInput).bindToControlChange(16, 64)

//-----------------------------------------------------------------------------
// 3. HOST MAPPING - create mapping pages and host bindings
//-----------------------------------------------------------------------------

var page = deviceDriver.mMapping.makePage("DMD Page 1")

page.makeCommandBinding(button.mSurfaceValue, "File", "Save As")

Cheers,
DMDComposer

1 Like

please change

bindToControlChange(16, 64)

to

bindToControlChange(15, 64)

the channel numbers go from 0 to 15

2 Likes

Haha! I didn’t even think about it would be 0 based, but it is JS. Thank you Jochen!

OMG! I was wondering and trying desperately for 2 h trying to make my script work until I found this thread - then it took me 2 sec more! May be I could get this idea before - programming and GUI Midi-channel-numbers are usually counted differently :frowning:

1 Like