enc 1 to 8 table massmod

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

Inlets

bool32 fine

bool32 mode0

bool32 mode1

bool32 mode2

bool32 mode3

bool32 mode4

bool32 mode5

bool32 mode6

bool32 mode7

bool32 massmod

int32.positive offset

Outlets

None

Attributes

objref table

combo blocksize

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;

int32_t tstack[16] = {0};
int32_t vstack[16] = {0};
uint8_t clength;
uint8_t cread;
uint8_t cwrite;
uint32_t ccount;

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;

  if (inlet_massmod) {
    tstack[cwrite] = adr - ((adr / attr_blocksize) * attr_blocksize);
    vstack[cwrite] = attr_table.array[adr];
    clength++;
    cwrite++;
    cwrite = cwrite % 16;
  }

  slength--;
  sread++;
  sread = sread % 8;
}
Audio Rate
if (clength) {
  attr_table.array[ccount + tstack[cread]] = vstack[cread];
  ccount += attr_blocksize;
  if (ccount == attr_table.LENGTH) {
    ccount = 0;
    cread++;
    cread = cread % 16;
    clength--;
  }
}
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