You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to create a function which loads all samples from sd card.
This is what i have now:
void mf_LoadSample(char *fileName, int offset) {
if (fileName[0] != '.') {
char filePath[64];
static const char *dirName = "/samples/";
strcpy(filePath, dirName);
strcat(filePath, fileName);
Serial.printf("mf_LoadSample with filename %s \n", filePath);
// Sampler_LoadPatchFile(filePath);
}
}
void mf_LoadAvailableSamples() {
Serial.printf("List all .wav filenames in /samples:\n");
PatchManager_GetFileListExt(mf_LoadSample, 0);
}
When I run mf_LoadAvailableSamples() I get all wav file paths in the serial output of the mf_LoadSample() function.
The problem is, that as soon as I uncomment the Sampler_LoadPatchFile(filePath); line in the mf_LoadSample function
only the first sample is loaded. The rest is just ignored.
I think it has somehow to do with that the mf_LoadSample function is passed as a callback but I dont know how to solve the problem. Or is there a problem with missing termination characters?
Can someone help me?
Thanks in advance,
paul
I did it now in a way which seems to me very memory wasting, I can imagine there are much nicer ways to do it, but it works. Please let me know if you know better ways of doing it.
const uint8_t MAX_COLLECTED_FILES = 99;
char collectedFileNames[MAX_COLLECTED_FILES][64];
uint8_t collectCounter = 0;
void mf_CollectWavFile(char *fileName, int offset) {
if (fileName[0] != '.') {
char filePath[64];
filePath[0] = '\0';
static const char *dirName = "/samples/";
strcpy(filePath, dirName);
strcat(filePath, fileName);
Serial.printf("Collect sample with filename %s \n", filePath);
strcpy(collectedFileNames[collectCounter], filePath);
collectCounter++;
}
}
void mf_LoadAvailableSamples() {
// Init empty filenames
for (uint8_t i = 0; i < 100; i++) {
collectedFileNames[i][0] = 0;
}
// Start Collecting all available Filenames
PatchManager_GetFileListExt(mf_CollectWavFile, 0);
// Load wav files
for (uint8_t i = 0; i < MAX_COLLECTED_FILES; i++) {
if (collectedFileNames[i][0] != 0) {
Serial.printf("Load sample with filename %s \n", collectedFileNames[i]);
Sampler_LoadPatchFile(collectedFileNames[i]);
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I am trying to create a function which loads all samples from sd card.
This is what i have now:
When I run mf_LoadAvailableSamples() I get all wav file paths in the serial output of the mf_LoadSample() function.
The problem is, that as soon as I uncomment the Sampler_LoadPatchFile(filePath); line in the mf_LoadSample function
only the first sample is loaded. The rest is just ignored.
I think it has somehow to do with that the mf_LoadSample function is passed as a callback but I dont know how to solve the problem. Or is there a problem with missing termination characters?
Can someone help me?
Thanks in advance,
paul
I did it now in a way which seems to me very memory wasting, I can imagine there are much nicer ways to do it, but it works. Please let me know if you know better ways of doing it.
Beta Was this translation helpful? Give feedback.
All reactions