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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 916 - (hide annotations) (download)
Thu Aug 10 21:27:50 2006 UTC (14 years, 6 months ago) by schoenebeck
File size: 19498 byte(s)
* src/gigdump.cpp: print global file informations

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

  ViewVC Help
Powered by ViewVC