Script won't run past first function
I'm a beginner in JS.... I had this working, but for some reason it suddenly stopped working. WHY... won't the code won't execute beyond the first function??
inlets = 2;
outlets = 3;
var vals = [0, 0];// gets values from input array
var p = 60; //pitch
var v = 100; //velocity
var c = 1; //MIDI channel
var counter1 = 0; //counts through loop
function msg_int(val) //checks for input - this code from Max tutorial and works fine
{
if (inlet == 1) {
vals[1] = val;
} else {
vals[0] = val;
//post(vals[0]); // uncomment these to verify input values
//post(vals[1]);
//post(counter1); // uncomment this to see counter1 value
//post();
}
}
function wtf() // trying to figure out why nothing runs past the first function!
// Even this simple function won't run.
{
if (counter1 == 0) {
post("why not working");
post();
}
}
//now comes the important stuff I had working but won't work now
function note1on()
{
if (counter1 == 0 && vals[0] > 100 && vals[0] < 150 && vals[1] > 150 && vals[1] < 350) {
outlet(2, c); //outputs MIDI channel on right outlet
outlet(1, v); //outputs vel on middle outlet
outlet(0, p); //outputs pitch on right outlet - plays note
counter1++;
} else {
post("note not on");
post();
}
}
it's in your function note1on. Once you detect a note on you raise counter1 by 1 (to 1) after that your first condition (counter1 == 0) will be always false.