rndWeightSeq

weighted random gate generator with 4 channels each channel has 4 sequences: -rnd chance per step (when slider is at max, it will always generate a trigger on that step) -play length per step (gatelength->also max length for fill) -retrigger per step (for fills) -delay per step (for swing) -rnd chance for any gate anywhere -rnd chance for changing the current gatelength -width for random gatelength->adds to step gatelength value -rnd chance for random retrigger -width for random retrigger->adds to step retrigger value -rnd chance for random delay -width for rnd chance random delay->adds to step delay -maximum count length for the 4 sequencers (wraps back to step 0 when reaching maximum count) -maximum "main" count length for the internal counter.
Author: Remco van der Most
License: BSD
Github: sss/patt/rndWeightSeq.axo

Inlets

charptr32 filename

bool32 trig

bool32 rst

bool32 load

Outlets

bool32 o1

bool32 o2

bool32 o3

bool32 o4

int32 cnt

Parameters

bool32.mom rnd

bool32.mom clear

bool32.mom save

bool32.mom load

int32.vradio output

int32.vradio parameter

frac32.u.map Gchance

frac32.u.map Pchance

frac32.u.map Pwidth

frac32.u.map Rchance

frac32.u.map Rwidth

frac32.u.map Dchance

frac32.u.map Dwidth

int32 length1

int32 length2

int32 length3

int32 length4

int32 mainlength

frac32.u.mapvsl b0

frac32.u.mapvsl b1

frac32.u.mapvsl b2

frac32.u.mapvsl b3

frac32.u.mapvsl b4

frac32.u.mapvsl b5

frac32.u.mapvsl b6

frac32.u.mapvsl b7

frac32.u.mapvsl b8

frac32.u.mapvsl b9

frac32.u.mapvsl b10

frac32.u.mapvsl b11

frac32.u.mapvsl b12

frac32.u.mapvsl b13

frac32.u.mapvsl b14

frac32.u.mapvsl b15

Displays

bool32 chance

bool32 gatelength

bool32 retrigger

bool32 delay

Declaration
static const uint32_t LENGTHPOW = (10);
static const uint32_t LENGTH = (1024);
static const uint32_t LENGTHMASK = (1023);
int8_t *array;
int count;
int ttrig;
int strig;
int ltrig;
int rtrig;
int ctrig;
int i;
int gate[4];
int32_t val[4];
int32_t CNT[4];
int32_t repeat[4];
int32_t pulsewidth[4];
int32_t delay[4];
int rGate[4];
int32_t Array[256];
uint32_t cnt;
int32_t Time;
int32_t Count[4];
uint32_t write;

uint32_t writepos;
int32_t prev;
int Rtrig;
Init
static int8_t _array[1 << (LENGTHPOW << 2)] __attribute__((section(".sdram")));
array = &_array[0];
int i;
writepos = 0;
for (i = 0; i < (LENGTH << 2); i++)
  array[i] = 0;
strig = 0;
ltrig = 0;
rtrig = 0;
ctrig = 0;
Control Rate
write += 1;
write = write & 1023;
cnt += 1;
if ((param_save > 0) && !strig) {
  strig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_written;
  err = f_open(&FileObject, inlet_filename, FA_WRITE | FA_CREATE_ALWAYS);
  if (err != FR_OK) {
    report_fatfs_error(err, "inlet_filename");
    return;
  }
  int rem_sz = sizeof(*Array) * (256);
  int offset = 0;
  while (rem_sz > 0) {
    if (rem_sz > sizeof(fbuff)) {
      memcpy((char *)fbuff, (char *)(&Array[0]) + offset, sizeof(fbuff));
      err = f_write(&FileObject, fbuff, sizeof(fbuff), &bytes_written);
      rem_sz -= sizeof(fbuff);
      offset += sizeof(fbuff);
    } else {
      memcpy((char *)fbuff, (char *)(&Array[0]) + offset, rem_sz);
      err = f_write(&FileObject, fbuff, rem_sz, &bytes_written);
      rem_sz = 0;
    }
  }
  if (err != FR_OK)
    report_fatfs_error(err, "inlet_filename");
  err = f_close(&FileObject);
  if (err != FR_OK)
    report_fatfs_error(err, "inlet_filename");
} else if (!(param_save > 0)) {
  strig = 0;
}
int load = param_load + inlet_load;
if ((load > 0) && !ltrig) {
  ltrig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_read;
  err = f_open(&FileObject, inlet_filename, FA_READ | FA_OPEN_EXISTING);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  }
  int rem_sz = sizeof(*Array) * (256);
  int offset = 0;
  while (rem_sz > 0) {
    if (rem_sz > sizeof(fbuff)) {
      err = f_read(&FileObject, fbuff, sizeof(fbuff), &bytes_read);
      if (bytes_read == 0)
        break;
      memcpy((char *)(&Array[0]) + offset, (char *)fbuff, bytes_read);
      rem_sz -= bytes_read;
      offset += bytes_read;
    } else {
      err = f_read(&FileObject, fbuff, rem_sz, &bytes_read);
      memcpy((char *)(&Array[0]) + offset, (char *)fbuff, bytes_read);
      rem_sz = 0;
    }
  }
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  };
  err = f_close(&FileObject);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  };
} else if (!(load > 0)) {
  ltrig = 0;
}

