mOnActivate and Deactivate triggered more than once

Hi, as the title says, upon changing pages, I get multiple (2) mOnActivate and Deactivate events. In fact, even at first activation, I get 3 times the mOnActivate event. I see no reason for this, so it may be a bug, otherwise I would be happy to know the reason behind this.

In the following sample, I have two pages with a pageNext binding, to demonstrate the issue.

To me, the mOnActivate event is important, because I’m using it to initialize some leds of my controller. When it gets triggered multiple times, my controller behaves erratically. I’ve already found a workaround, however, in my opinion, this has to be investigated, unless of course there is something quite wrong with my configuration and the below code works as expected to other users’ ones.

var midiremote_api = require('midiremote_api_v1')

var deviceDriver = midiremote_api.makeDeviceDriver('Test', 'test', 'test')

var midiInput = deviceDriver.mPorts.makeMidiInput("in")
var midiOutput = deviceDriver.mPorts.makeMidiOutput("out")

var detectWin = deviceDriver.makeDetectionUnit()
detectWin
    .detectPortPair(midiInput, midiOutput)
    .expectInputNameStartsWith('aPort')
    .expectOutputNameStartsWith('aPort')
    
makeActivationHandling(deviceDriver, midiOutput,midiInput)

var surface = deviceDriver.mSurface

var surfaceElements = makeSurfaceElements()

function makeSurfaceElements() {
    
    var surfaceElements = {}
    
    var button=surface.makeButton(0,0,10,10)
    button.mSurfaceValue.mMidiBinding.setInputPort(midiInput).bindToNote(0,60)
    surfaceElements.button=button 

    return surfaceElements

}

makeHostMapping(midiremote_api.mDefaults, deviceDriver, surfaceElements, surface, midiOutput)

function makeActivationHandling(deviceDriver, midiOutput,midiInput) {
    
    deviceDriver.mOnActivate = function (context) {
        console.log("Activating device")
    }
}

//----------------------------------------------------------------------------------------------------------------------
/**
 * @param {MR_HostDefaults} hostDefaults
 * @param {MR_DeviceDriver} deviceDriver
 * @param {Object} surfaceElements
 */
function makeHostMapping(hostDefaults, deviceDriver, surfaceElements, surface, midiOutput) {
    
    var resPage = makePage("somePage",hostDefaults, deviceDriver, surfaceElements, midiOutput)
    var page=resPage.page
    
    page.mOnActivate = (function (context,activeMapping) {
        console.log("activating page 1")
        this.onActivate(context)
    }).bind({ onActivate: resPage.onActivate })

    page.mOnDeactivate = (function (context,activeMapping) {
        console.log("deactivating page 1")
        this.onDeactivate(context)
    }).bind({ onDeactivate: resPage.onDeactivate })

    var resPage2 = makePage("somePage2",hostDefaults, deviceDriver, surfaceElements, midiOutput)
    var page2=resPage2.page
    
    page2.mOnActivate = (function (context,activeMapping) {
        console.log("activating page 2")
        this.onActivate(context)
    }).bind({ onActivate: resPage2.onActivate })
    
    page2.mOnDeactivate = (function (context,activeMapping) {
        console.log("deactivating page 2")
        this.onDeactivate(context)
    }).bind({ onDeactivate: resPage2.onDeactivate })

}

function makePage(name,hostDefaults, /** @type {MR_DeviceDriver} */deviceDriver, surfaceElements, midiOutput) {
  /** @type {MR_FactoryMappingPage} */
    var page = deviceDriver.mMapping.makePage(name)

    page.makeActionBinding(surfaceElements.button.mSurfaceValue,deviceDriver.mAction.mNextPage)
  
    var onActivate = function (context) {
        console.log("defaultOnActivate")
    }

    var OnDeactivate=function(context){
        console.log("defaultOnDeactivate")
    }
    
    return { page, onActivate,OnDeactivate}
}



1 Like