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