IO

Author:
License: GPL
Github: rbrt/smplr/IO.axo

Inlets

frac32.positive offset

frac32.positive range

int32.positive toSlot

charptr32 filename

charptr32 sampleName

bool32.rising save

bool32.rising load

bool32.rising delete

bool32.rising trash

bool32.rising saveSample

bool32.rising loadSample

Outlets

None

Attributes

objref smplr

objref SDapi

combo directory

combo loadSlotAndDefrag

Declaration
bool trig;
bool load;
bool save;
int rem_sz;
uint8_t bytes;
int prev;
char fn[16];
char df[16];

// prepare filename
void prep_name(const char *fname, const char *suffix)
    __attribute__((noinline)) {
  memset(&fn[0], 0, 16);
  if (attr_directory)
    strcpy(&fn[0], "/");
  memcpy(&fn[attr_directory], &fname[0], 8);
  strcat(&fn[0], suffix);
}
Init
bytes = sizeof(*attr_smplr.WAVE);
Control Rate
if (inlet_delete && !trig) {
  trig = 1;
  prep_name(inlet_filename, ".raw");
  attr_SDapi.fdelete(fn);
  prep_name(inlet_filename, ".lpr");
  attr_SDapi.fdelete(fn);
  prep_name(inlet_filename, ".glb");
  attr_SDapi.fdelete(fn);
}

if (inlet_trash && !trig) {
  trig = 1;
  prep_name(inlet_filename, ".xxx");
  strcpy(df, fn);
  prep_name(inlet_filename, ".lpr");
  attr_SDapi.frename(fn, df);
}

if (inlet_load && !trig) {
  trig = 1;
  prep_name(inlet_filename, ".glb");
  attr_SDapi.fload(fn, (char *)&attr_smplr.GLOBAL[0], 64);
  prep_name(inlet_filename, ".raw");
  rem_sz = attr_smplr.REC_HEAD * bytes;
  attr_SDapi.fload(fn, (char *)&attr_smplr.WAVE[0], rem_sz);
  prep_name(inlet_filename, ".lpr");
  attr_SDapi.fload(fn, (char *)&attr_smplr.array[0], 16384);
}
if (inlet_save && !trig) {
  trig = 1;
  attr_smplr.defrag();
  prep_name(inlet_filename, ".glb");
  attr_SDapi.fsave(fn, (char *)&attr_smplr.GLOBAL[0], 64);
  rem_sz = attr_smplr.REC_HEAD * bytes;
  prep_name(inlet_filename, ".raw");
  attr_SDapi.fsave(fn, (char *)&attr_smplr.WAVE[0], rem_sz);
  prep_name(inlet_filename, ".lpr");
  attr_SDapi.fsave(fn, (char *)&attr_smplr.array[0], 16384);
}

if (inlet_saveSample && !trig) {
  trig = 1;
  rem_sz = (inlet_range >> attr_smplr.SHIFT) * bytes;
  prep_name(inlet_sampleName, ".raw");
  attr_SDapi.fsave(
      fn, (char *)&attr_smplr.WAVE[inlet_offset >> attr_smplr.SHIFT], rem_sz);
}

if (inlet_loadSample && !trig) {
  trig = 1;
  attr_smplr.delete_slot(inlet_toSlot);
  if (attr_loadSlotAndDefrag)
    (attr_smplr.defrag());
  prep_name(inlet_sampleName, ".raw");
  int filesize = attr_SDapi.fsize(fn);
  int dstsize = (attr_smplr.W_LENGTH - attr_smplr.REC_HEAD) * bytes;
  rem_sz = (filesize > dstsize) ? dstsize : filesize;
  attr_SDapi.fload(fn, (char *)&attr_smplr.WAVE[attr_smplr.REC_HEAD], rem_sz);
  attr_smplr.array[(inlet_toSlot << 5) + 28] = attr_smplr.REC_HEAD;
  attr_smplr.array[(inlet_toSlot << 5) + 29] =
      (rem_sz / bytes) + attr_smplr.REC_HEAD;
  attr_smplr.array[(inlet_toSlot << 5) + 30] = 1;
  attr_smplr.REC_HEAD += (rem_sz / bytes);
}

if (!inlet_load && !inlet_save && !inlet_delete && !inlet_trash &&
    !inlet_saveSample && !inlet_loadSample)
  trig = 0;

Privacy

© 2024 Zrna Research