dynamic_fluidsynth.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 May 2013 21:21:23 -0700
changeset 617 87116a42526e
parent 601 05123263dab3
child 711 f40c5ac95b12
permissions -rw-r--r--
Cleaned up whitespace for the 2.0.0 release
chewi@506
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@601
     3
  Copyright (C) 1997-2013 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 = {
slouken@617
    31
    0, NULL
chewi@506
    32
};
chewi@506
    33
chewi@506
    34
#ifdef FLUIDSYNTH_DYNAMIC
chewi@506
    35
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
slouken@617
    36
    fluidsynth.FUNC = (SIG) SDL_LoadFunction(fluidsynth.handle, #FUNC); \
slouken@617
    37
    if (fluidsynth.FUNC == NULL) { SDL_UnloadObject(fluidsynth.handle); return -1; }
chewi@506
    38
#else
chewi@506
    39
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
slouken@617
    40
    fluidsynth.FUNC = FUNC;
chewi@506
    41
#endif
chewi@506
    42
chewi@506
    43
int Mix_InitFluidSynth()
chewi@506
    44
{
slouken@617
    45
    if ( fluidsynth.loaded == 0 ) {
chewi@506
    46
#ifdef FLUIDSYNTH_DYNAMIC
slouken@617
    47
        fluidsynth.handle = SDL_LoadObject(FLUIDSYNTH_DYNAMIC);
slouken@617
    48
        if ( fluidsynth.handle == NULL ) return -1;
chewi@506
    49
#endif
chewi@506
    50
slouken@617
    51
        FLUIDSYNTH_LOADER(delete_fluid_player, int (*)(fluid_player_t*));
slouken@617
    52
        FLUIDSYNTH_LOADER(delete_fluid_settings, void (*)(fluid_settings_t*));
slouken@617
    53
        FLUIDSYNTH_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*));
slouken@617
    54
        FLUIDSYNTH_LOADER(fluid_player_add, int (*)(fluid_player_t*, const char*));
slouken@617
    55
        FLUIDSYNTH_LOADER(fluid_player_add_mem, int (*)(fluid_player_t*, const void*, size_t));
slouken@617
    56
        FLUIDSYNTH_LOADER(fluid_player_get_status, int (*)(fluid_player_t*));
slouken@617
    57
        FLUIDSYNTH_LOADER(fluid_player_play, int (*)(fluid_player_t*));
slouken@617
    58
        FLUIDSYNTH_LOADER(fluid_player_set_loop, int (*)(fluid_player_t*, int));
slouken@617
    59
        FLUIDSYNTH_LOADER(fluid_player_stop, int (*)(fluid_player_t*));
slouken@617
    60
        FLUIDSYNTH_LOADER(fluid_settings_setnum, int (*)(fluid_settings_t*, const char*, double));
slouken@617
    61
        FLUIDSYNTH_LOADER(fluid_synth_get_settings, fluid_settings_t* (*)(fluid_synth_t*));
slouken@617
    62
        FLUIDSYNTH_LOADER(fluid_synth_set_gain, void (*)(fluid_synth_t*, float));
slouken@617
    63
        FLUIDSYNTH_LOADER(fluid_synth_sfload, int(*)(fluid_synth_t*, const char*, int));
slouken@617
    64
        FLUIDSYNTH_LOADER(fluid_synth_write_s16, int(*)(fluid_synth_t*, int, void*, int, int, void*, int, int));
slouken@617
    65
        FLUIDSYNTH_LOADER(new_fluid_player, fluid_player_t* (*)(fluid_synth_t*));
slouken@617
    66
        FLUIDSYNTH_LOADER(new_fluid_settings, fluid_settings_t* (*)(void));
slouken@617
    67
        FLUIDSYNTH_LOADER(new_fluid_synth, fluid_synth_t* (*)(fluid_settings_t*));
slouken@617
    68
    }
slouken@617
    69
    ++fluidsynth.loaded;
chewi@506
    70
slouken@617
    71
    return 0;
chewi@506
    72
}
chewi@506
    73
chewi@506
    74
void Mix_QuitFluidSynth()
chewi@506
    75
{
slouken@617
    76
    if ( fluidsynth.loaded == 0 ) {
slouken@617
    77
        return;
slouken@617
    78
    }
slouken@617
    79
    if ( fluidsynth.loaded == 1 ) {
chewi@506
    80
#ifdef FLUIDSYNTH_DYNAMIC
slouken@617
    81
        SDL_UnloadObject(fluidsynth.handle);
chewi@506
    82
#endif
slouken@617
    83
    }
slouken@617
    84
    --fluidsynth.loaded;
chewi@506
    85
}
chewi@506
    86
chewi@506
    87
#endif /* USE_FLUIDSYNTH_MIDI */