led enc

Author:
License: GPL
Github: rbrt/testing/led enc.axo

Inlets

int32 row

frac32.positive v0

frac32.positive v1

frac32.positive v2

frac32.positive v3

frac32.positive v4

frac32.positive v5

frac32.positive v6

frac32.positive v7

bool32.risingfalling mute

bool32.rising redraw

Outlets

None

Declaration
bool trig;
char text[77];
uint8_t data[77] = {240, 71, 127, 21};

int8_t fb;
int16_t nb;

uint8_t celloffset[8] = {0, 9, 17, 26, 34, 43, 51, 60};
int32_t in[8];
int32_t prev[8];
int32_t v;

int i;
int ii;
bool doit;
Init
#define BARS_ONE_L 0x03
#define BARS_ONE_R 0x04
#define BARS_TWO 0x05
#define BARS_NONE 0x06
data[5] = 0;
data[6] = 69;
data[7] = 0;
data[76] = 247;
Control Rate
if (!inlet_mute) {
  in[0] = inlet_v0;
  in[1] = inlet_v1;
  in[2] = inlet_v2;
  in[3] = inlet_v3;
  in[4] = inlet_v4;
  in[5] = inlet_v5;
  in[6] = inlet_v6;
  in[7] = inlet_v7;

  if (!doit) {
    for (i = 0; i < 8; i++)
      if (in[i] != prev[i]) {
        prev[i] = in[i];
        doit = 1;
      }
  }

  if (inlet_redraw && !trig) {
    trig = 1;
    doit = 1;
  }
  if (!inlet_redraw)
    trig = 0;

  if (doit && !MidiGetOutputBufferPending(MIDI_DEVICE_USB_HOST)) {
    data[4] = inlet_row + 24;
    for (i = 0; i < 8; i++) {
      for (ii = 0; ii < 8; ii++)
        text[ii + celloffset[i]] = BARS_NONE;
      v = in[i];
      if (v <= 0)
        v = 0;
      nb = (((v >> 20) + 1) << 4) >> 7;
      fb = nb >> 1;
      for (ii = 0; ii < fb; ii++)
        text[ii + celloffset[i]] = BARS_TWO;
      if (nb % 2)
        text[fb + celloffset[i]] = BARS_ONE_L;
    }

    for (i = 0; i < 68; i++)
      data[i + 8] = text[i] ? text[i] : 32;
    MidiSendSysEx(MIDI_DEVICE_USB_HOST, 2, data, 77);
    doit = 0;
  }
}

Privacy

© 2024 Zrna Research