/[svn]/libgig/trunk/src/sf2dump.cpp
ViewVC logotype

Contents of /libgig/trunk/src/sf2dump.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2020 - (show annotations) (download)
Fri Oct 30 16:25:27 2009 UTC (14 years, 5 months ago) by iliev
File size: 11842 byte(s)
* sf2: 24bit support
* sf2: loop support
* sf2: implemented overridingRootKey
* sf2: implemented instrument global region
* sf2: bugfix: some regions were ignored

1 /***************************************************************************
2 * *
3 * libgig - C++ cross-platform Gigasampler format file access library *
4 * *
5 * Copyright (C) 2003-2009 by Christian Schoenebeck *
6 * <cuse@users.sourceforge.net> *
7 * Copyright (C) 2009 by Grigor Iliev <grigor@grigoriliev.com> *
8 * *
9 * This program is part of libsf2. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the Free Software *
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
24 * MA 02111-1307 USA *
25 ***************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <iostream>
32 #include <cstdlib>
33 #include <string>
34 #include <sstream>
35
36 #include "SF.h"
37
38 using namespace std;
39
40 string Revision();
41 void PrintVersion();
42 void PrintSamples(sf2::File* sf);
43 void PrintInstruments(sf2::File* sf);
44 void PrintPeresets(sf2::File* sf);
45 void PrintRegion(int idx, sf2::Region* reg);
46 void PrintModulatorItem(sf2::ModulatorItem* mod);
47 void PrintModulator(sf2::Modulator& mod);
48 void PrintUsage();
49 void PrintSfInfo(sf2::File* sf);
50
51 string GetControllerType(sf2::Modulator& mod);
52 string GetControllerSource(sf2::Modulator& mod);
53 string GetSampleType(uint16_t type);
54
55 int main(int argc, char *argv[])
56 {
57 if (argc <= 1) {
58 PrintUsage();
59 return EXIT_FAILURE;
60 }
61 if (argv[1][0] == '-') {
62 switch (argv[1][1]) {
63 case 'v':
64 PrintVersion();
65 return EXIT_SUCCESS;
66 }
67 }
68 FILE* hFile = fopen(argv[1], "r");
69 if (!hFile) {
70 cout << "Invalid file argument!" << endl << endl;
71 void PrintUsage();
72 return EXIT_FAILURE;
73 }
74 fclose(hFile);
75 try {
76 RIFF::File* riff = new RIFF::File(argv[1]);
77 sf2::File* sf = new sf2::File(riff);
78 PrintSfInfo(sf);
79 PrintSamples(sf);
80 cout << endl;
81 PrintInstruments(sf);
82 PrintPeresets(sf);
83 delete sf;
84 delete riff;
85 }
86 catch (RIFF::Exception e) {
87 e.PrintMessage();
88 return EXIT_FAILURE;
89 }
90 catch (...) {
91 cout << "Unknown exception while trying to parse file." << endl;
92 return EXIT_FAILURE;
93 }
94
95 return EXIT_SUCCESS;
96 }
97
98 void PrintSfInfo(sf2::File* sf) {
99 cout << "File info:" << endl;
100 cout << "\tVersion: " << sf->pInfo->pVer->Major << "." << sf->pInfo->pVer->Minor << endl;
101 cout << "\tBank Name: " << sf->pInfo->BankName << endl;
102 cout << "\tSound Engine: " << sf->pInfo->SoundEngine << endl;
103 cout << "\tSound ROM Name: " << sf->pInfo->RomName << endl;
104 cout << "\tSound ROM Version: " << sf->pInfo->pRomVer->Major << "." << sf->pInfo->pRomVer->Minor << endl;
105 cout << "\tCreation Date: " << sf->pInfo->CreationDate << endl;
106 cout << "\tEngineers: " << sf->pInfo->Engineers << endl;
107 cout << "\tProduct: " << sf->pInfo->Product << endl;
108 cout << "\tCopyright: " << sf->pInfo->Copyright << endl;
109 cout << "\tComments: " << sf->pInfo->Comments << endl;
110 cout << "\tSoftware: " << sf->pInfo->Software << endl << endl;
111 }
112
113 void PrintSamples(sf2::File* sf) {
114 cout << "Samples (" << sf->GetSampleCount() << "): " << endl;
115 for (int i = 0; i < sf->GetSampleCount(); i++) {
116 sf2::Sample* s = sf->GetSample(i);
117 cout << "\t" << s->Name << " (Depth: " << ((s->GetFrameSize() / s->GetChannelCount()) * 8);
118 cout << " SampleRate: " << s->SampleRate;
119 cout << ", Pitch: " << ((int)s->OriginalPitch);
120 cout << ", Pitch Correction: " << ((int)s->PitchCorrection )<< endl;
121 cout << "\t\tStart: " << s->Start << ", End: " << s->End;
122 cout << ", Start Loop: " << s->StartLoop << ", End Loop: " << s->EndLoop << endl;
123 cout << "\t\tSample Type: " << GetSampleType(s->SampleType) << ", Sample Link: " << s->SampleLink << ")" << endl;
124 }
125 }
126
127 void PrintInstruments(sf2::File* sf) {
128 cout << "Instruments (" << sf->GetInstrumentCount() << "): " << endl;
129 for (int i = 0; i < sf->GetInstrumentCount(); i++) {
130 sf2::Instrument* instr = sf->GetInstrument(i);
131 cout << "\t" << instr->Name << " (";
132 cout << "Instrument bag: " << instr->InstBagNdx << ")" << endl;
133 cout << "\t Regions (" << instr->GetRegionCount() << ")" << endl;
134
135 if (instr->pGlobalRegion) PrintRegion(-1, instr->pGlobalRegion);
136
137 for (int j = 0; j < instr->GetRegionCount(); j++) {
138 PrintRegion(j, instr->GetRegion(j));
139 }
140 cout << endl;
141 }
142 }
143
144 void PrintPeresets(sf2::File* sf) {
145 cout << "Presets (" << sf->GetPresetCount() << "): " << endl;
146 for (int i = 0; i < sf->GetPresetCount(); i++) { /* exclude the terminal header - EOP */
147 sf2::Preset* p = sf->GetPreset(i);
148 cout << "\t" << p->Name << " (Preset: " << p->PresetNum << ", Bank: " << p->Bank;
149 cout << ", Preset bag: " << p->PresetBagNdx << ")" << endl;
150
151 if (p->pGlobalRegion) PrintRegion(-1, p->pGlobalRegion);
152
153 for (int j = 0; j < p->GetRegionCount(); j++) {
154 PrintRegion(j, p->GetRegion(j));
155 }
156 cout << endl;
157 }
158 }
159
160 void PrintRegion(int idx, sf2::Region* reg) {
161 if (idx == -1) cout << "\t\tGlobal Region " << endl;
162 else cout << "\t\tRegion " << idx << endl;
163 sf2::Sample* s = reg->GetSample();
164 if (s != NULL) {
165 cout << "\t\t Sample: " << s->Name << ", Fine Tune: " << reg->fineTune;
166 if (reg->coarseTune) cout << ", Coarse Tune: " << reg->coarseTune;
167 if (reg->overridingRootKey != -1) cout << ", Overriding Root Key: " << reg->overridingRootKey;
168 if (reg->HasLoop) {
169 cout << ", Loop Start: " << reg->LoopStart << ", Loop End: " << reg->LoopEnd;
170 }
171 cout << endl;
172 }
173 cout << "\t\t Key range=";
174 if (reg->loKey == NONE && reg->hiKey == NONE) cout << "None";
175 else cout << reg->loKey << "-" << reg->hiKey;
176 cout << ", Velocity range=";
177 if (reg->minVel == NONE && reg->maxVel == NONE) cout << "None" << endl;
178 else cout << reg->minVel << "-" << reg->maxVel << endl;
179
180 if (reg->pInstrument != NULL) {
181 cout << "\t\t Instrument: " << reg->pInstrument->Name << endl;
182 }
183
184 cout << "\t\t\tEG1PreAttackDelay=" << reg->EG1PreAttackDelay << "s, EG1Attack=" << reg->EG1Attack;
185 cout << "s, EG1Hold=" << reg->EG1Hold << "s, EG1Decay=" << reg->EG1Decay << "s, EG1Sustain=";
186 cout << reg->EG1Sustain << "permille, EG1Release=" << reg->EG1Release << "s" << endl;
187
188 cout << "\t\t\tEG2PreAttackDelay=" << reg->EG2PreAttackDelay << "s, EG2Attack=" << reg->EG2Attack;
189 cout << "s, EG2Hold=" << reg->EG2Hold << "s, EG2Decay=" << reg->EG2Decay << "s, EG2Sustain=";
190 cout << reg->EG2Sustain << "permille, EG2Release=" << reg->EG2Release << "s" << endl;
191
192 cout << "\t\t\tModulators (" << reg->modulators.size() << ")" << endl;
193
194 for (int i = 0; i < reg->modulators.size(); i++) {
195 cout << "\t\t\tModulator " << i << endl;
196 PrintModulatorItem(&reg->modulators[i]);
197 }
198 }
199
200 void PrintModulatorItem(sf2::ModulatorItem* mod) {
201 cout << "\t\t\t ModSrcOper" << endl;
202 PrintModulator(mod->ModSrcOper);
203
204 cout << "\t\t\t ModAmtSrcOper" << endl;
205 PrintModulator(mod->ModAmtSrcOper);
206 cout << "\t\t\t Amount: " << mod->ModAmount << endl;
207
208 if (mod->ModDestOper & (1 << 15)) {
209 cout << "\t\t\t ModDestOper: " << (mod->ModDestOper ^ (1 << 15)) << endl;
210 } else {
211 cout << "\t\t\t ModDestOper: " << mod->ModDestOper << endl;
212 }
213 }
214
215 void PrintModulator(sf2::Modulator& mod) {
216 cout << "\t\t\t\tController Type: " << GetControllerType(mod) << endl;
217 cout << "\t\t\t\tController Source: " << GetControllerSource(mod) << endl;
218 cout << "\t\t\t\tDirection: ";
219 cout << (mod.Direction ? "max -> min" : "min -> max") << endl;
220 cout << "\t\t\t\tPolarity: ";
221 cout << (mod.Polarity ? "Bipolar" : "Unipolar") << endl;
222 }
223
224 string GetControllerType(sf2::Modulator& mod) {
225 string s;
226 switch(mod.Type) {
227 case sf2::Modulator::LINEAR:
228 s = "Linear"; break;
229 case sf2::Modulator::CONCAVE:
230 s = "Concave"; break;
231 case sf2::Modulator::CONVEX:
232 s = "Convex"; break;
233 case sf2::Modulator::SWITCH:
234 s = "Switch"; break;
235 }
236
237 return s;
238 }
239
240 string GetControllerSource(sf2::Modulator& mod) {
241 if (mod.MidiPalete) {
242 stringstream ss;
243 ss << "MIDI controller " << mod.Index;
244 return ss.str();
245 }
246
247 string s;
248 switch(mod.Index) {
249 case sf2::Modulator::NO_CONTROLLER:
250 s = "No controller"; break;
251 case sf2::Modulator::NOTE_ON_VELOCITY:
252 s = "Note-On Velocity"; break;
253 case sf2::Modulator::NOTE_ON_KEY_NUMBER:
254 s = "Note-On Key Number"; break;
255 case sf2::Modulator::POLY_PRESSURE:
256 s = "Poly Pressure"; break;
257 case sf2::Modulator::CHANNEL_PRESSURE:
258 s = "Channel Pressure"; break;
259 case sf2::Modulator::PITCH_WHEEL:
260 s = "Pitch Wheel"; break;
261 case sf2::Modulator::PITCH_WHEEL_SENSITIVITY:
262 s = "Pitch Wheel Sensitivity"; break;
263 case sf2::Modulator::LINK:
264 s = "Link"; break;
265 default: s = "Unknown controller source";
266 }
267
268 return s;
269 }
270
271 string Revision() {
272 string s = "$Revision: 1.2 $";
273 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
274 }
275
276 void PrintVersion() {
277 cout << "sf2dump revision " << Revision() << endl;
278 cout << "using " << sf2::libraryName() << " " << sf2::libraryVersion() << endl;
279 }
280
281 void PrintUsage() {
282 cout << "sf2dump - parses SF2 files and prints out the content." << endl;
283 cout << endl;
284 cout << "Usage: sf2dump [-v] FILE" << endl;
285 cout << endl;
286 cout << " -v Print version and exit." << endl;
287 cout << endl;
288 }
289
290 string GetSampleType(uint16_t type) {
291 switch(type) {
292 case sf2::Sample::MONO_SAMPLE : return "Mono Sample";
293 case sf2::Sample::RIGHT_SAMPLE : return "Right Sample";
294 case sf2::Sample::LEFT_SAMPLE : return "Left Sample";
295 case sf2::Sample::LINKED_SAMPLE : return "Linked Sample";
296 case sf2::Sample::ROM_MONO_SAMPLE : return "ROM Mono Sample";
297 case sf2::Sample::ROM_RIGHT_SAMPLE : return "ROM Right Sample";
298 case sf2::Sample::ROM_LEFT_SAMPLE : return "ROM Left Sample";
299 case sf2::Sample::ROM_LINKED_SAMPLE : return "ROM Linked Sample";
300 default: return "Unknown";
301 }
302 }

  ViewVC Help
Powered by ViewVC