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