Fluidsynth: support relative paths in soundfont_dir

to enable the AppImage to find its own bundled soundfont file
This commit is contained in:
Fabian Greffrath 2023-09-17 22:20:33 +02:00
parent d447d1e5af
commit 60030a8d4f
2 changed files with 22 additions and 3 deletions

View File

@ -36,6 +36,7 @@
#include "w_wad.h" #include "w_wad.h"
#include "z_zone.h" #include "z_zone.h"
#include "i_glob.h" #include "i_glob.h"
#include "d_iwad.h" // [FG] D_DoomExeDir()
char *soundfont_path = ""; char *soundfont_path = "";
char *soundfont_dir = ""; char *soundfont_dir = "";
@ -124,8 +125,19 @@ static void AddSoundFont(const char *path)
static void ScanDir(const char *dir) static void ScanDir(const char *dir)
{ {
glob_t *glob = I_StartMultiGlob(dir, GLOB_FLAG_NOCASE|GLOB_FLAG_SORTED, char *rel = NULL;
glob_t *glob;
// [FG] relative to the executable directory
if (dir[0] == '.')
{
rel = M_StringJoin(D_DoomExeDir(), DIR_SEPARATOR_S, dir, NULL);
dir = rel;
}
glob = I_StartMultiGlob(dir, GLOB_FLAG_NOCASE|GLOB_FLAG_SORTED,
"*.sf2", "*.sf3", NULL); "*.sf2", "*.sf3", NULL);
while(1) while(1)
{ {
const char *filename = I_NextGlob(glob); const char *filename = I_NextGlob(glob);
@ -139,6 +151,11 @@ static void ScanDir(const char *dir)
} }
I_EndGlob(glob); I_EndGlob(glob);
if (rel)
{
free(rel);
}
} }
static void GetSoundFonts(void) static void GetSoundFonts(void)

View File

@ -484,7 +484,9 @@ default_t defaults[] = {
{.s = "/usr/share/soundfonts:" {.s = "/usr/share/soundfonts:"
/* Debian/Ubuntu/OpenSUSE */ /* Debian/Ubuntu/OpenSUSE */
"/usr/share/sounds/sf2:" "/usr/share/sounds/sf2:"
"/usr/share/sounds/sf3"}, "/usr/share/sounds/sf3:"
/* AppImage */
"../share/" PROJECT_SHORTNAME "/soundfonts"},
#endif #endif
{0}, string, ss_none, wad_no, {0}, string, ss_none, wad_no,
"FluidSynth soundfont directories" "FluidSynth soundfont directories"