matrix toggle

toggles the elements of a table with the 8x8 matrix of a 'launchpad'. 'offset' sets the table index to start at, 'startpad' sets the first pad of the launchpad's active area, 'length' sets the length of the area. 'blocksize' sets the size of the data-block.
Author: robert schirmer
License: BSD
Github: rbrt/launchpad/matrix toggle.axo

Inlets

int32 offset

int32 start

int32 length

bool32.risingfalling active

Outlets

int32 pad index if inside range

bool32.pulse pulse if an element is set to ON

Parameters

int32 offset

int32 start

int32 length

bool32.tgl active

Attributes

combo blocksize

objref table

Declaration
int8_t _note1;
uint8_t _gate1;
uint8_t matrix;
uint8_t prevmatrix;
uint8_t lastmatrix;

uint8_t start;
uint8_t end;

uint8_t bitmask1 = 0b10001110;

int32_t _value;
int32_t _cc;
int32_t offset;

int rtrig;
int ntrig;
bool op;
Control Rate
offset = inlet_offset + param_offset;
start = inlet_start + param_start;
end = (start + (inlet_length + param_length));

matrix = (_note1 - ((_note1 >> 4) << 3));

if ((matrix >= start) && (matrix < end)) {
  outlet_matrix = matrix;
  lastmatrix = matrix;

  if (inlet_active || param_active) {
    if (((_gate1 > 0) && !ntrig) || (matrix != prevmatrix)) {
      ntrig = 1;
      op = attr_table.array[(matrix << attr_blocksize) + offset];
      op = !op;
      attr_table.array[(matrix << attr_blocksize) + offset] =
          (op * ((1 << 27) - 1 >> attr_table.GAIN));
      if (op)
        rtrig = 1;
    }
    if (!(_gate1 > 0))
      ntrig = 0;
  }

} else {
  if (!lastmatrix)
    lastmatrix = start;
  outlet_matrix = lastmatrix;
}

prevmatrix = matrix;
outlet_trig = rtrig;
rtrig = 0;
Midi Handler
if ((status == MIDI_NOTE_ON + attr_midichannel) && (data2)) {
  if ((data1 - 8) & bitmask1) {
    _note1 = data1;
    _gate1 = 1;
  }
} 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