#ifndef _FLUID_DEFSFONT_H
#define _FLUID_DEFSFONT_H
#include "fluidlite.h"
#include "fluidsynth_priv.h"
#include "fluid_list.h"
#define SF_SAMPMODES_LOOP 1
#define SF_SAMPMODES_UNROLL 2
#define SF_MIN_SAMPLERATE 400
#define SF_MAX_SAMPLERATE 50000
#define SF_MIN_SAMPLE_LENGTH 32
typedef struct _SFVersion
{
unsigned short major;
unsigned short minor;
}
SFVersion;
typedef struct _SFMod
{
unsigned short src;
unsigned short dest;
signed short amount;
unsigned short amtsrc;
unsigned short trans;
}
SFMod;
typedef union _SFGenAmount
{
signed short sword;
unsigned short uword;
struct
{
unsigned char lo;
unsigned char hi;
}
range;
}
SFGenAmount;
typedef struct _SFGen
{
unsigned short id;
SFGenAmount amount;
}
SFGen;
typedef struct _SFZone
{
fluid_list_t *instsamp;
fluid_list_t *gen;
fluid_list_t *mod;
}
SFZone;
typedef struct _SFSample
{
char name[21];
unsigned char samfile;
unsigned int start;
unsigned int end;
unsigned int loopstart;
unsigned int loopend;
unsigned int samplerate;
unsigned char origpitch;
signed char pitchadj;
unsigned short sampletype;
}
SFSample;
typedef struct _SFInst
{
char name[21];
fluid_list_t *zone;
}
SFInst;
typedef struct _SFPreset
{
char name[21];
unsigned short prenum;
unsigned short bank;
unsigned int libr;
unsigned int genre;
unsigned int morph;
fluid_list_t *zone;
}
SFPreset;
typedef struct _SFData
{
SFVersion version;
SFVersion romver;
unsigned int samplepos;
unsigned int samplesize;
char *fname;
FILE *sffd;
fluid_list_t *info;
fluid_list_t *preset;
fluid_list_t *inst;
fluid_list_t *sample;
}
SFData;
enum
{ UNKN_ID, RIFF_ID, LIST_ID, SFBK_ID,
INFO_ID, SDTA_ID, PDTA_ID,
IFIL_ID, ISNG_ID, INAM_ID, IROM_ID,
IVER_ID, ICRD_ID, IENG_ID, IPRD_ID,
ICOP_ID, ICMT_ID, ISFT_ID,
SNAM_ID, SMPL_ID,
PHDR_ID, PBAG_ID, PMOD_ID, PGEN_ID,
IHDR_ID, IBAG_ID, IMOD_ID, IGEN_ID,
SHDR_ID
};
typedef enum
{ Gen_StartAddrOfs, Gen_EndAddrOfs, Gen_StartLoopAddrOfs,
Gen_EndLoopAddrOfs, Gen_StartAddrCoarseOfs, Gen_ModLFO2Pitch,
Gen_VibLFO2Pitch, Gen_ModEnv2Pitch, Gen_FilterFc, Gen_FilterQ,
Gen_ModLFO2FilterFc, Gen_ModEnv2FilterFc, Gen_EndAddrCoarseOfs,
Gen_ModLFO2Vol, Gen_Unused1, Gen_ChorusSend, Gen_ReverbSend, Gen_Pan,
Gen_Unused2, Gen_Unused3, Gen_Unused4,
Gen_ModLFODelay, Gen_ModLFOFreq, Gen_VibLFODelay, Gen_VibLFOFreq,
Gen_ModEnvDelay, Gen_ModEnvAttack, Gen_ModEnvHold, Gen_ModEnvDecay,
Gen_ModEnvSustain, Gen_ModEnvRelease, Gen_Key2ModEnvHold,
Gen_Key2ModEnvDecay, Gen_VolEnvDelay, Gen_VolEnvAttack,
Gen_VolEnvHold, Gen_VolEnvDecay, Gen_VolEnvSustain, Gen_VolEnvRelease,
Gen_Key2VolEnvHold, Gen_Key2VolEnvDecay, Gen_Instrument,
Gen_Reserved1, Gen_KeyRange, Gen_VelRange,
Gen_StartLoopAddrCoarseOfs, Gen_Keynum, Gen_Velocity,
Gen_Attenuation, Gen_Reserved2, Gen_EndLoopAddrCoarseOfs,
Gen_CoarseTune, Gen_FineTune, Gen_SampleId, Gen_SampleModes,
Gen_Reserved3, Gen_ScaleTune, Gen_ExclusiveClass, Gen_OverrideRootKey,
Gen_Dummy
}
Gen_Type;
#define Gen_MaxValid Gen_Dummy - 1
#define Gen_Count Gen_Dummy
#define GenArrSize sizeof(SFGenAmount)*Gen_Count
typedef enum
{
None,
Unit_Smpls,
Unit_32kSmpls,
Unit_Cent,
Unit_HzCent,
Unit_TCent,
Unit_cB,
Unit_Percent,
Unit_Semitone,
Unit_Range
}
Gen_Unit;
extern unsigned short badgen[];
extern unsigned short badpgen[];
void sfont_init_chunks (void);
void sfont_close (SFData * sf, fluid_fileapi_t * fileapi);
void sfont_free_zone (SFZone * zone);
int sfont_preset_compare_func (void* a, void* b);
void sfont_zone_delete (SFData * sf, fluid_list_t ** zlist, SFZone * zone);
fluid_list_t *gen_inlist (int gen, fluid_list_t * genlist);
int gen_valid (int gen);
int gen_validp (int gen);
#define CHNKIDSTR(id) &idlist[(id - 1) * 4]
#define SFPHDRSIZE 38
#define SFBAGSIZE 4
#define SFMODSIZE 10
#define SFGENSIZE 4
#define SFIHDRSIZE 22
#define SFSHDRSIZE 46
typedef struct _SFChunk
{
unsigned int id;
unsigned int size;
}
SFChunk;
typedef struct _SFPhdr
{
unsigned char name[20];
unsigned short preset;
unsigned short bank;
unsigned short pbagndx;
unsigned int library;
unsigned int genre;
unsigned int morphology;
}
SFPhdr;
typedef struct _SFBag
{
unsigned short genndx;
unsigned short modndx;
}
SFBag;
typedef struct _SFIhdr
{
char name[20];
unsigned short ibagndx;
}
SFIhdr;
typedef struct _SFShdr
{
char name[20];
unsigned int start;
unsigned int end;
unsigned int loopstart;
unsigned int loopend;
unsigned int samplerate;
unsigned char origpitch;
signed char pitchadj;
unsigned short samplelink;
unsigned short sampletype;
}
SFShdr;
extern char idlist[];
SFData *sfload_file (const char * fname, fluid_fileapi_t * fileapi);
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#define GPOINTER_TO_INT(p) ((uintptr) (p))
#define GINT_TO_POINTER(i) ((void *) (uintptr)(i))
char* g_strdup (const char *str);
#if !(defined (G_STMT_START) && defined (G_STMT_END))
# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
# define G_STMT_START (void)(
# define G_STMT_END )
# else
# if (defined (sun) || defined (__sun__))
# define G_STMT_START if (1)
# define G_STMT_END else (void)0
# else
# define G_STMT_START do
# define G_STMT_END while (0)
# endif
# endif
#endif
#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((unsigned short) ( \
(((unsigned short) (val) & (unsigned short) 0x00ffU) << 8) | \
(((unsigned short) (val) & (unsigned short) 0xff00U) >> 8)))
#define GUINT32_SWAP_LE_BE_CONSTANT(val) ((unsigned int) ( \
(((unsigned int) (val) & (unsigned int) 0x000000ffU) << 24) | \
(((unsigned int) (val) & (unsigned int) 0x0000ff00U) << 8) | \
(((unsigned int) (val) & (unsigned int) 0x00ff0000U) >> 8) | \
(((unsigned int) (val) & (unsigned int) 0xff000000U) >> 24)))
#define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
#define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
#define GINT16_TO_LE(val) ((signed short) (val))
#define GUINT16_TO_LE(val) ((unsigned short) (val))
#define GINT16_TO_BE(val) ((signed short) GUINT16_SWAP_LE_BE (val))
#define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val))
#define GINT32_TO_LE(val) ((signed int) (val))
#define GUINT32_TO_LE(val) ((unsigned int) (val))
#define GINT32_TO_BE(val) ((signed int) GUINT32_SWAP_LE_BE (val))
#define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val))
#define GINT16_FROM_LE(val) (GINT16_TO_LE (val))
#define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val))
#define GINT16_FROM_BE(val) (GINT16_TO_BE (val))
#define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val))
#define GINT32_FROM_LE(val) (GINT32_TO_LE (val))
#define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val))
#define GINT32_FROM_BE(val) (GINT32_TO_BE (val))
#define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val))
#define FAIL 0
#define OK 1
enum
{ ErrWarn, ErrFatal, ErrStatus, ErrCorr, ErrEof, ErrMem, Errno,
ErrRead, ErrWrite
};
#define ErrMax ErrWrite
#define ErrnoStart Errno
#define ErrnoEnd ErrWrite
int gerr (int ev, char * fmt, ...);
typedef struct _fluid_defsfont_t fluid_defsfont_t;
typedef struct _fluid_defpreset_t fluid_defpreset_t;
typedef struct _fluid_preset_zone_t fluid_preset_zone_t;
typedef struct _fluid_inst_t fluid_inst_t;
typedef struct _fluid_inst_zone_t fluid_inst_zone_t;
fluid_sfloader_t* new_fluid_defsfloader(void);
int delete_fluid_defsfloader(fluid_sfloader_t* loader);
fluid_sfont_t* fluid_defsfloader_load(fluid_sfloader_t* loader, const char* filename);
int fluid_defsfont_sfont_delete(fluid_sfont_t* sfont);
char* fluid_defsfont_sfont_get_name(fluid_sfont_t* sfont);
fluid_preset_t* fluid_defsfont_sfont_get_preset(fluid_sfont_t* sfont, unsigned int bank, unsigned int prenum);
void fluid_defsfont_sfont_iteration_start(fluid_sfont_t* sfont);
int fluid_defsfont_sfont_iteration_next(fluid_sfont_t* sfont, fluid_preset_t* preset);
int fluid_defpreset_preset_delete(fluid_preset_t* preset);
char* fluid_defpreset_preset_get_name(fluid_preset_t* preset);
int fluid_defpreset_preset_get_banknum(fluid_preset_t* preset);
int fluid_defpreset_preset_get_num(fluid_preset_t* preset);
int fluid_defpreset_preset_noteon(fluid_preset_t* preset, fluid_synth_t* synth, int chan, int key, int vel);
struct _fluid_defsfont_t
{
char* filename;
unsigned int samplepos;
unsigned int samplesize;
short* sampledata;
fluid_list_t* sample;
fluid_defpreset_t* preset;
fluid_preset_t iter_preset;
fluid_defpreset_t* iter_cur;
};
fluid_defsfont_t* new_fluid_defsfont(void);
int delete_fluid_defsfont(fluid_defsfont_t* sfont);
int fluid_defsfont_load(fluid_defsfont_t* sfont, const char* file, fluid_fileapi_t * fileapi);
char* fluid_defsfont_get_name(fluid_defsfont_t* sfont);
fluid_defpreset_t* fluid_defsfont_get_preset(fluid_defsfont_t* sfont, unsigned int bank, unsigned int prenum);
void fluid_defsfont_iteration_start(fluid_defsfont_t* sfont);
int fluid_defsfont_iteration_next(fluid_defsfont_t* sfont, fluid_preset_t* preset);
int fluid_defsfont_load_sampledata(fluid_defsfont_t* sfont, fluid_fileapi_t * fileapi);
int fluid_defsfont_add_sample(fluid_defsfont_t* sfont, fluid_sample_t* sample);
int fluid_defsfont_add_preset(fluid_defsfont_t* sfont, fluid_defpreset_t* preset);
fluid_sample_t* fluid_defsfont_get_sample(fluid_defsfont_t* sfont, char *s);
struct _fluid_defpreset_t
{
fluid_defpreset_t* next;
fluid_defsfont_t* sfont;
char name[21];
unsigned int bank;
unsigned int num;
fluid_preset_zone_t* global_zone;
fluid_preset_zone_t* zone;
};
fluid_defpreset_t* new_fluid_defpreset(fluid_defsfont_t* sfont);
int delete_fluid_defpreset(fluid_defpreset_t* preset);
fluid_defpreset_t* fluid_defpreset_next(fluid_defpreset_t* preset);
int fluid_defpreset_import_sfont(fluid_defpreset_t* preset, SFPreset* sfpreset, fluid_defsfont_t* sfont);
int fluid_defpreset_set_global_zone(fluid_defpreset_t* preset, fluid_preset_zone_t* zone);
int fluid_defpreset_add_zone(fluid_defpreset_t* preset, fluid_preset_zone_t* zone);
fluid_preset_zone_t* fluid_defpreset_get_zone(fluid_defpreset_t* preset);
fluid_preset_zone_t* fluid_defpreset_get_global_zone(fluid_defpreset_t* preset);
int fluid_defpreset_get_banknum(fluid_defpreset_t* preset);
int fluid_defpreset_get_num(fluid_defpreset_t* preset);
char* fluid_defpreset_get_name(fluid_defpreset_t* preset);
int fluid_defpreset_noteon(fluid_defpreset_t* preset, fluid_synth_t* synth, int chan, int key, int vel);
struct _fluid_preset_zone_t
{
fluid_preset_zone_t* next;
char* name;
fluid_inst_t* inst;
int keylo;
int keyhi;
int vello;
int velhi;
fluid_gen_t gen[GEN_LAST];
fluid_mod_t * mod;
};
fluid_preset_zone_t* new_fluid_preset_zone(char* name);
int delete_fluid_preset_zone(fluid_preset_zone_t* zone);
fluid_preset_zone_t* fluid_preset_zone_next(fluid_preset_zone_t* preset);
int fluid_preset_zone_import_sfont(fluid_preset_zone_t* zone, SFZone* sfzone, fluid_defsfont_t* sfont);
int fluid_preset_zone_inside_range(fluid_preset_zone_t* zone, int key, int vel);
fluid_inst_t* fluid_preset_zone_get_inst(fluid_preset_zone_t* zone);
struct _fluid_inst_t
{
char name[21];
fluid_inst_zone_t* global_zone;
fluid_inst_zone_t* zone;
};
fluid_inst_t* new_fluid_inst(void);
int delete_fluid_inst(fluid_inst_t* inst);
int fluid_inst_import_sfont(fluid_inst_t* inst, SFInst *sfinst, fluid_defsfont_t* sfont);
int fluid_inst_set_global_zone(fluid_inst_t* inst, fluid_inst_zone_t* zone);
int fluid_inst_add_zone(fluid_inst_t* inst, fluid_inst_zone_t* zone);
fluid_inst_zone_t* fluid_inst_get_zone(fluid_inst_t* inst);
fluid_inst_zone_t* fluid_inst_get_global_zone(fluid_inst_t* inst);
struct _fluid_inst_zone_t
{
fluid_inst_zone_t* next;
char* name;
fluid_sample_t* sample;
int keylo;
int keyhi;
int vello;
int velhi;
fluid_gen_t gen[GEN_LAST];
fluid_mod_t * mod;
};
fluid_inst_zone_t* new_fluid_inst_zone(char* name);
int delete_fluid_inst_zone(fluid_inst_zone_t* zone);
fluid_inst_zone_t* fluid_inst_zone_next(fluid_inst_zone_t* zone);
int fluid_inst_zone_import_sfont(fluid_inst_zone_t* zone, SFZone *sfzone, fluid_defsfont_t* sfont);
int fluid_inst_zone_inside_range(fluid_inst_zone_t* zone, int key, int vel);
fluid_sample_t* fluid_inst_zone_get_sample(fluid_inst_zone_t* zone);
fluid_sample_t* new_fluid_sample(void);
int delete_fluid_sample(fluid_sample_t* sample);
int fluid_sample_import_sfont(fluid_sample_t* sample, SFSample* sfsample, fluid_defsfont_t* sfont);
int fluid_sample_in_rom(fluid_sample_t* sample);
#endif