dynamic_fluidsynth.c
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 13 Oct 2018 23:02:04 +0300
branchSDL-1.2
changeset 908 6b860486ce24
parent 518 8bc9b5fd2aae
child 601 05123263dab3
permissions -rw-r--r--
Mix_InitMP3: unload dll if mpg123_init() fails.
chewi@506
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@518
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
chewi@506
     4
slouken@518
     5
  This software is provided 'as-is', without any express or implied
slouken@518
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@518
     7
  arising from the use of this software.
chewi@506
     8
slouken@518
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@518
    10
  including commercial applications, and to alter it and redistribute it
slouken@518
    11
  freely, subject to the following restrictions:
chewi@506
    12
slouken@518
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@518
    14
     claim that you wrote the original software. If you use this software
slouken@518
    15
     in a product, an acknowledgment in the product documentation would be
slouken@518
    16
     appreciated but is not required.
slouken@518
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@518
    18
     misrepresented as being the original software.
slouken@518
    19
  3. This notice may not be removed or altered from any source distribution.
chewi@506
    20
slouken@518
    21
  James Le Cuirot
slouken@518
    22
  chewi@aura-online.co.uk
chewi@506
    23
*/
chewi@506
    24
chewi@506
    25
#ifdef USE_FLUIDSYNTH_MIDI
chewi@506
    26
chewi@506
    27
#include "SDL_loadso.h"
chewi@506
    28
#include "dynamic_fluidsynth.h"
chewi@506
    29
chewi@506
    30
fluidsynth_loader fluidsynth = {
chewi@506
    31
	0, NULL
chewi@506
    32
};
chewi@506
    33
chewi@506
    34
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    35
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
chewi@506
    36
	fluidsynth.FUNC = (SIG) SDL_LoadFunction(fluidsynth.handle, #FUNC); \
chewi@506
    37
	if (fluidsynth.FUNC == NULL) { SDL_UnloadObject(fluidsynth.handle); return -1; }
chewi@506
    38
#else
chewi@506
    39
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
chewi@506
    40
	fluidsynth.FUNC = FUNC;
chewi@506
    41
#endif
chewi@506
    42
chewi@506
    43
int Mix_InitFluidSynth()
chewi@506
    44
{
chewi@506
    45
	if ( fluidsynth.loaded == 0 ) {
chewi@506
    46
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    47
		fluidsynth.handle = SDL_LoadObject(FLUIDSYNTH_DYNAMIC);
chewi@506
    48
		if ( fluidsynth.handle == NULL ) return -1;
chewi@506
    49
#endif
chewi@506
    50
chewi@506
    51
		FLUIDSYNTH_LOADER(delete_fluid_player, int (*)(fluid_player_t*));
chewi@506
    52
		FLUIDSYNTH_LOADER(delete_fluid_settings, void (*)(fluid_settings_t*));
chewi@506
    53
		FLUIDSYNTH_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*));
chewi@506
    54
		FLUIDSYNTH_LOADER(fluid_player_add, int (*)(fluid_player_t*, const char*));
chewi@506
    55
		FLUIDSYNTH_LOADER(fluid_player_add_mem, int (*)(fluid_player_t*, const void*, size_t));
chewi@506
    56
		FLUIDSYNTH_LOADER(fluid_player_get_status, int (*)(fluid_player_t*));
chewi@506
    57
		FLUIDSYNTH_LOADER(fluid_player_play, int (*)(fluid_player_t*));
chewi@506
    58
		FLUIDSYNTH_LOADER(fluid_player_set_loop, int (*)(fluid_player_t*, int));
chewi@506
    59
		FLUIDSYNTH_LOADER(fluid_player_stop, int (*)(fluid_player_t*));
chewi@506
    60
		FLUIDSYNTH_LOADER(fluid_settings_setnum, int (*)(fluid_settings_t*, const char*, double));
chewi@506
    61
		FLUIDSYNTH_LOADER(fluid_synth_get_settings, fluid_settings_t* (*)(fluid_synth_t*));
chewi@506
    62
		FLUIDSYNTH_LOADER(fluid_synth_set_gain, void (*)(fluid_synth_t*, float));
chewi@506
    63
		FLUIDSYNTH_LOADER(fluid_synth_sfload, int(*)(fluid_synth_t*, const char*, int));
chewi@506
    64
		FLUIDSYNTH_LOADER(fluid_synth_write_s16, int(*)(fluid_synth_t*, int, void*, int, int, void*, int, int));
chewi@506
    65
		FLUIDSYNTH_LOADER(new_fluid_player, fluid_player_t* (*)(fluid_synth_t*));
chewi@506
    66
		FLUIDSYNTH_LOADER(new_fluid_settings, fluid_settings_t* (*)(void));
chewi@506
    67
		FLUIDSYNTH_LOADER(new_fluid_synth, fluid_synth_t* (*)(fluid_settings_t*));
chewi@506
    68
	}
chewi@506
    69
	++fluidsynth.loaded;
chewi@506
    70
chewi@506
    71
	return 0;
chewi@506
    72
}
chewi@506
    73
chewi@506
    74
void Mix_QuitFluidSynth()
chewi@506
    75
{
chewi@506
    76
	if ( fluidsynth.loaded == 0 ) {
chewi@506
    77
		return;
chewi@506
    78
	}
chewi@506
    79
	if ( fluidsynth.loaded == 1 ) {
chewi@506
    80
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    81
		SDL_UnloadObject(fluidsynth.handle);
chewi@506
    82
#endif
chewi@506
    83
	}
chewi@506
    84
	--fluidsynth.loaded;
chewi@506
    85
}
chewi@506
    86
chewi@506
    87
#endif /* USE_FLUIDSYNTH_MIDI */