led row value ubf attr

Author:
License: GPL
Github: rbrt/push/led row value ubf attr.axo

Inlets

bool32.rising redraw

int32 row

bool32.risingfalling mute

frac32 v0

frac32 v1

frac32 v2

frac32 v3

frac32 v4

frac32 v5

frac32 v6

frac32 v7

Outlets

None

Attributes

objref LEDmaster

spinner row

combo mode0

combo mode1

combo mode2

combo mode3

combo mode4

combo mode5

combo mode6

combo mode7

Declaration
bool trig;
bool mtrig;

int8_t fb;
int16_t nb;

uint8_t prerow;
uint8_t count;

int32_t in[8];
int32_t prev[8];
uint8_t mode[8];
int8_t v;

bool doit;
bool update;
uint8_t row;
uint16_t offset;
Init
#define BARS_ONE_L 0x03
#define BARS_ONE_R 0x04
#define BARS_TWO 0x05
#define BARS_NONE 0x06

mode[0] = attr_mode0;
mode[1] = attr_mode1;
mode[2] = attr_mode2;
mode[3] = attr_mode3;
mode[4] = attr_mode4;
mode[5] = attr_mode5;
mode[6] = attr_mode6;
mode[7] = attr_mode7;
Control Rate
if (!inlet_mute && !mtrig) {
  mtrig = 1;
  update = 1;
  count = 0;
}
if (inlet_mute)
  mtrig = 0;
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;

  row = (inlet_row + attr_row) % 4;

  if (inlet_redraw && !trig) {
    trig = 1;
    update = 1;
    count = 0;
  }
  if (!inlet_redraw)
    trig = 0;
  if (row != prerow) {
    prerow = row;
    update = 1;
    count = 0;
  }

  offset = attr_LEDmaster.array[count + 308] + (row * 77);

  if ((in[count] != prev[count]) || update) {
    prev[count] = in[count];
    v = in[count] >> 20;
    switch (mode[count]) {
    case 0: {
      if (v <= 0)
        v = 0;
      memset(attr_LEDmaster.array + offset, BARS_NONE, 8);
      nb = ((v + 1) << 4) >> 7;
      fb = nb >> 1;
      memset(attr_LEDmaster.array + offset, BARS_TWO, fb);
      if (nb % 2)
        attr_LEDmaster.array[fb + offset] = BARS_ONE_L;
      break;
    }
    case 1: {
      v = (v >> 1) + 64;
      memset(attr_LEDmaster.array + offset, BARS_NONE, 8);
      if (v == 64) {
        attr_LEDmaster.array[4 + offset] = 60;
        attr_LEDmaster.array[3 + offset] = 62;
      }
      if (v > 64) {
        attr_LEDmaster.array[3 + offset] = 62;
        nb = (((v + 1) << 4) >> 7) - 8;
        fb = nb >> 1;
        memset(attr_LEDmaster.array + offset + 4, BARS_TWO, fb);
        if (nb % 2)
          attr_LEDmaster.array[fb + 4 + offset] = BARS_ONE_L;
      }
      if (v < 64) {
        attr_LEDmaster.array[4 + offset] = 60;
        nb = 8 - (((v + 6) << 4) >> 7);
        fb = nb >> 1;
        memset(attr_LEDmaster.array + offset + (4 - fb), BARS_TWO, fb);
        if (nb % 2)
          attr_LEDmaster.array[offset + 3 - fb] = BARS_ONE_R;
      }
      break;
    }
    case 2: {
      char out[6];
      float v = (float(in[count])) / (float)((1 << 21) - 100);
      int wi = v;
      float f = fabs(v - wi);
      int fi = f * 100;
      if (v >= 0)
        out[0] = ' ';
      else
        out[0] = '-';
      wi = fabs(wi);
      out[1] = '0' + (wi / 10);
      out[2] = '0' + (wi % 10);
      out[3] = ',';
      out[4] = '0' + (fi / 10);
      out[5] = '0' + (fi % 10);
      out[6] = 32;
      out[7] = 32;
      memset(attr_LEDmaster.array + offset, 32, 8);
      memcpy(&attr_LEDmaster.array[offset], out, 6);
      break;
    }
    }
    doit = 1;
  }

  if ((doit && !attr_LEDmaster.ROW) && !attr_LEDmaster.LOCKED) {
    attr_LEDmaster.ROW = row + 1;
    doit = 0;
  }
  count++;
  count = count % 8;
  if (!count)
    update = 0;
}

Privacy

© 2024 Zrna Research