keyb zone poly

useful for polyphonic midi. noteOn issues a pulse whenever a note-on occurs, note returns the note number, with 'noteshift' added (or substracted) same for note off. hold is 1 if any keys are on hold. gate is true when velocity > 0
Author: Robert Schirmer
License: BSD
Github: rbrt/poly/keyb zone poly.axo

Inlets

None

Outlets

int32.positive note number +/- 'noteshift'

int32.positive velocity

bool32 any notes on hold?

bool32 status of current note

bool32.pulse pulse on note-on

bool32.pulse pulse on note-off

Attributes

spinner startNote

spinner endNote

spinner channel

spinner noteshift

Declaration
uint8_t _note;
int8_t count;
uint8_t _velo;
uint8_t pren;
uint8_t prev;

uint8_t nstack[16] = {0};
uint8_t vstack[16] = {0};
uint8_t slength;
uint8_t sread;
uint8_t swrite;
uint8_t thin;
Init
slength = 0;
_note = 0;
_velo = 0;
Control Rate
outlet_noteOn = 0;
outlet_noteOff = 0;

if (!thin) {
  thin = 2;
  if (slength) {
    _note = nstack[sread];
    _velo = vstack[sread];
    if (_velo) {
      outlet_noteOn = 1;
      count++;
    } else {
      outlet_noteOff = 1;
      count--;
    }
    sread++;
    sread = sread % 16;
    slength--;
  }
} else
  thin--;

outlet_gate = bool(_velo);
outlet_hold = bool(count);
outlet_note = _note;
outlet_velo = _velo;
Midi Handler
if ((status == MIDI_NOTE_ON + (attr_channel - 1)) && (data2)) {
  if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
    nstack[swrite] = data1 + attr_noteshift;
    vstack[swrite] = data2;
    slength++;
    swrite++;
    swrite = swrite % 16;
  }
}
if (((status == MIDI_NOTE_ON + (attr_channel - 1)) && (!data2)) ||
    (status == MIDI_NOTE_OFF + (attr_channel - 1))) {
  if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
    nstack[swrite] = data1 + attr_noteshift;
    vstack[swrite] = 0;
    slength++;
    swrite++;
    swrite = swrite % 16;
  }
} else if ((status == (attr_channel - 1) + MIDI_CONTROL_CHANGE) &&
           (data1 == MIDI_C_ALL_NOTES_OFF)) {
  _velo = 0;
  count = 0;
  slength = 0;
}

Privacy

© 2024 Zrna Research