matrix step edit

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 step edit.axo

Inlets

int32 offset

int32 start

int32 length

bool32.risingfalling active

Outlets

bool32.pulse pulse if an element is changed

int32 pad index if inside range

int32 pad index if a pad is held down

Parameters

int32 offset

int32 start

int32 length

bool32.tgl active

Attributes

combo blocksize

spinner hold

objref step

objref mod

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

uint8_t start;
uint8_t end;

uint8_t bitmask1 = 0b10001110;

int32_t _value;
int32_t _cc;

int rtrig;
int ntrig;
bool op;
bool ttrig;
uint32_t tc;

int32_t tv;
Control Rate
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 && !ntrig) || (matrix != prevmatrix)) {
      ntrig = 1;
      op = attr_step.array[matrix];
      tv = attr_mod.array[(matrix << attr_blocksize)];
      if (!tv)
        attr_mod.array[(matrix << attr_blocksize)] =
            (1 << 27) - 1 >> attr_mod.GAIN;
      attr_step.array[matrix] = ((!op) << 27) - !op >> attr_step.GAIN;
      rtrig = 1;
    }
    if (!_gate1) {
      ntrig = 0;
      ttrig = 0;
    }

    tc += _gate1;
    if ((matrix != prevmatrix) || (!_gate1))
      tc = 0;
    if ((tc > attr_hold) && (!ttrig)) {
      attr_step.array[matrix] = (op << 27) - op >> attr_step.GAIN;
      attr_mod.array[(matrix << attr_blocksize)] = tv;
      ttrig = 1;
      hold = matrix;
    }
  }
} else {
  if (!lastmatrix)
    lastmatrix = start;
  outlet_matrix = lastmatrix;
}

prevmatrix = matrix;
outlet_trig = rtrig;
outlet_hold = hold;
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