mkxp/src/fluid-fun.cpp

74 lines
1.2 KiB
C++
Raw Normal View History

#include "fluid-fun.h"
#include <string.h>
#include <SDL_loadso.h>
#include <SDL_platform.h>
#include "debugwriter.h"
#ifdef SHARED_FLUID
#include <fluidsynth.h>
#endif
#ifdef __LINUX__
#define FLUID_LIB "libfluidsynth.so.1"
#elif __MACOSX__
#define FLUID_LIB "libfluidsynth.dylib.1"
#elif __WINDOWS__
#define FLUID_LIB "fluidsynth.dll"
#else
#error "platform not recognized"
#endif
struct FluidFunctions fluid;
static void *so;
void initFluidFunctions()
{
#ifdef SHARED_FLUID
#define FLUID_FUN(name, type) \
fluid.name = fluid_##name;
#define FLUID_FUN2(name, type, real_name) \
fluid.name = real_name;
#else
so = SDL_LoadObject(FLUID_LIB);
if (!so)
goto fail;
#define FLUID_FUN(name, type) \
fluid.name = (type) SDL_LoadFunction(so, "fluid_" #name); \
if (!fluid.name) \
goto fail;
#define FLUID_FUN2(name, type, real_name) \
fluid.name = (type) SDL_LoadFunction(so, #real_name); \
if (!fluid.name) \
goto fail;
#endif
FLUID_FUNCS
FLUID_FUNCS2
return;
#ifndef SHARED_FLUID
fail:
Debug() << "Failed to load " FLUID_LIB ". Midi playback is disabled.";
memset(&fluid, 0, sizeof(fluid));
finiFluidFunctions();
#endif
}
void finiFluidFunctions()
{
#ifndef SHARED_FLUID
SDL_UnloadObject(so);
#endif
}