if (!(prev == (param_output + param_parameter + param_load))) {
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b0],
                     Array[0 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b1],
                     Array[1 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b2],
                     Array[2 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b3],
                     Array[3 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b4],
                     Array[4 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b5],
                     Array[5 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b6],
                     Array[6 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b7],
                     Array[7 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b8],
                     Array[8 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b9],
                     Array[9 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b10],
                     Array[10 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b11],
                     Array[11 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b12],
                     Array[12 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b13],
                     Array[13 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b14],
                     Array[14 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b15],
                     Array[15 + param_parameter * 16 + param_output * 64],
                     0xFFFD);
}

if ((inlet_rst) && !Rtrig) {
  Rtrig = 1;
  count = -1;
} else if (inlet_rst == 0) {
  Rtrig = 0;
}
disp_chance = 0;
disp_gatelength = 0;
disp_retrigger = 0;
disp_delay = 0;

if (param_parameter == 0) {
  disp_chance = 1;
}
if (param_parameter == 1) {
  disp_gatelength = 1;
}
if (param_parameter == 2) {
  disp_retrigger = 1;
}
if (param_parameter == 3) {
  disp_delay = 1;
}
if ((ltrig == 0) && (strig == 0)) {
  Array[0 + param_parameter * 16 + param_output * 64] = param_b0;
  Array[1 + param_parameter * 16 + param_output * 64] = param_b1;
  Array[2 + param_parameter * 16 + param_output * 64] = param_b2;
  Array[3 + param_parameter * 16 + param_output * 64] = param_b3;
  Array[4 + param_parameter * 16 + param_output * 64] = param_b4;
  Array[5 + param_parameter * 16 + param_output * 64] = param_b5;
  Array[6 + param_parameter * 16 + param_output * 64] = param_b6;
  Array[7 + param_parameter * 16 + param_output * 64] = param_b7;
  Array[8 + param_parameter * 16 + param_output * 64] = param_b8;
  Array[9 + param_parameter * 16 + param_output * 64] = param_b9;
  Array[10 + param_parameter * 16 + param_output * 64] = param_b10;
  Array[11 + param_parameter * 16 + param_output * 64] = param_b11;
  Array[12 + param_parameter * 16 + param_output * 64] = param_b12;
  Array[13 + param_parameter * 16 + param_output * 64] = param_b13;
  Array[14 + param_parameter * 16 + param_output * 64] = param_b14;
  Array[15 + param_parameter * 16 + param_output * 64] = param_b15;
}

if ((inlet_trig > 0) && !ttrig) {
  Time = cnt;
  cnt = 0;
  ttrig = 1;
  count += 1;
  count = count - (count / param_mainlength) * param_mainlength;

  Count[0] = count - (count / param_length1) * param_length1;
  Count[1] = count - (count / param_length2) * param_length2;
  Count[2] = count - (count / param_length3) * param_length3;
  Count[3] = count - (count / param_length4) * param_length4;
  for (i = 0; i < 4; i++) {
    val[i] = (int32_t)((GenerateRandomNumber() >> 5));
    gate[i] = Array[Count[i] + i * 64] > val[i] ? 1 : 0;
    repeat[i] =
        (((uint32_t)((GenerateRandomNumber()))) >> 5) < (param_Rchance) ? 1 : 0;
    if (repeat[i] > 0) {
      repeat[i] =
          ___SMMUL(((uint32_t)((GenerateRandomNumber())) >> 24), param_Rwidth);
    }
    delay[i] =
        (((uint32_t)((GenerateRandomNumber()))) >> 5) < (param_Dchance) ? 1 : 0;
    if (delay[i] > 0) {
      delay[i] = ___SMMUL(((uint32_t)((GenerateRandomNumber())) >> 5),
                          param_Dwidth << 4);
    }
    pulsewidth[i] =
        (((uint32_t)((GenerateRandomNumber()))) >> 5) < (param_Pchance) ? 1 : 0;
    if (pulsewidth[i] > 0) {
      pulsewidth[i] = ___SMMUL(
          ___SMMUL(((uint32_t)((GenerateRandomNumber())) >> 5), Time << 5) << 3,
          param_Pwidth << 2);
    }
    rGate[i] =
        (((uint32_t)((GenerateRandomNumber()))) >> 5) < (param_Gchance) ? 1 : 0;
  }
} else if (inlet_trig <= 0) {
  ttrig = 0;
}

