dirlist

load table from sdcard
Author: Johannes Taelman
License: BSD
Github: rbrt/testing/dirlist.axo

Inlets

bool32.rising trigger

bool32.rising delete

int32.positive index

Outlets

int32 test

charptr32 OUT1

charptr32 out2

charptr32 out3

charptr32 out4

bool32 trig

Attributes

table filter

Declaration
bool trig;
bool dtrig;
bool test;
bool redraw;
int count;

char out1[9];
char out2[9];
char out3[9];
char out4[9];

uint8_t pre;
char old_n[16];
char new_n[16];
char wrk[3];
uint8_t *fout;
Init
static uint8_t _fout[attr_poly][512] __attribute__((section(".sdram")));
fout = &_fout[parent->polyIndex][0];
int i;
for (i = 0; i < 512; i++)
  fout[i] = 0;

char att[4];
strcpy(&att[0], "attr_filter");
strncpy(&wrk[0], &att[1], 1);
strncpy(&wrk[1], &att[2], 1);
strncpy(&wrk[2], &att[3], 1);
Control Rate
outlet_trig = 0;
FIL FileObject;
FRESULT res;
FILINFO fno;
DIR dir;

#if _USE_LFN
fno.lfname = 0;
fno.lfsize = 0;
#endif

if ((inlet_getDir && !trig) || redraw) {
  memset(&fout[0], 0, 512);
  trig = 1;
  count = 0;
  f_opendir(&dir, "/");
  for (;;) {
    res = f_readdir(&dir, &fno);
    if (res != FR_OK || fno.fname[0] == 0)
      break;
    if (count < 128) {
      int len = strlen(fno.fname);
      if ((fno.fname[len - 3] == wrk[0]) && (fno.fname[len - 2] == wrk[1]) &&
          (fno.fname[len - 1] == wrk[2])) {
        memcpy(&fout[count << 3], fno.fname, ((len - 4) > 0) ? (len - 4) : 1);
        count++;
      }
    }
  }
}

if (!inlet_getDir)
  trig = 0;
outlet_test = count;

if ((inlet_index != pre) || redraw) {
  redraw = 0;
  pre = inlet_index;
  memcpy(&out1[0], &fout[(pre + 0) << 3], 8);
  memcpy(&out2[0], &fout[(pre + 1) << 3], 8);
  memcpy(&out3[0], &fout[(pre + 2) << 3], 8);
  memcpy(&out4[0], &fout[(pre + 3) << 3], 8);
  outlet_trig = 1;
}

if (inlet_delete && !dtrig) {
  redraw = 1;
  dtrig = 1;
  old_n[0] = '/';
  new_n[0] = '/';
  strcpy(&old_n[1], &out1[0]);
  strcpy(&new_n[1], &out1[0]);
  strcat(&old_n[0], "attr_filter");
  strcat(&new_n[0], ".xxx");
  f_rename(&old_n[0], &new_n[0]);
}
if (!inlet_delete)
  dtrig = 0;

outlet_OUT1 = &out1[0];
outlet_out2 = &out2[0];
outlet_out3 = &out3[0];
outlet_out4 = &out4[0];

Privacy

© 2024 Zrna Research