int32.positive slot
bool32.rising trig
bool32.rising clear the recorders data
bool32.rising defrag
bool32.rising save
bool32.rising load
bool32.risingfalling copy
bool32.risingfalling move
bool32.risingfalling delete
int32 test
bool32 delete
bool32 done
combo size
uint8_t SHIFT;
bool REC;
bool RECSTATE;
uint8_t RECSLOT;
int32_t RECPOS;
uint32_t *array;
int16_t *WAVE;
static const uint32_t W_LENGTHPOW = (attr_size);
static const uint32_t W_LENGTH = (1 << attr_size);
static const uint32_t W_LENGTHMASK = ((1 << attr_size) - 1);
static const uint32_t LENGTHPOW = (13);
static const uint32_t LENGTH = (1 << 13);
static const uint32_t LENGTHMASK = ((1 << 13) - 1);
static const uint32_t GAIN = 0;
static const uint32_t BITS = 32;
bool ctrig;
bool dtrig;
bool cpytrig;
bool cpytemptrig;
bool del;
bool clrtrig;
bool mtrig;
bool move;
uint8_t mslot;
uint8_t srcslot;
bool deletetrig;
bool copytrig;
uint32_t sstart;
uint32_t send;
uint32_t slength;
int32_t paramtemp[32];
uint8_t delcount;
// save + load
char c[64];
int offset;
int pval;
uint8_t index;
bool save;
bool load;
bool busy;
bool trig;
int rem_sz;
char *t_adr;
char fn[32];
void delete_slot(uint8_t target) {
if (array[(target << 5) + 2]) {
sstart = array[target << 5];
send = array[(target << 5) + 1];
int i;
for (i = 0; i < 32; i++)
array[(target << 5) + i] = 0;
bool check = 1;
for (i = 0; i < 127; i++)
if (array[(i << 5) + 1] == send)
check = 0;
if (check) {
array[delcount + 4096] = sstart;
array[delcount + 4350] = send;
delcount++;
}
}
}
SHIFT = (27 - W_LENGTHPOW);
int i;
static uint32_t _array[attr_poly][8192] __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];
for (i = 0; i < 8192; i++)
array[i] = 0;
static int16_t _WAVE[attr_poly][W_LENGTH] __attribute__((section(".sdram")));
WAVE = &_WAVE[parent->polyIndex][0];
for (i = 0; i < W_LENGTH; i++)
WAVE[i] = 0;
mslot = inlet_slot % 126;
outlet_delete = 0;
// delete
if (inlet_delete && inlet_trig && !dtrig) {
delete_slot(mslot);
dtrig = 1;
outlet_delete = 1;
}
// compact
if (inlet_defrag && !ctrig) {
ctrig = 1;
int i;
for (i = 0; i < delcount; i++) {
sstart = array[i + 4096];
send = array[i + 4350];
slength = (send - sstart);
int shift_index;
for (shift_index = 0; shift_index < 4096; shift_index += 32)
if (array[shift_index] >= send) {
array[shift_index] -= slength;
array[shift_index + 1] -= slength;
}
int move_samples;
for (move_samples = send; move_samples < RECPOS; move_samples++)
WAVE[move_samples - slength] = WAVE[move_samples];
int shift_chunks;
for (shift_chunks = 0; shift_chunks < delcount; shift_chunks++)
if (array[shift_chunks + 4096] >= send) {
array[shift_chunks + 4096] -= slength;
array[shift_chunks + 4350] -= slength;
}
RECPOS -= slength;
}
delcount = 0;
}
// paste
if (inlet_trig && cpytemptrig && !cpytrig && (inlet_copy || move)) {
cpytrig = 1;
delete_slot(mslot);
int i;
for (i = 0; i < 32; i++)
array[(mslot << 5) + i] = paramtemp[i];
if (move) {
for (i = 0; i < 32; i++)
array[(srcslot << 5) + i] = 0;
outlet_delete = 1;
move = 0;
}
}
// copy
if (inlet_trig && !cpytemptrig && (inlet_copy || move)) {
cpytemptrig = 1;
srcslot = mslot;
int i;
for (i = 0; i < 32; i++)
paramtemp[i] = array[(mslot << 5) + i];
}
// move
if (inlet_move && !mtrig) {
mtrig = 1;
move = 1;
}
// clear
if (inlet_clear && !clrtrig) {
clrtrig = 1;
delcount = 0;
int i;
for (i = 0; i < 8192; i++)
array[i] = 0;
RECPOS = 0;
}
if (!inlet_copy && !inlet_move)
cpytemptrig = 0;
if (!inlet_move) {
mtrig = 0;
move = 0;
}
if (!inlet_trig) {
cpytrig = 0;
dtrig = 0;
}
if (!inlet_clear)
clrtrig = 0;
if (!inlet_defrag)
ctrig = 0;
outlet_test = delcount;
// save + load
outlet_done = 0;
switch (index ? index : 0) {
case 0: {
rem_sz = sizeof(*array) * 8192;
t_adr = (char *)(&array[0]);
memcpy(&fn[0], "sst.prm", 6);
break;
}
case 1: {
rem_sz = sizeof(*WAVE) * W_LENGTH;
t_adr = (char *)(&WAVE[0]);
memcpy(&fn[0], "sst.raw", 6);
break;
}
}
if (inlet_save && !trig) {
save = 1;
index = 0;
busy = 1;
trig = 1;
}
if (!inlet_save && !busy)
trig = 0;
if (save) {
array[4604] = RECPOS;
array[4605] = delcount;
FIL FileObject;
FRESULT err;
UINT bytes_written;
err = f_open(&FileObject, fn, FA_WRITE | FA_CREATE_ALWAYS);
// if (err != FR_OK) {report_fatfs_error(err,fn); save = 0;busy = 0;goto
// ERROR;}
int offset = 0;
while (rem_sz > 0) {
if (rem_sz > sizeof(fbuff)) {
memcpy((char *)fbuff, t_adr + offset, sizeof(fbuff));
err = f_write(&FileObject, fbuff, sizeof(fbuff), &bytes_written);
rem_sz -= sizeof(fbuff);
offset += sizeof(fbuff);
} else {
memcpy((char *)fbuff, t_adr + offset, rem_sz);
err = f_write(&FileObject, fbuff, rem_sz, &bytes_written);
rem_sz = 0;
}
}
if (err != FR_OK)
report_fatfs_error(err, fn);
err = f_close(&FileObject);
if (err != FR_OK)
report_fatfs_error(err, fn);
index++;
if (index == 2) {
save = 0;
busy = 0;
outlet_done = 1;
}
}
if (inlet_load && !trig) {
load = 1;
index = 0;
busy = 1;
trig = 1;
}
if (!inlet_load && !busy)
trig = 0;
if (load) {
FIL FileObject;
FRESULT err;
UINT bytes_read;
err = f_open(&FileObject, fn, FA_READ | FA_OPEN_EXISTING);
// if (err != FR_OK) { report_fatfs_error(err,fn); load = 0;busy = 0;goto
// ERROR;}
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(t_adr + offset, (char *)fbuff, bytes_read);
rem_sz -= bytes_read;
offset += bytes_read;
} else {
err = f_read(&FileObject, fbuff, rem_sz, &bytes_read);
memcpy(t_adr + offset, (char *)fbuff, bytes_read);
rem_sz = 0;
}
}
if (err != FR_OK) {
report_fatfs_error(err, fn);
return;
};
err = f_close(&FileObject);
if (err != FR_OK) {
report_fatfs_error(err, fn);
return;
};
index++;
if (index == 2) {
load = 0;
busy = 0;
outlet_done = 1;
RECPOS = array[4604];
delcount = array[4605];
}
}
ERROR : outlet_test = busy;