table toggle

toggle elements of a table with midi-notes.set the range of the notes to use as toggles with 'startnote',the length of the range with 'length'.the start of the area of the table to work on is set with 'offset'.
Author: robert schirmer
License: BSD
Github: rbrt/midi/in/table toggle.axo

Inlets

int32 offset

int32 startnote

int32 length

bool32.risingfalling active

Outlets

bool32.pulse pulse if an element of the table is set to ON

int32 note index if inside range

Parameters

int32 offset

int32 startnote

int32 length

bool32.tgl active

Attributes

objref table

combo blocksize

Declaration
int8_t _note1;
uint8_t _gate1;
uint8_t _velo1;
uint8_t prevnote;
uint8_t lastnote;

uint8_t start;
uint8_t end;

int trig;
int ntrig;
bool op;

uint32_t offset;
Control Rate
start = inlet_startnote + param_startnote;
end = (start + (inlet_length + param_length));
offset = (inlet_offset + param_offset);

if ((_note1 >= start) && (_note1 < end)) {
  outlet_note = _note1;
  lastnote = _note1;

  if (inlet_active || param_active) {
    if (((_gate1 > 0) && !ntrig) || (_note1 != prevnote)) {
      ntrig = 1;
      op = attr_table.array[((_note1 - start) << attr_blocksize) + offset];
      op = !op;
      attr_table.array[((_note1 - start) << attr_blocksize) + offset] =
          (op * ((1 << 27) - 1 >> attr_table.GAIN));
      if (op)
        trig = 1;
    }
    if (!(_gate1 > 0))
      ntrig = 0;
  }
} else {
  if (!lastnote)
    lastnote = start;
  outlet_note = lastnote;
}

prevnote = _note1;
outlet_trig = trig;
trig = 0;
Midi Handler
if ((status == MIDI_NOTE_ON + attr_midichannel) && (data2)) {

  _note1 = data1;
  _gate1 = 1;
  _velo1 = data2;

} else if (((status == MIDI_NOTE_ON + attr_midichannel) && (!data2)) ||
           (status == MIDI_NOTE_OFF + attr_midichannel)) {
  if (_note1 == data1) {
    _gate1 = 0;
  }

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

Privacy

© 2024 Zrna Research