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