8chanceSeq

quad randomisable trigger sequencer Each color has it's own chance.
Author: Remco van der Most
License: BSD
Github: sss/sel/8chanceSeq.axo

Inlets

int32 count

bool32 gate

bool32 save

bool32 load

charptr32 filename

Outlets

bool32 1

bool32 2

bool32 3

bool32 4

bool32 5

bool32 6

bool32 7

bool32 8

Parameters

int2x16 1

int2x16 2

int2x16 3

int2x16 4

int2x16 5

int2x16 6

int2x16 7

int2x16 8

frac32.u.map white

frac32.u.map light

frac32.u.map dark

frac32.u.map black

frac32.u.map pattern

bool32.mom save

bool32.mom load

Attributes

spinner patterns

Declaration
static const uint32_t LENGTH = 8;
static const int patt = attr_patterns;
uint32_t *array;

int select[4];
int gate[8];
int prev;
int ltrig;
int strig;
int prv;
Init
static uint32_t _array[LENGTH * patt] __attribute__((section(".sdram")));
array = &_array[0];
Control Rate
int save = param_save + inlet_save;
int load = param_load + inlet_load;

if ((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) * (LENGTH * patt);
  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 (!(save > 0))
  strig = 0;

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) * (LENGTH * patt);
  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;

int32_t P = ___SMMUL(param_pattern << 3, patt << 2) << 3;
int i;

if (!(prv == P + load)) {
  for (i = 0; i < 8; i++) {
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_1 + i],
                       array[i + P], 0xFFFD);
  }
}

array[P] = param_1;
array[P + 1] = param_2;
array[P + 2] = param_3;
array[P + 3] = param_4;
array[P + 4] = param_5;
array[P + 5] = param_6;
array[P + 6] = param_7;
array[P + 7] = param_8;
select[0] = param_white;
select[1] = param_light;
select[2] = param_dark;
select[3] = param_black;

int count = inlet_count;
if (!(count == prev)) {
  gate[0] = select[param_1 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[1] = select[param_2 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[2] = select[param_3 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[3] = select[param_4 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[4] = select[param_5 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[5] = select[param_6 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[6] = select[param_7 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
  gate[7] = select[param_8 >> (inlet_count << 1) & 3] >
                    ((int32_t)(GenerateRandomNumber() >> 5))
                ? 1
                : 0;
}

outlet_1 = gate[0] && inlet_gate;
outlet_2 = gate[1] && inlet_gate;
outlet_3 = gate[2] && inlet_gate;
outlet_4 = gate[3] && inlet_gate;
outlet_5 = gate[4] && inlet_gate;
outlet_6 = gate[5] && inlet_gate;
outlet_7 = gate[6] && inlet_gate;
outlet_8 = gate[7] && inlet_gate;
prev = count;
prv = P + load;

Privacy

© 2024 Zrna Research