Skip to content
Permalink
Browse files

timidity / music_timidity.c updates (bug #4896):

* Timidity_init(): Library doesn't care about common timidity.cfg
system locations any more, callers are responsible for it. It now
takes a config_path argument as the full path of timidity.cfg.
If the config file argument contains a parent directory, that will
be added to timidity search path.  The config file is supposed to
contain any other dirs that needs to be added to the search path:
therefore no need adding several predefined directory paths to the
search paths either: they are now removed.

* configury: New --with-timidity-cfg=FILE option to set the default
config file of the library.

* music.c, New public apis Mix_SetTimidityCfg and Mix_GetTimidityCfg
Allows the mixer library user to set his own timidity config file.

* music_timidity.c, TIMIDITY_Open(): Calls Timidity_Init() with a
config file parameter now.  The config file parameter priority is
like the following:

- TIMIDITY_CFG environment var: highest priority, try nothing else.
- Mix_GetTimidityCfg() result: second priority (set by user of the
  mixer library using Mix_SetTimidityCfg()), nothing else is tried.
- If the above two are absent, a few OS-specific predefined config
  file paths are tried.  If that fails, Timidity_init() called with
  a NULL param so that the library's default config file is tried.
  • Loading branch information
sezero committed Dec 17, 2019
1 parent 8700723 commit c909cffb79408a001ab20ed13d51b6bfc7b91a2e
@@ -1,4 +1,6 @@
2.0.5:
Ozkan Sezer - Sun Dec 17 14:56:04 2019
* Timidity improvements. New Mix_SetTimidityCfg() public api.
Ozkan Sezer - Sun Dec 08 10:20:40 2019
* Improved mp3 tag detection/skipping
Ozkan Sezer - Thu Dec 05 01:41:50 2019
@@ -904,6 +904,7 @@ enable_music_mod_mikmod
enable_music_mod_mikmod_shared
enable_music_midi
enable_music_midi_timidity
with_timidity_cfg
enable_music_midi_native
enable_music_midi_fluidsynth
enable_music_midi_fluidsynth_shared
@@ -1615,6 +1616,8 @@ Optional Packages:
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-sdl-prefix=PFX Prefix where SDL is installed (optional)
--with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)
--with-timidity-cfg=FILE
Specify full path to timidity.cfg
Some influential environment variables:
CC C compiler command
@@ -3939,13 +3942,13 @@ if ${lt_cv_nm_interface+:} false; then :
else
lt_cv_nm_interface="BSD nm"
echo "int some_variable = 0;" > conftest.$ac_ext
(eval echo "\"\$as_me:3942: $ac_compile\"" >&5)
(eval echo "\"\$as_me:3945: $ac_compile\"" >&5)
(eval "$ac_compile" 2>conftest.err)
cat conftest.err >&5
(eval echo "\"\$as_me:3945: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval echo "\"\$as_me:3948: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
cat conftest.err >&5
(eval echo "\"\$as_me:3948: output\"" >&5)
(eval echo "\"\$as_me:3951: output\"" >&5)
cat conftest.out >&5
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
lt_cv_nm_interface="MS dumpbin"
@@ -5156,7 +5159,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
echo '#line 5159 "configure"' > conftest.$ac_ext
echo '#line 5162 "configure"' > conftest.$ac_ext
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
(eval $ac_compile) 2>&5
ac_status=$?
@@ -6986,11 +6989,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:6989: $lt_compile\"" >&5)
(eval echo "\"\$as_me:6992: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:6993: \$? = $ac_status" >&5
echo "$as_me:6996: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -7325,11 +7328,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:7328: $lt_compile\"" >&5)
(eval echo "\"\$as_me:7331: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:7332: \$? = $ac_status" >&5
echo "$as_me:7335: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -7430,11 +7433,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:7433: $lt_compile\"" >&5)
(eval echo "\"\$as_me:7436: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:7437: \$? = $ac_status" >&5
echo "$as_me:7440: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -7485,11 +7488,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:7488: $lt_compile\"" >&5)
(eval echo "\"\$as_me:7491: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:7492: \$? = $ac_status" >&5
echo "$as_me:7495: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -9854,7 +9857,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 9857 "configure"
#line 9860 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -9950,7 +9953,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 9953 "configure"
#line 9956 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12118,6 +12121,16 @@ fi
if test x$enable_music_midi_timidity = xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -DMUSIC_MID_TIMIDITY -I\$(srcdir)/src/codecs/timidity"
SOURCES="$SOURCES $srcdir/src/codecs/timidity/*.c"
timidity_cfg=no

# Check whether --with-timidity-cfg was given.
if test "${with_timidity_cfg+set}" = set; then :
withval=$with_timidity_cfg; timidity_cfg="$withval"
fi

if test x$timidity_cfg != xyes -a x$timidity_cfg != xno; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -DTIMIDITY_CFG=\\\"$timidity_cfg\\\""
fi
fi
# Check whether --enable-music-midi-native was given.
if test "${enable_music_midi_native+set}" = set; then :
@@ -361,6 +361,12 @@ AC_HELP_STRING([--enable-music-midi-timidity], [enable timidity MIDI output [[de
if test x$enable_music_midi_timidity = xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -DMUSIC_MID_TIMIDITY -I\$(srcdir)/src/codecs/timidity"
SOURCES="$SOURCES $srcdir/src/codecs/timidity/*.c"
timidity_cfg=no
AC_ARG_WITH([timidity-cfg],
AC_HELP_STRING([--with-timidity-cfg=FILE], [Specify full path to timidity.cfg]), timidity_cfg="$withval", [])
if test x$timidity_cfg != xyes -a x$timidity_cfg != xno; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -DTIMIDITY_CFG=\\\"$timidity_cfg\\\""
fi
fi
AC_ARG_ENABLE([music-midi-native],
AC_HELP_STRING([--enable-music-midi-native], [enable native MIDI music output [[default=yes]]]),
@@ -627,6 +627,10 @@ extern DECLSPEC int SDLCALL Mix_SetSoundFonts(const char *paths);
extern DECLSPEC const char* SDLCALL Mix_GetSoundFonts(void);
extern DECLSPEC int SDLCALL Mix_EachSoundFont(int (SDLCALL *function)(const char*, void*), void *data);

/* Set/Get full path of Timidity config file (e.g. /etc/timidity.cfg) */
extern DECLSPEC int SDLCALL Mix_SetTimidityCfg(const char *path);
extern DECLSPEC const char* SDLCALL Mix_GetTimidityCfg(void);

/* Get the Mix_Chunk currently associated with a mixer channel
Returns NULL if it's an invalid channel, or there's no chunk associated.
*/
@@ -41,10 +41,40 @@ typedef struct
static int TIMIDITY_Seek(void *context, double position);
static void TIMIDITY_Delete(void *context);

/* Config file should contain any other directory that needs
* to be added to the search path. The library adds the path
* of the config file to its search path, too. */
#if defined(__WIN32__) || defined(__OS2__)
# define TIMIDITY_CFG "C:\\TIMIDITY\\TIMIDITY.CFG"
#else /* unix: */
# define TIMIDITY_CFG_ETC "/etc/timidity.cfg"
# define TIMIDITY_CFG_FREEPATS "/etc/timidity/freepats.cfg"
#endif

static int TIMIDITY_Open(const SDL_AudioSpec *spec)
{
const char *cfg;
int rc = -1;

(void) spec;
return Timidity_Init();

cfg = SDL_getenv("TIMIDITY_CFG");
if(!cfg) cfg = Mix_GetTimidityCfg();
if (cfg) {
return Timidity_Init(cfg); /* env or user override: no other tries */
}
#if defined(TIMIDITY_CFG)
if (rc < 0) rc = Timidity_Init(TIMIDITY_CFG);
#endif
#if defined(TIMIDITY_CFG_ETC)
if (rc < 0) rc = Timidity_Init(TIMIDITY_CFG_ETC);
#endif
#if defined(TIMIDITY_CFG_FREEPATS)
if (rc < 0) rc = Timidity_Init(TIMIDITY_CFG_FREEPATS);
#endif
if (rc < 0) rc = Timidity_Init(NULL); /* library's default cfg. */

return rc;
}

static void TIMIDITY_Close(void)
@@ -22,6 +22,16 @@
#include "options.h"
#include "common.h"

#if defined(__WIN32__) || defined(__OS2__)
#define CHAR_DIRSEP '\\'
#define is_dirsep(c) ((c) == '/' || (c) == '\\')
#define is_abspath(p) ((p)[0] == '/' || (p)[0] == '\\' || ((p)[0] && (p)[1] == ':'))
#else /* unix: */
#define CHAR_DIRSEP '/'
#define is_dirsep(c) ((c) == '/')
#define is_abspath(p) ((p)[0] == '/')
#endif

/* The paths in this list will be tried whenever we're reading a file */
static PathList *pathlist = NULL; /* This is a linked list */

@@ -42,7 +52,7 @@ SDL_RWops *open_file(const char *name)
if ((rw = SDL_RWFromFile(name, "rb")))
return rw;

if (name[0] != PATH_SEP)
if (!is_abspath(name))
{
char current_filename[1024];
PathList *plp = pathlist;
@@ -55,9 +65,9 @@ SDL_RWops *open_file(const char *name)
if(l)
{
strcpy(current_filename, plp->path);
if(current_filename[l - 1] != PATH_SEP)
if(!is_dirsep(current_filename[l - 1]))
{
current_filename[l] = PATH_SEP;
current_filename[l] = CHAR_DIRSEP;
current_filename[l + 1] = '\0';
}
}
@@ -88,21 +98,21 @@ void *safe_malloc(size_t count)
}

/* This adds a directory to the path list */
void add_to_pathlist(const char *s)
void add_to_pathlist(const char *s, size_t l)
{
PathList *plp = safe_malloc(sizeof(PathList));

if (plp == NULL)
return;

plp->path = safe_malloc(strlen(s) + 1);
plp->path = safe_malloc(l + 1);
if (plp->path == NULL)
{
free(plp);
free (plp);
return;
}

strcpy(plp->path, s);
strncpy(plp->path, s, l);
plp->path[l] = 0;
plp->next = pathlist;
pathlist = plp;
}
@@ -15,6 +15,6 @@ typedef struct {
} PathList;

extern SDL_RWops *open_file(const char *name);
extern void add_to_pathlist(const char *s);
extern void add_to_pathlist(const char *s, size_t len);
extern void *safe_malloc(size_t count);
extern void free_pathlist(void);
@@ -71,17 +71,8 @@

/* You could specify a complete path, e.g. "/etc/timidity.cfg", and
then specify the library directory in the configuration file. */
#define CONFIG_FILE "timidity.cfg"
#define CONFIG_FILE_ETC "/etc/timidity.cfg"
#define CONFIG_FILE_ETC_TIMIDITY_FREEPATS "/etc/timidity/freepats.cfg"

#if defined(__WIN32__) || defined(__OS2__)
#define DEFAULT_PATH "C:\\TIMIDITY"
#else
#define DEFAULT_PATH "/etc/timidity"
#define DEFAULT_PATH1 "/usr/share/timidity"
#define DEFAULT_PATH2 "/usr/local/share/timidity"
#define DEFAULT_PATH3 "/usr/local/lib/timidity"
#ifndef TIMIDITY_CFG
#define TIMIDITY_CFG "timidity.cfg"
#endif

/* These affect general volume */
@@ -107,11 +98,4 @@
#define PI 3.14159265358979323846
#endif

/* The path separator (D.M.) */
#if defined(__WIN32__) || defined(__OS2__)
# define PATH_SEP '\\'
#else
# define PATH_SEP '/'
#endif

#define SNDDBG(X)
@@ -203,7 +203,7 @@ static int read_config_file(const char *name)
goto fail;
}
for (i=1; i<words; i++)
add_to_pathlist(w[i]);
add_to_pathlist(w[i], strlen(w[i]));
}
else if (!strcmp(w[0], "source"))
{
@@ -398,7 +398,7 @@ static int read_config_file(const char *name)
return -2;
}

int Timidity_Init_NoConfig()
int Timidity_Init_NoConfig(void)
{
/* Allocate memory for the standard tonebank and drumset */
master_tonebank[0] = safe_malloc(sizeof(ToneBank));
@@ -414,40 +414,25 @@ int Timidity_Init_NoConfig()
return 0;
}

int Timidity_Init()
int Timidity_Init(const char *config_file)
{
const char *env = SDL_getenv("TIMIDITY_CFG");

/* !!! FIXME: This may be ugly, but slightly less so than requiring the
* default search path to have only one element. I think.
*
* We only need to include the likely locations for the config
* file itself since that file should contain any other directory
* that needs to be added to the search path.
*/
#ifdef DEFAULT_PATH
add_to_pathlist(DEFAULT_PATH);
#endif
#ifdef DEFAULT_PATH1
add_to_pathlist(DEFAULT_PATH1);
#endif
#ifdef DEFAULT_PATH2
add_to_pathlist(DEFAULT_PATH2);
#endif
#ifdef DEFAULT_PATH3
add_to_pathlist(DEFAULT_PATH3);
#endif
const char *p;

Timidity_Init_NoConfig();

if (!env || read_config_file(env)<0) {
if (read_config_file(CONFIG_FILE)<0) {
if (read_config_file(CONFIG_FILE_ETC)<0) {
if (read_config_file(CONFIG_FILE_ETC_TIMIDITY_FREEPATS)<0) {
return(-1);
}
}
}
if (config_file == NULL || *config_file == '\0')
config_file = TIMIDITY_CFG;

p = strrchr(config_file, '/');
#if defined(__WIN32__)||defined(__OS2__)
if (!p) p = strrchr(config_file, '\\');
#endif
if (p != NULL)
add_to_pathlist(config_file, p - config_file + 1);

if (read_config_file(config_file) < 0) {
Timidity_Exit();
return -1;
}
return 0;
}
@@ -146,7 +146,7 @@ typedef struct {

/* Some of these are not defined in timidity.c but are here for convenience */

extern int Timidity_Init(void);
extern int Timidity_Init(const char *config_file);
extern int Timidity_Init_NoConfig(void);
extern void Timidity_SetVolume(MidiSong *song, int volume);
extern int Timidity_PlaySome(MidiSong *song, void *stream, Sint32 len);

0 comments on commit c909cff

Please sign in to comment.