led value b 2 bar

Author:
License: GPL
Github: rbrt/push/led value b 2 bar.axo

Inlets

frac32 in

bool32 mode

Outlets

charptr32 out

bool32.pulse trig

Declaration
char out[9];
int8_t v;
int8_t prev;
int8_t fb;
int16_t nb;
bool prem;
Init
#define BARS_ONE_L 0x03
#define BARS_ONE_R 0x04
#define BARS_TWO 0x05
#define BARS_NONE 0x06
Control Rate
outlet_trig = 0;
v = inlet_in >> 20;
if ((v != prev) || (inlet_mode != prem)) {
  prev = v;
  prem = inlet_mode;
  if (!inlet_mode) {
    if (v <= 0)
      v = 0;
    memset(out, BARS_NONE, 8);
    nb = ((v + 1) << 4) >> 7;
    fb = nb >> 1;
    memset(out, BARS_TWO, fb);
    if (nb % 2)
      out[fb] = BARS_ONE_L;
  } else {
    v = (v >> 1) + 64;
    memset(out, BARS_NONE, 8);
    out[4] = BARS_ONE_L;
    if (v > 64) {
      nb = (((v + 1) << 4) >> 7) - 8;
      fb = nb >> 1;
      memset(out + 4, BARS_TWO, fb);
      if (nb % 2)
        out[fb + 4] = BARS_ONE_L;
    } else {
      nb = 8 - (((v + 1) << 4) >> 7);
      fb = nb >> 1;
      memset(out + (4 - fb), BARS_TWO, fb);
      if (nb % 2)
        out[3 - fb] = BARS_ONE_R;
    }
  }
  outlet_trig = 1;
}
outlet_out = out;

Privacy

© 2024 Zrna Research