mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-10 23:01:59 +00:00
- Removed FileReader from SoundFont manager.
- renamed close_file to tf_close for consistency.
This commit is contained in:
parent
c4387459bb
commit
56991a9ace
16 changed files with 147 additions and 199 deletions
|
@ -50,7 +50,7 @@ FSoundFontManager sfmanager;
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
std::pair<FileReader *, FString> FSoundFontReader::LookupFile(const char *name)
|
std::pair<FileRdr, FString> FSoundFontReader::LookupFile(const char *name)
|
||||||
{
|
{
|
||||||
if (!IsAbsPath(name))
|
if (!IsAbsPath(name))
|
||||||
{
|
{
|
||||||
|
@ -58,12 +58,12 @@ std::pair<FileReader *, FString> FSoundFontReader::LookupFile(const char *name)
|
||||||
{
|
{
|
||||||
FString fullname = mPaths[i] + name;
|
FString fullname = mPaths[i] + name;
|
||||||
auto fr = OpenFile(fullname);
|
auto fr = OpenFile(fullname);
|
||||||
if (fr != nullptr) return std::make_pair(fr, fullname);
|
if (fr.isOpen()) return std::make_pair(std::move(fr), fullname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto fr = OpenFile(name);
|
auto fr = OpenFile(name);
|
||||||
if (fr != nullptr) return std::make_pair(fr, name);
|
if (!fr.isOpen()) name = "";
|
||||||
return std::make_pair(nullptr, FString());
|
return std::make_pair(std::move(fr), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -117,7 +117,7 @@ FSF2Reader::FSF2Reader(const char *fn)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FileReader *FSF2Reader::OpenMainConfigFile()
|
FileRdr FSF2Reader::OpenMainConfigFile()
|
||||||
{
|
{
|
||||||
if (mMainConfigForSF2.IsNotEmpty())
|
if (mMainConfigForSF2.IsNotEmpty())
|
||||||
{
|
{
|
||||||
|
@ -126,15 +126,14 @@ FileReader *FSF2Reader::OpenMainConfigFile()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FSF2Reader::OpenFile(const char *name)
|
FileRdr FSF2Reader::OpenFile(const char *name)
|
||||||
{
|
{
|
||||||
|
FileRdr fr;
|
||||||
if (mFilename.CompareNoCase(name) == 0)
|
if (mFilename.CompareNoCase(name) == 0)
|
||||||
{
|
{
|
||||||
auto fr = new FileReader;
|
fr.OpenFile(name);
|
||||||
if (fr->Open(name)) return fr;
|
|
||||||
delete fr;
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -153,12 +152,12 @@ FZipPatReader::~FZipPatReader()
|
||||||
if (resf != nullptr) delete resf;
|
if (resf != nullptr) delete resf;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FZipPatReader::OpenMainConfigFile()
|
FileRdr FZipPatReader::OpenMainConfigFile()
|
||||||
{
|
{
|
||||||
return OpenFile("timidity.cfg");
|
return OpenFile("timidity.cfg");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FZipPatReader::OpenFile(const char *name)
|
FileRdr FZipPatReader::OpenFile(const char *name)
|
||||||
{
|
{
|
||||||
if (resf != nullptr)
|
if (resf != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -194,8 +193,8 @@ FPatchSetReader::FPatchSetReader(const char *filename)
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
mAllowAbsolutePaths = true;
|
mAllowAbsolutePaths = true;
|
||||||
FileReader *fr = new FileReader;
|
FileRdr fr;
|
||||||
if (fr->Open(filename))
|
if (fr.OpenFile(filename))
|
||||||
{
|
{
|
||||||
mFullPathToConfig = filename;
|
mFullPathToConfig = filename;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +203,7 @@ FPatchSetReader::FPatchSetReader(const char *filename)
|
||||||
for(auto c : paths)
|
for(auto c : paths)
|
||||||
{
|
{
|
||||||
FStringf fullname("%s/%s", c, filename);
|
FStringf fullname("%s/%s", c, filename);
|
||||||
if (fr->Open(fullname))
|
if (fr.OpenFile(fullname))
|
||||||
{
|
{
|
||||||
mFullPathToConfig = fullname;
|
mFullPathToConfig = fullname;
|
||||||
}
|
}
|
||||||
|
@ -224,23 +223,21 @@ FPatchSetReader::FPatchSetReader()
|
||||||
mAllowAbsolutePaths = true;
|
mAllowAbsolutePaths = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FPatchSetReader::OpenMainConfigFile()
|
FileRdr FPatchSetReader::OpenMainConfigFile()
|
||||||
{
|
{
|
||||||
auto fr = new FileReader;
|
FileRdr fr;
|
||||||
if (fr->Open(mFullPathToConfig)) return fr;
|
fr.OpenFile(mFullPathToConfig);
|
||||||
delete fr;
|
return fr;
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FPatchSetReader::OpenFile(const char *name)
|
FileRdr FPatchSetReader::OpenFile(const char *name)
|
||||||
{
|
{
|
||||||
FString path;
|
FString path;
|
||||||
if (IsAbsPath(name)) path = name;
|
if (IsAbsPath(name)) path = name;
|
||||||
else path = mBasePath + name;
|
else path = mBasePath + name;
|
||||||
auto fr = new FileReader;
|
FileRdr fr;
|
||||||
if (fr->Open(path)) return fr;
|
fr.OpenFile(path);
|
||||||
delete fr;
|
return fr;
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -252,7 +249,6 @@ FileReader *FPatchSetReader::OpenFile(const char *name)
|
||||||
FLumpPatchSetReader::FLumpPatchSetReader(const char *filename)
|
FLumpPatchSetReader::FLumpPatchSetReader(const char *filename)
|
||||||
{
|
{
|
||||||
mLumpIndex = Wads.CheckNumForFullName(filename);
|
mLumpIndex = Wads.CheckNumForFullName(filename);
|
||||||
FileReader *fr = new FileReader;
|
|
||||||
|
|
||||||
mBasePath = filename;
|
mBasePath = filename;
|
||||||
FixPathSeperator(mBasePath);
|
FixPathSeperator(mBasePath);
|
||||||
|
@ -260,19 +256,19 @@ FLumpPatchSetReader::FLumpPatchSetReader(const char *filename)
|
||||||
if (mBasePath.Len() > 0 && mBasePath.Back() != '/') mBasePath += '/';
|
if (mBasePath.Len() > 0 && mBasePath.Back() != '/') mBasePath += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FLumpPatchSetReader::OpenMainConfigFile()
|
FileRdr FLumpPatchSetReader::OpenMainConfigFile()
|
||||||
{
|
{
|
||||||
return Wads.ReopenLumpNum(mLumpIndex);
|
return Wads.ReopenLumpNum(mLumpIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *FLumpPatchSetReader::OpenFile(const char *name)
|
FileRdr FLumpPatchSetReader::OpenFile(const char *name)
|
||||||
{
|
{
|
||||||
FString path;
|
FString path;
|
||||||
if (IsAbsPath(name)) return nullptr; // no absolute paths in the lump directory.
|
if (IsAbsPath(name)) return FileRdr(); // no absolute paths in the lump directory.
|
||||||
path = mBasePath + name;
|
path = mBasePath + name;
|
||||||
auto index = Wads.CheckNumForFullName(path);
|
auto index = Wads.CheckNumForFullName(path);
|
||||||
if (index < 0) return nullptr;
|
if (index < 0) return FileRdr();
|
||||||
return Wads.ReopenLumpNum(index);
|
return Wads.ReopenLumpReader(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -41,9 +41,9 @@ protected:
|
||||||
public:
|
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 FileRdr OpenMainConfigFile() = 0; // this is special because it needs to be synthesized for .sf files and set some restrictions for patch sets
|
||||||
virtual FileReader *OpenFile(const char *name) = 0;
|
virtual FileRdr OpenFile(const char *name) = 0;
|
||||||
std::pair<FileReader *, FString> LookupFile(const char *name);
|
std::pair<FileRdr , FString> LookupFile(const char *name);
|
||||||
void AddPath(const char *str);
|
void AddPath(const char *str);
|
||||||
virtual FString basePath() const
|
virtual FString basePath() const
|
||||||
{
|
{
|
||||||
|
@ -63,8 +63,8 @@ class FSF2Reader : public FSoundFontReader
|
||||||
FString mFilename;
|
FString mFilename;
|
||||||
public:
|
public:
|
||||||
FSF2Reader(const char *filename);
|
FSF2Reader(const char *filename);
|
||||||
virtual FileReader *OpenMainConfigFile() override;
|
virtual FileRdr OpenMainConfigFile() override;
|
||||||
virtual FileReader *OpenFile(const char *name) override;
|
virtual FileRdr OpenFile(const char *name) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -79,8 +79,8 @@ class FZipPatReader : public FSoundFontReader
|
||||||
public:
|
public:
|
||||||
FZipPatReader(const char *filename);
|
FZipPatReader(const char *filename);
|
||||||
~FZipPatReader();
|
~FZipPatReader();
|
||||||
virtual FileReader *OpenMainConfigFile() override;
|
virtual FileRdr OpenMainConfigFile() override;
|
||||||
virtual FileReader *OpenFile(const char *name) override;
|
virtual FileRdr OpenFile(const char *name) override;
|
||||||
bool isOk() { return resf != nullptr; }
|
bool isOk() { return resf != nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ class FLumpPatchSetReader : public FSoundFontReader
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FLumpPatchSetReader(const char *filename);
|
FLumpPatchSetReader(const char *filename);
|
||||||
virtual FileReader *OpenMainConfigFile() override;
|
virtual FileRdr OpenMainConfigFile() override;
|
||||||
virtual FileReader *OpenFile(const char *name) override;
|
virtual FileRdr OpenFile(const char *name) override;
|
||||||
virtual FString basePath() const override
|
virtual FString basePath() const override
|
||||||
{
|
{
|
||||||
return mBasePath;
|
return mBasePath;
|
||||||
|
@ -120,8 +120,8 @@ class FPatchSetReader : public FSoundFontReader
|
||||||
public:
|
public:
|
||||||
FPatchSetReader();
|
FPatchSetReader();
|
||||||
FPatchSetReader(const char *filename);
|
FPatchSetReader(const char *filename);
|
||||||
virtual FileReader *OpenMainConfigFile() override;
|
virtual FileRdr OpenMainConfigFile() override;
|
||||||
virtual FileReader *OpenFile(const char *name) override;
|
virtual FileRdr OpenFile(const char *name) override;
|
||||||
virtual FString basePath() const override
|
virtual FString basePath() const override
|
||||||
{
|
{
|
||||||
return mBasePath;
|
return mBasePath;
|
||||||
|
|
|
@ -153,7 +153,6 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss
|
||||||
{
|
{
|
||||||
Instrument *ip;
|
Instrument *ip;
|
||||||
Sample *sp;
|
Sample *sp;
|
||||||
FileReader *fp;
|
|
||||||
GF1PatchHeader header;
|
GF1PatchHeader header;
|
||||||
GF1InstrumentData idata;
|
GF1InstrumentData idata;
|
||||||
GF1LayerData layer_data;
|
GF1LayerData layer_data;
|
||||||
|
@ -164,19 +163,19 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss
|
||||||
if (!name || gus_sfreader == nullptr) return nullptr;
|
if (!name || gus_sfreader == nullptr) return nullptr;
|
||||||
|
|
||||||
/* Open patch file */
|
/* Open patch file */
|
||||||
fp = gus_sfreader->LookupFile(name).first;
|
auto fp = gus_sfreader->LookupFile(name).first;
|
||||||
if (fp == NULL)
|
if (!fp.isOpen())
|
||||||
{
|
{
|
||||||
/* Try with various extensions */
|
/* Try with various extensions */
|
||||||
FString tmp = name;
|
FString tmp = name;
|
||||||
tmp += ".pat";
|
tmp += ".pat";
|
||||||
fp = gus_sfreader->LookupFile(tmp).first;
|
fp = gus_sfreader->LookupFile(tmp).first;
|
||||||
if (fp == NULL)
|
if (!fp.isOpen())
|
||||||
{
|
{
|
||||||
#ifdef __unix__ // Windows isn't case-sensitive.
|
#ifdef __unix__ // Windows isn't case-sensitive.
|
||||||
tmp.ToUpper();
|
tmp.ToUpper();
|
||||||
fp = gus_sfreader->LookupFile(tmp).first;
|
fp = gus_sfreader->LookupFile(tmp).first;
|
||||||
if (fp == NULL)
|
if (!fp.isOpen())
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
noluck = true;
|
noluck = true;
|
||||||
|
@ -194,26 +193,23 @@ static Instrument *load_instrument(Renderer *song, const char *name, int percuss
|
||||||
|
|
||||||
/* Read some headers and do cursory sanity checks. */
|
/* Read some headers and do cursory sanity checks. */
|
||||||
|
|
||||||
if (sizeof(header) != fp->Read(&header, sizeof(header)))
|
if (sizeof(header) != fp.Read(&header, sizeof(header)))
|
||||||
{
|
{
|
||||||
failread:
|
failread:
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Error reading instrument.\n", name);
|
cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Error reading instrument.\n", name);
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strncmp(header.Header, GF1_HEADER_TEXT, HEADER_SIZE - 4) != 0)
|
if (strncmp(header.Header, GF1_HEADER_TEXT, HEADER_SIZE - 4) != 0)
|
||||||
{
|
{
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Not an instrument.\n", name);
|
cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Not an instrument.\n", name);
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strcmp(header.Header + 8, "110") < 0)
|
if (strcmp(header.Header + 8, "110") < 0)
|
||||||
{
|
{
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Is an old and unsupported patch version.\n", name);
|
cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Is an old and unsupported patch version.\n", name);
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (sizeof(idata) != fp->Read(&idata, sizeof(idata)))
|
if (sizeof(idata) != fp.Read(&idata, sizeof(idata)))
|
||||||
{
|
{
|
||||||
goto failread;
|
goto failread;
|
||||||
}
|
}
|
||||||
|
@ -226,18 +222,16 @@ failread:
|
||||||
if (header.Instruments != 1 && header.Instruments != 0) /* instruments. To some patch makers, 0 means 1 */
|
if (header.Instruments != 1 && header.Instruments != 0) /* instruments. To some patch makers, 0 means 1 */
|
||||||
{
|
{
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle patches with %d instruments.\n", header.Instruments);
|
cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle patches with %d instruments.\n", header.Instruments);
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idata.Layers != 1 && idata.Layers != 0) /* layers. What's a layer? */
|
if (idata.Layers != 1 && idata.Layers != 0) /* layers. What's a layer? */
|
||||||
{
|
{
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle instruments with %d layers.\n", idata.Layers);
|
cmsg(CMSG_ERROR, VERB_NORMAL, "Can't handle instruments with %d layers.\n", idata.Layers);
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof(layer_data) != fp->Read(&layer_data, sizeof(layer_data)))
|
if (sizeof(layer_data) != fp.Read(&layer_data, sizeof(layer_data)))
|
||||||
{
|
{
|
||||||
goto failread;
|
goto failread;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +239,6 @@ failread:
|
||||||
if (layer_data.Samples == 0)
|
if (layer_data.Samples == 0)
|
||||||
{
|
{
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "Instrument has 0 samples.\n");
|
cmsg(CMSG_ERROR, VERB_NORMAL, "Instrument has 0 samples.\n");
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,12 +248,11 @@ failread:
|
||||||
memset(ip->sample, 0, sizeof(Sample) * layer_data.Samples);
|
memset(ip->sample, 0, sizeof(Sample) * layer_data.Samples);
|
||||||
for (i = 0; i < layer_data.Samples; ++i)
|
for (i = 0; i < layer_data.Samples; ++i)
|
||||||
{
|
{
|
||||||
if (sizeof(patch_data) != fp->Read(&patch_data, sizeof(patch_data)))
|
if (sizeof(patch_data) != fp.Read(&patch_data, sizeof(patch_data)))
|
||||||
{
|
{
|
||||||
fail:
|
fail:
|
||||||
cmsg(CMSG_ERROR, VERB_NORMAL, "Error reading sample %d.\n", i);
|
cmsg(CMSG_ERROR, VERB_NORMAL, "Error reading sample %d.\n", i);
|
||||||
delete ip;
|
delete ip;
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +414,7 @@ fail:
|
||||||
}
|
}
|
||||||
sp->data = (sample_t *)safe_malloc(sp->data_length);
|
sp->data = (sample_t *)safe_malloc(sp->data_length);
|
||||||
|
|
||||||
if (sp->data_length != fp->Read(sp->data, sp->data_length))
|
if (sp->data_length != fp.Read(sp->data, sp->data_length))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
convert_sample_data(sp, sp->data);
|
convert_sample_data(sp, sp->data);
|
||||||
|
@ -469,7 +461,6 @@ fail:
|
||||||
sp->data_length = sp->loop_end;
|
sp->data_length = sp->loop_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete fp;
|
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Timidity
|
||||||
FontFile *Fonts;
|
FontFile *Fonts;
|
||||||
extern std::unique_ptr<FSoundFontReader> gus_sfreader;
|
extern std::unique_ptr<FSoundFontReader> gus_sfreader;
|
||||||
|
|
||||||
FontFile *ReadDLS(const char *filename, FileReader *f)
|
FontFile *ReadDLS(const char *filename, FileRdr &f)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -57,15 +57,14 @@ void font_add(const char *filename, int load_order)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileReader *fp = gus_sfreader->LookupFile(filename).first;
|
FileRdr fp = gus_sfreader->LookupFile(filename).first;
|
||||||
|
|
||||||
if (fp != NULL)
|
if (fp.isOpen())
|
||||||
{
|
{
|
||||||
if ((font = ReadSF2(filename, fp)) || (font = ReadDLS(filename, fp)))
|
if ((font = ReadSF2(filename, fp)) || (font = ReadDLS(filename, fp)))
|
||||||
{
|
{
|
||||||
font->SetAllOrders(load_order);
|
font->SetAllOrders(load_order);
|
||||||
}
|
}
|
||||||
delete fp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class CBadVer {};
|
||||||
struct ListHandler
|
struct ListHandler
|
||||||
{
|
{
|
||||||
uint32_t ID;
|
uint32_t ID;
|
||||||
void (*Parser)(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
void (*Parser)(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -162,15 +162,15 @@ static const SFGenComposite DefaultGenerators =
|
||||||
-1 // overridingRootKey
|
-1 // overridingRootKey
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ParseIfil(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseSmpl(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseSm24(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParsePhdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseBag(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseMod(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseGen(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseInst(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
static void ParseShdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen);
|
static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen);
|
||||||
|
|
||||||
ListHandler INFOHandlers[] =
|
ListHandler INFOHandlers[] =
|
||||||
{
|
{
|
||||||
|
@ -225,87 +225,87 @@ static int32_t calc_rate(Renderer *song, int diff, double sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline uint32_t read_id(FileReader *f)
|
static inline uint32_t read_id(FileRdr &f)
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
if (f->Read(&id, 4) != 4)
|
if (f.Read(&id, 4) != 4)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int read_byte(FileReader *f)
|
static inline int read_byte(FileRdr &f)
|
||||||
{
|
{
|
||||||
uint8_t x;
|
uint8_t x;
|
||||||
if (f->Read(&x, 1) != 1)
|
if (f.Read(&x, 1) != 1)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int read_char(FileReader *f)
|
static inline int read_char(FileRdr &f)
|
||||||
{
|
{
|
||||||
int8_t x;
|
int8_t x;
|
||||||
if (f->Read(&x, 1) != 1)
|
if (f.Read(&x, 1) != 1)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int read_uword(FileReader *f)
|
static inline int read_uword(FileRdr &f)
|
||||||
{
|
{
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
if (f->Read(&x, 2) != 2)
|
if (f.Read(&x, 2) != 2)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
return LittleShort(x);
|
return LittleShort(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int read_sword(FileReader *f)
|
static inline int read_sword(FileRdr &f)
|
||||||
{
|
{
|
||||||
int16_t x;
|
int16_t x;
|
||||||
if (f->Read(&x, 2) != 2)
|
if (f.Read(&x, 2) != 2)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
return LittleShort(x);
|
return LittleShort(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t read_dword(FileReader *f)
|
static inline uint32_t read_dword(FileRdr &f)
|
||||||
{
|
{
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
if (f->Read(&x, 4) != 4)
|
if (f.Read(&x, 4) != 4)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
return LittleLong(x);
|
return LittleLong(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void read_name(FileReader *f, char name[21])
|
static inline void read_name(FileRdr &f, char name[21])
|
||||||
{
|
{
|
||||||
if (f->Read(name, 20) != 20)
|
if (f.Read(name, 20) != 20)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
name[20] = 0;
|
name[20] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void skip_chunk(FileReader *f, uint32_t len)
|
static inline void skip_chunk(FileRdr &f, uint32_t len)
|
||||||
{
|
{
|
||||||
// RIFF, like IFF, adds an extra pad byte to the end of
|
// RIFF, like IFF, adds an extra pad byte to the end of
|
||||||
// odd-sized chunks so that new chunks are always on even
|
// odd-sized chunks so that new chunks are always on even
|
||||||
// byte boundaries.
|
// byte boundaries.
|
||||||
if (f->Seek(len + (len & 1), SEEK_CUR) != 0)
|
if (f.Seek(len + (len & 1), FileRdr::SeekCur) != 0)
|
||||||
{
|
{
|
||||||
throw CIOErr();
|
throw CIOErr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_list(FileReader *f, uint32_t id, uint32_t filelen, uint32_t &chunklen)
|
static void check_list(FileRdr &f, uint32_t id, uint32_t filelen, uint32_t &chunklen)
|
||||||
{
|
{
|
||||||
if (read_id(f) != ID_LIST)
|
if (read_id(f) != ID_LIST)
|
||||||
{
|
{
|
||||||
|
@ -322,7 +322,7 @@ static void check_list(FileReader *f, uint32_t id, uint32_t filelen, uint32_t &c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseIfil(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseIfil(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
uint16_t major, minor;
|
uint16_t major, minor;
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ static void ParseIfil(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu
|
||||||
sf2->MinorVersion = minor;
|
sf2->MinorVersion = minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseLIST(SFFile *sf2, FileReader *f, uint32_t chunklen, ListHandler *handlers)
|
static void ParseLIST(SFFile *sf2, FileRdr &f, uint32_t chunklen, ListHandler *handlers)
|
||||||
{
|
{
|
||||||
ListHandler *handler;
|
ListHandler *handler;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
@ -375,7 +375,7 @@ static void ParseLIST(SFFile *sf2, FileReader *f, uint32_t chunklen, ListHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseINFO(SFFile *sf2, FileReader *f, uint32_t chunklen)
|
static void ParseINFO(SFFile *sf2, FileRdr &f, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
sf2->MinorVersion = -1;
|
sf2->MinorVersion = -1;
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ static void ParseINFO(SFFile *sf2, FileReader *f, uint32_t chunklen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseSdta(SFFile *sf2, FileReader *f, uint32_t chunklen)
|
static void ParseSdta(SFFile *sf2, FileRdr &f, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
ParseLIST(sf2, f, chunklen, SdtaHandlers);
|
ParseLIST(sf2, f, chunklen, SdtaHandlers);
|
||||||
if (sf2->SampleDataOffset == 0)
|
if (sf2->SampleDataOffset == 0)
|
||||||
|
@ -404,7 +404,7 @@ static void ParseSdta(SFFile *sf2, FileReader *f, uint32_t chunklen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseSmpl(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseSmpl(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
// Only use the first smpl chunk. (Or should we reject files with more than one?)
|
// Only use the first smpl chunk. (Or should we reject files with more than one?)
|
||||||
if (sf2->SampleDataOffset == 0)
|
if (sf2->SampleDataOffset == 0)
|
||||||
|
@ -413,13 +413,13 @@ static void ParseSmpl(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu
|
||||||
{ // Chunk must be an even number of bytes.
|
{ // Chunk must be an even number of bytes.
|
||||||
throw CBadForm();
|
throw CBadForm();
|
||||||
}
|
}
|
||||||
sf2->SampleDataOffset = f->Tell();
|
sf2->SampleDataOffset = (uint32_t)f.Tell();
|
||||||
sf2->SizeSampleData = chunklen >> 1;
|
sf2->SizeSampleData = chunklen >> 1;
|
||||||
}
|
}
|
||||||
skip_chunk(f, chunklen);
|
skip_chunk(f, chunklen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseSm24(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseSm24(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
// The sm24 chunk is ignored if the file version is < 2.04
|
// The sm24 chunk is ignored if the file version is < 2.04
|
||||||
if (sf2->MinorVersion >= 4)
|
if (sf2->MinorVersion >= 4)
|
||||||
|
@ -427,19 +427,19 @@ static void ParseSm24(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu
|
||||||
// Only use the first sm24 chunk. (Or should we reject files with more than one?)
|
// Only use the first sm24 chunk. (Or should we reject files with more than one?)
|
||||||
if (sf2->SampleDataLSBOffset == 0)
|
if (sf2->SampleDataLSBOffset == 0)
|
||||||
{
|
{
|
||||||
sf2->SampleDataLSBOffset = f->Tell();
|
sf2->SampleDataLSBOffset = (uint32_t)f.Tell();
|
||||||
sf2->SizeSampleDataLSB = chunklen;
|
sf2->SizeSampleDataLSB = chunklen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
skip_chunk(f, chunklen);
|
skip_chunk(f, chunklen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParsePdta(SFFile *sf2, FileReader *f, uint32_t chunklen)
|
static void ParsePdta(SFFile *sf2, FileRdr &f, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
ParseLIST(sf2, f, chunklen, PdtaHandlers);
|
ParseLIST(sf2, f, chunklen, PdtaHandlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParsePhdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParsePhdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
SFPreset *preset;
|
SFPreset *preset;
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ static void ParsePhdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseBag(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseBag(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
SFBag *bags, *bag;
|
SFBag *bags, *bag;
|
||||||
uint16_t prev_mod = 0;
|
uint16_t prev_mod = 0;
|
||||||
|
@ -539,7 +539,7 @@ static void ParseBag(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseMod(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseMod(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
// Section 7.4, page 23:
|
// Section 7.4, page 23:
|
||||||
// It [the PMOD sub-chunk] is always a multiple of ten bytes in length,
|
// It [the PMOD sub-chunk] is always a multiple of ten bytes in length,
|
||||||
|
@ -552,7 +552,7 @@ static void ParseMod(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chun
|
||||||
skip_chunk(f, chunklen);
|
skip_chunk(f, chunklen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseGen(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseGen(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
SFGenList *gens, *gen;
|
SFGenList *gens, *gen;
|
||||||
int numgens;
|
int numgens;
|
||||||
|
@ -604,7 +604,7 @@ static void ParseGen(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseInst(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseInst(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
SFInst *inst;
|
SFInst *inst;
|
||||||
|
@ -639,7 +639,7 @@ static void ParseInst(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseShdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chunklen)
|
static void ParseShdr(SFFile *sf2, FileRdr &f, uint32_t chunkid, uint32_t chunklen)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
SFSample *sample;
|
SFSample *sample;
|
||||||
|
@ -698,7 +698,7 @@ static void ParseShdr(SFFile *sf2, FileReader *f, uint32_t chunkid, uint32_t chu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SFFile *ReadSF2(const char *filename, FileReader *f)
|
SFFile *ReadSF2(const char *filename, FileRdr &f)
|
||||||
{
|
{
|
||||||
SFFile *sf2 = NULL;
|
SFFile *sf2 = NULL;
|
||||||
uint32_t filelen;
|
uint32_t filelen;
|
||||||
|
@ -1508,33 +1508,32 @@ void SFFile::ApplyGeneratorsToRegion(SFGenComposite *gen, SFSample *sfsamp, Rend
|
||||||
|
|
||||||
void SFFile::LoadSample(SFSample *sample)
|
void SFFile::LoadSample(SFSample *sample)
|
||||||
{
|
{
|
||||||
FileReader *fp = gus_sfreader->LookupFile(Filename).first;
|
FileRdr fp = gus_sfreader->LookupFile(Filename).first;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (fp == NULL)
|
if (!fp.isOpen())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sample->InMemoryData = new float[sample->End - sample->Start + 1];
|
sample->InMemoryData = new float[sample->End - sample->Start + 1];
|
||||||
fp->Seek(SampleDataOffset + sample->Start * 2, SEEK_SET);
|
fp.Seek(SampleDataOffset + sample->Start * 2, FileRdr::SeekSet);
|
||||||
// Load 16-bit sample data.
|
// Load 16-bit sample data.
|
||||||
for (i = 0; i < sample->End - sample->Start; ++i)
|
for (i = 0; i < sample->End - sample->Start; ++i)
|
||||||
{
|
{
|
||||||
int16_t samp;
|
int16_t samp;
|
||||||
*fp >> samp;
|
fp >> samp;
|
||||||
sample->InMemoryData[i] = samp / 32768.f;
|
sample->InMemoryData[i] = samp / 32768.f;
|
||||||
}
|
}
|
||||||
if (SampleDataLSBOffset != 0)
|
if (SampleDataLSBOffset != 0)
|
||||||
{ // Load lower 8 bits of 24-bit sample data.
|
{ // Load lower 8 bits of 24-bit sample data.
|
||||||
fp->Seek(SampleDataLSBOffset + sample->Start, SEEK_SET);
|
fp.Seek(SampleDataLSBOffset + sample->Start, FileRdr::SeekSet);
|
||||||
for (i = 0; i < sample->End - sample->Start; ++i)
|
for (i = 0; i < sample->End - sample->Start; ++i)
|
||||||
{
|
{
|
||||||
uint8_t samp;
|
uint8_t samp;
|
||||||
*fp >> samp;
|
fp >> samp;
|
||||||
sample->InMemoryData[i] = ((((int32_t(sample->InMemoryData[i] * 32768) << 8) | samp) << 8) >> 8) / 8388608.f;
|
sample->InMemoryData[i] = ((((int32_t(sample->InMemoryData[i] * 32768) << 8) | samp) << 8) >> 8) / 8388608.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Final 0 byte is for interpolation.
|
// Final 0 byte is for interpolation.
|
||||||
sample->InMemoryData[i] = 0;
|
sample->InMemoryData[i] = 0;
|
||||||
delete fp;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,4 +315,4 @@ struct SFFile : public Timidity::FontFile
|
||||||
int NumSamples;
|
int NumSamples;
|
||||||
};
|
};
|
||||||
|
|
||||||
SFFile *ReadSF2(const char *filename, FileReader *f);
|
SFFile *ReadSF2(const char *filename, FileRdr &f);
|
||||||
|
|
|
@ -82,7 +82,7 @@ static bool InitReader(const char *config_file)
|
||||||
|
|
||||||
static int read_config_file(const char *name, bool ismain)
|
static int read_config_file(const char *name, bool ismain)
|
||||||
{
|
{
|
||||||
FileReader *fp;
|
FileRdr fp;
|
||||||
char tmp[1024], *cp;
|
char tmp[1024], *cp;
|
||||||
ToneBank *bank = NULL;
|
ToneBank *bank = NULL;
|
||||||
int i, j, k, line = 0, words;
|
int i, j, k, line = 0, words;
|
||||||
|
@ -103,12 +103,12 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
{
|
{
|
||||||
fp = gus_sfreader->LookupFile(name).first;
|
fp = gus_sfreader->LookupFile(name).first;
|
||||||
}
|
}
|
||||||
if (fp == nullptr)
|
if (!fp .isOpen())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fp->Gets(tmp, sizeof(tmp)))
|
while (fp.Gets(tmp, sizeof(tmp)))
|
||||||
{
|
{
|
||||||
line++;
|
line++;
|
||||||
FCommandLine w(tmp, true);
|
FCommandLine w(tmp, true);
|
||||||
|
@ -207,7 +207,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (words < 2)
|
if (words < 2)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: No soundfont given\n", name, line);
|
Printf("%s: line %d: No soundfont given\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (words > 2 && !strcmp(w[2], "remove"))
|
if (words > 2 && !strcmp(w[2], "remove"))
|
||||||
|
@ -223,7 +222,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (!(cp = strchr(w[i], '=')))
|
if (!(cp = strchr(w[i], '=')))
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: bad soundfont option %s\n", name, line, w[i]);
|
Printf("%s: line %d: bad soundfont option %s\n", name, line, w[i]);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +239,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (words < 3)
|
if (words < 3)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: syntax error\n", name, line);
|
Printf("%s: line %d: syntax error\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +255,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: font subcommand must be 'order' or 'exclude'\n", name, line);
|
Printf("%s: line %d: font subcommand must be 'order' or 'exclude'\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (i < words)
|
if (i < words)
|
||||||
|
@ -312,7 +308,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (words < 2)
|
if (words < 2)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: No directory given\n", name, line);
|
Printf("%s: line %d: No directory given\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
for (i = 1; i < words; i++)
|
for (i = 1; i < words; i++)
|
||||||
|
@ -340,7 +335,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (words != 2)
|
if (words != 2)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: Must specify exactly one patch name\n", name, line);
|
Printf("%s: line %d: Must specify exactly one patch name\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
def_instr_name = w[1];
|
def_instr_name = w[1];
|
||||||
|
@ -350,14 +344,12 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (words < 2)
|
if (words < 2)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: No drum set number given\n", name, line);
|
Printf("%s: line %d: No drum set number given\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
i = atoi(w[1]);
|
i = atoi(w[1]);
|
||||||
if (i < 0 || i > 127)
|
if (i < 0 || i > 127)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: Drum set must be between 0 and 127\n", name, line);
|
Printf("%s: line %d: Drum set must be between 0 and 127\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (drumset[i] == NULL)
|
if (drumset[i] == NULL)
|
||||||
|
@ -371,14 +363,12 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (words < 2)
|
if (words < 2)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: No bank number given\n", name, line);
|
Printf("%s: line %d: No bank number given\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
i = atoi(w[1]);
|
i = atoi(w[1]);
|
||||||
if (i < 0 || i > 127)
|
if (i < 0 || i > 127)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: Tone bank must be between 0 and 127\n", name, line);
|
Printf("%s: line %d: Tone bank must be between 0 and 127\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (tonebank[i] == NULL)
|
if (tonebank[i] == NULL)
|
||||||
|
@ -392,20 +382,17 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if ((words < 2) || (*w[0] < '0' || *w[0] > '9'))
|
if ((words < 2) || (*w[0] < '0' || *w[0] > '9'))
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: syntax error\n", name, line);
|
Printf("%s: line %d: syntax error\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
i = atoi(w[0]);
|
i = atoi(w[0]);
|
||||||
if (i < 0 || i > 127)
|
if (i < 0 || i > 127)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: Program must be between 0 and 127\n", name, line);
|
Printf("%s: line %d: Program must be between 0 and 127\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (bank == NULL)
|
if (bank == NULL)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: Must specify tone bank or drum set before assignment\n", name, line);
|
Printf("%s: line %d: Must specify tone bank or drum set before assignment\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
bank->tone[i].note = bank->tone[i].pan =
|
bank->tone[i].note = bank->tone[i].pan =
|
||||||
|
@ -440,7 +427,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if (!(cp=strchr(w[j], '=')))
|
if (!(cp=strchr(w[j], '=')))
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: bad patch option %s\n", name, line, w[j]);
|
Printf("%s: line %d: bad patch option %s\n", name, line, w[j]);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
*cp++ = 0;
|
*cp++ = 0;
|
||||||
|
@ -454,7 +440,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9'))
|
if ((k < 0 || k > 127) || (*cp < '0' || *cp > '9'))
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: note must be between 0 and 127\n", name, line);
|
Printf("%s: line %d: note must be between 0 and 127\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
bank->tone[i].note = k;
|
bank->tone[i].note = k;
|
||||||
|
@ -474,7 +459,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: panning must be left, right, "
|
Printf("%s: line %d: panning must be left, right, "
|
||||||
"center, or between -100 and 100\n", name, line);
|
"center, or between -100 and 100\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
bank->tone[i].pan = k;
|
bank->tone[i].pan = k;
|
||||||
|
@ -488,7 +472,6 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: keep must be env or loop\n", name, line);
|
Printf("%s: line %d: keep must be env or loop\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,28 +486,17 @@ static int read_config_file(const char *name, bool ismain)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: strip must be env, loop, or tail\n", name, line);
|
Printf("%s: line %d: strip must be env, loop, or tail\n", name, line);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Printf("%s: line %d: bad patch option %s\n", name, line, w[j]);
|
Printf("%s: line %d: bad patch option %s\n", name, line, w[j]);
|
||||||
delete fp;
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (ferror(fp))
|
|
||||||
{
|
|
||||||
Printf("Can't read %s: %s\n", name, strerror(errno));
|
|
||||||
close_file(fp);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
delete fp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#define TIMIDITY_H
|
#define TIMIDITY_H
|
||||||
|
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
|
#include "files.h"
|
||||||
class FileReader;
|
|
||||||
|
|
||||||
namespace Timidity
|
namespace Timidity
|
||||||
{
|
{
|
||||||
|
@ -362,7 +361,7 @@ void font_order(int order, int bank, int preset, int keynote);
|
||||||
Instrument *load_instrument_font(struct Renderer *song, const char *font, int drum, int bank, int instrument);
|
Instrument *load_instrument_font(struct Renderer *song, const char *font, int drum, int bank, int instrument);
|
||||||
Instrument *load_instrument_font_order(struct Renderer *song, int order, int drum, int bank, int instrument);
|
Instrument *load_instrument_font_order(struct Renderer *song, int order, int drum, int bank, int instrument);
|
||||||
|
|
||||||
FontFile *ReadDLS(const char *filename, FileReader *f);
|
FontFile *ReadDLS(const char *filename, FileRdr &f);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mix.h
|
mix.h
|
||||||
|
|
|
@ -130,7 +130,7 @@ double flt_rand()
|
||||||
|
|
||||||
struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader)
|
struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader)
|
||||||
{
|
{
|
||||||
FileReader *fr;
|
FileRdr fr;
|
||||||
FString filename;
|
FString filename;
|
||||||
if (name == nullptr)
|
if (name == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -140,60 +140,56 @@ struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto res = sfreader->LookupFile(name);
|
auto res = sfreader->LookupFile(name);
|
||||||
fr = res.first;
|
fr = std::move(res.first);
|
||||||
filename = res.second;
|
filename = res.second;
|
||||||
}
|
}
|
||||||
if (fr == nullptr) return nullptr;
|
if (!fr.isOpen()) return nullptr;
|
||||||
|
|
||||||
auto tf = new timidity_file;
|
auto tf = new timidity_file;
|
||||||
tf->url = fr;
|
tf->url = std::move(fr);
|
||||||
tf->filename = filename.GetChars();
|
tf->filename = filename.GetChars();
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This closes files opened with open_file */
|
/* This closes files opened with open_file */
|
||||||
void close_file(struct timidity_file *tf)
|
void tf_close(struct timidity_file *tf)
|
||||||
{
|
{
|
||||||
if (tf->url != NULL)
|
tf->url.Close();
|
||||||
{
|
|
||||||
tf->url->Close();
|
|
||||||
delete tf->url;
|
|
||||||
}
|
|
||||||
delete tf;
|
delete tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is meant for skipping a few bytes. */
|
/* This is meant for skipping a few bytes. */
|
||||||
void skip(struct timidity_file *tf, size_t len)
|
void skip(struct timidity_file *tf, size_t len)
|
||||||
{
|
{
|
||||||
tf->url->Seek((long)len, SEEK_CUR);
|
tf->url.Seek((long)len, FileRdr::SeekCur);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tf_gets(char *buff, int n, struct timidity_file *tf)
|
char *tf_gets(char *buff, int n, struct timidity_file *tf)
|
||||||
{
|
{
|
||||||
return tf->url->Gets(buff, n);
|
return tf->url.Gets(buff, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tf_getc(struct timidity_file *tf)
|
int tf_getc(struct timidity_file *tf)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
auto read = tf->url->Read(&c, 1);
|
auto read = tf->url.Read(&c, 1);
|
||||||
return read == 0 ? EOF : c;
|
return read == 0 ? EOF : c;
|
||||||
}
|
}
|
||||||
|
|
||||||
long tf_read(void *buff, int32_t size, int32_t nitems, struct timidity_file *tf)
|
long tf_read(void *buff, int32_t size, int32_t nitems, struct timidity_file *tf)
|
||||||
{
|
{
|
||||||
return tf->url->Read(buff, size * nitems) / size;
|
return (long)tf->url.Read(buff, size * nitems) / size;
|
||||||
}
|
}
|
||||||
|
|
||||||
long tf_seek(struct timidity_file *tf, long offset, int whence)
|
long tf_seek(struct timidity_file *tf, long offset, int whence)
|
||||||
{
|
{
|
||||||
|
|
||||||
return tf->url->Seek(offset, whence);
|
return (long)tf->url.Seek(offset, (FileRdr::ESeek)whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
long tf_tell(struct timidity_file *tf)
|
long tf_tell(struct timidity_file *tf)
|
||||||
{
|
{
|
||||||
return tf->url->Tell();
|
return (long)tf->url.Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,12 @@ namespace TimidityPlus
|
||||||
|
|
||||||
struct timidity_file
|
struct timidity_file
|
||||||
{
|
{
|
||||||
FileReader *url;
|
FileRdr url;
|
||||||
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, FSoundFontReader *);
|
||||||
extern void close_file(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);
|
||||||
int tf_getc(struct timidity_file *tf);
|
int tf_getc(struct timidity_file *tf);
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace TimidityPlus
|
||||||
ctl_cmsg(CMSG_ERROR, VERB_NORMAL, \
|
ctl_cmsg(CMSG_ERROR, VERB_NORMAL, \
|
||||||
"Too many errors... Give up read %s", name); \
|
"Too many errors... Give up read %s", name); \
|
||||||
reuse_mblock(&varbuf); \
|
reuse_mblock(&varbuf); \
|
||||||
close_file(tf); return 1; }
|
tf_close(tf); return 1; }
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1427,7 +1427,7 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_
|
||||||
continue;
|
continue;
|
||||||
case READ_CONFIG_RECURSION:
|
case READ_CONFIG_RECURSION:
|
||||||
reuse_mblock(&varbuf);
|
reuse_mblock(&varbuf);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return READ_CONFIG_RECURSION;
|
return READ_CONFIG_RECURSION;
|
||||||
case READ_CONFIG_FILE_NOT_FOUND:
|
case READ_CONFIG_FILE_NOT_FOUND:
|
||||||
break;
|
break;
|
||||||
|
@ -1610,7 +1610,7 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reuse_mblock(&varbuf);
|
reuse_mblock(&varbuf);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return (errcnt == 0) ? READ_CONFIG_SUCCESS : READ_CONFIG_ERROR;
|
return (errcnt == 0) ? READ_CONFIG_SUCCESS : READ_CONFIG_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -667,20 +667,20 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
|
||||||
&& memcmp(tmp, "GF1PATCH100\0ID#000002", 22))) {
|
&& memcmp(tmp, "GF1PATCH100\0ID#000002", 22))) {
|
||||||
/* don't know what the differences are */
|
/* don't know what the differences are */
|
||||||
ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "%s: not an instrument", name);
|
ctl_cmsg(CMSG_ERROR, VERB_NORMAL, "%s: not an instrument", name);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* instruments. To some patch makers, 0 means 1 */
|
/* instruments. To some patch makers, 0 means 1 */
|
||||||
if (tmp[82] != 1 && tmp[82] != 0) {
|
if (tmp[82] != 1 && tmp[82] != 0) {
|
||||||
ctl_cmsg(CMSG_ERROR, VERB_NORMAL,
|
ctl_cmsg(CMSG_ERROR, VERB_NORMAL,
|
||||||
"Can't handle patches with %d instruments", tmp[82]);
|
"Can't handle patches with %d instruments", tmp[82]);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (tmp[151] != 1 && tmp[151] != 0) { /* layers. What's a layer? */
|
if (tmp[151] != 1 && tmp[151] != 0) { /* layers. What's a layer? */
|
||||||
ctl_cmsg(CMSG_ERROR, VERB_NORMAL,
|
ctl_cmsg(CMSG_ERROR, VERB_NORMAL,
|
||||||
"Can't handle instruments with %d layers", tmp[151]);
|
"Can't handle instruments with %d layers", tmp[151]);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ip = (Instrument *)safe_malloc(sizeof(Instrument));
|
ip = (Instrument *)safe_malloc(sizeof(Instrument));
|
||||||
|
@ -697,7 +697,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
|
||||||
free(ip->sample[j].data);
|
free(ip->sample[j].data);
|
||||||
free(ip->sample);
|
free(ip->sample);
|
||||||
free(ip);
|
free(ip);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sp = &(ip->sample[i]);
|
sp = &(ip->sample[i]);
|
||||||
|
@ -964,7 +964,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
|
||||||
ctl_cmsg(CMSG_INFO, VERB_DEBUG, " - Stripping tail");
|
ctl_cmsg(CMSG_INFO, VERB_DEBUG, " - Stripping tail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
store_instrument_cache(ip, name, panning, amp, note_to_use,
|
store_instrument_cache(ip, name, panning, amp, note_to_use,
|
||||||
strip_loop, strip_envelope, strip_tail);
|
strip_loop, strip_envelope, strip_tail);
|
||||||
return ip;
|
return ip;
|
||||||
|
|
|
@ -283,10 +283,10 @@ int Instruments::import_wave_discriminant(char *sample_file)
|
||||||
if (tf_read(buf, 12, 1, tf) != 1
|
if (tf_read(buf, 12, 1, tf) != 1
|
||||||
|| memcmp(&buf[0], "RIFF", 4) != 0 || memcmp(&buf[8], "WAVE", 4) != 0)
|
|| memcmp(&buf[0], "RIFF", 4) != 0 || memcmp(&buf[8], "WAVE", 4) != 0)
|
||||||
{
|
{
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ int Instruments::import_wave_load(char *sample_file, Instrument *inst)
|
||||||
if (tf_read(buf, 12, 1, tf) != 1
|
if (tf_read(buf, 12, 1, tf) != 1
|
||||||
|| memcmp(&buf[0], "RIFF", 4) != 0 || memcmp(&buf[8], "WAVE", 4) != 0)
|
|| memcmp(&buf[0], "RIFF", 4) != 0 || memcmp(&buf[8], "WAVE", 4) != 0)
|
||||||
{
|
{
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//ctl_cmsg(CMSG_INFO,VERB_NOISY,"Loading WAV: %s", sample_file);
|
//ctl_cmsg(CMSG_INFO,VERB_NOISY,"Loading WAV: %s", sample_file);
|
||||||
|
@ -378,7 +378,7 @@ int Instruments::import_wave_load(char *sample_file, Instrument *inst)
|
||||||
type_index = 4 - (chunk_size & 1);
|
type_index = 4 - (chunk_size & 1);
|
||||||
type_size = 8 + (chunk_size & 1);
|
type_size = 8 + (chunk_size & 1);
|
||||||
}
|
}
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
if (chunk_flags & WAVE_CHUNKFLAG_SAMPLER)
|
if (chunk_flags & WAVE_CHUNKFLAG_SAMPLER)
|
||||||
{
|
{
|
||||||
uint8_t modes;
|
uint8_t modes;
|
||||||
|
@ -557,10 +557,10 @@ int Instruments::import_aiff_discriminant(char *sample_file)
|
||||||
|| memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0
|
|| memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0
|
||||||
|| (buf[8 + 3] != 'F' && buf[8 + 3] != 'C'))
|
|| (buf[8 + 3] != 'F' && buf[8 + 3] != 'C'))
|
||||||
{
|
{
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst)
|
||||||
|| memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0
|
|| memcmp(&buf[0], "FORM", 4) != 0 || memcmp(&buf[8], "AIF", 3) != 0
|
||||||
|| (buf[8 + 3] != 'F' && buf[8 + 3] != 'C'))
|
|| (buf[8 + 3] != 'F' && buf[8 + 3] != 'C'))
|
||||||
{
|
{
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
compressed = buf[8 + 3] == 'C';
|
compressed = buf[8 + 3] == 'C';
|
||||||
|
@ -684,7 +684,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst)
|
||||||
{
|
{
|
||||||
if (marker_data != NULL)
|
if (marker_data != NULL)
|
||||||
free(marker_data);
|
free(marker_data);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(chunk_flags & AIFF_CHUNKFLAG_SOUNDREAD))
|
if (!(chunk_flags & AIFF_CHUNKFLAG_SOUNDREAD))
|
||||||
|
@ -693,7 +693,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst)
|
||||||
{
|
{
|
||||||
if (marker_data != NULL)
|
if (marker_data != NULL)
|
||||||
free(marker_data);
|
free(marker_data);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -729,7 +729,7 @@ int Instruments::import_aiff_load(char *sample_file, Instrument *inst)
|
||||||
}
|
}
|
||||||
if (marker_data != NULL)
|
if (marker_data != NULL)
|
||||||
free(marker_data);
|
free(marker_data);
|
||||||
close_file(tf);
|
tf_close(tf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,10 +223,7 @@ void Instruments::free_soundfonts()
|
||||||
SFInsts *sf, *next;
|
SFInsts *sf, *next;
|
||||||
|
|
||||||
for (sf = sfrecs; sf != NULL; sf = next) {
|
for (sf = sfrecs; sf != NULL; sf = next) {
|
||||||
if ((sf->tf != NULL) && (sf->tf->url != NULL))
|
tf_close(sf->tf);
|
||||||
free(sf->tf->url);
|
|
||||||
if (sf->tf != NULL)
|
|
||||||
free(sf->tf);
|
|
||||||
reuse_mblock(&sf->pool);
|
reuse_mblock(&sf->pool);
|
||||||
next = sf->next;
|
next = sf->next;
|
||||||
free(sf);
|
free(sf);
|
||||||
|
@ -308,7 +305,7 @@ void Instruments::init_sf(SFInsts *rec)
|
||||||
free_soundfont(&sfinfo);
|
free_soundfont(&sfinfo);
|
||||||
|
|
||||||
if (opt_sf_close_each_file) {
|
if (opt_sf_close_each_file) {
|
||||||
close_file(rec->tf);
|
tf_close(rec->tf);
|
||||||
rec->tf = NULL;
|
rec->tf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,7 +321,7 @@ void Instruments::init_load_soundfont(void)
|
||||||
void Instruments::end_soundfont(SFInsts *rec)
|
void Instruments::end_soundfont(SFInsts *rec)
|
||||||
{
|
{
|
||||||
if (rec->tf) {
|
if (rec->tf) {
|
||||||
close_file(rec->tf);
|
tf_close(rec->tf);
|
||||||
rec->tf = NULL;
|
rec->tf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +380,7 @@ Instrument *Instruments::try_load_soundfont(SFInsts *rec, int order, int bank,in
|
||||||
inst = load_from_file(rec, ip);
|
inst = load_from_file(rec, ip);
|
||||||
|
|
||||||
if (opt_sf_close_each_file) {
|
if (opt_sf_close_each_file) {
|
||||||
close_file(rec->tf);
|
tf_close(rec->tf);
|
||||||
rec->tf = NULL;
|
rec->tf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ bool _WM_InitReader(const char *config_file)
|
||||||
|
|
||||||
unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
||||||
{
|
{
|
||||||
FileReader *fp;
|
FileRdr fp;
|
||||||
|
|
||||||
if (filename == nullptr)
|
if (filename == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -72,13 +72,13 @@ unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
||||||
fp = wm_sfreader->OpenFile(filename);
|
fp = wm_sfreader->OpenFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp == NULL)
|
if (!fp.isOpen())
|
||||||
{
|
{
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno);
|
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
long fsize = fp->GetLength();
|
auto fsize = fp.GetLength();
|
||||||
|
|
||||||
if (fsize > WM_MAXFILESIZE)
|
if (fsize > WM_MAXFILESIZE)
|
||||||
{
|
{
|
||||||
|
@ -95,9 +95,8 @@ unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp->Read(data, fsize);
|
fp.Read(data, fsize);
|
||||||
delete fp;
|
|
||||||
data[fsize] = 0;
|
data[fsize] = 0;
|
||||||
*size = fsize;
|
*size = (long)fsize;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -676,7 +676,7 @@ static int WM_LoadConfig(const char *config_file, bool main) {
|
||||||
int token_count = 0;
|
int token_count = 0;
|
||||||
auto config_parm = config_file;
|
auto config_parm = config_file;
|
||||||
|
|
||||||
FileReader *fr = nullptr;
|
FileRdr fr;
|
||||||
if (main)
|
if (main)
|
||||||
{
|
{
|
||||||
if (!_WM_InitReader(config_file)) return -1; // unable to open this as a config file.
|
if (!_WM_InitReader(config_file)) return -1; // unable to open this as a config file.
|
||||||
|
|
Loading…
Reference in a new issue