I'd like to use a custom velocity note message to set the value of a modal widget to 1. I used the Math.abs() so that every time the message is received, the value of "AppleScript - KB1" modal alternates between 0 and 1. What am I doing wrong?
I rewrote the input filter and now it looks like this:
oscInFilter: function(data) {
if (data.host === 'midi' && data.port === 'SessionKiano') {
var {address, args, host, port} = data
if (args[0].value == 2 && args[1].value == 94 && args[2].value == 3) {
// In the scripting property of the button push widget I would write: set('AppleScript - KB1', Math.abs(get('AppleScript - KB1')-1))
receive('AppleScript - KB1', 1, 1) // should change the value of the widget to 1, but it's not...
console.log("Hello!")
return
}
}
return data
}
The console prints the message "Hello!", but the widget in the client doesn't receive the value change.
Isn't the variable aaa supposed to be stored somewhere? I now it's not stored because everytime the console.log() function is triggered, just ones are displayed in the console (trigger 1 = 1, trigger 2 = 1, trigger 3 = 1, etc).
if (data.host === 'midi' && data.port === 'SessionKiano') {
var {address, args, host, port} = data
var aaa = 0
if (args[0].value == 2 && args[1].value == 94 && args[2].value == 3) {
aaa = Math.abs(aaa-1)
receive('/AppleScript - KB1', 1, aaa)
console.log(aaa) // every time the MIDI message is received, the console prints only ones (1, 1, 1, 1, ...)
return
}
}
First console print (first trigger): 0 (initial value of aaa) minus 1 equals -1.
Absolute value of -1 is 1, so here aaa is 1 (first trigger should print 1).
Second console print (second trigger):
Now aaa is 1 (it should be, at least, if it was somehow stored / made persistent).
So, this time I should have 1 (new value of aaa) minus 1.
Absolute value of 0 is 0, isn't it? If it is, the second trigger should print 0 (not 1 again).
You're right! I've tried at first to initialise the variable in a different place, but I was always doing it inside the module.exports code block. Now it works! Hurray!
(because I've initialised the variable before the module.export block)