mOnColorChange on Simple/Next Device - Help with Midi Remote API JavaScript

Dear all,
I am learning the MIDI Remote API but failing to implement mOnColorChange to send the track colors of selected tracks to my MIDI controller.
I succeed in making the Simple and Next Devices work (from the Remote API Reference), but the Real World Device is overwhelming (I even get a “Type Error: invalid module load callback return value (line 136)” in the MIDI Script Console when copy/pasting the code into VS).
The reference says for SelectedTrackChannel:

mOnColorChange : function (activeDevice : ActiveDevice, activeMapping : ActiveMapping, r : number, g : number, b : number, a : number, isActive : boolean)

But how do I actually implement this on Simple or on Next Device?
Could someone please tell me what exactly to write and where?

Here is the Simple code:

// 2. SURFACE LAYOUT - create control elements and midi bindings
var knob1 = deviceDriver.mSurface.makeKnob(0, 0, 1, 1.5)
knob1.mSurfaceValue.mMidiBinding
.setInputPort(midiInput)
.setOutputPort(midiOutput)
.bindToControlChange (0, 21) // channel 0, cc 21

// 3. HOST MAPPING - create mapping pages and host bindings
var page = deviceDriver.mMapping.makePage(‘Example Mixer Page’)
var hostSelectedTrackChannel = page.mHostAccess.mTrackSelection.mMixerChannel
page.makeValueBinding(knob1.mSurfaceValue, hostSelectedTrackChannel.mValue.mVolume)

or the Next code:

// 2. SURFACE LAYOUT - create control elements and midi bindings
var faders =
var numChannels = 4

for(var channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
var fader = deviceDriver.mSurface.makeFader(channelIndex * 2 + 0.5, 2, 1, 6)
fader.mSurfaceValue.mMidiBinding
.setInputPort(midiInput).setOutputPort(midiOutput)
.bindToControlChange (0, 29 + channelIndex)
faders.push(fader)
}

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

var page = deviceDriver.mMapping.makePage(‘Example Mixer Page’)

var hostMixerBankZone = page.mHostAccess.mMixConsole.makeMixerBankZone()
.excludeInputChannels()
.excludeOutputChannels()

for(var channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
var hostMixerBankChannel = hostMixerBankZone.makeMixerBankChannel()
var faderSurfaceValue = faders[channelIndex].mSurfaceValue;
page.makeValueBinding(faderSurfaceValue, hostMixerBankChannel.mValue.mVolume)
}

Thanks a lot in advance!

Hi, if you upload your script, we can all have a look and see the issue.

1 Like

Hi m.c
Thanks a lot for your reply!
Here is my JS file. I had to rename to xml to be able to upload it here. As you will see I am a total newbie… :sweat_smile:
By the way, where is the sysex stored or where can I find it? I have to tell the software of my midi controller where to find it.
Intech_Grid.xml (2.5 KB)

This is the main issue you should address first, scripting comes after. I think you should contact the manufacturer to provide you with the proper sysex message implementation for sending color info to your controller.

Other than that, here’s your script a bit edited, so you can have an idea how to proceed, once you get the sysex info:

//-----------------------------------------------------------------------------
// 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('Intech', 'Grid', 'Claroscuro')

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

deviceDriver.setInitialSysexFile('mySysex.syx', 5)

// define all possible namings the devices MIDI ports could have
// NOTE: Windows and MacOS handle port naming differently
deviceDriver.makeDetectionUnit().detectPortPair(midiInput, midiOutput)
    .expectInputNameEquals('Intech Grid MIDI device')
    .expectOutputNameEquals('Intech Grid MIDI device')
    
//-----------------------------------------------------------------------------
// 2. SURFACE LAYOUT - create control elements and midi bindings
//-----------------------------------------------------------------------------

var faders = []

var numChannels = 4

for(var channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
    
    var fader = deviceDriver.mSurface.makeFader(channelIndex * 2 + 0.5, 2, 1, 6)
    
    fader.mSurfaceValue.mMidiBinding
        .setInputPort(midiInput).setOutputPort(midiOutput)
        .bindToControlChange (14, 20 + channelIndex)

    faders.push(fader)

}

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

var page = deviceDriver.mMapping.makePage('Example Mixer Page')

var hostMixerBankZone = page.mHostAccess.mMixConsole.makeMixerBankZone()
    .excludeInputChannels()
    .excludeOutputChannels()

for(var channelIndex = 0; channelIndex < numChannels; ++channelIndex) {
    
    var hostMixerBankChannel = hostMixerBankZone.makeMixerBankChannel()

    var faderSurfaceValue = faders[channelIndex].mSurfaceValue

    page.makeValueBinding(faderSurfaceValue, hostMixerBankChannel.mValue.mVolume)

    hostMixerBankChannel.mOnColorChange=function(activeDevice,activeMapping,r,g,b,a,isActive){

        //here we're translating the r,g,b response to the proper 0-127 range
        var r127=Math.round(127*r)
        var g127=Math.round(127*g)
        var b127=Math.round(127*b)

        //Here we have to construct the sysex
        //Normally it is a collection of bytes specified by the manufacturer, followed by the channel number (it's the variable I have below "channelIndex"), and then the RGB color in bytes as I've set them up above
        
        var channelIndex=this.channelIndex
        
        var sysex=[]

        //Here we send the sysex
        midiOutput.sendMidi(activeDevice,sysex)

    }.bind({channelIndex})

}

2 Likes

Thanks a lot m.c!!!
I will ask the manufacturer of the devices about the sysex.

Hi @clar0scur0 ,

there are issues regarding “setInitialSysexFile”. Please use this code snippet instead:


deviceDriver.mOnActivate = function (activeDevice) {
    midiOutput.sendSysexFile(activeDevice, 'myfile.syx', 5)
}
1 Like

Ah, good to know (though I don’t have devices needing this)! Curious why it happens.

Vielen Dank Jochen!