array[(write + ___SMMUL(delay[0] << 3, Time << 2) +
       ___SMMUL(Array[Count[0] + 48] << 3, Time << 2)) &
      1023] =
    (gate[0] + rGate[0]) &&
    ((___SMMUL(Array[Count[0] + 16] << 3, Time << 2) + pulsewidth[0]) >= cnt - 5
         ? 1
         : 0) &&
    (CNT[0]);
array[((write + ___SMMUL(delay[1] << 3, Time << 2) +
        ___SMMUL(Array[Count[1] + 48 + 64] << 3, Time << 2)) &
       1023) +
      1024] = (gate[1] + rGate[1]) &&
              ((___SMMUL(Array[Count[1] + 16 + 64] << 3, Time << 2) +
                pulsewidth[1]) >= cnt - 5
                   ? 1
                   : 0) &&
              (CNT[1]);
array[((write + ___SMMUL(delay[2] << 3, Time << 2) +
        ___SMMUL(Array[Count[2] + 48 + 128] << 3, Time << 2)) &
       1023) +
      2048] = (gate[2] + rGate[2]) &&
              ((___SMMUL(Array[Count[2] + 16 + 128] << 3, Time << 2) +
                pulsewidth[2]) >= cnt - 5
                   ? 1
                   : 0) &&
              (CNT[2]);
array[((write + ___SMMUL(delay[3] << 3, Time << 2) +
        ___SMMUL(Array[Count[3] + 48 + 192] << 3, Time << 2)) &
       1023) +
      3072] = (gate[3] + rGate[3]) &&
              ((___SMMUL(Array[Count[3] + 16 + 192] << 3, Time << 2) +
                pulsewidth[3]) >= cnt - 5
                   ? 1
                   : 0) &&
              (CNT[3]);

outlet_o1 = array[write];
outlet_o2 = array[write + 1024];
outlet_o3 = array[write + 2048];
outlet_o4 = array[write + 3072];
outlet_cnt = cnt;
prev = param_output + param_parameter + param_load;

CNT[0] =
    (cnt -
     (cnt / (Time / (1 + repeat[0] + ___SMMUL(Array[Count[0] + 32], 7 << 5)))) *
         (Time / (1 + repeat[0] + ___SMMUL(Array[Count[0] + 32], 7 << 5)))) <
            Time / 8
        ? 1
        : 0;
CNT[1] = (cnt - (cnt / (Time / (1 + repeat[1] +
                                ___SMMUL(Array[Count[1] + 32 + 64], 7 << 5)))) *
                    (Time / (1 + repeat[1] +
                             ___SMMUL(Array[Count[1] + 32 + 64], 7 << 5)))) <
                 Time / 8
             ? 1
             : 0;
CNT[2] =
    (cnt -
     (cnt /
      (Time / (1 + repeat[2] + ___SMMUL(Array[Count[2] + 32 + 128], 7 << 5)))) *
         (Time / (1 + repeat[2] +
                  ___SMMUL(Array[Count[2] + 32 + 128], 7 << 5)))) < Time / 8
        ? 1
        : 0;
CNT[3] =
    (cnt -
     (cnt /
      (Time / (1 + repeat[3] + ___SMMUL(Array[Count[3] + 32 + 192], 7 << 5)))) *
         (Time / (1 + repeat[3] +
                  ___SMMUL(Array[Count[3] + 32 + 192], 7 << 5)))) < Time / 8
        ? 1
        : 0;

if ((param_rnd > 0) && !rtrig) {
  rtrig = 1;
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b0],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b1],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b2],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b3],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b4],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b5],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b6],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b7],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b8],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b9],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b10],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b11],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b12],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b13],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b14],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b15],
                     (((uint32_t)((GenerateRandomNumber()))) >> 5), 0xFFFD);
} else if (param_rnd <= 0) {
  rtrig = 0;
}

if ((param_clear > 0) && !ctrig) {
  ctrig = 1;
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b0], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b1], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b2], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b3], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b4], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b5], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b6], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b7], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b8], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b9], 0, 0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b10], 0,
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b11], 0,
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b12], 0,
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b13], 0,
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b14], 0,
                     0xFFFD);
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_b15], 0,
                     0xFFFD);
} else if (param_clear <= 0) {
  ctrig = 0;
}

Privacy

© 2024 Zrna Research