enc 1 to 8 u table

Receives Midi Continuous Controller messages from any CC number and channel.
Author: Johannes Taelman
License: BSD
Github: rbrt/push/enc 1 to 8 u table.axo

Inlets

int32.positive offset

bool32 fine

Outlets

None

Attributes

objref table

Declaration
int8_t vel;
uint8_t offset;
int inc;
uint8_t op;
uint32_t fine;
uint32_t adr;

uint8_t ccstack[8] = {0};
int8_t cvstack[8] = {0};
uint8_t slength;
uint8_t sread;
uint8_t swrite;
Init
vel = 0;
Control Rate
if (attr_table.BITS == 32) {
  op = 28;
  fine = 32 << 12;
}
if (attr_table.BITS == 16) {
  op = 16;
  fine = 16 << 2;
}
if (attr_table.BITS == 8) {
  op = 8;
  fine = 1;
}

if (slength) {
  offset = ccstack[sread];
  vel = cvstack[sread];
  if (!inlet_fine)
    inc = (vel << (21 - attr_table.GAIN));
  else
    inc = (vel > 0) ? fine : (fine * -1);
  adr = inlet_offset + offset;
  if (adr < attr_table.LENGTH) {
    attr_table.array[adr] = __SSAT((attr_table.array[adr] + inc), op);
    if (attr_table.array[adr] < 0)
      attr_table.array[adr] = 0;
  }
  slength--;
  sread++;
  sread = sread % 8;
}
Midi Handler
if ((status & 0xF0) == MIDI_CONTROL_CHANGE) {
  if ((data1 >= 71) && (data1 <= 78)) {
    ccstack[swrite] = data1 - 71;
    cvstack[swrite] = (data2 & 0x40) ? (128 - data2) * -1 : data2;
    slength++;
    swrite++;
    swrite = swrite % 8;
  }
}

Privacy

© 2024 Zrna Research