- rewrote the ZMusic interface so that it is free of C++ constructs.

Now it is ready to put in a DLL.
This commit is contained in:
Christoph Oelckers 2020-01-02 01:26:01 +01:00
commit d2ca1ea4e0
19 changed files with 224 additions and 182 deletions

View file

@ -7,7 +7,6 @@
#include "vectors.h"
#include "tarray.h"
#include "zmusic/sounddecoder.h"
#include "../../libraries/music_common/fileio.h"
#include "tflags.h"
enum EChanFlag

View file

@ -193,11 +193,26 @@ static const char* mus_pathToSoundFont(const char* sfname, int type)
return info ? info->mFilename.GetChars() : nullptr;
}
static MusicIO::SoundFontReaderInterface* mus_openSoundFont(const char* sfname, int type)
static void* mus_openSoundFont(const char* sfname, int type)
{
return sfmanager.OpenSoundFont(sfname, type);
}
static ZMusicCustomReader* mus_sfopenfile(void* handle, const char* fn)
{
return reinterpret_cast<FSoundFontReader*>(handle)->open_interface(fn);
}
static void mus_sfaddpath(void *handle, const char* path)
{
reinterpret_cast<FSoundFontReader*>(handle)->AddPath(path);
}
static void mus_sfclose(void* handle)
{
reinterpret_cast<FSoundFontReader*>(handle)->close();
}
//==========================================================================
//
@ -266,7 +281,7 @@ void I_InitMusic (void)
#endif // _WIN32
snd_mididevice.Callback();
Callbacks callbacks;
Callbacks callbacks{};
callbacks.Fluid_MessageFunc = Printf;
callbacks.GUS_MessageFunc = callbacks.Timidity_Messagefunc = tim_printfunc;
@ -274,6 +289,9 @@ void I_InitMusic (void)
callbacks.NicePath = mus_NicePath;
callbacks.PathForSoundfont = mus_pathToSoundFont;
callbacks.OpenSoundFont = mus_openSoundFont;
callbacks.SF_OpenFile = mus_sfopenfile;
callbacks.SF_AddToSearchPath = mus_sfaddpath;
callbacks.SF_Close = mus_sfclose;
ZMusic_SetCallbacks(&callbacks);
SetupGenMidi();

View file

@ -135,30 +135,17 @@ FileReader FSoundFontReader::Open(const char *name, std::string& filename)
//
//==========================================================================
MusicIO::FileInterface* FSoundFontReader::open_interface(const char* name)
ZMusicCustomReader* FSoundFontReader::open_interface(const char* name)
{
std::string filename;
FileReader fr = Open(name, filename);
if (!fr.isOpen()) return nullptr;
auto fri = new FileReaderMusicInterface(fr);
fri->filename = std::move(filename);
auto fri = GetMusicReader(fr);
return fri;
}
//==========================================================================
//
// The file interface for the backend
//
//==========================================================================
struct MusicIO::FileInterface* FSoundFontReader::open_file(const char* name)
{
return open_interface(name);
}
//==========================================================================
//
// Note that the file type has already been checked

View file

@ -19,8 +19,7 @@ struct FSoundFontInfo
//
//==========================================================================
class FSoundFontReader : public MusicIO::SoundFontReaderInterface
// Yes, it's 3 copies of essentially the same interface, but since we want to keep the 3 renderers as isolated modules we have to pull in their own implementations here.
class FSoundFontReader
{
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.
@ -52,15 +51,12 @@ public:
}
virtual FileReader Open(const char* name, std::string &filename);
virtual void close()
{
delete this;
}
// Timidity++ interface
struct MusicIO::FileInterface* open_file(const char* name) override;
void add_search_path(const char* name) override
{
return AddPath(name);
}
MusicIO::FileInterface* open_interface(const char* name);
ZMusicCustomReader* open_interface(const char* name);
};

View file

@ -1,45 +1,9 @@
#pragma once
#include "../libraries/music_common/fileio.h"
#include "zmusic/zmusic.h"
#include "files.h"
struct FileReaderMusicInterface : public MusicIO::FileInterface
{
FileReader fr;
FileReaderMusicInterface(FileReader& fr_in)
{
fr = std::move(fr_in);
}
char* gets(char* buff, int n) override
{
if (!fr.isOpen()) return nullptr;
return fr.Gets(buff, n);
}
long read(void* buff, int32_t size) override
{
if (!fr.isOpen()) return 0;
return (long)fr.Read(buff, 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();
}
FileReader& getReader()
{
return fr;
}
};
inline ZMusicCustomReader *GetMusicReader(FileReader& fr)
{
auto zcr = new ZMusicCustomReader;