wyatt8740

SDL fluidsynth soundfonts patch

Feb 2nd, 2015
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 35.03 KB | None | 0 0
  1. # HG changeset patch
  2. # User James Le Cuirot <[email protected]>
  3. # Date 1300631658 0
  4. # Node ID 586ae09f8176d138751c694636c169d016b0fb66
  5. # Parent  5b24d089d9f5577d5cce615da0b523c31216b8ac
  6. Add FluidSynth backend and generic SoundFont functions. No FluidSynth DLL or headers for MSVC in this commit.
  7.  
  8. diff -r 5b24d089d9f5 -r 586ae09f8176 Makefile.in
  9. --- a/Makefile.in   Tue Mar 15 23:11:29 2011 -0700
  10. +++ b/Makefile.in   Sun Mar 20 14:34:18 2011 +0000
  11. @@ -39,7 +39,7 @@
  12.  PLAYWAVE_OBJECTS = @PLAYWAVE_OBJECTS@
  13.  PLAYMUS_OBJECTS = @PLAYMUS_OBJECTS@
  14.  
  15. -DIST = Android.mk CHANGES COPYING CWProjects.sea.bin MPWmake.sea.bin Makefile.in SDL_mixer.pc.in README SDL_mixer.h SDL_mixer.qpg.in SDL_mixer.spec SDL_mixer.spec.in VisualC.zip Watcom-OS2.zip Xcode.tar.gz acinclude autogen.sh build-scripts configure configure.in dynamic_flac.c dynamic_flac.h dynamic_mod.c dynamic_mod.h dynamic_mp3.c dynamic_mp3.h dynamic_ogg.c dynamic_ogg.h effect_position.c effect_stereoreverse.c effects_internal.c effects_internal.h gcc-fat.sh libmikmod-3.1.12.zip load_aiff.c load_aiff.h load_flac.c load_flac.h load_ogg.c load_ogg.h load_voc.c load_voc.h mixer.c music.c music_cmd.c music_cmd.h music_flac.c music_flac.h music_mad.c music_mad.h music_mod.c music_mod.h music_modplug.c music_modplug.h music_ogg.c music_ogg.h native_midi native_midi_gpl playmus.c playwave.c timidity wavestream.c wavestream.h version.rc
  16. +DIST = Android.mk CHANGES COPYING CWProjects.sea.bin MPWmake.sea.bin Makefile.in SDL_mixer.pc.in README SDL_mixer.h SDL_mixer.qpg.in SDL_mixer.spec SDL_mixer.spec.in VisualC.zip Watcom-OS2.zip Xcode.tar.gz acinclude autogen.sh build-scripts configure configure.in dynamic_flac.c dynamic_flac.h dynamic_fluidsynth.c dynamic_fluidsynth.h dynamic_mod.c dynamic_mod.h dynamic_mp3.c dynamic_mp3.h dynamic_ogg.c dynamic_ogg.h effect_position.c effect_stereoreverse.c effects_internal.c effects_internal.h fluidsynth.c fluidsynth.h gcc-fat.sh libmikmod-3.1.12.zip load_aiff.c load_aiff.h load_flac.c load_flac.h load_ogg.c load_ogg.h load_voc.c load_voc.h mixer.c music.c music_cmd.c music_cmd.h music_flac.c music_flac.h music_mad.c music_mad.h music_mod.c music_mod.h music_modplug.c music_modplug.h music_ogg.c music_ogg.h native_midi native_midi_gpl playmus.c playwave.c timidity wavestream.c wavestream.h version.rc
  17.  
  18.  LT_AGE      = @LT_AGE@
  19.  LT_CURRENT  = @LT_CURRENT@
  20. diff -r 5b24d089d9f5 -r 586ae09f8176 SDL_mixer.h
  21. --- a/SDL_mixer.h   Tue Mar 15 23:11:29 2011 -0700
  22. +++ b/SDL_mixer.h   Sun Mar 20 14:34:18 2011 +0000
  23. @@ -67,10 +67,11 @@
  24.  
  25.  typedef enum
  26.  {
  27. -    MIX_INIT_FLAC = 0x00000001,
  28. -    MIX_INIT_MOD  = 0x00000002,
  29. -    MIX_INIT_MP3  = 0x00000004,
  30. -    MIX_INIT_OGG  = 0x00000008
  31. +    MIX_INIT_FLAC        = 0x00000001,
  32. +    MIX_INIT_MOD         = 0x00000002,
  33. +    MIX_INIT_MP3         = 0x00000004,
  34. +    MIX_INIT_OGG         = 0x00000008,
  35. +    MIX_INIT_FLUIDSYNTH  = 0x00000016
  36.  } MIX_InitFlags;
  37.  
  38.  /* Loads dynamic libraries and prepares them for use.  Flags should be
  39. @@ -605,6 +606,11 @@
  40.  extern DECLSPEC int SDLCALL Mix_SetSynchroValue(int value);
  41.  extern DECLSPEC int SDLCALL Mix_GetSynchroValue(void);
  42.  
  43. +/* Set/Get/Iterate SoundFonts paths to use by supported MIDI backends */
  44. +extern DECLSPEC int SDLCALL Mix_SetSoundFonts(const char *paths);
  45. +extern DECLSPEC const char* SDLCALL Mix_GetSoundFonts();
  46. +extern DECLSPEC int SDLCALL Mix_EachSoundFont(int (*function)(const char*, void*), void *data);
  47. +
  48.  /* Get the Mix_Chunk currently associated with a mixer channel
  49.      Returns NULL if it's an invalid channel, or there's no chunk associated.
  50.  */
  51. diff -r 5b24d089d9f5 -r 586ae09f8176 VisualC/SDL_mixer.dsp
  52. --- a/VisualC/SDL_mixer.dsp Tue Mar 15 23:11:29 2011 -0700
  53. +++ b/VisualC/SDL_mixer.dsp Sun Mar 20 14:34:18 2011 +0000
  54. @@ -44,7 +44,7 @@
  55.  # PROP Ignore_Export_Lib 0
  56.  # PROP Target_Dir ""
  57.  # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
  58. -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\mikmod" /I "..\timidity" /I "..\native_midi" /I "vorbis\include" /I "smpeg\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "WAV_MUSIC" /D "MOD_MUSIC" /D MOD_DYNAMIC=\"mikmod.dll\" /D "MID_MUSIC" /D "USE_TIMIDITY_MIDI" /D "USE_NATIVE_MIDI" /D "OGG_MUSIC" /D OGG_DYNAMIC=\"libvorbisfile-3.dll\" /D "MP3_MUSIC" /D MP3_DYNAMIC=\"smpeg.dll\" /YX /FD /c
  59. +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\mikmod" /I "..\timidity" /I "..\native_midi" /I "fluidsynth\include" /I "vorbis\include" /I "smpeg\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "WAV_MUSIC" /D "MOD_MUSIC" /D MOD_DYNAMIC=\"mikmod.dll\" /D "MID_MUSIC" /D "USE_TIMIDITY_MIDI" /D "USE_NATIVE_MIDI" /D "USE_FLUIDSYNTH_MIDI" /D FLUIDSYNTH_DYNAMIC=\"libfluidsynth.dll\" /D "OGG_MUSIC" /D OGG_DYNAMIC=\"libvorbisfile-3.dll\" /D "MP3_MUSIC" /D MP3_DYNAMIC=\"smpeg.dll\" /YX /FD /c
  60.  # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
  61.  # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
  62.  # ADD BASE RSC /l 0x409 /d "NDEBUG"
  63. @@ -70,7 +70,7 @@
  64.  # PROP Ignore_Export_Lib 0
  65.  # PROP Target_Dir ""
  66.  # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
  67. -# ADD CPP /nologo /MD /W3 /Gm /GX /Zi /Od /I "..\mikmod" /I "..\timidity" /I "..\native_midi" /I "vorbis\include" /I "smpeg\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "WAV_MUSIC" /D "MOD_MUSIC" /D MOD_DYNAMIC=\"mikmod.dll\" /D MOD_DYNAMIC=\"mikmod.dll\" /D "MID_MUSIC" /D "USE_TIMIDITY_MIDI" /D "USE_NATIVE_MIDI" /D "OGG_MUSIC" /D OGG_DYNAMIC=\"libvorbisfile-3.dll\" /D "MP3_MUSIC" /D MP3_DYNAMIC=\"smpeg.dll\" /YX /FD /c
  68. +# ADD CPP /nologo /MD /W3 /Gm /GX /Zi /Od /I "..\mikmod" /I "..\timidity" /I "..\native_midi" /I "fluidsynth\include" /I "vorbis\include" /I "smpeg\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "WAV_MUSIC" /D "MOD_MUSIC" /D MOD_DYNAMIC=\"mikmod.dll\" /D MOD_DYNAMIC=\"mikmod.dll\" /D "MID_MUSIC" /D "USE_TIMIDITY_MIDI" /D "USE_NATIVE_MIDI" /D "USE_FLUIDSYNTH_MIDI" /D FLUIDSYNTH_DYNAMIC=\"libfluidsynth.dll\" /D "OGG_MUSIC" /D OGG_DYNAMIC=\"libvorbisfile-3.dll\" /D "MP3_MUSIC" /D MP3_DYNAMIC=\"smpeg.dll\" /YX /FD /c
  69.  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  70.  # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  71.  # ADD BASE RSC /l 0x409 /d "_DEBUG"
  72. @@ -98,6 +98,14 @@
  73.  # End Source File
  74.  # Begin Source File
  75.  
  76. +SOURCE=..\dynamic_fluidsynth.c
  77. +# End Source File
  78. +# Begin Source File
  79. +
  80. +SOURCE=..\dynamic_fluidsynth.h
  81. +# End Source File
  82. +# Begin Source File
  83. +
  84.  SOURCE=..\dynamic_mod.c
  85.  # End Source File
  86.  # Begin Source File
  87. @@ -138,6 +146,14 @@
  88.  # End Source File
  89.  # Begin Source File
  90.  
  91. +SOURCE=..\fluidsynth.c
  92. +# End Source File
  93. +# Begin Source File
  94. +
  95. +SOURCE=..\fluidsynth.h
  96. +# End Source File
  97. +# Begin Source File
  98. +
  99.  SOURCE=..\load_aiff.c
  100.  # End Source File
  101.  # Begin Source File
  102. diff -r 5b24d089d9f5 -r 586ae09f8176 VisualC/SDL_mixer.vcproj
  103. --- a/VisualC/SDL_mixer.vcproj  Tue Mar 15 23:11:29 2011 -0700
  104. +++ b/VisualC/SDL_mixer.vcproj  Sun Mar 20 14:34:18 2011 +0000
  105. @@ -48,8 +48,8 @@
  106.                 Name="VCCLCompilerTool"
  107.                 AdditionalOptions="/D OGG_DYNAMIC=\&quot;libvorbisfile-3.dll\&quot;"
  108.                 Optimization="0"
  109. -               AdditionalIncludeDirectories="..\timidity;..\native_midi;mikmod\include;smpeg\include;vorbis\include"
  110. -               PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MOD_DYNAMIC=\&quot;mikmod.dll\&quot;;MID_MUSIC;USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;OGG_MUSIC;OGG_DYNAMIC=\&quot;libvorbisfile-3.dll\&quot;;MP3_MUSIC;MP3_DYNAMIC=\&quot;smpeg.dll\&quot;"
  111. +               AdditionalIncludeDirectories="..\timidity;..\native_midi;fluidsynth\include;mikmod\include;smpeg\include;vorbis\include"
  112. +               PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MOD_DYNAMIC=\&quot;mikmod.dll\&quot;;MID_MUSIC;USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;USE_FLUIDSYNTH_MIDI;FLUIDSYNTH_DYNAMIC=\&quot;libfluidsynth.dll\&quot;;OGG_MUSIC;OGG_DYNAMIC=\&quot;libvorbisfile-3.dll\&quot;;MP3_MUSIC;MP3_DYNAMIC=\&quot;smpeg.dll\&quot;"
  113.                 MinimalRebuild="true"
  114.                 RuntimeLibrary="2"
  115.                 PrecompiledHeaderFile=".\Debug/SDL_mixer.pch"
  116. @@ -145,8 +145,8 @@
  117.                 AdditionalOptions="/D OGG_DYNAMIC=\&quot;libvorbisfile-3.dll\&quot;"
  118.                 Optimization="2"
  119.                 InlineFunctionExpansion="1"
  120. -               AdditionalIncludeDirectories="..\timidity;..\native_midi;mikmod\include;smpeg\include;vorbis\include"
  121. -               PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MID_MUSIC;MOD_DYNAMIC=\&quot;mikmod.dll\&quot;;USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;OGG_MUSIC;OGG_DYNAMIC=\&quot;libvorbisfile-3.dll\&quot;;MP3_MUSIC;MP3_DYNAMIC=\&quot;smpeg.dll\&quot;"
  122. +               AdditionalIncludeDirectories="..\timidity;..\native_midi;fluidsynth/include;mikmod\include;smpeg\include;vorbis\include"
  123. +               PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MID_MUSIC;MOD_DYNAMIC=\&quot;mikmod.dll\&quot;;USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;USE_FLUIDSYNTH_MIDI;FLUIDSYNTH_DYNAMIC=\&quot;libfluidsynth.dll\&quot;;OGG_MUSIC;OGG_DYNAMIC=\&quot;libvorbisfile-3.dll\&quot;;MP3_MUSIC;MP3_DYNAMIC=\&quot;smpeg.dll\&quot;"
  124.                 StringPooling="true"
  125.                 RuntimeLibrary="2"
  126.                 EnableFunctionLevelLinking="true"
  127. @@ -219,6 +219,14 @@
  128.             >
  129.         </File>
  130.         <File
  131. +           RelativePath="..\dynamic_fluidsynth.c"
  132. +           >
  133. +       </File>
  134. +       <File
  135. +           RelativePath="..\dynamic_fluidsynth.h"
  136. +           >
  137. +       </File>
  138. +       <File
  139.             RelativePath="..\dynamic_mod.c"
  140.             >
  141.         </File>
  142. @@ -349,6 +357,14 @@
  143.             >
  144.         </File>
  145.         <File
  146. +           RelativePath="..\fluidsynth.c"
  147. +           >
  148. +       </File>
  149. +       <File
  150. +           RelativePath="..\fluidsynth.h"
  151. +           >
  152. +       </File>
  153. +       <File
  154.             RelativePath="..\load_aiff.c"
  155.             >
  156.             <FileConfiguration
  157. diff -r 5b24d089d9f5 -r 586ae09f8176 configure.in
  158. --- a/configure.in  Tue Mar 15 23:11:29 2011 -0700
  159. +++ b/configure.in  Sun Mar 20 14:34:18 2011 +0000
  160. @@ -387,6 +387,49 @@
  161.              SOURCES="$SOURCES $srcdir/native_midi_gpl/*.c"
  162.          fi
  163.      fi
  164. +    AC_ARG_ENABLE([music-fluidsynth-midi],
  165. +AC_HELP_STRING([--enable-music-fluidsynth-midi], [enable FluidSynth MIDI output [[default=yes]]]),
  166. +                  [], [enable_music_fluidsynth_midi=yes])
  167. +    AC_ARG_ENABLE([music-fluidsynth-shared],
  168. +AC_HELP_STRING([--enable-music-fluidsynth-shared], [dynamically load FluidSynth support [[default=yes]]]),
  169. +                  [], [enable_music_fluidsynth_shared=yes])
  170. +    if test x$enable_music_fluidsynth_midi = xyes; then
  171. +        AC_CHECK_HEADER([fluidsynth.h], [have_fluidsynth_hdr=yes])
  172. +        AC_CHECK_LIB([fluidsynth], [fluid_player_add_mem], [have_fluidsynth_lib=yes])
  173. +        if test x$have_fluidsynth_hdr = xyes -a x$have_fluidsynth_lib = xyes; then
  174. +            case "$host" in
  175. +                *-*-darwin*)
  176. +                    fluidsynth_lib=[`find_lib libfluidsynth.dylib`]
  177. +                    if test x$fluidsynth_lib = x; then
  178. +                        fluidsynth_lib=[`find_lib libfluidsynth.[0-9]`]
  179. +                    fi
  180. +                    if test x$fluidsynth_lib = x; then
  181. +                        fluidsynth_lib=[`find_lib libfluidsynth.[0-9]*`]
  182. +                    fi
  183. +                    ;;
  184. +                *-*-cygwin* | *-*-mingw32*)
  185. +                    fluidsynth_lib=[`find_lib "fluidsynth*.dll"`]
  186. +                    ;;
  187. +                *)
  188. +                    fluidsynth_lib=[`find_lib "libfluidsynth.so.[0-9]"`]
  189. +                    if test x$fluidsynth_lib = x; then
  190. +                        fluidsynth_lib=[`find_lib "libfluidsynth.so.[0-9]*"`]
  191. +                    fi
  192. +                    ;;
  193. +            esac
  194. +            SOURCES="$SOURCES $srcdir/dynamic_fluidsynth.c $srcdir/fluidsynth.c"
  195. +            EXTRA_CFLAGS="$EXTRA_CFLAGS -DUSE_FLUIDSYNTH_MIDI"
  196. +            if test x$enable_music_fluidsynth_shared = xyes && test x$fluidsynth_lib != x; then
  197. +                echo "-- dynamic libfluidsyth -> $fluidsynth_lib"
  198. +                EXTRA_CFLAGS="$EXTRA_CFLAGS -DFLUIDSYNTH_DYNAMIC=\\\"$fluidsynth_lib\\\""
  199. +            else
  200. +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lfluidsynth"
  201. +            fi
  202. +        else
  203. +            AC_MSG_WARN([*** Unable to find FluidSynth library (http://www.fluidsynth.org/)])
  204. +            AC_MSG_WARN([FluidSynth support disabled])
  205. +        fi
  206. +    fi
  207.  fi
  208.  
  209.  AC_ARG_ENABLE([music-ogg],
  210. diff -r 5b24d089d9f5 -r 586ae09f8176 dynamic_fluidsynth.c
  211. --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
  212. +++ b/dynamic_fluidsynth.c  Sun Mar 20 14:34:18 2011 +0000
  213. @@ -0,0 +1,85 @@
  214. +/*
  215. +    SDL_mixer:  An audio mixer library based on the SDL library
  216. +    Copyright (C) 1997-2011 Sam Lantinga
  217. +
  218. +    This library is free software; you can redistribute it and/or
  219. +    modify it under the terms of the GNU Library General Public
  220. +    License as published by the Free Software Foundation; either
  221. +    version 2 of the License, or (at your option) any later version.
  222. +
  223. +    This library is distributed in the hope that it will be useful,
  224. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  225. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  226. +    Library General Public License for more details.
  227. +
  228. +    You should have received a copy of the GNU Library General Public
  229. +    License along with this library; if not, write to the Free
  230. +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  231. +
  232. +    James Le Cuirot
  233. +*/
  234. +
  235. +#ifdef USE_FLUIDSYNTH_MIDI
  236. +
  237. +#include "SDL_loadso.h"
  238. +#include "dynamic_fluidsynth.h"
  239. +
  240. +fluidsynth_loader fluidsynth = {
  241. +   0, NULL
  242. +};
  243. +
  244. +#ifdef FLUIDSYNTH_DYNAMIC
  245. +#define FLUIDSYNTH_LOADER(FUNC, SIG) \
  246. +   fluidsynth.FUNC = (SIG) SDL_LoadFunction(fluidsynth.handle, #FUNC); \
  247. +   if (fluidsynth.FUNC == NULL) { SDL_UnloadObject(fluidsynth.handle); return -1; }
  248. +#else
  249. +#define FLUIDSYNTH_LOADER(FUNC, SIG) \
  250. +   fluidsynth.FUNC = FUNC;
  251. +#endif
  252. +
  253. +int Mix_InitFluidSynth()
  254. +{
  255. +   if ( fluidsynth.loaded == 0 ) {
  256. +#ifdef FLUIDSYNTH_DYNAMIC
  257. +       fluidsynth.handle = SDL_LoadObject(FLUIDSYNTH_DYNAMIC);
  258. +       if ( fluidsynth.handle == NULL ) return -1;
  259. +#endif
  260. +
  261. +       FLUIDSYNTH_LOADER(delete_fluid_player, int (*)(fluid_player_t*));
  262. +       FLUIDSYNTH_LOADER(delete_fluid_settings, void (*)(fluid_settings_t*));
  263. +       FLUIDSYNTH_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*));
  264. +       FLUIDSYNTH_LOADER(fluid_player_add, int (*)(fluid_player_t*, const char*));
  265. +       FLUIDSYNTH_LOADER(fluid_player_add_mem, int (*)(fluid_player_t*, const void*, size_t));
  266. +       FLUIDSYNTH_LOADER(fluid_player_get_status, int (*)(fluid_player_t*));
  267. +       FLUIDSYNTH_LOADER(fluid_player_play, int (*)(fluid_player_t*));
  268. +       FLUIDSYNTH_LOADER(fluid_player_set_loop, int (*)(fluid_player_t*, int));
  269. +       FLUIDSYNTH_LOADER(fluid_player_stop, int (*)(fluid_player_t*));
  270. +       FLUIDSYNTH_LOADER(fluid_settings_setnum, int (*)(fluid_settings_t*, const char*, double));
  271. +       FLUIDSYNTH_LOADER(fluid_synth_get_settings, fluid_settings_t* (*)(fluid_synth_t*));
  272. +       FLUIDSYNTH_LOADER(fluid_synth_set_gain, void (*)(fluid_synth_t*, float));
  273. +       FLUIDSYNTH_LOADER(fluid_synth_sfload, int(*)(fluid_synth_t*, const char*, int));
  274. +       FLUIDSYNTH_LOADER(fluid_synth_write_s16, int(*)(fluid_synth_t*, int, void*, int, int, void*, int, int));
  275. +       FLUIDSYNTH_LOADER(new_fluid_player, fluid_player_t* (*)(fluid_synth_t*));
  276. +       FLUIDSYNTH_LOADER(new_fluid_settings, fluid_settings_t* (*)(void));
  277. +       FLUIDSYNTH_LOADER(new_fluid_synth, fluid_synth_t* (*)(fluid_settings_t*));
  278. +   }
  279. +   ++fluidsynth.loaded;
  280. +
  281. +   return 0;
  282. +}
  283. +
  284. +void Mix_QuitFluidSynth()
  285. +{
  286. +   if ( fluidsynth.loaded == 0 ) {
  287. +       return;
  288. +   }
  289. +   if ( fluidsynth.loaded == 1 ) {
  290. +#ifdef FLUIDSYNTH_DYNAMIC
  291. +       SDL_UnloadObject(fluidsynth.handle);
  292. +#endif
  293. +   }
  294. +   --fluidsynth.loaded;
  295. +}
  296. +
  297. +#endif /* USE_FLUIDSYNTH_MIDI */
  298. diff -r 5b24d089d9f5 -r 586ae09f8176 dynamic_fluidsynth.h
  299. --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
  300. +++ b/dynamic_fluidsynth.h  Sun Mar 20 14:34:18 2011 +0000
  301. @@ -0,0 +1,55 @@
  302. +/*
  303. +    SDL_mixer:  An audio mixer library based on the SDL library
  304. +    Copyright (C) 1997-2011 Sam Lantinga
  305. +
  306. +    This library is free software; you can redistribute it and/or
  307. +    modify it under the terms of the GNU Library General Public
  308. +    License as published by the Free Software Foundation; either
  309. +    version 2 of the License, or (at your option) any later version.
  310. +
  311. +    This library is distributed in the hope that it will be useful,
  312. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  313. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  314. +    Library General Public License for more details.
  315. +
  316. +    You should have received a copy of the GNU Library General Public
  317. +    License along with this library; if not, write to the Free
  318. +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  319. +
  320. +    James Le Cuirot
  321. +*/
  322. +
  323. +#ifdef USE_FLUIDSYNTH_MIDI
  324. +
  325. +#include <fluidsynth.h>
  326. +
  327. +typedef struct {
  328. +   int loaded;
  329. +   void *handle;
  330. +
  331. +   int (*delete_fluid_player)(fluid_player_t*);
  332. +   void (*delete_fluid_settings)(fluid_settings_t*);
  333. +   int (*delete_fluid_synth)(fluid_synth_t*);
  334. +   int (*fluid_player_add)(fluid_player_t*, const char*);
  335. +   int (*fluid_player_add_mem)(fluid_player_t*, const void*, size_t);
  336. +   int (*fluid_player_get_status)(fluid_player_t*);
  337. +   int (*fluid_player_play)(fluid_player_t*);
  338. +   int (*fluid_player_set_loop)(fluid_player_t*, int);
  339. +   int (*fluid_player_stop)(fluid_player_t*);
  340. +   int (*fluid_settings_setnum)(fluid_settings_t*, const char*, double);
  341. +   fluid_settings_t* (*fluid_synth_get_settings)(fluid_synth_t*);
  342. +   void (*fluid_synth_set_gain)(fluid_synth_t*, float);
  343. +   int (*fluid_synth_sfload)(fluid_synth_t*, const char*, int);
  344. +   int (*fluid_synth_write_s16)(fluid_synth_t*, int, void*, int, int, void*, int, int);
  345. +   fluid_player_t* (*new_fluid_player)(fluid_synth_t*);
  346. +   fluid_settings_t* (*new_fluid_settings)(void);
  347. +   fluid_synth_t* (*new_fluid_synth)(fluid_settings_t*);
  348. +} fluidsynth_loader;
  349. +
  350. +extern fluidsynth_loader fluidsynth;
  351. +
  352. +#endif /* USE_FLUIDSYNTH_MIDI */
  353. +
  354. +extern int Mix_InitFluidSynth();
  355. +extern void Mix_QuitFluidSynth();
  356. diff -r 5b24d089d9f5 -r 586ae09f8176 fluidsynth.c
  357. --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
  358. +++ b/fluidsynth.c  Sun Mar 20 14:34:18 2011 +0000
  359. @@ -0,0 +1,222 @@
  360. +/*
  361. +    SDL_mixer:  An audio mixer library based on the SDL library
  362. +    Copyright (C) 1997-2011 Sam Lantinga
  363. +
  364. +    This library is free software; you can redistribute it and/or
  365. +    modify it under the terms of the GNU Library General Public
  366. +    License as published by the Free Software Foundation; either
  367. +    version 2 of the License, or (at your option) any later version.
  368. +
  369. +    This library is distributed in the hope that it will be useful,
  370. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  371. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  372. +    Library General Public License for more details.
  373. +
  374. +    You should have received a copy of the GNU Library General Public
  375. +    License along with this library; if not, write to the Free
  376. +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  377. +
  378. +    James Le Cuirot
  379. +*/
  380. +
  381. +#include "fluidsynth.h"
  382. +#include "SDL_mixer.h"
  383. +#include <stdio.h>
  384. +#include <sys/types.h>
  385. +
  386. +static Uint16 format;
  387. +static Uint8 channels;
  388. +static int freq;
  389. +
  390. +int fluidsynth_check_soundfont(const char *path, void *data)
  391. +{
  392. +   FILE *file = fopen(path, "r");
  393. +
  394. +   if (file) {
  395. +       fclose(file);
  396. +       return 1;
  397. +   } else {
  398. +       Mix_SetError("Failed to access the SoundFont %s", path);
  399. +       return 0;
  400. +   }
  401. +}
  402. +
  403. +int fluidsynth_load_soundfont(const char *path, void *data)
  404. +{
  405. +   /* If this fails, it's too late to try Timidity so pray that at least one works. */
  406. +   fluidsynth.fluid_synth_sfload((fluid_synth_t*) data, path, 1);
  407. +   return 1;
  408. +}
  409. +
  410. +int fluidsynth_init(SDL_AudioSpec *mixer)
  411. +{
  412. +   if (!Mix_EachSoundFont(fluidsynth_check_soundfont, NULL))
  413. +       return -1;
  414. +
  415. +   format = mixer->format;
  416. +   channels = mixer->channels;
  417. +   freq = mixer->freq;
  418. +
  419. +   return 0;
  420. +}
  421. +
  422. +FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynthMidiSong*, void*), void *data)
  423. +{
  424. +   FluidSynthMidiSong *song;
  425. +   fluid_settings_t *settings = NULL;
  426. +
  427. +   if ((song = malloc(sizeof(FluidSynthMidiSong)))) {
  428. +       memset(song, 0, sizeof(FluidSynthMidiSong));
  429. +
  430. +       if (SDL_BuildAudioCVT(&song->convert, AUDIO_S16, 2, freq, format, channels, freq) >= 0) {
  431. +           if ((settings = fluidsynth.new_fluid_settings())) {
  432. +               fluidsynth.fluid_settings_setnum(settings, "synth.sample-rate", (double) freq);
  433. +
  434. +               if ((song->synth = fluidsynth.new_fluid_synth(settings))) {
  435. +                   if (Mix_EachSoundFont(fluidsynth_load_soundfont, (void*) song->synth)) {
  436. +                       if ((song->player = fluidsynth.new_fluid_player(song->synth))) {
  437. +                           if (function(song, data)) return song;
  438. +                           fluidsynth.delete_fluid_player(song->player);
  439. +                       } else {
  440. +                           Mix_SetError("Failed to create FluidSynth player");
  441. +                       }
  442. +                   }
  443. +                   fluidsynth.delete_fluid_synth(song->synth);
  444. +               } else {
  445. +                   Mix_SetError("Failed to create FluidSynth synthesizer");
  446. +               }
  447. +               fluidsynth.delete_fluid_settings(settings);
  448. +           } else {
  449. +               Mix_SetError("Failed to create FluidSynth settings");
  450. +           }
  451. +       } else {
  452. +           Mix_SetError("Failed to set up audio conversion");
  453. +       }
  454. +       free(song);
  455. +   } else {
  456. +       Mix_SetError("Insufficient memory for song");
  457. +   }
  458. +   return NULL;
  459. +}
  460. +
  461. +int fluidsynth_loadsong_internal(FluidSynthMidiSong *song, void *data)
  462. +{
  463. +   const char* path = (const char*) data;
  464. +
  465. +   if (fluidsynth.fluid_player_add(song->player, path) == FLUID_OK) {
  466. +       return 1;
  467. +   } else {
  468. +       Mix_SetError("FluidSynth failed to load %s", path);
  469. +       return 0;
  470. +   }
  471. +}
  472. +
  473. +int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data)
  474. +{
  475. +   off_t offset;
  476. +   size_t size;
  477. +   char *buffer;
  478. +   SDL_RWops *rw = (SDL_RWops*) data;
  479. +
  480. +   offset = SDL_RWtell(rw);
  481. +   SDL_RWseek(rw, 0, RW_SEEK_END);
  482. +   size = SDL_RWtell(rw) - offset;
  483. +   SDL_RWseek(rw, offset, RW_SEEK_SET);
  484. +
  485. +   if ((buffer = (char*) malloc(size))) {
  486. +       if(SDL_RWread(rw, buffer, size, 1) == 1) {
  487. +           if (fluidsynth.fluid_player_add_mem(song->player, buffer, size) == FLUID_OK) {
  488. +               return 1;
  489. +           } else {
  490. +               Mix_SetError("FluidSynth failed to load in-memory song");
  491. +           }
  492. +       } else {
  493. +           Mix_SetError("Failed to read in-memory song");
  494. +       }
  495. +       free(buffer);
  496. +   } else {
  497. +       Mix_SetError("Insufficient memory for song");
  498. +   }
  499. +   return 0;
  500. +}
  501. +
  502. +FluidSynthMidiSong *fluidsynth_loadsong(const char *midifile)
  503. +{
  504. +   return fluidsynth_loadsong_common(fluidsynth_loadsong_internal, (void*) midifile);
  505. +}
  506. +
  507. +FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw)
  508. +{
  509. +   return fluidsynth_loadsong_common(fluidsynth_loadsong_RW_internal, (void*) rw);
  510. +}
  511. +
  512. +void fluidsynth_freesong(FluidSynthMidiSong *song)
  513. +{
  514. +   if (!song) return;
  515. +   fluidsynth.delete_fluid_player(song->player);
  516. +   fluidsynth.delete_fluid_settings(fluidsynth.fluid_synth_get_settings(song->synth));
  517. +   fluidsynth.delete_fluid_synth(song->synth);
  518. +   free(song);
  519. +}
  520. +
  521. +void fluidsynth_start(FluidSynthMidiSong *song)
  522. +{
  523. +   fluidsynth.fluid_player_set_loop(song->player, 1);
  524. +   fluidsynth.fluid_player_play(song->player);
  525. +}
  526. +
  527. +void fluidsynth_stop(FluidSynthMidiSong *song)
  528. +{
  529. +   fluidsynth.fluid_player_stop(song->player);
  530. +}
  531. +
  532. +int fluidsynth_active(FluidSynthMidiSong *song)
  533. +{
  534. +   return fluidsynth.fluid_player_get_status(song->player) == FLUID_PLAYER_PLAYING ? 1 : 0;
  535. +}
  536. +
  537. +void fluidsynth_setvolume(FluidSynthMidiSong *song, int volume)
  538. +{
  539. +   /* FluidSynth's default is 0.2. Make 0.8 the maximum. */
  540. +   fluidsynth.fluid_synth_set_gain(song->synth, (float) (volume * 0.00625));
  541. +}
  542. +
  543. +int fluidsynth_playsome(FluidSynthMidiSong *song, void *dest, int dest_len)
  544. +{
  545. +   int result = -1;
  546. +   int frames = dest_len / channels / ((format & 0xFF) / 8);
  547. +   int src_len = frames * 4; /* 16-bit stereo */
  548. +   void *src = dest;
  549. +
  550. +   if (dest_len < src_len) {
  551. +       if (!(src = malloc(src_len))) {
  552. +           Mix_SetError("Insufficient memory for audio conversion");
  553. +           return result;
  554. +       }
  555. +   }
  556. +
  557. +   if (fluidsynth.fluid_synth_write_s16(song->synth, frames, src, 0, 2, src, 1, 2) != FLUID_OK) {
  558. +       Mix_SetError("Error generating FluidSynth audio");
  559. +       goto finish;
  560. +   }
  561. +
  562. +   song->convert.buf = src;
  563. +   song->convert.len = src_len;
  564. +
  565. +   if (SDL_ConvertAudio(&song->convert) < 0) {
  566. +       Mix_SetError("Error during audio conversion");
  567. +       goto finish;
  568. +   }
  569. +
  570. +   if (src != dest)
  571. +       memcpy(dest, src, dest_len);
  572. +
  573. +   result = 0;
  574. +
  575. +finish:
  576. +   if (src != dest)
  577. +       free(src);
  578. +
  579. +   return result;
  580. +}
  581. diff -r 5b24d089d9f5 -r 586ae09f8176 fluidsynth.h
  582. --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
  583. +++ b/fluidsynth.h  Sun Mar 20 14:34:18 2011 +0000
  584. @@ -0,0 +1,46 @@
  585. +/*
  586. +    SDL_mixer:  An audio mixer library based on the SDL library
  587. +    Copyright (C) 1997-2011 Sam Lantinga
  588. +
  589. +    This library is free software; you can redistribute it and/or
  590. +    modify it under the terms of the GNU Library General Public
  591. +    License as published by the Free Software Foundation; either
  592. +    version 2 of the License, or (at your option) any later version.
  593. +
  594. +    This library is distributed in the hope that it will be useful,
  595. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  596. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  597. +    Library General Public License for more details.
  598. +
  599. +    You should have received a copy of the GNU Library General Public
  600. +    License along with this library; if not, write to the Free
  601. +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  602. +
  603. +    James Le Cuirot
  604. +*/
  605. +
  606. +#ifndef _FLUIDSYNTH_H_
  607. +#define _FLUIDSYNTH_H_
  608. +
  609. +#include "dynamic_fluidsynth.h"
  610. +#include <SDL_rwops.h>
  611. +#include <SDL_audio.h>
  612. +
  613. +typedef struct {
  614. +   SDL_AudioCVT convert;
  615. +   fluid_synth_t *synth;
  616. +   fluid_player_t* player;
  617. +} FluidSynthMidiSong;
  618. +
  619. +int fluidsynth_init(SDL_AudioSpec *mixer);
  620. +FluidSynthMidiSong *fluidsynth_loadsong(const char *midifile);
  621. +FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw);
  622. +void fluidsynth_freesong(FluidSynthMidiSong *song);
  623. +void fluidsynth_start(FluidSynthMidiSong *song);
  624. +void fluidsynth_stop(FluidSynthMidiSong *song);
  625. +int fluidsynth_active(FluidSynthMidiSong *song);
  626. +void fluidsynth_setvolume(FluidSynthMidiSong *song, int volume);
  627. +int fluidsynth_playsome(FluidSynthMidiSong *song, void *stream, int len);
  628. +
  629. +#endif /* _FLUIDSYNTH_H_ */
  630. diff -r 5b24d089d9f5 -r 586ae09f8176 mixer.c
  631. --- a/mixer.c   Tue Mar 15 23:11:29 2011 -0700
  632. +++ b/mixer.c   Sun Mar 20 14:34:18 2011 +0000
  633. @@ -107,6 +107,11 @@
  634.  static const char **chunk_decoders = NULL;
  635.  static int num_decoders = 0;
  636.  
  637. +/* Semicolon-separated SoundFont paths */
  638. +#ifdef MID_MUSIC
  639. +extern char* soundfont_paths;
  640. +#endif
  641. +
  642.  int Mix_GetNumChunkDecoders(void)
  643.  {
  644.     return(num_decoders);
  645. @@ -144,6 +149,15 @@
  646.  {
  647.     int result = 0;
  648.  
  649. +   if (flags & MIX_INIT_FLUIDSYNTH) {
  650. +#ifdef USE_FLUIDSYNTH_MIDI
  651. +       if ((initialized & MIX_INIT_FLUIDSYNTH) || Mix_InitFluidSynth() == 0) {
  652. +           result |= MIX_INIT_FLUIDSYNTH;
  653. +       }
  654. +#else
  655. +       Mix_SetError("Mixer not built with FluidSynth support");
  656. +#endif
  657. +   }
  658.     if (flags & MIX_INIT_FLAC) {
  659.  #ifdef FLAC_MUSIC
  660.         if ((initialized & MIX_INIT_FLAC) || Mix_InitFLAC() == 0) {
  661. @@ -187,6 +201,11 @@
  662.  
  663.  void Mix_Quit()
  664.  {
  665. +#ifdef USE_FLUIDSYNTH_MIDI
  666. +   if (initialized & MIX_INIT_FLUIDSYNTH) {
  667. +       Mix_QuitFluidSynth();
  668. +   }
  669. +#endif
  670.  #ifdef FLAC_MUSIC
  671.     if (initialized & MIX_INIT_FLAC) {
  672.         Mix_QuitFLAC();
  673. @@ -207,6 +226,11 @@
  674.         Mix_QuitOgg();
  675.     }
  676.  #endif
  677. +#ifdef MID_MUSIC
  678. +   if (soundfont_paths) {
  679. +       free(soundfont_paths);
  680. +   }
  681. +#endif
  682.     initialized = 0;
  683.  }
  684.  
  685. diff -r 5b24d089d9f5 -r 586ae09f8176 music.c
  686. --- a/music.c   Tue Mar 15 23:11:29 2011 -0700
  687. +++ b/music.c   Sun Mar 20 14:34:18 2011 +0000
  688. @@ -48,14 +48,12 @@
  689.  #  ifdef USE_TIMIDITY_MIDI
  690.  #    include "timidity.h"
  691.  #  endif
  692. +#  ifdef USE_FLUIDSYNTH_MIDI
  693. +#    include "fluidsynth.h"
  694. +#  endif
  695.  #  ifdef USE_NATIVE_MIDI
  696.  #    include "native_midi.h"
  697.  #  endif
  698. -#  if defined(USE_TIMIDITY_MIDI) && defined(USE_NATIVE_MIDI)
  699. -#    define MIDI_ELSE  else
  700. -#  else
  701. -#    define MIDI_ELSE
  702. -#  endif
  703.  #endif
  704.  #ifdef OGG_MUSIC
  705.  #include "music_ogg.h"
  706. @@ -101,6 +99,9 @@
  707.  #ifdef USE_TIMIDITY_MIDI
  708.         MidiSong *midi;
  709.  #endif
  710. +#ifdef USE_FLUIDSYNTH_MIDI
  711. +       FluidSynthMidiSong *fluidsynthmidi;
  712. +#endif
  713.  #ifdef USE_NATIVE_MIDI
  714.         NativeMidiSong *nativemidi;
  715.  #endif
  716. @@ -128,6 +129,9 @@
  717.  static int timidity_ok;
  718.  static int samplesize;
  719.  #endif
  720. +#ifdef USE_FLUIDSYNTH_MIDI
  721. +static int fluidsynth_ok;
  722. +#endif
  723.  #ifdef USE_NATIVE_MIDI
  724.  static int native_midi_ok;
  725.  #endif
  726. @@ -140,6 +144,11 @@
  727.  static const char **music_decoders = NULL;
  728.  static int num_decoders = 0;
  729.  
  730. +/* Semicolon-separated SoundFont paths */
  731. +#ifdef MID_MUSIC
  732. +char* soundfont_paths = NULL;
  733. +#endif
  734. +
  735.  int Mix_GetNumMusicDecoders(void)
  736.  {
  737.     return(num_decoders);
  738. @@ -270,15 +279,22 @@
  739.                 break;
  740.  #endif
  741.  #ifdef MID_MUSIC
  742. +           case MUS_MID:
  743. +#ifdef USE_FLUIDSYNTH_MIDI
  744. +               if ( fluidsynth_ok ) {
  745. +                   fluidsynth_playsome(music_playing->data.fluidsynthmidi, stream, len);
  746. +                   goto skip;
  747. +               }
  748. +#endif
  749.  #ifdef USE_TIMIDITY_MIDI
  750. -           case MUS_MID:
  751.                 if ( timidity_ok ) {
  752.                     int samples = len / samplesize;
  753.                     Timidity_PlaySome(stream, samples);
  754. +                   goto skip;
  755.                 }
  756. +#endif
  757.                 break;
  758.  #endif
  759. -#endif
  760.  #ifdef OGG_MUSIC
  761.             case MUS_OGG:
  762.                
  763. @@ -306,6 +322,7 @@
  764.         }
  765.     }
  766.  
  767. +skip:
  768.     /* Handle seamless music looping */
  769.     if (left > 0 && left < len && music_halt_or_loop()) {
  770.         music_mixer(udata, stream+(len-left), left);
  771. @@ -341,9 +358,21 @@
  772.         timidity_ok = 0;
  773.     }
  774.  #endif
  775. +#ifdef USE_FLUIDSYNTH_MIDI
  776. +   if ( fluidsynth_init(mixer) == 0 ) {
  777. +       fluidsynth_ok = 1;
  778. +       add_music_decoder("FLUIDSYNTH");
  779. +   } else {
  780. +       fluidsynth_ok = 0;
  781. +   }
  782. +#endif
  783.  #ifdef USE_NATIVE_MIDI
  784. +#ifdef USE_FLUIDSYNTH_MIDI
  785. +   native_midi_ok = !fluidsynth_ok;
  786. +   if ( native_midi_ok )
  787. +#endif
  788.  #ifdef USE_TIMIDITY_MIDI
  789. -   native_midi_ok = !timidity_ok;
  790. +       native_midi_ok = !timidity_ok;
  791.     if ( !native_midi_ok ) {
  792.         native_midi_ok = (getenv("SDL_NATIVE_MUSIC") != NULL);
  793.     }
  794. @@ -469,7 +498,17 @@
  795.                 Mix_SetError("%s", native_midi_error());
  796.                 music->error = 1;
  797.             }
  798. -       } MIDI_ELSE
  799. +           goto skip;
  800. +       }
  801. +#endif
  802. +#ifdef USE_FLUIDSYNTH_MIDI
  803. +       if ( fluidsynth_ok ) {
  804. +           music->data.fluidsynthmidi = fluidsynth_loadsong(file);
  805. +           if ( music->data.fluidsynthmidi == NULL ) {
  806. +               music->error = 1;
  807. +           }
  808. +           goto skip;
  809. +       }
  810.  #endif
  811.  #ifdef USE_TIMIDITY_MIDI
  812.         if ( timidity_ok ) {
  813. @@ -565,6 +604,8 @@
  814.         Mix_SetError("Unrecognized music format");
  815.         music->error = 1;
  816.     }
  817. +
  818. +skip:
  819.     if ( music->error ) {
  820.         free(music);
  821.         music = NULL;
  822. @@ -616,11 +657,19 @@
  823.  #ifdef USE_NATIVE_MIDI
  824.                 if ( native_midi_ok ) {
  825.                     native_midi_freesong(music->data.nativemidi);
  826. -               } MIDI_ELSE
  827. +                   goto skip;
  828. +               }
  829. +#endif
  830. +#ifdef USE_FLUIDSYNTH_MIDI
  831. +               if ( fluidsynth_ok ) {
  832. +                   fluidsynth_freesong(music->data.fluidsynthmidi);
  833. +                   goto skip;
  834. +               }
  835.  #endif
  836.  #ifdef USE_TIMIDITY_MIDI
  837.                 if ( timidity_ok ) {
  838.                     Timidity_FreeSong(music->data.midi);
  839. +                   goto skip;
  840.                 }
  841.  #endif
  842.                 break;
  843. @@ -649,6 +698,8 @@
  844.                 /* Unknown music type?? */
  845.                 break;
  846.         }
  847. +
  848. +    skip:
  849.         free(music);
  850.     }
  851.  }
  852. @@ -720,11 +771,19 @@
  853.  #ifdef USE_NATIVE_MIDI
  854.         if ( native_midi_ok ) {
  855.             native_midi_start(music->data.nativemidi);
  856. -       } MIDI_ELSE
  857. +           goto skip;
  858. +       }
  859. +#endif
  860. +#ifdef USE_FLUIDSYNTH_MIDI
  861. +       if (fluidsynth_ok ) {
  862. +           fluidsynth_start(music->data.fluidsynthmidi);
  863. +           goto skip;
  864. +       }
  865.  #endif
  866.  #ifdef USE_TIMIDITY_MIDI
  867.         if ( timidity_ok ) {
  868.             Timidity_Start(music->data.midi);
  869. +           goto skip;
  870.         }
  871.  #endif
  872.         break;
  873. @@ -757,6 +816,7 @@
  874.         break;
  875.     }
  876.  
  877. +skip:
  878.     /* Set the playback position, note any errors if an offset is used */
  879.     if ( retval == 0 ) {
  880.         if ( position > 0.0 ) {
  881. @@ -929,11 +989,19 @@
  882.  #ifdef USE_NATIVE_MIDI
  883.         if ( native_midi_ok ) {
  884.             native_midi_setvolume(volume);
  885. -       } MIDI_ELSE
  886. +           return;
  887. +       }
  888. +#endif
  889. +#ifdef USE_FLUIDSYNTH_MIDI
  890. +       if ( fluidsynth_ok ) {
  891. +           fluidsynth_setvolume(music_playing->data.fluidsynthmidi, volume);
  892. +           return;
  893. +       }
  894.  #endif
  895.  #ifdef USE_TIMIDITY_MIDI
  896.         if ( timidity_ok ) {
  897.             Timidity_SetVolume(volume);
  898. +           return;
  899.         }
  900.  #endif
  901.         break;
  902. @@ -1012,11 +1080,19 @@
  903.  #ifdef USE_NATIVE_MIDI
  904.         if ( native_midi_ok ) {
  905.             native_midi_stop();
  906. -       } MIDI_ELSE
  907. +           goto skip;
  908. +       }
  909. +#endif
  910. +#ifdef USE_FLUIDSYNTH_MIDI
  911. +       if ( fluidsynth_ok ) {
  912. +           fluidsynth_stop(music_playing->data.fluidsynthmidi);
  913. +           goto skip;
  914. +       }
  915.  #endif
  916.  #ifdef USE_TIMIDITY_MIDI
  917.         if ( timidity_ok ) {
  918.             Timidity_Stop();
  919. +           goto skip;
  920.         }
  921.  #endif
  922.         break;
  923. @@ -1045,6 +1121,8 @@
  924.         /* Unknown music type?? */
  925.         return;
  926.     }
  927. +
  928. +skip:
  929.     music_playing->fading = MIX_NO_FADING;
  930.     music_playing = NULL;
  931.  }
  932. @@ -1173,12 +1251,21 @@
  933.         if ( native_midi_ok ) {
  934.             if ( ! native_midi_active() )
  935.                 playing = 0;
  936. -       } MIDI_ELSE
  937. +           goto skip;
  938. +       }
  939. +#endif
  940. +#ifdef USE_FLUIDSYNTH_MIDI
  941. +       if ( fluidsynth_ok ) {
  942. +           if ( ! fluidsynth_active(music_playing->data.fluidsynthmidi) )
  943. +               playing = 0;
  944. +           goto skip;
  945. +       }
  946.  #endif
  947.  #ifdef USE_TIMIDITY_MIDI
  948.         if ( timidity_ok ) {
  949.             if ( ! Timidity_Active() )
  950.                 playing = 0;
  951. +           goto skip;
  952.         }
  953.  #endif
  954.         break;
  955. @@ -1214,6 +1301,8 @@
  956.         playing = 0;
  957.         break;
  958.     }
  959. +
  960. +skip:
  961.     return(playing);
  962.  }
  963.  int Mix_PlayingMusic(void)
  964. @@ -1393,7 +1482,17 @@
  965.                 Mix_SetError("%s", native_midi_error());
  966.                 music->error = 1;
  967.             }
  968. -       } MIDI_ELSE
  969. +           goto skip;
  970. +       }
  971. +#endif
  972. +#ifdef USE_FLUIDSYNTH_MIDI
  973. +       if ( fluidsynth_ok ) {
  974. +           music->data.fluidsynthmidi = fluidsynth_loadsong_RW(rw);
  975. +           if ( music->data.fluidsynthmidi == NULL ) {
  976. +               music->error = 1;
  977. +           }
  978. +           goto skip;
  979. +       }
  980.  #endif
  981.  #ifdef USE_TIMIDITY_MIDI
  982.         if ( timidity_ok ) {
  983. @@ -1436,9 +1535,72 @@
  984.         Mix_SetError("Unrecognized music format");
  985.         music->error=1;
  986.     }
  987. +
  988. +skip:
  989.     if (music->error) {
  990.         free(music);
  991.         music=NULL;
  992.     }
  993.     return(music);
  994.  }
  995. +
  996. +int Mix_SetSoundFonts(const char *paths)
  997. +{
  998. +#ifdef MID_MUSIC
  999. +   if (soundfont_paths) {
  1000. +       free(soundfont_paths);
  1001. +       soundfont_paths = NULL;
  1002. +   }
  1003. +
  1004. +   if (paths) {
  1005. +       if (!(soundfont_paths = strdup(paths))) {
  1006. +           Mix_SetError("Insufficient memory to set SoundFonts");
  1007. +           return 0;
  1008. +       }
  1009. +   }
  1010. +#endif
  1011. +   return 1;
  1012. +}
  1013. +
  1014. +#ifdef MID_MUSIC
  1015. +const char* Mix_GetSoundFonts()
  1016. +{
  1017. +   const char* force = getenv("SDL_FORCE_SOUNDFONTS");
  1018. +
  1019. +   if (!soundfont_paths || (force && force[0] == '1')) {
  1020. +       return getenv("SDL_SOUNDFONTS");
  1021. +   } else {
  1022. +       return soundfont_paths;
  1023. +   }
  1024. +}
  1025. +
  1026. +int Mix_EachSoundFont(int (*function)(const char*, void*), void *data)
  1027. +{
  1028. +   char *context, *path, *paths;
  1029. +   const char* cpaths = Mix_GetSoundFonts();
  1030. +
  1031. +   if (!cpaths) {
  1032. +       Mix_SetError("No SoundFonts have been requested");
  1033. +       return 0;
  1034. +   }
  1035. +
  1036. +   if (!(paths = strdup(cpaths))) {
  1037. +       Mix_SetError("Insufficient memory to iterate over SoundFonts");
  1038. +       return 0;
  1039. +   }
  1040. +
  1041. +#ifdef _WIN32
  1042. +   for (path = strtok_s(paths, ";", &context); path; path = strtok_s(NULL, ";", &context)) {
  1043. +#else
  1044. +   for (path = strtok_r(paths, ":;", &context); path; path = strtok_r(NULL, ":;", &context)) {
  1045. +#endif
  1046. +       if (!function(path, data)) {
  1047. +           free(paths);
  1048. +           return 0;
  1049. +       }
  1050. +   }
  1051. +
  1052. +   free(paths);
  1053. +   return 1;
  1054. +}
  1055. +#endif
Advertisement
Add Comment
Please, Sign In to add comment