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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1264 - (show annotations) (download)
Sun Jul 29 10:51:09 2007 UTC (16 years, 8 months ago) by persson
File size: 20925 byte(s)
* added write support for 24 bit samples
* set default version to 3 when creating a new file
* more chunk order fixes
* 3ewg is now bigger in v3
* one more einf field figured out
* added some dimension strings to gigdump

1 /***************************************************************************
2 * *
3 * libgig - C++ cross-platform Gigasampler format file access library *
4 * *
5 * Copyright (C) 2003-2006 by Christian Schoenebeck *
6 * <cuse@users.sourceforge.net> *
7 * *
8 * This program is part of libgig. *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
23 * MA 02111-1307 USA *
24 ***************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29
30 #include <iostream>
31 #include <cstdlib>
32 #include <string>
33
34 #include "gig.h"
35
36 using namespace std;
37
38 string Revision();
39 void PrintVersion();
40 void PrintFileInformations(gig::File* gig);
41 void PrintGroups(gig::File* gig);
42 void PrintSamples(gig::File* gig);
43 void PrintInstruments(gig::File* gig);
44 void PrintRegions(gig::Instrument* instr);
45 void PrintUsage();
46 void PrintDimensionRegions(gig::Region* rgn);
47
48 int main(int argc, char *argv[])
49 {
50 if (argc <= 1) {
51 PrintUsage();
52 return EXIT_FAILURE;
53 }
54 if (argv[1][0] == '-') {
55 switch (argv[1][1]) {
56 case 'v':
57 PrintVersion();
58 return EXIT_SUCCESS;
59 }
60 }
61 FILE* hFile = fopen(argv[1], "r");
62 if (!hFile) {
63 cout << "Invalid file argument!" << endl;
64 return EXIT_FAILURE;
65 }
66 fclose(hFile);
67 try {
68 RIFF::File* riff = new RIFF::File(argv[1]);
69 gig::File* gig = new gig::File(riff);
70 PrintFileInformations(gig);
71 cout << endl;
72 PrintGroups(gig);
73 cout << endl;
74 PrintSamples(gig);
75 cout << endl;
76 PrintInstruments(gig);
77 delete gig;
78 delete riff;
79 }
80 catch (RIFF::Exception e) {
81 e.PrintMessage();
82 return EXIT_FAILURE;
83 }
84 catch (...) {
85 cout << "Unknown exception while trying to parse file." << endl;
86 return EXIT_FAILURE;
87 }
88
89 return EXIT_SUCCESS;
90 }
91
92 void PrintFileInformations(gig::File* gig) {
93 cout << "Global File Informations:" << endl;
94 cout << " Total instruments: " << gig->Instruments << endl;
95 if (gig->pVersion) {
96 cout << " Version: " << gig->pVersion->major << "."
97 << gig->pVersion->minor << "."
98 << gig->pVersion->release << "."
99 << gig->pVersion->build << endl;
100 }
101 if (gig->pInfo) {
102 if (gig->pInfo->Name.size())
103 cout << " Name: '" << gig->pInfo->Name << "'\n";
104 if (gig->pInfo->ArchivalLocation.size())
105 cout << " ArchivalLocation: '" << gig->pInfo->ArchivalLocation << "'\n";
106 if (gig->pInfo->CreationDate.size())
107 cout << " CreationDate: '" << gig->pInfo->CreationDate << "'\n";
108 if (gig->pInfo->Comments.size())
109 cout << " Comments: '" << gig->pInfo->Comments << "'\n";
110 if (gig->pInfo->Product.size())
111 cout << " Product: '" << gig->pInfo->Product << "'\n";
112 if (gig->pInfo->Copyright.size())
113 cout << " Copyright: '" << gig->pInfo->Copyright << "'\n";
114 if (gig->pInfo->Artists.size())
115 cout << " Artists: '" << gig->pInfo->Artists << "'\n";
116 if (gig->pInfo->Genre.size())
117 cout << " Genre: '" << gig->pInfo->Genre << "'\n";
118 if (gig->pInfo->Keywords.size())
119 cout << " Keywords: '" << gig->pInfo->Keywords << "'\n";
120 if (gig->pInfo->Engineer.size())
121 cout << " Engineer: '" << gig->pInfo->Engineer << "'\n";
122 if (gig->pInfo->Technician.size())
123 cout << " Technician: '" << gig->pInfo->Technician << "'\n";
124 if (gig->pInfo->Software.size())
125 cout << " Software: '" << gig->pInfo->Software << "'\n";
126 if (gig->pInfo->Medium.size())
127 cout << " Medium: '" << gig->pInfo->Medium << "'\n";
128 if (gig->pInfo->Source.size())
129 cout << " Source: '" << gig->pInfo->Source << "'\n";
130 if (gig->pInfo->SourceForm.size())
131 cout << " SourceForm: '" << gig->pInfo->SourceForm << "'\n";
132 if (gig->pInfo->Commissioned.size())
133 cout << " Commissioned: '" << gig->pInfo->Commissioned << "'\n";
134 }
135 }
136
137 void PrintGroups(gig::File* gig) {
138 int groups = 0;
139 cout << "ALL defined Groups:" << endl;
140 for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup()) {
141 groups++;
142 string name = pGroup->Name;
143 if (name == "") name = "<NO NAME>";
144 else name = '\"' + name + '\"';
145 cout << " Group " << groups << ")" << endl;
146 cout << " Name: " << name << endl;
147 }
148 }
149
150 void PrintSamples(gig::File* gig) {
151 int samples = 0;
152 cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
153 gig::Sample* pSample = gig->GetFirstSample();
154 while (pSample) {
155 samples++;
156 // determine sample's name
157 string name = pSample->pInfo->Name;
158 if (name == "") name = "<NO NAME>";
159 else name = '\"' + name + '\"';
160 // determine group this sample belongs to
161 int iGroup = 1;
162 for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup(), iGroup++) {
163 if (pGroup == pSample->GetGroup()) break;
164 }
165 // print sample info
166 cout << " Sample " << samples << ") " << name << ", ";
167 cout << "Group " << iGroup << ", ";
168 cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops";
169 if (pSample->Loops) {
170 cout << " (Type: ";
171 switch (pSample->LoopType) {
172 case gig::loop_type_normal: cout << "normal)"; break;
173 case gig::loop_type_bidirectional: cout << "pingpong)"; break;
174 case gig::loop_type_backward: cout << "reverse)"; break;
175 }
176 cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd;
177 cout << ", LoopPlayCount=" << pSample->LoopPlayCount;
178 }
179 cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl;
180 pSample = gig->GetNextSample();
181 }
182 }
183
184 void PrintInstruments(gig::File* gig) {
185 int instruments = 0;
186 cout << "Available Instruments:" << endl;
187 gig::Instrument* pInstrument = gig->GetFirstInstrument();
188 while (pInstrument) {
189 instruments++;
190 string name = pInstrument->pInfo->Name;
191 if (name == "") name = "<NO NAME>";
192 else name = '\"' + name + '\"';
193 cout << " Instrument " << instruments << ") " << name << ", ";
194
195 cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
196 PrintRegions(pInstrument);
197
198 pInstrument = gig->GetNextInstrument();
199 }
200 }
201
202 void PrintRegions(gig::Instrument* instr) {
203 int iRegion = 1;
204 gig::Region* pRegion = instr->GetFirstRegion();
205 while (pRegion) {
206 cout << " Region " << iRegion++ << ") ";
207 gig::Sample* pSample = pRegion->GetSample();
208 if (pSample) {
209 cout << "Sample: ";
210 if (pSample->pInfo->Name != "") {
211 cout << "\"" << pSample->pInfo->Name << "\", ";
212 }
213 cout << pSample->SamplesPerSecond << "Hz, " << endl;
214 }
215 else {
216 cout << "<NO_VALID_SAMPLE_REFERENCE> ";
217 }
218 cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
219 cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl;
220 cout << " Loops=" << pRegion->SampleLoops << endl;
221 cout << " Dimensions=" << pRegion->Dimensions << endl;
222 for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) {
223 cout << " Dimension[" << iDimension << "]: Type=";
224 gig::dimension_def_t DimensionDef = pRegion->pDimensionDefinitions[iDimension];
225 switch (DimensionDef.dimension) {
226 case gig::dimension_none:
227 cout << "NONE";
228 break;
229 case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono).
230 cout << "SAMPLECHANNEL";
231 break;
232 case gig::dimension_layer: { // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers).
233 gig::crossfade_t crossfade = pRegion->pDimensionRegions[iDimension]->Crossfade;
234 cout << "LAYER (Crossfade in_start=" << (int) crossfade.in_start << ",in_end=" << (int) crossfade.in_end << ",out_start=" << (int) crossfade.out_start << ",out_end=" << (int) crossfade.out_end << ")";
235 break;
236 }
237 case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined).
238 cout << "VELOCITY";
239 break;
240 case gig::dimension_channelaftertouch: // Channel Key Pressure
241 cout << "AFTERTOUCH";
242 break;
243 case gig::dimension_releasetrigger: // Special dimension for triggering samples on releasing a key.
244 cout << "RELEASETRIGGER";
245 break;
246 case gig::dimension_keyboard: // Key Position
247 cout << "KEYBOARD";
248 break;
249 case gig::dimension_roundrobin: // Different samples triggered each time a note is played, dimension regions selected in sequence
250 cout << "ROUNDROBIN";
251 break;
252 case gig::dimension_random: // Different samples triggered each time a note is played, random order
253 cout << "RANDOM";
254 break;
255 case gig::dimension_smartmidi: // For MIDI tools like legato and repetition mode
256 cout << "SMARTMIDI";
257 break;
258 case gig::dimension_roundrobinkeyboard: // Different samples triggered each time a note is played, any key advances the counter
259 cout << "ROUNDROBINKEYBOARD";
260 break;
261 case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1)
262 cout << "MODWHEEL";
263 break;
264 case gig::dimension_breath: // Breath Controller (Coarse, MIDI Controller 2)
265 cout << "BREATH";
266 break;
267 case gig::dimension_foot: // Foot Pedal (Coarse, MIDI Controller 4)
268 cout << "FOOT";
269 break;
270 case gig::dimension_portamentotime: // Portamento Time (Coarse, MIDI Controller 5)
271 cout << "PORTAMENTOTIME";
272 break;
273 case gig::dimension_effect1: // Effect Controller 1 (Coarse, MIDI Controller 12)
274 cout << "EFFECT1";
275 break;
276 case gig::dimension_effect2: // Effect Controller 2 (Coarse, MIDI Controller 13)
277 cout << "EFFECT2";
278 break;
279 case gig::dimension_genpurpose1: // General Purpose Controller 1 (Slider, MIDI Controller 16)
280 cout << "GENPURPOSE1";
281 break;
282 case gig::dimension_genpurpose2: // General Purpose Controller 2 (Slider, MIDI Controller 17)
283 cout << "GENPURPOSE2";
284 break;
285 case gig::dimension_genpurpose3: // General Purpose Controller 3 (Slider, MIDI Controller 18)
286 cout << "GENPURPOSE3";
287 break;
288 case gig::dimension_genpurpose4: // General Purpose Controller 4 (Slider, MIDI Controller 19)
289 cout << "GENPURPOSE4";
290 break;
291 case gig::dimension_sustainpedal: // Sustain Pedal (MIDI Controller 64)
292 cout << "SUSTAINPEDAL";
293 break;
294 case gig::dimension_portamento: // Portamento (MIDI Controller 65)
295 cout << "PORTAMENTO";
296 break;
297 case gig::dimension_sostenutopedal: // Sostenuto Pedal (MIDI Controller 66)
298 cout << "SOSTENUTOPEDAL";
299 break;
300 case gig::dimension_softpedal: // Soft Pedal (MIDI Controller 67)
301 cout << "SOFTPEDAL";
302 break;
303 case gig::dimension_genpurpose5: // General Purpose Controller 5 (Button, MIDI Controller 80)
304 cout << "GENPURPOSE5";
305 break;
306 case gig::dimension_genpurpose6: // General Purpose Controller 6 (Button, MIDI Controller 81)
307 cout << "GENPURPOSE6";
308 break;
309 case gig::dimension_genpurpose7: // General Purpose Controller 7 (Button, MIDI Controller 82)
310 cout << "GENPURPOSE7";
311 break;
312 case gig::dimension_genpurpose8: // General Purpose Controller 8 (Button, MIDI Controller 83)
313 cout << "GENPURPOSE8";
314 break;
315 case gig::dimension_effect1depth: // Effect 1 Depth (MIDI Controller 91)
316 cout << "EFFECT1DEPTH";
317 break;
318 case gig::dimension_effect2depth: // Effect 2 Depth (MIDI Controller 92)
319 cout << "EFFECT2DEPTH";
320 break;
321 case gig::dimension_effect3depth: // Effect 3 Depth (MIDI Controller 93)
322 cout << "EFFECT3DEPTH";
323 break;
324 case gig::dimension_effect4depth: // Effect 4 Depth (MIDI Controller 94)
325 cout << "EFFECT4DEPTH";
326 break;
327 case gig::dimension_effect5depth: // Effect 5 Depth (MIDI Controller 95)
328 cout << "EFFECT5DEPTH";
329 break;
330 default:
331 cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !";
332 break;
333 }
334 cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones;
335 cout << ", SplitType=";
336 switch (DimensionDef.split_type) {
337 case gig::split_type_normal:
338 cout << "NORMAL" << endl;
339 break;
340 case gig::split_type_bit:
341 cout << "BIT" << endl;
342 break;
343 default:
344 cout << "UNKNOWN" << endl;
345 }
346 }
347
348 PrintDimensionRegions(pRegion);
349
350 pRegion = instr->GetNextRegion();
351 }
352 }
353
354 void PrintDimensionRegions(gig::Region* rgn) {
355 int dimensionRegions = 0;
356 gig::DimensionRegion* pDimensionRegion;
357 while (dimensionRegions < rgn->DimensionRegions) {
358 pDimensionRegion = rgn->pDimensionRegions[dimensionRegions];
359 if (!pDimensionRegion) break;
360
361 cout << " Dimension Region " << dimensionRegions + 1 << ")" << endl;
362
363 gig::Sample* pSample = pDimensionRegion->pSample;
364 if (pSample) {
365 cout << " Sample: ";
366 if (pSample->pInfo->Name != "") {
367 cout << "\"" << pSample->pInfo->Name << "\", ";
368 }
369 cout << pSample->SamplesPerSecond << "Hz, ";
370 cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl;
371 }
372 else {
373 cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl;
374 }
375 cout << " LFO1Frequency=" << pDimensionRegion->LFO1Frequency << "Hz, LFO1InternalDepth=" << pDimensionRegion-> LFO1InternalDepth << ", LFO1ControlDepth=" << pDimensionRegion->LFO1ControlDepth << " LFO1Controller=" << pDimensionRegion->LFO1Controller << endl;
376 cout << " LFO2Frequency=" << pDimensionRegion->LFO2Frequency << "Hz, LFO2InternalDepth=" << pDimensionRegion-> LFO2InternalDepth << ", LFO2ControlDepth=" << pDimensionRegion->LFO2ControlDepth << " LFO2Controller=" << pDimensionRegion->LFO2Controller << endl;
377 cout << " LFO3Frequency=" << pDimensionRegion->LFO3Frequency << "Hz, LFO3InternalDepth=" << pDimensionRegion-> LFO3InternalDepth << ", LFO3ControlDepth=" << pDimensionRegion->LFO3ControlDepth << " LFO3Controller=" << pDimensionRegion->LFO3Controller << endl;
378 cout << " EG1PreAttack=" << pDimensionRegion->EG1PreAttack << "permille, EG1Attack=" << pDimensionRegion->EG1Attack << "s, EG1Decay1=" << pDimensionRegion->EG1Decay1 << "s, EG1Sustain=" << pDimensionRegion->EG1Sustain << "permille, EG1Release=" << pDimensionRegion->EG1Release << "s, EG1Decay2=" << pDimensionRegion->EG1Decay2 << "s, EG1Hold=" << pDimensionRegion->EG1Hold << endl;
379 cout << " EG2PreAttack=" << pDimensionRegion->EG2PreAttack << "permille, EG2Attack=" << pDimensionRegion->EG2Attack << "s, EG2Decay1=" << pDimensionRegion->EG2Decay1 << "s, EG2Sustain=" << pDimensionRegion->EG2Sustain << "permille, EG2Release=" << pDimensionRegion->EG2Release << "s, EG2Decay2=" << pDimensionRegion->EG2Decay2 << "s" << endl;
380 cout << " VCFEnabled=" << pDimensionRegion->VCFEnabled << ", VCFType=" << pDimensionRegion->VCFType << ", VCFCutoff=" << (int) pDimensionRegion->VCFCutoff << ", VCFResonance=" << (int) pDimensionRegion->VCFResonance << ", VCFCutoffController=" << pDimensionRegion->VCFCutoffController << endl;
381 cout << " VelocityResponseCurve=";
382 switch (pDimensionRegion->VelocityResponseCurve) {
383 case gig::curve_type_nonlinear:
384 cout << "NONLINEAR";
385 break;
386 case gig::curve_type_linear:
387 cout << "LINEAR";
388 break;
389 case gig::curve_type_special:
390 cout << "SPECIAL";
391 break;
392 case gig::curve_type_unknown:
393 default:
394 cout << "UNKNOWN - please report this !";
395 }
396 cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl;
397 cout << " Pan=" << (int) pDimensionRegion->Pan << endl;
398
399 dimensionRegions++;
400 }
401 }
402
403 string Revision() {
404 string s = "$Revision: 1.23 $";
405 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
406 }
407
408 void PrintVersion() {
409 cout << "gigdump revision " << Revision() << endl;
410 cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl;
411 }
412
413 void PrintUsage() {
414 cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
415 cout << endl;
416 cout << "Usage: gigdump [-v] FILE" << endl;
417 cout << endl;
418 cout << " -v Print version and exit." << endl;
419 cout << endl;
420 }

  ViewVC Help
Powered by ViewVC