Debian Codegraph @

sfont.h

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