mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-14 00:21:34 +00:00
- moved the instrument set maintenance out of the Timidity++ library into the player class.
This removes the dependency on the sound font manager from the low level library, reducing the direct dependencies to FileReader and SoundFontReader.
This commit is contained in:
parent
df7a4bb0d9
commit
2cf8cc47df
7 changed files with 27 additions and 23 deletions
|
@ -45,6 +45,7 @@
|
||||||
class TimidityPPMIDIDevice : public SoftSynthMIDIDevice
|
class TimidityPPMIDIDevice : public SoftSynthMIDIDevice
|
||||||
{
|
{
|
||||||
static TimidityPlus::Instruments *instruments;
|
static TimidityPlus::Instruments *instruments;
|
||||||
|
static FString configName;
|
||||||
int sampletime;
|
int sampletime;
|
||||||
public:
|
public:
|
||||||
TimidityPPMIDIDevice(const char *args, int samplerate);
|
TimidityPPMIDIDevice(const char *args, int samplerate);
|
||||||
|
@ -70,6 +71,7 @@ protected:
|
||||||
void ComputeOutput(float *buffer, int len);
|
void ComputeOutput(float *buffer, int len);
|
||||||
};
|
};
|
||||||
TimidityPlus::Instruments *TimidityPPMIDIDevice::instruments;
|
TimidityPlus::Instruments *TimidityPPMIDIDevice::instruments;
|
||||||
|
FString TimidityPPMIDIDevice::configName;
|
||||||
|
|
||||||
// Config file to use
|
// Config file to use
|
||||||
CUSTOM_CVAR(String, timidity_config, "gzdoom", CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
CUSTOM_CVAR(String, timidity_config, "gzdoom", CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
|
@ -95,7 +97,7 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args, int samplerate)
|
||||||
if (args == NULL || *args == 0) args = timidity_config;
|
if (args == NULL || *args == 0) args = timidity_config;
|
||||||
|
|
||||||
Renderer = nullptr;
|
Renderer = nullptr;
|
||||||
if (instruments != nullptr && !instruments->checkConfig(args))
|
if (instruments != nullptr && configName.CompareNoCase(args)) // Only load instruments if they have changed from the last played song.
|
||||||
{
|
{
|
||||||
delete instruments;
|
delete instruments;
|
||||||
instruments = nullptr;
|
instruments = nullptr;
|
||||||
|
@ -103,14 +105,19 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args, int samplerate)
|
||||||
TimidityPlus::set_playback_rate(SampleRate);
|
TimidityPlus::set_playback_rate(SampleRate);
|
||||||
|
|
||||||
if (instruments == nullptr)
|
if (instruments == nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto sfreader = sfmanager.OpenSoundFont(args, SF_SF2 | SF_GUS);
|
||||||
|
if (sfreader != nullptr)
|
||||||
{
|
{
|
||||||
instruments = new TimidityPlus::Instruments;
|
instruments = new TimidityPlus::Instruments;
|
||||||
if (!instruments->load(args))
|
if (!instruments->load(sfreader))
|
||||||
{
|
{
|
||||||
delete instruments;
|
delete instruments;
|
||||||
instruments = nullptr;
|
instruments = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (instruments != nullptr)
|
if (instruments != nullptr)
|
||||||
{
|
{
|
||||||
Renderer = new TimidityPlus::Player(instruments);
|
Renderer = new TimidityPlus::Player(instruments);
|
||||||
|
|
|
@ -44,6 +44,11 @@ public:
|
||||||
|
|
||||||
virtual ~FSoundFontReader() {}
|
virtual ~FSoundFontReader() {}
|
||||||
virtual FileReader OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets
|
virtual FileReader OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets
|
||||||
|
virtual FString MainConfigFileName()
|
||||||
|
{
|
||||||
|
return basePath() + "timidity.cfg";
|
||||||
|
}
|
||||||
|
|
||||||
virtual FileReader OpenFile(const char *name) = 0;
|
virtual FileReader OpenFile(const char *name) = 0;
|
||||||
std::pair<FileReader , FString> LookupFile(const char *name);
|
std::pair<FileReader , FString> LookupFile(const char *name);
|
||||||
void AddPath(const char *str);
|
void AddPath(const char *str);
|
||||||
|
|
|
@ -127,14 +127,14 @@ double flt_rand()
|
||||||
return (int)GenRand_Real1();
|
return (int)GenRand_Real1();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader)
|
struct timidity_file *open_file(const char *name, SoundFontReaderInterface *sfreader)
|
||||||
{
|
{
|
||||||
FileReader fr;
|
FileReader fr;
|
||||||
FString filename;
|
FString filename;
|
||||||
if (name == nullptr)
|
if (name == nullptr)
|
||||||
{
|
{
|
||||||
fr = sfreader->OpenMainConfigFile();
|
fr = sfreader->OpenMainConfigFile();
|
||||||
filename = sfreader->basePath() + "timidity.cfg";
|
filename = sfreader->MainConfigFileName();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
namespace TimidityPlus
|
namespace TimidityPlus
|
||||||
{
|
{
|
||||||
|
//class SoundFontReaderInterface;
|
||||||
|
using SoundFontReaderInterface = FSoundFontReader;
|
||||||
|
|
||||||
struct timidity_file
|
struct timidity_file
|
||||||
{
|
{
|
||||||
|
@ -39,7 +41,7 @@ struct timidity_file
|
||||||
std::string filename;
|
std::string filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct timidity_file *open_file(const char *name, FSoundFontReader *);
|
extern struct timidity_file *open_file(const char *name, SoundFontReaderInterface *);
|
||||||
extern void tf_close(struct timidity_file *tf);
|
extern void tf_close(struct timidity_file *tf);
|
||||||
extern void skip(struct timidity_file *tf, size_t len);
|
extern void skip(struct timidity_file *tf, size_t len);
|
||||||
extern char *tf_gets(char *buff, int n, struct timidity_file *tf);
|
extern char *tf_gets(char *buff, int n, struct timidity_file *tf);
|
||||||
|
|
|
@ -643,7 +643,7 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_
|
||||||
{
|
{
|
||||||
char *c = strdup_mblock(&varbuf, tf->filename.c_str());
|
char *c = strdup_mblock(&varbuf, tf->filename.c_str());
|
||||||
basedir = c;
|
basedir = c;
|
||||||
for (; c; c++) if (*c == '\\') *c = '/';
|
for (; *c; c++) if (*c == '\\') *c = '/';
|
||||||
sep = (char*)strrchr(basedir, '/');
|
sep = (char*)strrchr(basedir, '/');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -52,16 +52,13 @@ Instruments::Instruments()
|
||||||
memcpy(layer_items, static_layer_items, sizeof(layer_items));
|
memcpy(layer_items, static_layer_items, sizeof(layer_items));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Instruments::load(const char *config)
|
bool Instruments::load(SoundFontReaderInterface *sf)
|
||||||
{
|
{
|
||||||
sfreader = sfmanager.OpenSoundFont(config, SF_SF2 | SF_GUS);
|
sfreader = sf;
|
||||||
if (sfreader == nullptr) return false;
|
|
||||||
|
|
||||||
if (read_config_file(nullptr, 0, 0) == RC_OK)
|
if (read_config_file(nullptr, 0, 0) == RC_OK)
|
||||||
{
|
{
|
||||||
init_load_soundfont();
|
init_load_soundfont();
|
||||||
set_default_instrument();
|
set_default_instrument();
|
||||||
configFileName = config;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "sflayer.h"
|
#include "sflayer.h"
|
||||||
#include "sfitem.h"
|
#include "sfitem.h"
|
||||||
|
|
||||||
class FSoundFontReader;
|
|
||||||
|
|
||||||
namespace TimidityPlus
|
namespace TimidityPlus
|
||||||
{
|
{
|
||||||
|
@ -233,7 +232,7 @@ struct SampleImporter;
|
||||||
class Instruments
|
class Instruments
|
||||||
{
|
{
|
||||||
std::string configFileName;
|
std::string configFileName;
|
||||||
FSoundFontReader *sfreader;
|
SoundFontReaderInterface *sfreader;
|
||||||
|
|
||||||
ToneBank standard_tonebank, standard_drumset;
|
ToneBank standard_tonebank, standard_drumset;
|
||||||
|
|
||||||
|
@ -462,7 +461,7 @@ class Instruments
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Instruments();
|
Instruments();
|
||||||
bool load(const char *config);
|
bool load(SoundFontReaderInterface *);
|
||||||
~Instruments();
|
~Instruments();
|
||||||
|
|
||||||
const ToneBank *toneBank(int i) const
|
const ToneBank *toneBank(int i) const
|
||||||
|
@ -556,12 +555,6 @@ public:
|
||||||
{
|
{
|
||||||
set_default_instrument(def_instr_name);
|
set_default_instrument(def_instr_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkConfig(const char *filename)
|
|
||||||
{
|
|
||||||
return configFileName.compare(filename) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue