2016-03-01 15:47:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2018-02-22 23:48:03 +00:00
|
|
|
#include <memory>
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
#include "timidity.h"
|
2019-09-24 21:08:56 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "instrum.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "sf2.h"
|
2019-09-24 21:08:56 +00:00
|
|
|
|
2019-09-25 15:26:19 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <strings.h>
|
|
|
|
#define stricmp strcasecmp
|
|
|
|
#endif
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
namespace Timidity
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
FontFile *Instruments::ReadDLS(const char *filename, timidity_file *f)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
void Instruments::font_freeall()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
FontFile *font, *next;
|
|
|
|
|
|
|
|
for (font = Fonts; font != NULL; font = next)
|
|
|
|
{
|
|
|
|
next = font->Next;
|
|
|
|
delete font;
|
|
|
|
}
|
|
|
|
Fonts = NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
FontFile * Instruments::font_find(const char *filename)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
for (FontFile *font = Fonts; font != NULL; font = font->Next)
|
|
|
|
{
|
2019-09-24 09:07:32 +00:00
|
|
|
if (stricmp(filename, font->Filename.c_str()) == 0)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
void Instruments::font_add(const char *filename, int load_order)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
FontFile *font;
|
|
|
|
|
|
|
|
font = font_find(filename);
|
|
|
|
if (font != NULL)
|
|
|
|
{
|
|
|
|
font->SetAllOrders(load_order);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-28 21:17:16 +00:00
|
|
|
auto fp = sfreader->open_file(filename);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
if (fp)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if ((font = ReadSF2(filename, fp)) || (font = ReadDLS(filename, fp)))
|
|
|
|
{
|
2019-09-24 21:08:56 +00:00
|
|
|
font->Next = Fonts;
|
|
|
|
Fonts = font;
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
font->SetAllOrders(load_order);
|
|
|
|
}
|
2019-09-24 21:08:56 +00:00
|
|
|
fp->close();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
void Instruments::font_remove(const char *filename)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
FontFile *font;
|
|
|
|
|
|
|
|
font = font_find(filename);
|
|
|
|
if (font != NULL)
|
|
|
|
{
|
|
|
|
// Don't actually remove the font from the list, because instruments
|
|
|
|
// from it might be loaded using the %font extension.
|
|
|
|
font->SetAllOrders(255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
void Instruments::font_order(int order, int bank, int preset, int keynote)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
for (FontFile *font = Fonts; font != NULL; font = font->Next)
|
|
|
|
{
|
|
|
|
font->SetOrder(order, bank, preset, keynote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
Instrument *Renderer::load_instrument_font(const char *font, int drum, int bank, int instr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-09-24 21:08:56 +00:00
|
|
|
FontFile *fontfile = instruments->font_find(font);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (fontfile != NULL)
|
|
|
|
{
|
2019-09-24 21:08:56 +00:00
|
|
|
return fontfile->LoadInstrument(this, drum, bank, instr);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:08:56 +00:00
|
|
|
Instrument *Renderer::load_instrument_font_order(int order, int drum, int bank, int instr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-09-24 21:08:56 +00:00
|
|
|
for (FontFile *font = instruments->Fonts; font != NULL; font = font->Next)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-09-24 21:08:56 +00:00
|
|
|
Instrument *ip = font->LoadInstrument(this, drum, bank, instr);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (ip != NULL)
|
|
|
|
{
|
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-24 09:07:32 +00:00
|
|
|
FontFile::FontFile(const char *filename)
|
2016-03-01 15:47:10 +00:00
|
|
|
: Filename(filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FontFile::~FontFile()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|