1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
//=============================================================================
// MuseScore sftools
//
// Copyright (C) 2010 Werner Schweer and others
//
// This work is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// In addition, as a special exception, licensor gives permission to
// link the code of this work with the OpenSSL Library (or with modified
// versions of OpenSSL that use the same license as OpenSSL), and
// distribute linked combinations including the two. You must obey the
// GNU General Public License in all respects for all of the code used
// other than OpenSSL. If you modify this file, you may extend this
// exception to your version of the file, but you are not obligated to
// do so. If you do not wish to do so, delete this exception statement
// from your version. (This exception is necessary should this work be
// included in a GPL-licenced work.)
//
// See COPYING.LIB for the licence text and disclaimer of warranty.
//=============================================================================
#ifndef __SOUNDFONT_H__
#define __SOUNDFONT_H__
#include <QtCore/QString>
#include <QtCore/QList>
class Xml;
class QFile;
//---------------------------------------------------------
// sfVersionTag
//---------------------------------------------------------
struct sfVersionTag {
int major;
int minor;
};
enum Modulator {
};
enum Generator {
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
};
enum Transform { Linear };
//---------------------------------------------------------
// ModulatorList
//---------------------------------------------------------
struct ModulatorList {
Modulator src;
Generator dst;
int amount;
Modulator amtSrc;
Transform transform;
};
//---------------------------------------------------------
// GeneratorList
//---------------------------------------------------------
union GeneratorAmount {
short sword;
ushort uword;
struct {
uchar lo, hi;
};
};
struct GeneratorList {
Generator gen;
GeneratorAmount amount;
};
//---------------------------------------------------------
// Zone
//---------------------------------------------------------
struct Zone {
QList<GeneratorList*> generators;
QList<ModulatorList*> modulators;
int instrumentIndex;
};
//---------------------------------------------------------
// Preset
//---------------------------------------------------------
struct Preset {
char* name {0};
int preset {0};
int bank {0};
int presetBagNdx {0}; // used only for read
int library {0};
int genre {0};
int morphology {0};
QList<Zone*> zones;
};
//---------------------------------------------------------
// Instrument
//---------------------------------------------------------
struct Instrument {
char* name;
int index; // used only for read
QList<Zone*> zones;
Instrument();
~Instrument();
};
//---------------------------------------------------------
// Sample
//---------------------------------------------------------
struct Sample {
char* name;
uint start;
uint end;
uint loopstart;
uint loopend;
uint samplerate;
int origpitch;
int pitchadj;
int sampletype;
Sample();
~Sample();
};
//---------------------------------------------------------
// SoundFont
//---------------------------------------------------------
class SoundFont {
QString path;
sfVersionTag version;
char* engine;
char* name;
char* date;
char* comment;
char* tools;
char* creator;
char* product;
char* copyright;
int samplePos;
int sampleLen;
QList<Preset*> presets;
QList<Instrument*> instruments;
QList<Zone*> pZones;
QList<Zone*> iZones;
QList<Sample*> samples;
QFile* file;
FILE* f;
double _oggQuality;
double _oggAmp;
qint64 _oggSerial;
unsigned readDword();
int readWord();
int readShort();
int readByte();
int readChar();
int readFourcc(const char*);
int readFourcc(char*);
void readSignature(const char* signature);
void readSignature(char* signature);
void skip(int);
void readSection(const char* fourcc, int len);
void readVersion();
char* readString(int);
void readPhdr(int);
void readBag(int, QList<Zone*>*);
void readMod(int, QList<Zone*>*);
void readGen(int, QList<Zone*>*);
void readInst(int);
void readShdr(int);
void writeDword(int);
void writeWord(unsigned short int);
void writeByte(unsigned char);
void writeChar(char);
void writeShort(short);
void write(const char* p, int n);
void write(Xml&, Zone*);
bool writeSampleFile(Sample*, QString);
void writeSample(const Sample*);
void writeStringSection(const char* fourcc, char* s);
void writePreset(int zoneIdx, const Preset*);
void writeModulator(const ModulatorList*);
void writeGenerator(const GeneratorList*);
void writeInstrument(int zoneIdx, const Instrument*);
void writeIfil();
void writeSmpl();
void writePhdr();
void writeBag(const char* fourcc, QList<Zone*>*);
void writeMod(const char* fourcc, const QList<Zone*>*);
void writeGen(const char* fourcc, QList<Zone*>*);
void writeInst();
void writeShdr();
int writeCompressedSample(Sample*);
bool writeCSample(Sample*, int);
char* readCompressedSample(Sample*);
public:
SoundFont(const QString&);
~SoundFont();
bool read();
bool write(QFile*, double oggQuality, double oggAmp, qint64 oggSerial);
bool readXml(QFile*);
bool writeXml(QFile*);
bool writeCode(QList<int>);
bool writeCode();
void dumpPresets();
};
#endif
|