dynamic_fluidsynth.c 3.3 KB

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