Javascript help needed for writing an object
I need help with writing a javascript offset
The function below produces values at the output.
But I want outlet(1, inpitch+1)
and outlet(2, invelocity/2)
How do I get the values of these 2 inputs into the arguments of the function.
Or how can I assign the values to variables within the function.
inlets = 2; // Define the number of inlets
outlets = 2; // Define the number of outlets
setinletassist(0,"inpitch")
setinletassist(1,"invelocity")
setoutletassist(0,"outpitch")
setoutletassist(1,"outvelocity")
function msg_int(pitch, invelocity){
outlet(0,100+1)
outlet(1,100/2)
}
The function arguments "pitch" and "invelocity" do not correspond to inlets like you have written. The built-in function msg_int() defines how the JS responds to ONE Int (hence the name of the function) arriving at ANY inlet. Use the this.inlet property to determine which inlet the message arrived in.
So what you're after would roughly be:
function msg_int(v) {
if (this.inlet == 1) {
outlet(1, v/2);
} else if (this.inlet == 0) {
outlet(0, v + 1);
}
}
But you may want to only allow output of velocity after receiving in inlet 0, which I'm sure you can figure out how to work out.