- implemented an abstract sound font reader interface for Timidity++.

The only dependency left on the main GZDoom code are the CVars, which will be dealt with next.
This commit is contained in:
Christoph Oelckers 2019-09-23 13:53:28 +02:00
parent 16ab52c5f3
commit cf6d0c3127
11 changed files with 72 additions and 54 deletions

View file

@ -37,6 +37,7 @@
#include "i_musicinterns.h"
#include "v_text.h"
#include "doomerrors.h"
#include "i_soundfont.h"
#include "timiditypp/timidity.h"
#include "timiditypp/instrum.h"

View file

@ -35,6 +35,7 @@
#include <ctype.h>
#include <assert.h>
#include "i_soundfont.h"
#include "i_soundinternal.h"
#include "cmdlib.h"
#include "i_system.h"
#include "gameconfigfile.h"
@ -43,6 +44,33 @@
FSoundFontManager sfmanager;
struct timidity_file_FileReader : public TimidityPlus::timidity_file
{
FileReader fr;
char* gets(char* buff, int n) override
{
if (!fr.isOpen()) return nullptr;
return fr.Gets(buff, n);
}
long read(void* buff, int32_t size, int32_t nitems) override
{
if (!fr.isOpen()) return 0;
return (long)fr.Read(buff, size * nitems) / size;
}
long seek(long offset, int whence) override
{
if (!fr.isOpen()) return 0;
return (long)fr.Seek(offset, (FileReader::ESeek)whence);
}
long tell() override
{
if (!fr.isOpen()) return 0;
return (long)fr.Tell();
}
};
//==========================================================================
//
// returns both a file reader and the full name of the looked up file
@ -122,15 +150,15 @@ FileReader FSoundFontReader::Open(const char *name, std::string& filename)
//
//==========================================================================
struct TimidityPlus::timidity_file* FSoundFontReader::open_timidity_file(const char* name)
struct TimidityPlus::timidity_file* FSoundFontReader::open_timidityplus_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);
auto tf = new timidity_file_FileReader;
tf->fr = std::move(fr);
tf->filename = std::move(filename);
return tf;
}

View file

@ -3,6 +3,7 @@
#include "doomtype.h"
#include "w_wad.h"
#include "files.h"
#include "timiditypp/timidity_file.h"
enum
{
@ -20,17 +21,13 @@ struct FSoundFontInfo
int type;
};
namespace TimidityPlus
{
struct timidity_file;
}
//==========================================================================
//
//
//
//==========================================================================
class FSoundFontReader
class FSoundFontReader : public TimidityPlus::SoundFontReaderInterface
{
protected:
// This is only doable for loose config files that get set as sound fonts. All other cases read from a contained environment where this does not apply.
@ -62,7 +59,11 @@ public:
}
virtual FileReader Open(const char* name, std::string &filename);
virtual struct TimidityPlus::timidity_file* open_timidity_file(const char* name);
virtual struct TimidityPlus::timidity_file* open_timidityplus_file(const char* name);
virtual void timidityplus_add_path(const char* name)
{
return AddPath(name);
}
};
//==========================================================================

View file

