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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 929 - (show annotations) (download)
Tue Oct 24 22:24:45 2006 UTC (17 years, 5 months ago) by schoenebeck
File size: 20033 byte(s)
* support for Gigasampler's sample groups added

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

  ViewVC Help
Powered by ViewVC