I’m using osdialog_file to save a file. In my testing on windows, it does not force the user to enter a path that matches one of the filters, so I need to have logic that adds the file extension if missing.
But now I am supporting multiple file formats and I don’t know how to tell which file type the user has selected.
static const char FILE_FILTERS[] = "Wave (.wav):wav,WAV;Aiff (.aiff .aif):aiff,AIFF,aif,AIF";
void saveDialog() {
osdialog_filters* filters = osdialog_filters_parse(FILE_FILTERS);
DEFER({osdialog_filters_free(filters);});
char* pathC = osdialog_file(OSDIALOG_SAVE, fileDir.empty() ? NULL : fileDir.c_str(), NULL, filters);
if (!pathC) {
// Fail silently
return;
}
std::string path = pathC;
std::free(pathC);
//***
//This section no longer works since I want to support two different file types
//***
if (system::getExtension(path) != ".wav") {
path += ".wav";
}
//***
fileDir = system::getDirectory(path);
MyModule* module = dynamic_cast<MyModule*>(this->module);
module->saveSample(path);
}
Can you elaborate why you need the choice for type in your module?
The .aiff is mostly used with Logic Users as it’s still the default in that DAW. But Logic opens .wav files totally fine and even let’s you change the default file type to .wav.
So I get why you’d want to support „loading“ aiff files (ie. Sample playback) but why save to that format?
Knowing you, there’s probably a solid reason that I can’t think of right now