keyb zone poly

an approach to midi polyphony.a 'map' of currently active notes is stored in a table with the same name as the object that can be referenced from 'outside'. currentNote,gate and velo correspond to the actual events,noteOn issues a pulse whenever a note-on occurs. notecount puts out the number of notes curently on hold,hold is 1 if any keys are on hold.
Author: Robert Schirmer
License: BSD
Github: rbrt/old/keyb zone poly.axo

Inlets

bool32.rising clear

Outlets

int32 note number of active key

int32 number of notes currently held down

bool32 key pressed or released ?

bool32 any notes on hold?

frac32.positive velocity of active key

bool32.pulse pulse on note-on

bool32.pulse noteOff

Attributes

spinner startNote

spinner endNote

Declaration
int8_t _note;
uint8_t _gate;
uint8_t _velo;
uint8_t _rvelo;
uint8_t _touch;
uint8_t count;
bool trig;
bool trigoff;
bool rtrig;

static const uint32_t LENGTHPOW = 7;
static const uint32_t LENGTH = 1 << 7;
static const uint32_t LENGTHMASK = (1 << 7) - 1;
static const uint32_t BITS = 8;
static const uint32_t GAIN = 20;
int8_t array[LENGTH];
Init
_gate = 0;
_note = 0;
_touch = 0;
Control Rate
outlet_currentNote = _note;
outlet_currentGate = _gate << 27;
outlet_currentVelo = _velo << 20;

outlet_noteOn = trig;
outlet_noteOff = trigoff;
trig = 0;
trigoff = 0;

outlet_notecount = count;
outlet_hold = bool(count);

if (inlet_clear && !rtrig) {
  {
    int i;
    for (i = 0; i < LENGTH; i++)
      array[i] = 0;
  }
  rtrig = 1;
  count = 0;
}

if (!inlet_clear)
  rtrig = 0;
Midi Handler
if ((status == MIDI_NOTE_ON + attr_midichannel) && (data2)) {
  if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
    _velo = data2;
    if (!array[data1])
      trig = 1;
    _note = data1;
    _gate = 1;
    count += 1;
    array[data1] = _velo;
  }
}
if (((status == MIDI_NOTE_ON + attr_midichannel) && (!data2)) ||
    (status == MIDI_NOTE_OFF + attr_midichannel)) {
  if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
    if (array[data1])
      trigoff = 1;
    array[data1] = 0;
    if (count)
      count -= 1;
    _velo = data2;
    _note = data1;
    _gate = 0;
  }
}

else if ((status == attr_midichannel + MIDI_CONTROL_CHANGE) &&
         (data1 == MIDI_C_ALL_NOTES_OFF)) {
  _gate = 0;
}

Privacy

© 2024 Zrna Research