Execute script when pressing the already selected button of a switch

Hi, I noticed that on a switch, if I tap the last item that was selected, it won't re-execute the script. Any way to change this behavior?

Oops, just realized i can do set('this',0) at the end of the script :slight_smile:

Hi @datalooper Where exactly did you put set('this',0)? I tried in the myCustomModule.js and also in the .json in the onValue.

  oscOutFilter: function (data) {
    // Filter outgoing osc messages
    var { address, args, host, port, clientId } = data;
    // same as oscInFilter
    // return data if you want the message to be sent
    return data;
  },


};

set('this',0);
var channel = 16
var velocity = 127
var note = value
send('midi:Logic', '/note', channel, note, 127)
send('midi:Logic', '/note', channel, note, 0)
set('this',0)

@jean-emmanuel, would this still work in v1.25.5?

Thanks,

Eric

Cracked it! This onValue adds the ability to re-trigger the switch. Also, I set value to -1 so the first switch doesn't start out active.

// switch's onValue property
// since the message is sent here we could set bypass to true
// to prevent sending the default messages based on
// address, preArgs and target
var channel = 16
var velocity = 127
var note = value
var cc = 110
send('midi:Logic', '/note', channel, note, 127)
send('midi:Logic', '/note', channel, note, 0)
send('midi:Logic', '/control', channel, cc, value)
//enable multiple taps
setTimeout(reset, 1000)
function reset() {
  set("this", -1, {send:false})
}
1 Like