music.c
changeset 801 46acd70caa6a
parent 797 b4b6adff699a
child 802 98ee7bc3833a
     1.1 --- a/music.c	Sat Oct 21 01:32:12 2017 -0700
     1.2 +++ b/music.c	Sat Oct 21 02:10:33 2017 -0700
     1.3 @@ -66,7 +66,7 @@
     1.4  static int num_decoders = 0;
     1.5  
     1.6  /* Semicolon-separated SoundFont paths */
     1.7 -char* soundfont_paths = NULL;
     1.8 +static char* soundfont_paths = NULL;
     1.9  
    1.10  /* Interfaces for the various music interfaces, ordered by priority */
    1.11  static Mix_MusicInterface *s_music_interfaces[] =
    1.12 @@ -297,6 +297,13 @@
    1.13      int i;
    1.14      SDL_bool use_native_midi = SDL_FALSE;
    1.15  
    1.16 +#ifdef MIX_INIT_SOUNDFONT_PATHS
    1.17 +    if (!soundfont_paths) {
    1.18 +        soundfont_paths = SDL_strdup(MIX_INIT_SOUNDFONT_PATHS);
    1.19 +    }
    1.20 +#endif
    1.21 +
    1.22 +
    1.23  #ifdef MUSIC_MID_NATIVE
    1.24      if (SDL_GetHintBoolean("SDL_NATIVE_MUSIC", SDL_FALSE) && native_midi_detect()) {
    1.25          use_native_midi = SDL_TRUE;
    1.26 @@ -929,9 +936,16 @@
    1.27          interface->opened = SDL_FALSE;
    1.28      }
    1.29  
    1.30 +    if (soundfont_paths) {
    1.31 +        SDL_free(soundfont_paths);
    1.32 +        soundfont_paths = NULL;
    1.33 +    }
    1.34 +
    1.35      /* rcg06042009 report available decoders at runtime. */
    1.36 -    SDL_free((void *)music_decoders);
    1.37 -    music_decoders = NULL;
    1.38 +    if (music_decoders) {
    1.39 +        SDL_free((void *)music_decoders);
    1.40 +        music_decoders = NULL;
    1.41 +    }
    1.42      num_decoders = 0;
    1.43  
    1.44      ms_per_step = 0;
    1.45 @@ -972,11 +986,36 @@
    1.46  
    1.47  const char* Mix_GetSoundFonts(void)
    1.48  {
    1.49 -    if (!soundfont_paths || SDL_GetHintBoolean("SDL_FORCE_SOUNDFONTS", SDL_FALSE)) {
    1.50 -        return SDL_getenv("SDL_SOUNDFONTS");
    1.51 -    } else {
    1.52 +    const char *env_paths = SDL_getenv("SDL_SOUNDFONTS");
    1.53 +    SDL_bool force_env_paths = SDL_GetHintBoolean("SDL_FORCE_SOUNDFONTS", SDL_FALSE);
    1.54 +    if (force_env_paths && (!env_paths || !*env_paths)) {
    1.55 +        force_env_paths = SDL_FALSE;
    1.56 +    }
    1.57 +    if (soundfont_paths && *soundfont_paths && !force_env_paths) {
    1.58          return soundfont_paths;
    1.59      }
    1.60 +    if (env_paths) {
    1.61 +        return env_paths;
    1.62 +    }
    1.63 +
    1.64 +    /* We don't have any sound fonts set programmatically or in the environment
    1.65 +       Time to start guessing where they might be...
    1.66 +     */
    1.67 +    {
    1.68 +        static char *s_soundfont_paths[] = {
    1.69 +            "/usr/share/sounds/sf2/FluidR3_GM.sf2"  /* Remember to add ',' here */
    1.70 +        };
    1.71 +        unsigned i;
    1.72 +
    1.73 +        for (i = 0; i < SDL_arraysize(s_soundfont_paths); ++i) {
    1.74 +            SDL_RWops *rwops = SDL_RWFromFile(s_soundfont_paths[i], "rb");
    1.75 +            if (rwops) {
    1.76 +                SDL_RWclose(rwops);
    1.77 +                return s_soundfont_paths[i];
    1.78 +            }
    1.79 +        }
    1.80 +    }
    1.81 +    return NULL;
    1.82  }
    1.83  
    1.84  int Mix_EachSoundFont(int (*function)(const char*, void*), void *data)