dynamic_fluidsynth.c
changeset 506 586ae09f8176
child 518 8bc9b5fd2aae
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dynamic_fluidsynth.c	Sun Mar 20 14:34:18 2011 +0000
     1.3 @@ -0,0 +1,85 @@
     1.4 +/*
     1.5 +    SDL_mixer:  An audio mixer library based on the SDL library
     1.6 +    Copyright (C) 1997-2011 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    James Le Cuirot
    1.23 +    chewi@aura-online.co.uk
    1.24 +*/
    1.25 +
    1.26 +#ifdef USE_FLUIDSYNTH_MIDI
    1.27 +
    1.28 +#include "SDL_loadso.h"
    1.29 +#include "dynamic_fluidsynth.h"
    1.30 +
    1.31 +fluidsynth_loader fluidsynth = {
    1.32 +	0, NULL
    1.33 +};
    1.34 +
    1.35 +#ifdef FLUIDSYNTH_DYNAMIC
    1.36 +#define FLUIDSYNTH_LOADER(FUNC, SIG) \
    1.37 +	fluidsynth.FUNC = (SIG) SDL_LoadFunction(fluidsynth.handle, #FUNC); \
    1.38 +	if (fluidsynth.FUNC == NULL) { SDL_UnloadObject(fluidsynth.handle); return -1; }
    1.39 +#else
    1.40 +#define FLUIDSYNTH_LOADER(FUNC, SIG) \
    1.41 +	fluidsynth.FUNC = FUNC;
    1.42 +#endif
    1.43 +
    1.44 +int Mix_InitFluidSynth()
    1.45 +{
    1.46 +	if ( fluidsynth.loaded == 0 ) {
    1.47 +#ifdef FLUIDSYNTH_DYNAMIC
    1.48 +		fluidsynth.handle = SDL_LoadObject(FLUIDSYNTH_DYNAMIC);
    1.49 +		if ( fluidsynth.handle == NULL ) return -1;
    1.50 +#endif
    1.51 +
    1.52 +		FLUIDSYNTH_LOADER(delete_fluid_player, int (*)(fluid_player_t*));
    1.53 +		FLUIDSYNTH_LOADER(delete_fluid_settings, void (*)(fluid_settings_t*));
    1.54 +		FLUIDSYNTH_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*));
    1.55 +		FLUIDSYNTH_LOADER(fluid_player_add, int (*)(fluid_player_t*, const char*));
    1.56 +		FLUIDSYNTH_LOADER(fluid_player_add_mem, int (*)(fluid_player_t*, const void*, size_t));
    1.57 +		FLUIDSYNTH_LOADER(fluid_player_get_status, int (*)(fluid_player_t*));
    1.58 +		FLUIDSYNTH_LOADER(fluid_player_play, int (*)(fluid_player_t*));
    1.59 +		FLUIDSYNTH_LOADER(fluid_player_set_loop, int (*)(fluid_player_t*, int));
    1.60 +		FLUIDSYNTH_LOADER(fluid_player_stop, int (*)(fluid_player_t*));
    1.61 +		FLUIDSYNTH_LOADER(fluid_settings_setnum, int (*)(fluid_settings_t*, const char*, double));
    1.62 +		FLUIDSYNTH_LOADER(fluid_synth_get_settings, fluid_settings_t* (*)(fluid_synth_t*));
    1.63 +		FLUIDSYNTH_LOADER(fluid_synth_set_gain, void (*)(fluid_synth_t*, float));
    1.64 +		FLUIDSYNTH_LOADER(fluid_synth_sfload, int(*)(fluid_synth_t*, const char*, int));
    1.65 +		FLUIDSYNTH_LOADER(fluid_synth_write_s16, int(*)(fluid_synth_t*, int, void*, int, int, void*, int, int));
    1.66 +		FLUIDSYNTH_LOADER(new_fluid_player, fluid_player_t* (*)(fluid_synth_t*));
    1.67 +		FLUIDSYNTH_LOADER(new_fluid_settings, fluid_settings_t* (*)(void));
    1.68 +		FLUIDSYNTH_LOADER(new_fluid_synth, fluid_synth_t* (*)(fluid_settings_t*));
    1.69 +	}
    1.70 +	++fluidsynth.loaded;
    1.71 +
    1.72 +	return 0;
    1.73 +}
    1.74 +
    1.75 +void Mix_QuitFluidSynth()
    1.76 +{
    1.77 +	if ( fluidsynth.loaded == 0 ) {
    1.78 +		return;
    1.79 +	}
    1.80 +	if ( fluidsynth.loaded == 1 ) {
    1.81 +#ifdef FLUIDSYNTH_DYNAMIC
    1.82 +		SDL_UnloadObject(fluidsynth.handle);
    1.83 +#endif
    1.84 +	}
    1.85 +	--fluidsynth.loaded;
    1.86 +}
    1.87 +
    1.88 +#endif /* USE_FLUIDSYNTH_MIDI */