desc: Live Input Quantize (GianniMIDI) in_pin:none out_pin:none slider1:16<1,16,1>quantize interval (bar/n) slider2:0<0,2,1{don't (good for one-shots),unquantized (note on & offs received within the same interval will not play),quantized (note on & offs received within the same interval will not play)}>send note offs import my-lib.jsfx-inc @init // msg methods function enqNoteOn() ( onQueue.push(this.toBits()); ); function cancelNoteOn(i) ( onQueue[i] = 0; ); function enqNoteOff() ( offQueue.push(this.toBits()); ); function posInQueue() local (i, pos) ( pos = -1; i = 0; while((pos == -1) && (i < onQueue.length)) ( _comp = onQueue[i]; _comp.parseBits(); (this.statusLo == _comp.statusLo) && (this.data1 == _comp.data1) && pos = i; i += 1; ); pos; ); // global methods function dequeue(queue*) ( while(queue.length > 0) ( _msg = queue.pop(); _msg.parseBits(); _msg.sendWithOffset(sampleOffset); ); ); onQueue.arrayInit(128); offQueue.arrayInit(128); clock.cInit(); @slider clock.setPeriodBars(1/slider1); @block sampleOffset = -1; @sample sampleOffset += 1; tempoChanged() && clock.setPeriodBars(1/slider1); while (msg.recv()) ( handled = 0; msg.isNoteOn() && ( (msg.posInQueue() < 0) && msg.enqNoteOn(); handled = 1; ); msg.isNoteOff() && ( slider2 > 0 && ( _pos = msg.posInQueue(); _pos > -1 ? cancelNoteOn(_pos) : (slider2 == 1 ? msg.sendWithOffset(sampleOffset) : msg.enqNoteOff()); ); handled = 1; ); !handled && msg.sendWithOffset(sampleOffset); ); clock.tick() && ( slider2 == 2 && dequeue(offQueue); dequeue(onQueue); );