note poly

useful for polyphonic midi. noteOn issues a pulse whenever a note-on occurs, note returns the note number. same for note off. hold is 1 if any keys are on hold.
Author: Robert Schirmer
License: BSD
Github: rbrt/old/note poly.axo

Inlets

None

Outlets

int32 note on note-on

int32 velocity

bool32.pulse pulse on note-on

bool32.pulse pulse on note-off

bool32 any notes on hold?

Attributes

spinner startNote

spinner endNote

spinner channel

Declaration
uint8_t _note;
uint8_t count;
uint8_t _velo;
bool trigon;
bool trigoff;
Init
_note = 0;
trigon = 0;
trigoff = 0;
Control Rate
outlet_note = _note;
outlet_velo = _velo;
outlet_noteOn = trigon;
outlet_noteOff = trigoff;
trigon = 0;
trigoff = 0;
outlet_gate = bool(count);
Midi Handler
if ((status == MIDI_NOTE_ON + (attr_channel - 1)) && (data2)) {
  if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
    trigon = 1;
    count += 1;
    _note = data1;
    _velo = data2;
  }
}
if (((status == MIDI_NOTE_ON + (attr_channel - 1)) && (!data2)) ||
    (status == MIDI_NOTE_OFF + (attr_channel - 1))) {
  if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
    if (count)
      count -= 1;
    _note = data1;
    trigoff = 1;
    _velo = 0;
  }
} else if ((status == (attr_channel - 1) + MIDI_CONTROL_CHANGE) &&
           (data1 == MIDI_C_ALL_NOTES_OFF)) {
  count = 0;
}

Privacy

© 2024 Zrna Research