led value b 2 bar attr

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

Inlets

frac32 in

Outlets

bool32.pulse trig

charptr32 out

Attributes

combo mode

Declaration
char out[9];
int8_t v;
int8_t prev;
int8_t fb;
int16_t nb;
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) {
  prev = v;
  if (!attr_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