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

Annotation of /libgig/trunk/src/tools/gigdump.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1953 - (hide annotations) (download)
Thu Jul 30 08:16:02 2009 UTC (14 years, 8 months ago) by schoenebeck
Original Path: libgig/trunk/src/gigdump.cpp
File size: 20923 byte(s)
* preparations for release 3.3.0

1 schoenebeck 2 /***************************************************************************
2     * *
3 schoenebeck 933 * libgig - C++ cross-platform Gigasampler format file access library *
4 schoenebeck 2 * *
5 schoenebeck 1953 * Copyright (C) 2003-2009 by Christian Schoenebeck *
6 schoenebeck 511 * <cuse@users.sourceforge.net> *
7 schoenebeck 2 * *
8 schoenebeck 933 * This program is part of libgig. *
9     * *
10 schoenebeck 2 * 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 schoenebeck 24 # include <config.h>
28 schoenebeck 2 #endif
29    
30     #include <iostream>
31     #include <cstdlib>
32 schoenebeck 518 #include <string>
33 schoenebeck 2
34     #include "gig.h"
35    
36     using namespace std;
37    
38 schoenebeck 518 string Revision();
39     void PrintVersion();
40 schoenebeck 916 void PrintFileInformations(gig::File* gig);
41 schoenebeck 929 void PrintGroups(gig::File* gig);
42 schoenebeck 2 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 schoenebeck 518 if (argv[1][0] == '-') {
55     switch (argv[1][1]) {
56     case 'v':
57     PrintVersion();
58     return EXIT_SUCCESS;
59     }
60     }
61 schoenebeck 2 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 schoenebeck 916 PrintFileInformations(gig);
71     cout << endl;
72 schoenebeck 929 PrintGroups(gig);
73     cout << endl;
74 schoenebeck 2 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 schoenebeck 916 void PrintFileInformations(gig::File* gig) {
93     cout << "Global File Informations:" << endl;
94     cout << " Total instruments: " << gig->Instruments << endl;
95     if (gig->pVersion) {
96 schoenebeck 1953 cout << " Version: " << gig->pVersion->major << "."
97 schoenebeck 916 << gig->pVersion->minor << "."
98     << gig->pVersion->release << "."
99 schoenebeck 1953 << gig->pVersion->build << endl;
100 schoenebeck 916 }
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 schoenebeck 929 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 schoenebeck 2 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 schoenebeck 931 // determine sample's name
157 schoenebeck 2 string name = pSample->pInfo->Name;
158     if (name == "") name = "<NO NAME>";
159     else name = '\"' + name + '\"';
160 schoenebeck 931 // 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 schoenebeck 2 cout << " Sample " << samples << ") " << name << ", ";
167 schoenebeck 931 cout << "Group " << iGroup << ", ";
168 schoenebeck 24 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 schoenebeck 511 cout << ", LoopPlayCount=" << pSample->LoopPlayCount;
178 schoenebeck 24 }
179     cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl;
180 schoenebeck 2 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 schoenebeck 282 cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl;
220 schoenebeck 2 cout << " Loops=" << pRegion->SampleLoops << endl;
221 schoenebeck 229 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 schoenebeck 402 case gig::dimension_layer: { // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers).
233 schoenebeck 235 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 schoenebeck 229 break;
236 schoenebeck 402 }
237 schoenebeck 229 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 persson 437 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 persson 1264 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 schoenebeck 229 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 schoenebeck 439 cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !";
332 schoenebeck 229 break;
333     }
334 schoenebeck 240 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 schoenebeck 229 }
347    
348 schoenebeck 2 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 schoenebeck 808 while (dimensionRegions < rgn->DimensionRegions) {
358 schoenebeck 2 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 schoenebeck 334 cout << pSample->SamplesPerSecond << "Hz, ";
370 persson 406 cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl;
371 schoenebeck 2 }
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 schoenebeck 231 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 schoenebeck 269 cout << " Pan=" << (int) pDimensionRegion->Pan << endl;
398 schoenebeck 2
399     dimensionRegions++;
400     }
401     }
402    
403 schoenebeck 518 string Revision() {
404 schoenebeck 1953 string s = "$Revision: 1.24 $";
405 schoenebeck 518 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 schoenebeck 2 void PrintUsage() {
414     cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
415     cout << endl;
416 schoenebeck 518 cout << "Usage: gigdump [-v] FILE" << endl;
417     cout << endl;
418     cout << " -v Print version and exit." << endl;
419     cout << endl;
420 schoenebeck 2 }

  ViewVC Help
Powered by ViewVC