- refactored the GUS/Timidity player's path building code so that it can also be used by WildMidi.

- fixed crash during sound reset - in this case I_ShutdownMusic should not close the WildMidi player.
This commit is contained in:
Christoph Oelckers 2015-12-29 20:38:08 +01:00
commit fe2dcfd588
11 changed files with 198 additions and 121 deletions

View file

@ -35,82 +35,6 @@
namespace Timidity
{
static TArray<FString> PathList;
FString BuildPath(FString base, const char *name)
{
FString current;
if (base.IsNotEmpty())
{
current = base;
if (current[current.Len() - 1] != '/') current += '/';
}
current += name;
return current;
}
/* This is meant to find and open files for reading. */
FileReader *open_filereader(const char *name, int open, int *plumpnum)
{
FileReader *fp;
FString current_filename;
if (!name || !(*name))
{
return 0;
}
/* First try the given name */
current_filename = name;
FixPathSeperator(current_filename);
int lumpnum = Wads.CheckNumForFullName(current_filename);
if (open != OM_FILE)
{
if (lumpnum >= 0)
{
fp = Wads.ReopenLumpNum(lumpnum);
if (plumpnum) *plumpnum = lumpnum;
return fp;
}
if (open == OM_LUMP) // search the path list when not loading the main config
{
for (unsigned int plp = PathList.Size(); plp-- != 0; )
{ /* Try along the path then */
current_filename = BuildPath(PathList[plp], name);
lumpnum = Wads.CheckNumForFullName(current_filename);
if (lumpnum >= 0)
{
fp = Wads.ReopenLumpNum(lumpnum);
if (plumpnum) *plumpnum = lumpnum;
return fp;
}
}
return NULL;
}
}
if (plumpnum) *plumpnum = -1;
fp = new FileReader;
if (fp->Open(current_filename)) return fp;
if (name[0] != '/')
{
for (unsigned int plp = PathList.Size(); plp-- != 0; )
{ /* Try along the path then */
current_filename = BuildPath(PathList[plp], name);
if (fp->Open(current_filename)) return fp;
}
}
delete fp;
/* Nothing could be opened. */
current_filename = "";
return NULL;
}
/* This'll allocate memory or die. */
@ -132,17 +56,5 @@ void *safe_malloc(size_t count)
return 0; // Unreachable.
}
/* This adds a directory to the path list */
void add_to_pathlist(const char *s)
{
FString copy = s;
FixPathSeperator(copy);
PathList.Push(copy);
}
void clear_pathlist()
{
PathList.Clear();
}
}

View file

@ -159,12 +159,12 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss
if (!name) return 0;
/* Open patch file */
if ((fp = open_filereader(name, openmode, NULL)) == NULL)
if ((fp = pathExpander.openFileReader(name, NULL)) == NULL)
{
/* Try with various extensions */
FString tmp = name;
tmp += ".pat";
if ((fp = open_filereader(tmp, openmode, NULL)) == NULL)
if ((fp = pathExpander.openFileReader(tmp, NULL)) == NULL)
{
#ifdef __unix__ // Windows isn't case-sensitive.
tmp.ToUpper();

View file

@ -54,7 +54,7 @@ void font_add(const char *filename, int load_order)
}
else
{
FileReader *fp = open_filereader(filename, openmode, NULL);
FileReader *fp = pathExpander.openFileReader(filename, NULL);
if (fp != NULL)
{

View file

@ -1502,7 +1502,7 @@ void SFFile::ApplyGeneratorsToRegion(SFGenComposite *gen, SFSample *sfsamp, Rend
void SFFile::LoadSample(SFSample *sample)
{
FileReader *fp = open_filereader(Filename, openmode, NULL);
FileReader *fp = pathExpander.openFileReader(Filename, NULL);
DWORD i;
if (fp == NULL)

View file

@ -42,10 +42,10 @@ CVAR(Int, gus_memsize, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
namespace Timidity
{
PathExpander pathExpander;
ToneBank *tonebank[MAXBANK], *drumset[MAXBANK];
static FString def_instr_name;
int openmode = OM_FILEORLUMP;
static int read_config_file(const char *name, bool ismain)
{
@ -62,21 +62,21 @@ static int read_config_file(const char *name, bool ismain)
return (-1);
}
if (ismain) openmode = OM_FILEORLUMP;
if (ismain) pathExpander.openmode = PathExpander::OM_FILEORLUMP;
if (!(fp = open_filereader(name, openmode, &lumpnum)))
if (!(fp = pathExpander.openFileReader(name, &lumpnum)))
return -1;
if (ismain)
{
if (lumpnum > 0)
{
openmode = OM_LUMP;
clear_pathlist(); // when reading from a PK3 we won't want to use any external path
pathExpander.openmode = PathExpander::OM_LUMP;
pathExpander.clearPathlist(); // when reading from a PK3 we don't want to use any external path
}
else
{
openmode = OM_FILE;
pathExpander.openmode = PathExpander::OM_FILE;
}
}
@ -288,7 +288,7 @@ static int read_config_file(const char *name, bool ismain)
return -2;
}
for (i = 1; i < words; i++)
add_to_pathlist(w[i]);
pathExpander.addToPathlist(w[i]);
}
else if (!strcmp(w[0], "source"))
{
@ -532,15 +532,15 @@ int LoadConfig(const char *filename)
* file itself since that file should contain any other directory
* that needs to be added to the search path.
*/
clear_pathlist();
pathExpander.clearPathlist();
#ifdef _WIN32
add_to_pathlist("C:\\TIMIDITY");
add_to_pathlist("\\TIMIDITY");
add_to_pathlist(progdir);
pathExpander.addToPathlist("C:\\TIMIDITY");
pathExpander.addToPathlist("\\TIMIDITY");
pathExpander.addToPathlist(progdir);
#else
add_to_pathlist("/usr/local/lib/timidity");
add_to_pathlist("/etc/timidity");
add_to_pathlist("/etc");
pathExpander.addToPathlist("/usr/local/lib/timidity");
pathExpander.addToPathlist("/etc/timidity");
pathExpander.addToPathlist("/etc");
#endif
/* Some functions get aggravated if not even the standard banks are available. */
@ -579,10 +579,10 @@ int LoadDMXGUS()
if (ultradir.IsNotEmpty())
{
ultradir += "/midi";
add_to_pathlist(ultradir.GetChars());
pathExpander.addToPathlist(ultradir.GetChars());
}
// Load DMXGUS lump and patches from gus_patchdir
add_to_pathlist(gus_patchdir);
pathExpander.addToPathlist(gus_patchdir);
char readbuffer[1024];
long size = data.GetLength();

View file

@ -21,6 +21,7 @@
#define TIMIDITY_H
#include "doomtype.h"
#include "pathexpander.h"
class FileReader;
@ -172,17 +173,8 @@ extern __inline__ double pow_x87_inline(double x,double y)
common.h
*/
#define OM_FILEORLUMP 0
#define OM_LUMP 1
#define OM_FILE 2
extern void add_to_pathlist(const char *s);
extern void clear_pathlist();
extern void *safe_malloc(size_t count);
FileReader *open_filereader(const char *name, int open, int *plumpnum);
extern int openmode;
/*
controls.h
*/
@ -627,6 +619,7 @@ int LoadConfig(const char *filename);
int LoadDMXGUS();
extern int LoadConfig();
extern void FreeAll();
extern PathExpander pathExpander;
extern ToneBank *tonebank[MAXBANK];
extern ToneBank *drumset[MAXBANK];