polycountMan

variable stage-beatlength counter. This module functions like the polycount module, but has a manual control for the length of each stage instead of being randomly generated. Set the internal table for the beatlength with the dedicated external module (arrayEdit module). -trig: connect main clock trigger (advisable to use my sss/midi/clock module to sync to midi-host->also outputs beat-sample-length for use with other modules). -r: connect to a reset source ("active" on midiclock, some clockdivider or manual button). -count: outputs the beat-count within each stage. Each new stage, this count will restart and count up to the stage-lenght. -steps: outputs the beat-length of the current stage (how many steps the count has in total of current stage). -stage: outputs the current stage-index number. -c: outputs a trigger each time the stage advances. -rst: outputs a trigger when all stages are completed and restarts at stage zero. -length attribute: sets the maximum length of a single pattern. -pattern attribute: sets the maximum amount of patterns to be made. -pattern input/control: sets which pattern to be read from the table. This is scaled to the max amount of patterns, this enables easy midi-control!
Author: Remco van der Most
License: BSD
Github: sss/logic/polycountMan.axo

Inlets

charptr32 filename

bool32.rising trigger

bool32.rising reset

bool32 save

bool32 load

Outlets

int32 count

int32 output

int32 stage

bool32.pulse carry pulse

bool32 rst

Parameters

frac32.u.map pattern

bool32.mom save

bool32.mom load

Attributes

spinner maxstages

spinner patterns

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

int ntrig;
int rtrig;
int count;
int cnt;
int length;
int rst;
int ltrig;
int strig;
Init
static uint8_t _array[LENGTH * patt] __attribute__((section(".sdram")));
array = &_array[0];

count = 0;
ntrig = 0;
rtrig = 0;
cnt = 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;

outlet_c = 0;
int32_t Patt = ___SMMUL(__USAT(param_pattern, 27) << 2, patt - 1 << 3);
Patt = Patt - Patt / patt * patt;
Patt = Patt * LENGTH;
rst = 0;
if ((inlet_r > 0) && !rtrig) {
  count = -1;
  cnt = -1;
  rst = 1;
  rtrig = 1;
} else if (!(inlet_r > 0))
  rtrig = 0;
if ((inlet_trig > 0) && !ntrig) {
  count += 1;
  if (count >= array[(cnt >= 0 ? cnt : 0) + Patt]) {
    cnt += 1;
    cnt = cnt - cnt / length * length;
    count = 0;
    outlet_c = 1;
  }
  ntrig = 1;
} else if (!(inlet_trig > 0))
  ntrig = 0;
outlet_rst = (cnt == 0 ? 1 : 0) || rst;
outlet_steps = array[(cnt >= 0 ? cnt : 0) + Patt];
outlet_count = count;
outlet_stage = cnt;

Privacy

© 2024 Zrna Research