Want to silence an error when loading soundfile
In this section https://github.com/grame-cncm/faust/blob/ae83d2718b2731ec4cb928cae74932b214314f09/architecture/faust/gui/Soundfile.h#L180-L192
when loading a soundfile with a relative path, I've noticed that checkFile(file_name) returns false and prints to cerr:
ERROR : cannot open 'snare.wav' (System error : The system cannot find the file specified.)
But then the next section of code looks for the file in sound_directories and succeeds. Can we silence the first error?
Can you prepare a PR for that ? Thanks.
I traced it to a usage of snprintf https://github.com/libsndfile/libsndfile/blob/9349a566e298ef6d6bed6c275dc1f5502bb2e028/src/file_io.c#L130 and https://github.com/libsndfile/libsndfile/blob/9349a566e298ef6d6bed6c275dc1f5502bb2e028/src/file_io.c#L616 but I don't know how to "ignore" some other function's call to snprintf. Someone suggested making a "shim" for it, which I'll look into more.
It might be best to check if the file exists and avoid calling sf_open https://github.com/grame-cncm/faust/blob/6ea29c8009273439232231185407ab676fe2e7dd/architecture/faust/gui/LibsndfileReader.h#L148
@sletz what do you think about using std::filesystem::exists to check if the file exists before calling sf_open? I can try that if you think it's a good idea.
Some pseudocode
#ifdef __cpp_lib_filesystem
#include <filesystem>
using fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem
#include <experimental/filesystem>
using fs = std::experimental::filesystem;
#else
// no file system support
#endif
bool checkFile(const std::string& path_name)
{
#if (defined(__cpp_lib_filesystem) || defined(__cpp_lib_experimental_filesystem))
if (!fs::exists(path_name) {
return false;
}
#endif
SF_INFO snd_info;
snd_info.format = 0;
SNDFILE* snd_file = sf_open(path_name.c_str(), SFM_READ, &snd_info);
return checkFileAux(snd_file, path_name);
}
OK for that.
Reopening because I think the changes to LibsndfileReader.h in this commit https://github.com/grame-cncm/faust/commit/ee1cd4adc1d0d8213fecdbbd7c6d51b09970439e got lost
Never mind. They're there. I need to identify what's causing something.