/[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 933 - (hide annotations) (download)
Fri Nov 24 12:50:05 2006 UTC (13 years, 4 months ago) by schoenebeck
Original Path: libgig/trunk/src/gigdump.cpp
File size: 20539 byte(s)
* preparations for release 3.1.0

1 schoenebeck 2 /***************************************************************************
2     * *
3 schoenebeck 933 * libgig - C++ cross-platform Gigasampler format file access library *
4 schoenebeck 2 * *
5 schoenebeck 916 * Copyright (C) 2003-2006 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     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 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 schoenebeck 229 case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1)
256     cout << "MODWHEEL";
257     break;
258     case gig::dimension_breath: // Breath Controller (Coarse, MIDI Controller 2)
259     cout << "BREATH";
260     break;
261     case gig::dimension_foot: // Foot Pedal (Coarse, MIDI Controller 4)
262     cout << "FOOT";
263     break;
264     case gig::dimension_portamentotime: // Portamento Time (Coarse, MIDI Controller 5)
265     cout << "PORTAMENTOTIME";
266     break;
267     case gig::dimension_effect1: // Effect Controller 1 (Coarse, MIDI Controller 12)
268     cout << "EFFECT1";
269     break;
270     case gig::dimension_effect2: // Effect Controller 2 (Coarse, MIDI Controller 13)
271     cout << "EFFECT2";
272     break;
273     case gig::dimension_genpurpose1: // General Purpose Controller 1 (Slider, MIDI Controller 16)
274     cout << "GENPURPOSE1";
275     break;
276     case gig::dimension_genpurpose2: // General Purpose Controller 2 (Slider, MIDI Controller 17)
277     cout << "GENPURPOSE2";
278     break;
279     case gig::dimension_genpurpose3: // General Purpose Controller 3 (Slider, MIDI Controller 18)
280     cout << "GENPURPOSE3";
281     break;
282     case gig::dimension_genpurpose4: // General Purpose Controller 4 (Slider, MIDI Controller 19)
283     cout << "GENPURPOSE4";
284     break;
285     case gig::dimension_sustainpedal: // Sustain Pedal (MIDI Controller 64)
286     cout << "SUSTAINPEDAL";
287     break;
288     case gig::dimension_portamento: // Portamento (MIDI Controller 65)
289     cout << "PORTAMENTO";
290     break;
291     case gig::dimension_sostenutopedal: // Sostenuto Pedal (MIDI Controller 66)
292     cout << "SOSTENUTOPEDAL";
293     break;
294     case gig::dimension_softpedal: // Soft Pedal (MIDI Controller 67)
295     cout << "SOFTPEDAL";
296     break;
297     case gig::dimension_genpurpose5: // General Purpose Controller 5 (Button, MIDI Controller 80)
298     cout << "GENPURPOSE5";
299     break;
300     case gig::dimension_genpurpose6: // General Purpose Controller 6 (Button, MIDI Controller 81)
301     cout << "GENPURPOSE6";
302     break;
303     case gig::dimension_genpurpose7: // General Purpose Controller 7 (Button, MIDI Controller 82)
304     cout << "GENPURPOSE7";
305     break;
306     case gig::dimension_genpurpose8: // General Purpose Controller 8 (Button, MIDI Controller 83)
307     cout << "GENPURPOSE8";
308     break;
309     case gig::dimension_effect1depth: // Effect 1 Depth (MIDI Controller 91)
310     cout << "EFFECT1DEPTH";
311     break;
312     case gig::dimension_effect2depth: // Effect 2 Depth (MIDI Controller 92)
313     cout << "EFFECT2DEPTH";
314     break;
315     case gig::dimension_effect3depth: // Effect 3 Depth (MIDI Controller 93)
316     cout << "EFFECT3DEPTH";
317     break;
318     case gig::dimension_effect4depth: // Effect 4 Depth (MIDI Controller 94)
319     cout << "EFFECT4DEPTH";
320     break;
321     case gig::dimension_effect5depth: // Effect 5 Depth (MIDI Controller 95)
322     cout << "EFFECT5DEPTH";
323     break;
324     default:
325 schoenebeck 439 cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !";
326 schoenebeck 229 break;
327     }
328 schoenebeck 240 cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones;
329     cout << ", SplitType=";
330     switch (DimensionDef.split_type) {
331     case gig::split_type_normal:
332     cout << "NORMAL" << endl;
333     break;
334     case gig::split_type_bit:
335     cout << "BIT" << endl;
336     break;
337     default:
338     cout << "UNKNOWN" << endl;
339     }
340 schoenebeck 229 }
341    
342 schoenebeck 2 PrintDimensionRegions(pRegion);
343    
344     pRegion = instr->GetNextRegion();
345     }
346     }
347    
348     void PrintDimensionRegions(gig::Region* rgn) {
349     int dimensionRegions = 0;
350     gig::DimensionRegion* pDimensionRegion;
351 schoenebeck 808 while (dimensionRegions < rgn->DimensionRegions) {
352 schoenebeck 2 pDimensionRegion = rgn->pDimensionRegions[dimensionRegions];
353     if (!pDimensionRegion) break;
354    
355     cout << " Dimension Region " << dimensionRegions + 1 << ")" << endl;
356    
357     gig::Sample* pSample = pDimensionRegion->pSample;
358     if (pSample) {
359     cout << " Sample: ";
360     if (pSample->pInfo->Name != "") {
361     cout << "\"" << pSample->pInfo->Name << "\", ";
362     }
363 schoenebeck 334 cout << pSample->SamplesPerSecond << "Hz, ";
364 persson 406 cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl;
365 schoenebeck 2 }
366     else {
367     cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl;
368     }
369     cout << " LFO1Frequency=" << pDimensionRegion->LFO1Frequency << "Hz, LFO1InternalDepth=" << pDimensionRegion-> LFO1InternalDepth << ", LFO1ControlDepth=" << pDimensionRegion->LFO1ControlDepth << " LFO1Controller=" << pDimensionRegion->LFO1Controller << endl;
370     cout << " LFO2Frequency=" << pDimensionRegion->LFO2Frequency << "Hz, LFO2InternalDepth=" << pDimensionRegion-> LFO2InternalDepth << ", LFO2ControlDepth=" << pDimensionRegion->LFO2ControlDepth << " LFO2Controller=" << pDimensionRegion->LFO2Controller << endl;
371     cout << " LFO3Frequency=" << pDimensionRegion->LFO3Frequency << "Hz, LFO3InternalDepth=" << pDimensionRegion-> LFO3InternalDepth << ", LFO3ControlDepth=" << pDimensionRegion->LFO3ControlDepth << " LFO3Controller=" << pDimensionRegion->LFO3Controller << endl;
372     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;
373     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;
374     cout << " VCFEnabled=" << pDimensionRegion->VCFEnabled << ", VCFType=" << pDimensionRegion->VCFType << ", VCFCutoff=" << (int) pDimensionRegion->VCFCutoff << ", VCFResonance=" << (int) pDimensionRegion->VCFResonance << ", VCFCutoffController=" << pDimensionRegion->VCFCutoffController << endl;
375 schoenebeck 231 cout << " VelocityResponseCurve=";
376     switch (pDimensionRegion->VelocityResponseCurve) {
377     case gig::curve_type_nonlinear:
378     cout << "NONLINEAR";
379     break;
380     case gig::curve_type_linear:
381     cout << "LINEAR";
382     break;
383     case gig::curve_type_special:
384     cout << "SPECIAL";
385     break;
386     case gig::curve_type_unknown:
387     default:
388     cout << "UNKNOWN - please report this !";
389     }
390     cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl;
391 schoenebeck 269 cout << " Pan=" << (int) pDimensionRegion->Pan << endl;
392 schoenebeck 2
393     dimensionRegions++;
394     }
395     }
396    
397 schoenebeck 518 string Revision() {
398 schoenebeck 933 string s = "$Revision: 1.22 $";
399 schoenebeck 518 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
400     }
401    
402     void PrintVersion() {
403     cout << "gigdump revision " << Revision() << endl;
404     cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl;
405     }
406    
407 schoenebeck 2 void PrintUsage() {
408     cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
409     cout << endl;
410 schoenebeck 518 cout << "Usage: gigdump [-v] FILE" << endl;
411     cout << endl;
412     cout << " -v Print version and exit." << endl;
413     cout << endl;
414 schoenebeck 2 }

  ViewVC Help
Powered by ViewVC