gzdoom/libraries/timidity/instrum_font.cpp

129 lines
2.2 KiB
C++
Raw Normal View History

2016-03-01 15:47:10 +00:00
#include <stdio.h>
#include <string.h>
#include <memory>
2016-03-01 15:47:10 +00:00
#include "timidity.h"
#include "common.h"
#include "instrum.h"
2016-03-01 15:47:10 +00:00
#include "sf2.h"
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
{
FontFile *Instruments::ReadDLS(const char *filename, timidity_file *f)
2016-03-01 15:47:10 +00:00
{
return NULL;
}
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;
}
FontFile * Instruments::font_find(const char *filename)
2016-03-01 15:47:10 +00:00
{
for (FontFile *font = Fonts; font != NULL; font = font->Next)
{
if (stricmp(filename, font->Filename.c_str()) == 0)
2016-03-01 15:47:10 +00:00
{
return font;
}
}
return NULL;
}
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
{
auto fp = sfreader->open_file(filename);
2016-03-01 15:47:10 +00:00
if (fp)
2016-03-01 15:47:10 +00:00
{
if ((font = ReadSF2(filename, fp)) || (font = ReadDLS(filename, fp)))
{
font->Next = Fonts;
Fonts = font;
2016-03-01 15:47:10 +00:00
font->SetAllOrders(load_order);
}
fp->close();
2016-03-01 15:47:10 +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);
}
}
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);
}
}
Instrument *Renderer::load_instrument_font(const char *font, int drum, int bank, int instr)
2016-03-01 15:47:10 +00:00
{
FontFile *fontfile = instruments->font_find(font);
2016-03-01 15:47:10 +00:00
if (fontfile != NULL)
{
return fontfile->LoadInstrument(this, drum, bank, instr);
2016-03-01 15:47:10 +00:00
}
return NULL;
}
Instrument *Renderer::load_instrument_font_order(int order, int drum, int bank, int instr)
2016-03-01 15:47:10 +00:00
{
for (FontFile *font = instruments->Fonts; font != NULL; font = font->Next)
2016-03-01 15:47:10 +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;
}
FontFile::FontFile(const char *filename)
2016-03-01 15:47:10 +00:00
: Filename(filename)
{
}
FontFile::~FontFile()
{
}
}