remind4

string multiplexer
Author: Smashed Transistors
License: LGPL
Github: tiar/string/remind4.axo

Inlets

bool32 chainTrig

charptr32 chainIn

frac32 i0

frac32 i1

frac32 i2

frac32 i3

Outlets

bool32 chainTrig

charptr32 string

Attributes

table prefix0

table prefix1

table prefix2

table prefix3

Declaration
int32_t m0, m1, m2, m3;
int32_t select;
char c0[7 + strlen("attr_prefix0")];
char *p0 = c0 + strlen("attr_prefix0");
char c1[7 + strlen("attr_prefix1")];
char *p1 = c1 + strlen("attr_prefix1");
char c2[7 + strlen("attr_prefix2")];
char *p2 = c2 + strlen("attr_prefix2");
char c3[7 + strlen("attr_prefix3")];
char *p3 = c3 + strlen("attr_prefix3");

char *p, *c;
Init
strcpy(&c0[0], "attr_prefix0");
strcpy(&c1[0], "attr_prefix1");
strcpy(&c2[0], "attr_prefix2");
strcpy(&c3[0], "attr_prefix3");

p = p0;
c = c0;

m0 = m1 = m2 = m3 = 0;
select = 0;
Control Rate
outlet_chainTrig = false;

if (inlet_chainTrig) {
  select = -1;
  outlet_chainTrig = true;
} else if (abs(inlet_i0 - m0) >= (1 << 21)) {
  select = 0;
  m0 = inlet_i0;
  outlet_chainTrig = true;
} else if (abs(inlet_i1 - m1) >= (1 << 21)) {
  select = 1;
  m1 = inlet_i1;
  outlet_chainTrig = true;
} else if (abs(inlet_i2 - m2) >= (1 << 21)) {
  select = 2;
  m2 = inlet_i2;
  outlet_chainTrig = true;
} else if (abs(inlet_i3 - m3) >= (1 << 21)) {
  select = 3;
  m3 = inlet_i3;
  outlet_chainTrig = true;
}

int32_t i;
switch (select) {
case -1:
  break;
case 0:
default:
  p = p0;
  c = c0;
  i = inlet_i0;
  break;
case 1:
  p = p1;
  c = c1;
  i = inlet_i1;
  break;
case 2:
  p = p2;
  c = c2;
  i = inlet_i2;
  break;
case 3:
  p = p3;
  c = c3;
  i = inlet_i3;
  break;
}
if (select >= 0) {
  float f = i * (1.0f / (1 << 21));
  if (i > 0)
    p[0] = '+';
  else if (i < 0) {
    p[0] = '-';
    f = -f;
  } else
    p[0] = ' ';
  if (f >= 1000) {
    p[1] = 127;
    p[2] = 127;
    p[3] = 0;
  } else {
    {
      int cent = (int)(f / 100);
      if (cent == 0)
        p[1] = ' ';
      else
        p[1] = '0' + cent;
      f -= cent * 100;
    }
    {
      int diz = (int)(f / 10);
      if (diz == 0)
        p[2] = ' ';
      else
        p[2] = '0' + diz;
      f -= diz * 10;
    }
    {
      int un = (int)(f);
      p[3] = '0' + un;
      f -= un * 1;
      p[4] = '.';
    }
    {
      int diz = (int)(f * 10);
      p[5] = '0' + diz;
      f -= diz * 10;
    }
    p[6] = 0;
  }

  outlet_out = c;
} else {
  outlet_out = (char *)inlet_chainIn;
}

Privacy

© 2024 Zrna Research