dynamic_fluidsynth.c
author James Le Cuirot <chewi@aura-online.co.uk>
Sun, 20 Mar 2011 14:34:18 +0000
changeset 506 586ae09f8176
child 518 8bc9b5fd2aae
permissions -rw-r--r--
Add FluidSynth backend and generic SoundFont functions. No FluidSynth DLL or headers for MSVC in this commit.
chewi@506
     1
/*
chewi@506
     2
    SDL_mixer:  An audio mixer library based on the SDL library
chewi@506
     3
    Copyright (C) 1997-2011 Sam Lantinga
chewi@506
     4
chewi@506
     5
    This library is free software; you can redistribute it and/or
chewi@506
     6
    modify it under the terms of the GNU Library General Public
chewi@506
     7
    License as published by the Free Software Foundation; either
chewi@506
     8
    version 2 of the License, or (at your option) any later version.
chewi@506
     9
chewi@506
    10
    This library is distributed in the hope that it will be useful,
chewi@506
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
chewi@506
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
chewi@506
    13
    Library General Public License for more details.
chewi@506
    14
chewi@506
    15
    You should have received a copy of the GNU Library General Public
chewi@506
    16
    License along with this library; if not, write to the Free
chewi@506
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
chewi@506
    18
chewi@506
    19
    James Le Cuirot
chewi@506
    20
    chewi@aura-online.co.uk
chewi@506
    21
*/
chewi@506
    22
chewi@506
    23
#ifdef USE_FLUIDSYNTH_MIDI
chewi@506
    24
chewi@506
    25
#include "SDL_loadso.h"
chewi@506
    26
#include "dynamic_fluidsynth.h"
chewi@506
    27
chewi@506
    28
fluidsynth_loader fluidsynth = {
chewi@506
    29
	0, NULL
chewi@506
    30
};
chewi@506
    31
chewi@506
    32
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    33
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
chewi@506
    34
	fluidsynth.FUNC = (SIG) SDL_LoadFunction(fluidsynth.handle, #FUNC); \
chewi@506
    35
	if (fluidsynth.FUNC == NULL) { SDL_UnloadObject(fluidsynth.handle); return -1; }
chewi@506
    36
#else
chewi@506
    37
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
chewi@506
    38
	fluidsynth.FUNC = FUNC;
chewi@506
    39
#endif
chewi@506
    40
chewi@506
    41
int Mix_InitFluidSynth()
chewi@506
    42
{
chewi@506
    43
	if ( fluidsynth.loaded == 0 ) {
chewi@506
    44
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    45
		fluidsynth.handle = SDL_LoadObject(FLUIDSYNTH_DYNAMIC);
chewi@506
    46
		if ( fluidsynth.handle == NULL ) return -1;
chewi@506
    47
#endif
chewi@506
    48
chewi@506
    49
		FLUIDSYNTH_LOADER(delete_fluid_player, int (*)(fluid_player_t*));
chewi@506
    50
		FLUIDSYNTH_LOADER(delete_fluid_settings, void (*)(fluid_settings_t*));
chewi@506
    51
		FLUIDSYNTH_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*));
chewi@506
    52
		FLUIDSYNTH_LOADER(fluid_player_add, int (*)(fluid_player_t*, const char*));
chewi@506
    53
		FLUIDSYNTH_LOADER(fluid_player_add_mem, int (*)(fluid_player_t*, const void*, size_t));
chewi@506
    54
		FLUIDSYNTH_LOADER(fluid_player_get_status, int (*)(fluid_player_t*));
chewi@506
    55
		FLUIDSYNTH_LOADER(fluid_player_play, int (*)(fluid_player_t*));
chewi@506
    56
		FLUIDSYNTH_LOADER(fluid_player_set_loop, int (*)(fluid_player_t*, int));
chewi@506
    57
		FLUIDSYNTH_LOADER(fluid_player_stop, int (*)(fluid_player_t*));
chewi@506
    58
		FLUIDSYNTH_LOADER(fluid_settings_setnum, int (*)(fluid_settings_t*, const char*, double));
chewi@506
    59
		FLUIDSYNTH_LOADER(fluid_synth_get_settings, fluid_settings_t* (*)(fluid_synth_t*));
chewi@506
    60
		FLUIDSYNTH_LOADER(fluid_synth_set_gain, void (*)(fluid_synth_t*, float));
chewi@506
    61
		FLUIDSYNTH_LOADER(fluid_synth_sfload, int(*)(fluid_synth_t*, const char*, int));
chewi@506
    62
		FLUIDSYNTH_LOADER(fluid_synth_write_s16, int(*)(fluid_synth_t*, int, void*, int, int, void*, int, int));
chewi@506
    63
		FLUIDSYNTH_LOADER(new_fluid_player, fluid_player_t* (*)(fluid_synth_t*));
chewi@506
    64
		FLUIDSYNTH_LOADER(new_fluid_settings, fluid_settings_t* (*)(void));
chewi@506
    65
		FLUIDSYNTH_LOADER(new_fluid_synth, fluid_synth_t* (*)(fluid_settings_t*));
chewi@506
    66
	}
chewi@506
    67
	++fluidsynth.loaded;
chewi@506
    68
chewi@506
    69
	return 0;
chewi@506
    70
}
chewi@506
    71
chewi@506
    72
void Mix_QuitFluidSynth()
chewi@506
    73
{
chewi@506
    74
	if ( fluidsynth.loaded == 0 ) {
chewi@506
    75
		return;
chewi@506
    76
	}
chewi@506
    77
	if ( fluidsynth.loaded == 1 ) {
chewi@506
    78
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    79
		SDL_UnloadObject(fluidsynth.handle);
chewi@506
    80
#endif
chewi@506
    81
	}
chewi@506
    82
	--fluidsynth.loaded;
chewi@506
    83
}
chewi@506
    84
chewi@506
    85
#endif /* USE_FLUIDSYNTH_MIDI */