- thinned out the FSoundFontReader interface a bit more by moving the file open code into the FSoundFontReader class itself.

This commit is contained in:
Christoph Oelckers 2019-09-23 12:45:26 +02:00 committed by drfrag
parent e968ef9ded
commit 9d5f4969e7
4 changed files with 47 additions and 20 deletions

View file

@ -41,6 +41,7 @@
#include "i_system.h"
#include "gameconfigfile.h"
#include "resourcefiles/resourcefile.h"
#include "timiditypp/common.h"
FSoundFontManager sfmanager;
@ -99,6 +100,44 @@ int FSoundFontReader::pathcmp(const char *p1, const char *p2)
return mCaseSensitivePaths? strcmp(p1, p2) : stricmp(p1, p2);
}
FileReader FSoundFontReader::Open(const char *name, std::string& filename)
{
FileReader fr;
if (name == nullptr)
{
fr = OpenMainConfigFile();
filename = MainConfigFileName();
}
else
{
auto res = LookupFile(name);
fr = std::move(res.first);
filename = res.second;
}
return fr;
}
//==========================================================================
//
// This is the interface function for Timidity++
//
//==========================================================================
struct TimidityPlus::timidity_file* FSoundFontReader::open_timidity_file(const char* name)
{
std::string filename;
FileReader fr = Open(name, filename);
if (!fr.isOpen()) return nullptr;
auto tf = new TimidityPlus::timidity_file;
tf->url = std::move(fr);
tf->filename = std::move(filename);
return tf;
}
//==========================================================================
//
// Note that the file type has already been checked

View file

@ -20,6 +20,10 @@ struct FSoundFontInfo
int type;
};
namespace TimidityPlus
{
struct timidity_file;
}
//==========================================================================
//
//
@ -56,6 +60,9 @@ public:
{
return ""; // archived patch sets do not use paths
}
virtual FileReader Open(const char* name, std::string &filename);
virtual struct TimidityPlus::timidity_file* open_timidity_file(const char* name);
};
//==========================================================================

View file

@ -132,25 +132,7 @@ double flt_rand()
struct timidity_file *open_file(const char *name, SoundFontReaderInterface *sfreader)
{
FileReader fr;
FString filename;
if (name == nullptr)
{
fr = sfreader->OpenMainConfigFile();
filename = sfreader->MainConfigFileName();
}
else
{
auto res = sfreader->LookupFile(name);
fr = std::move(res.first);
filename = res.second;
}
if (!fr.isOpen()) return nullptr;
auto tf = new timidity_file;
tf->url = std::move(fr);
tf->filename = filename.GetChars();
return tf;
return sfreader->open_timidity_file(name);
}
/* This closes files opened with open_file */

View file

@ -170,6 +170,5 @@ const int max_voices = DEFAULT_VOICES;
const int temper_type_mute = 0;
const int opt_preserve_silence = 0;
const int opt_init_keysig = 8;
}
#endif /* TIMIDITY_H_INCLUDED */