@ -36,6 +36,7 @@
#include "i_musicinterns.h"
#include "v_text.h"
#include "timidity.h"
#include "i_soundfont.h"
CUSTOM_CVAR(String, midi_config, "gzdoom", CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{

View file

@ -129,48 +129,27 @@ double flt_rand()
struct timidity_file *open_file(const char *name, SoundFontReaderInterface *sfreader)
{
return sfreader->open_timidity_file(name);
return sfreader->open_timidityplus_file(name);
}
/* This closes files opened with open_file */
void tf_close(struct timidity_file *tf)
{
tf->url.Close();
delete tf;
}
/* This is meant for skipping a few bytes. */
void skip(struct timidity_file *tf, size_t len)
{
tf->url.Seek((long)len, FileReader::SeekCur);
}
char *tf_gets(char *buff, int n, struct timidity_file *tf)
{
return tf->url.Gets(buff, n);
tf_seek(tf, (long)len, SEEK_CUR);
}
int tf_getc(struct timidity_file *tf)
{
unsigned char c;
auto read = tf->url.Read(&c, 1);
auto read = tf_read(&c, 1, 1, tf);
return read == 0 ? EOF : c;
}
long tf_read(void *buff, int32_t size, int32_t nitems, struct timidity_file *tf)
{
return (long)tf->url.Read(buff, size * nitems) / size;
}
long tf_seek(struct timidity_file *tf, long offset, int whence)
{
return (long)tf->url.Seek(offset, (FileReader::ESeek)whence);
}
long tf_tell(struct timidity_file *tf)
{
return (long)tf->url.Tell();
}
}

View file

@ -27,28 +27,34 @@
#include <string>
#include <vector>
#include <stdint.h>
#include "files.h"
#include "i_soundfont.h"
#include "timidity_file.h"
namespace TimidityPlus
{
//class SoundFontReaderInterface;
using SoundFontReaderInterface = FSoundFontReader;
struct timidity_file
inline char* tf_gets(char* buff, int n, struct timidity_file* tf)
{
FileReader url;
std::string filename;
};
return tf->gets(buff, n);
}
inline long tf_read(void* buff, int32_t size, int32_t nitems, struct timidity_file* tf)
{
return (long)tf->read(buff, size, nitems);
}
inline long tf_seek(struct timidity_file* tf, long offset, int whence)
{
return (long)tf->seek(offset, whence);
}
inline long tf_tell(struct timidity_file* tf)
{
return (long)tf->tell();
}
extern struct timidity_file *open_file(const char *name, SoundFontReaderInterface *);
extern void tf_close(struct timidity_file *tf);
extern void skip(struct timidity_file *tf, size_t len);
extern char *tf_gets(char *buff, int n, struct timidity_file *tf);
int tf_getc(struct timidity_file *tf);
extern long tf_read(void *buff, int32_t size, int32_t nitems, struct timidity_file *tf);
extern long tf_seek(struct timidity_file *tf, long offset, int whence);
extern long tf_tell(struct timidity_file *tf);
extern int int_rand(int n); /* random [0..n-1] */
double flt_rand();

View file

@ -1397,7 +1397,7 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_
continue;
}
for (i = 1; i < words; i++)
sfreader->AddPath(w[i]);
sfreader->timidityplus_add_path(w[i]);
}
else if (!strcmp(w[0], "source") || !strcmp(w[0], "trysource"))
{

View file

@ -1,7 +1,6 @@
#pragma once
#include <stdint.h>
#include "m_random.h"
#include "timidity.h"

View file

@ -36,6 +36,7 @@
#include "common.h"
#include "filter.h"
#include "sysdep.h"
namespace TimidityPlus
{

View file

@ -32,15 +32,10 @@
#include "resample.h"
#include "mix.h"
#include "optcode.h"
#include "c_cvars.h"
CUSTOM_CVAR(Float, min_sustain_time, 5000, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0) self = 0;
}
namespace TimidityPlus
{
extern float min_sustain_time;
#define FROM_FINAL_VOLUME(a) (a)

View file

@ -59,6 +59,7 @@ namespace TimidityPlus
float timidity_drum_power = 1.f;
int timidity_key_adjust = 0;
float timidity_tempo_adjust = 1.f;
float min_sustain_time = 5000;
// The following options have no generic use and are only meaningful for some SYSEX events not normally found in common MIDIs.
// For now they are kept as unchanging global variables
@ -196,6 +197,12 @@ CUSTOM_CVAR(Float, timidity_tempo_adjust, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
ChangeVarSync(TimidityPlus::timidity_tempo_adjust, *self);
}
CUSTOM_CVAR(Float, min_sustain_time, 5000, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0) self = 0;
ChangeVarSync(TimidityPlus::min_sustain_time, *self);
}
namespace TimidityPlus
{