enc 1 t o 8 u table+

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

Inlets

int32.positive offset

int32.positive slot

bool32.risingfalling fine

bool32.risingfalling copyToAll

bool32.risingfalling protect

bool32 holdOnly

bool32 excludeHold

Outlets

None

Attributes

objref table

objref holdmap

spinner pads

combo blocksize

Declaration
int8_t vel;
uint32_t offset;
int inc;
int32_t op;
uint32_t fine;
uint32_t adr;
uint8_t enc;
uint32_t index;
uint32_t preindex;
int32_t vindex;
uint32_t pos;

// clamp the value to the correct range
int32_t vrange(int32_t value, int32_t low, int32_t high) {
  int result;
  result = value;
  if (value >= (high))
    result = high - 1;
  if (value <= (low))
    result = low + 1;
  return result;
}

uint8_t nstack[8] = {0};
int8_t vstack[8] = {0};
uint8_t slength;
uint8_t sread;
uint8_t swrite;
Init
vel = 0;

if (attr_table.BITS == 32) {
  op = 1 << 27;
  fine = 32 << 12;
}
if (attr_table.BITS == 16) {
  op = 1 << 15;
  fine = 16 << 2;
}
if (attr_table.BITS == 8) {
  op = 1 << 7;
  fine = 1;
}
Control Rate
if (slength) {
  enc = nstack[sread];
  vel = vstack[sread];
  sread++;
  sread = sread % 8;
  slength--;

  if (!inlet_fine)
    inc = (vel << (21 - attr_table.GAIN));
  else
    inc = (vel > 0) ? fine : (fine * -1);
  index = inlet_offset + enc;

  if (index != preindex) {
    vindex = attr_table.array[index];
    preindex = index;
  }
  vindex = vrange(vindex + inc, 0, op);

  if (inlet_copyToAll) {
    offset = index - ((index / attr_blocksize) * attr_blocksize);
    int i;
    for (i = 0; i < attr_pads; i++) {
      if (!inlet_excludeHold || !attr_holdmap.array[i]) {
        pos = (i * attr_blocksize) + offset;
        if (!inlet_protect || (i != inlet_slot)) {
          if (inlet_holdOnly) {
            if (attr_holdmap.array[i])
              attr_table.array[pos] = vindex;
          } else
            attr_table.array[pos] = vindex;
        }
      }
    }
  } else if (!inlet_protect)
    attr_table.array[index] = vindex;
}
Midi Handler
if ((status & 0xF0) == MIDI_CONTROL_CHANGE) {
  if ((data1 >= 71) && (data1 <= 78)) {
    nstack[swrite] = data1 - 71;
    vstack[swrite] = (data2 & 0x40) ? (128 - data2) * -1 : data2;
    slength++;
    swrite++;
    swrite = swrite % 8;
  }
}

Privacy

© 2024 Zrna Research