From 16ab52c5f365239cdfe39e7c33423cca0649807a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 23 Sep 2019 12:45:26 +0200 Subject: [PATCH] - thinned out the FSoundFontReader interface a bit more by moving the file open code into the FSoundFontReader class itself. --- src/sound/music/i_soundfont.cpp | 39 +++++++++++++++++++++++++++++++++ src/sound/music/i_soundfont.h | 7 ++++++ src/sound/timiditypp/common.cpp | 20 +---------------- src/sound/timiditypp/timidity.h | 1 - 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/sound/music/i_soundfont.cpp b/src/sound/music/i_soundfont.cpp index a591eac97..1df64bddc 100644 --- a/src/sound/music/i_soundfont.cpp +++ b/src/sound/music/i_soundfont.cpp @@ -39,6 +39,7 @@ #include "i_system.h" #include "gameconfigfile.h" #include "resourcefiles/resourcefile.h" +#include "timiditypp/common.h" FSoundFontManager sfmanager; @@ -97,6 +98,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 diff --git a/src/sound/music/i_soundfont.h b/src/sound/music/i_soundfont.h index 9206e11ea..80a20486e 100644 --- a/src/sound/music/i_soundfont.h +++ b/src/sound/music/i_soundfont.h @@ -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); }; //========================================================================== diff --git a/src/sound/timiditypp/common.cpp b/src/sound/timiditypp/common.cpp index 8e642d9c9..3ea76febe 100644 --- a/src/sound/timiditypp/common.cpp +++ b/src/sound/timiditypp/common.cpp @@ -129,25 +129,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 */ diff --git a/src/sound/timiditypp/timidity.h b/src/sound/timiditypp/timidity.h index 5fe3667f6..ce528d46e 100644 --- a/src/sound/timiditypp/timidity.h +++ b/src/sound/timiditypp/timidity.h @@ -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 */