enc 1 to 8 table b

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

Inlets

int32.positive offset

bool32 fine

bool32 mode0

bool32 mode1

bool32 mode2

bool32 mode3

bool32 mode4

bool32 mode5

bool32 mode6

bool32 mode7

Outlets

None

Attributes

objref table

Declaration
int inc;
uint32_t fine;

uint8_t ccstack[8] = {0};
int8_t cvstack[8] = {0};
uint8_t slength;
uint8_t sread;
uint8_t swrite;

bool reset;
bool ftrig;
bool mode[8];
Init
fine = 32 << 12;
Control Rate
mode[0] = inlet_mode0;
mode[1] = inlet_mode1;
mode[2] = inlet_mode2;
mode[3] = inlet_mode3;
mode[4] = inlet_mode4;
mode[5] = inlet_mode5;
mode[6] = inlet_mode6;
mode[7] = inlet_mode7;

if (!inlet_fine && ftrig) {
  ftrig = 0;
  reset = 1;
}
if (inlet_fine)
  ftrig = 1;

if (slength) {
  uint8_t offset = ccstack[sread];
  int8_t vel = cvstack[sread];
  uint32_t adr = inlet_offset + offset;
  int32_t v = attr_table.array[adr] << attr_table.GAIN;
  if (!inlet_fine)
    inc = (vel << 21);
  else
    inc = (vel > 0) ? fine : (fine * -1);
  if (reset) {
    if (inc > 0)
      v = (v >> 21) << 21;
    else
      v = ((v >> 21) + 1) << 21;
    reset = 0;
  }
  v = __SSAT((v + inc), 28);

  if (mode[offset]) {
    if ((v > -(1 << 17)) && (v < (1 << 17)))
      v = 0;
  } else if (v < 0)
    v = 0;

  if (adr < attr_table.LENGTH)
    attr_table.array[adr] = v >> attr_table.GAIN;
  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