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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2984 - (show annotations) (download)
Tue Sep 20 15:13:58 2016 UTC (7 years, 7 months ago) by schoenebeck
File size: 23568 byte(s)
* src/tools/gigextract.cpp: Fix: if sample name contains a path separator
  (slash or backslash) then replace them by a minus sign to avoid file
  system issues.
* src/tools/gigdump.cpp: additionally print RIFF chunk file offset and
  RIFF chunk size of sample data.
* Bumped version (4.0.0.svn7).

1 /***************************************************************************
2 * *
3 * libgig - C++ cross-platform Gigasampler format file access library *
4 * *
5 * Copyright (C) 2003-2014 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 PrintScripts(gig::File* gig);
44 void PrintInstruments(gig::File* gig);
45 void PrintRegions(gig::Instrument* instr);
46 void PrintUsage();
47 void PrintDimensionRegions(gig::Region* rgn);
48
49 class PubSample : public gig::Sample {
50 public:
51 using DLS::Sample::pCkData;
52 };
53
54 int main(int argc, char *argv[])
55 {
56 if (argc <= 1) {
57 PrintUsage();
58 return EXIT_FAILURE;
59 }
60 if (argv[1][0] == '-') {
61 switch (argv[1][1]) {
62 case 'v':
63 PrintVersion();
64 return EXIT_SUCCESS;
65 }
66 }
67 FILE* hFile = fopen(argv[1], "r");
68 if (!hFile) {
69 cout << "Invalid file argument!" << endl;
70 return EXIT_FAILURE;
71 }
72 fclose(hFile);
73 try {
74 RIFF::File* riff = new RIFF::File(argv[1]);
75 gig::File* gig = new gig::File(riff);
76 PrintFileInformations(gig);
77 cout << endl;
78 PrintGroups(gig);
79 cout << endl;
80 PrintSamples(gig);
81 cout << endl;
82 PrintScripts(gig);
83 cout << endl;
84 PrintInstruments(gig);
85 delete gig;
86 delete riff;
87 }
88 catch (RIFF::Exception e) {
89 e.PrintMessage();
90 return EXIT_FAILURE;
91 }
92 catch (...) {
93 cout << "Unknown exception while trying to parse file." << endl;
94 return EXIT_FAILURE;
95 }
96
97 return EXIT_SUCCESS;
98 }
99
100 void PrintFileInformations(gig::File* gig) {
101 cout << "Global File Informations:" << endl;
102 cout << " Total instruments: " << gig->Instruments << endl;
103 if (gig->pVersion) {
104 cout << " Version: " << gig->pVersion->major << "."
105 << gig->pVersion->minor << "."
106 << gig->pVersion->release << "."
107 << gig->pVersion->build << endl;
108 }
109 if (gig->pInfo) {
110 if (gig->pInfo->Name.size())
111 cout << " Name: '" << gig->pInfo->Name << "'\n";
112 if (gig->pInfo->ArchivalLocation.size())
113 cout << " ArchivalLocation: '" << gig->pInfo->ArchivalLocation << "'\n";
114 if (gig->pInfo->CreationDate.size())
115 cout << " CreationDate: '" << gig->pInfo->CreationDate << "'\n";
116 if (gig->pInfo->Comments.size())
117 cout << " Comments: '" << gig->pInfo->Comments << "'\n";
118 if (gig->pInfo->Product.size())
119 cout << " Product: '" << gig->pInfo->Product << "'\n";
120 if (gig->pInfo->Copyright.size())
121 cout << " Copyright: '" << gig->pInfo->Copyright << "'\n";
122 if (gig->pInfo->Artists.size())
123 cout << " Artists: '" << gig->pInfo->Artists << "'\n";
124 if (gig->pInfo->Genre.size())
125 cout << " Genre: '" << gig->pInfo->Genre << "'\n";
126 if (gig->pInfo->Keywords.size())
127 cout << " Keywords: '" << gig->pInfo->Keywords << "'\n";
128 if (gig->pInfo->Engineer.size())
129 cout << " Engineer: '" << gig->pInfo->Engineer << "'\n";
130 if (gig->pInfo->Technician.size())
131 cout << " Technician: '" << gig->pInfo->Technician << "'\n";
132 if (gig->pInfo->Software.size())
133 cout << " Software: '" << gig->pInfo->Software << "'\n";
134 if (gig->pInfo->Medium.size())
135 cout << " Medium: '" << gig->pInfo->Medium << "'\n";
136 if (gig->pInfo->Source.size())
137 cout << " Source: '" << gig->pInfo->Source << "'\n";
138 if (gig->pInfo->SourceForm.size())
139 cout << " SourceForm: '" << gig->pInfo->SourceForm << "'\n";
140 if (gig->pInfo->Commissioned.size())
141 cout << " Commissioned: '" << gig->pInfo->Commissioned << "'\n";
142 }
143 }
144
145 void PrintGroups(gig::File* gig) {
146 int groups = 0;
147 cout << "ALL defined Groups:" << endl;
148 for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup()) {
149 groups++;
150 string name = pGroup->Name;
151 if (name == "") name = "<NO NAME>";
152 else name = '\"' + name + '\"';
153 cout << " Group " << groups << ")" << endl;
154 cout << " Name: " << name << endl;
155 }
156 }
157
158 void PrintSamples(gig::File* gig) {
159 int samples = 0;
160 cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
161 PubSample* pSample = (PubSample*) gig->GetFirstSample();
162 while (pSample) {
163 samples++;
164 // determine sample's name
165 string name = pSample->pInfo->Name;
166 if (name == "") name = "<NO NAME>";
167 else name = '\"' + name + '\"';
168 // determine group this sample belongs to
169 int iGroup = 1;
170 for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup(), iGroup++) {
171 if (pGroup == pSample->GetGroup()) break;
172 }
173 // print sample info
174 cout << " Sample " << samples << ") " << name << ", ";
175 cout << "Group " << iGroup << ", ";
176 cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops";
177 if (pSample->Loops) {
178 cout << " (Type: ";
179 switch (pSample->LoopType) {
180 case gig::loop_type_normal: cout << "normal)"; break;
181 case gig::loop_type_bidirectional: cout << "pingpong)"; break;
182 case gig::loop_type_backward: cout << "reverse)"; break;
183 }
184 cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd;
185 cout << ", LoopPlayCount=" << pSample->LoopPlayCount;
186 }
187 cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false")
188 << " foffset=" << pSample->pCkData->GetFilePos()
189 << " fsz=" << pSample->pCkData->GetSize()
190 << endl;
191 #if 0
192 {
193 const uint bufSize = 64;
194 unsigned char buf[bufSize] = {};
195 pSample->SetPos(0);
196 RIFF::file_offset_t n = pSample->pCkData->Read(&buf[0], bufSize, 1);
197 //RIFF::file_offset_t n = pSample->Read(&buf[0], bufSize / pSample->FrameSize);
198 cout << " FrameSize=" << pSample->FrameSize << ",Data[" << n << "]" << flush;
199 for (int x = 0; x < bufSize; ++x)
200 printf("%02x ", buf[x]);
201 printf("\n");
202 fflush(stdout);
203 }
204 #endif
205 pSample = (PubSample*) gig->GetNextSample();
206 }
207 }
208
209 void PrintScripts(gig::File* gig) {
210 cout << "ALL Available Real-Time Instrument Scripts (as there might be more than referenced by Instruments):" << endl;
211 for (int g = 0; gig->GetScriptGroup(g); ++g) {
212 gig::ScriptGroup* pGroup = gig->GetScriptGroup(g);
213 cout << " Group " << g+1 << ") '" << pGroup->Name << "'\n";
214 for (int s = 0; pGroup->GetScript(s); ++s) {
215 gig::Script* pScript = pGroup->GetScript(s);
216 cout << " Script " << s+1 << ") '" << pScript->Name << "':\n";
217 cout << "[START OF SCRIPT]\n";
218 cout << pScript->GetScriptAsText();
219 cout << "[END OF SCRIPT]\n";
220 }
221 }
222 }
223
224 void PrintInstruments(gig::File* gig) {
225 int instruments = 0;
226 cout << "Available Instruments:" << endl;
227 gig::Instrument* pInstrument = gig->GetFirstInstrument();
228 while (pInstrument) {
229 instruments++;
230 string name = pInstrument->pInfo->Name;
231 if (name == "") name = "<NO NAME>";
232 else name = '\"' + name + '\"';
233 cout << " Instrument " << instruments << ") " << name << ", ";
234
235 cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
236
237 cout << " ScriptSlots=" << pInstrument->ScriptSlotCount() << endl;
238 for (int s = 0; s < pInstrument->ScriptSlotCount(); ++s) {
239 gig::Script* pScript = pInstrument->GetScriptOfSlot(s);
240 string name = pScript->Name;
241 cout << " ScriptSlot[" << s << "]='" << name << "'\n";
242 }
243
244 PrintRegions(pInstrument);
245
246 pInstrument = gig->GetNextInstrument();
247 }
248 }
249
250 void PrintRegions(gig::Instrument* instr) {
251 int iRegion = 1;
252 gig::Region* pRegion = instr->GetFirstRegion();
253 while (pRegion) {
254 cout << " Region " << iRegion++ << ") ";
255 gig::Sample* pSample = pRegion->GetSample();
256 if (pSample) {
257 cout << "Sample: ";
258 if (pSample->pInfo->Name != "") {
259 cout << "\"" << pSample->pInfo->Name << "\", ";
260 }
261 cout << pSample->SamplesPerSecond << "Hz, " << endl;
262 }
263 else {
264 cout << "<NO_VALID_SAMPLE_REFERENCE> ";
265 }
266 cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
267 cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl;
268 cout << " Loops=" << pRegion->SampleLoops << endl;
269 cout << " Dimensions=" << pRegion->Dimensions << endl;
270 for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) {
271 cout << " Dimension[" << iDimension << "]: Type=";
272 gig::dimension_def_t DimensionDef = pRegion->pDimensionDefinitions[iDimension];
273 switch (DimensionDef.dimension) {
274 case gig::dimension_none:
275 cout << "NONE";
276 break;
277 case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono).
278 cout << "SAMPLECHANNEL";
279 break;
280 case gig::dimension_layer: { // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers).
281 gig::crossfade_t crossfade = pRegion->pDimensionRegions[iDimension]->Crossfade;
282 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 << ")";
283 break;
284 }
285 case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined).
286 cout << "VELOCITY";
287 break;
288 case gig::dimension_channelaftertouch: // Channel Key Pressure
289 cout << "AFTERTOUCH";
290 break;
291 case gig::dimension_releasetrigger: // Special dimension for triggering samples on releasing a key.
292 cout << "RELEASETRIGGER";
293 break;
294 case gig::dimension_keyboard: // Key Position
295 cout << "KEYBOARD";
296 break;
297 case gig::dimension_roundrobin: // Different samples triggered each time a note is played, dimension regions selected in sequence
298 cout << "ROUNDROBIN";
299 break;
300 case gig::dimension_random: // Different samples triggered each time a note is played, random order
301 cout << "RANDOM";
302 break;
303 case gig::dimension_smartmidi: // For MIDI tools like legato and repetition mode
304 cout << "SMARTMIDI";
305 break;
306 case gig::dimension_roundrobinkeyboard: // Different samples triggered each time a note is played, any key advances the counter
307 cout << "ROUNDROBINKEYBOARD";
308 break;
309 case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1)
310 cout << "MODWHEEL";
311 break;
312 case gig::dimension_breath: // Breath Controller (Coarse, MIDI Controller 2)
313 cout << "BREATH";
314 break;
315 case gig::dimension_foot: // Foot Pedal (Coarse, MIDI Controller 4)
316 cout << "FOOT";
317 break;
318 case gig::dimension_portamentotime: // Portamento Time (Coarse, MIDI Controller 5)
319 cout << "PORTAMENTOTIME";
320 break;
321 case gig::dimension_effect1: // Effect Controller 1 (Coarse, MIDI Controller 12)
322 cout << "EFFECT1";
323 break;
324 case gig::dimension_effect2: // Effect Controller 2 (Coarse, MIDI Controller 13)
325 cout << "EFFECT2";
326 break;
327 case gig::dimension_genpurpose1: // General Purpose Controller 1 (Slider, MIDI Controller 16)
328 cout << "GENPURPOSE1";
329 break;
330 case gig::dimension_genpurpose2: // General Purpose Controller 2 (Slider, MIDI Controller 17)
331 cout << "GENPURPOSE2";
332 break;
333 case gig::dimension_genpurpose3: // General Purpose Controller 3 (Slider, MIDI Controller 18)
334 cout << "GENPURPOSE3";
335 break;
336 case gig::dimension_genpurpose4: // General Purpose Controller 4 (Slider, MIDI Controller 19)
337 cout << "GENPURPOSE4";
338 break;
339 case gig::dimension_sustainpedal: // Sustain Pedal (MIDI Controller 64)
340 cout << "SUSTAINPEDAL";
341 break;
342 case gig::dimension_portamento: // Portamento (MIDI Controller 65)
343 cout << "PORTAMENTO";
344 break;
345 case gig::dimension_sostenutopedal: // Sostenuto Pedal (MIDI Controller 66)
346 cout << "SOSTENUTOPEDAL";
347 break;
348 case gig::dimension_softpedal: // Soft Pedal (MIDI Controller 67)
349 cout << "SOFTPEDAL";
350 break;
351 case gig::dimension_genpurpose5: // General Purpose Controller 5 (Button, MIDI Controller 80)
352 cout << "GENPURPOSE5";
353 break;
354 case gig::dimension_genpurpose6: // General Purpose Controller 6 (Button, MIDI Controller 81)
355 cout << "GENPURPOSE6";
356 break;
357 case gig::dimension_genpurpose7: // General Purpose Controller 7 (Button, MIDI Controller 82)
358 cout << "GENPURPOSE7";
359 break;
360 case gig::dimension_genpurpose8: // General Purpose Controller 8 (Button, MIDI Controller 83)
361 cout << "GENPURPOSE8";
362 break;
363 case gig::dimension_effect1depth: // Effect 1 Depth (MIDI Controller 91)
364 cout << "EFFECT1DEPTH";
365 break;
366 case gig::dimension_effect2depth: // Effect 2 Depth (MIDI Controller 92)
367 cout << "EFFECT2DEPTH";
368 break;
369 case gig::dimension_effect3depth: // Effect 3 Depth (MIDI Controller 93)
370 cout << "EFFECT3DEPTH";
371 break;
372 case gig::dimension_effect4depth: // Effect 4 Depth (MIDI Controller 94)
373 cout << "EFFECT4DEPTH";
374 break;
375 case gig::dimension_effect5depth: // Effect 5 Depth (MIDI Controller 95)
376 cout << "EFFECT5DEPTH";
377 break;
378 default:
379 cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !";
380 break;
381 }
382 cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones;
383 cout << ", SplitType=";
384 switch (DimensionDef.split_type) {
385 case gig::split_type_normal:
386 cout << "NORMAL" << endl;
387 break;
388 case gig::split_type_bit:
389 cout << "BIT" << endl;
390 break;
391 default:
392 cout << "UNKNOWN" << endl;
393 }
394 }
395
396 PrintDimensionRegions(pRegion);
397
398 pRegion = instr->GetNextRegion();
399 }
400 }
401
402 template<typename T_int>
403 static void printIntArray(T_int* array, int size) {
404 printf("{");
405 for (int i = 0; i < size; ++i)
406 printf("[%d]=%d,", i, array[i]);
407 printf("}");
408 fflush(stdout);
409 }
410
411 void PrintDimensionRegions(gig::Region* rgn) {
412 int dimensionRegions = 0;
413 gig::DimensionRegion* pDimensionRegion;
414 while (dimensionRegions < rgn->DimensionRegions) {
415 pDimensionRegion = rgn->pDimensionRegions[dimensionRegions];
416 if (!pDimensionRegion) break;
417
418 cout << " Dimension Region " << dimensionRegions + 1 << ")" << endl;
419
420 gig::Sample* pSample = pDimensionRegion->pSample;
421 if (pSample) {
422 cout << " Sample: ";
423 if (pSample->pInfo->Name != "") {
424 cout << "\"" << pSample->pInfo->Name << "\", ";
425 }
426 cout << pSample->SamplesPerSecond << "Hz, ";
427 cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl;
428 }
429 else {
430 cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl;
431 }
432 cout << " LFO1Frequency=" << pDimensionRegion->LFO1Frequency << "Hz, LFO1InternalDepth=" << pDimensionRegion-> LFO1InternalDepth << ", LFO1ControlDepth=" << pDimensionRegion->LFO1ControlDepth << " LFO1Controller=" << pDimensionRegion->LFO1Controller << endl;
433 cout << " LFO2Frequency=" << pDimensionRegion->LFO2Frequency << "Hz, LFO2InternalDepth=" << pDimensionRegion-> LFO2InternalDepth << ", LFO2ControlDepth=" << pDimensionRegion->LFO2ControlDepth << " LFO2Controller=" << pDimensionRegion->LFO2Controller << endl;
434 cout << " LFO3Frequency=" << pDimensionRegion->LFO3Frequency << "Hz, LFO3InternalDepth=" << pDimensionRegion-> LFO3InternalDepth << ", LFO3ControlDepth=" << pDimensionRegion->LFO3ControlDepth << " LFO3Controller=" << pDimensionRegion->LFO3Controller << endl;
435 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;
436 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;
437 cout << " VCFEnabled=" << pDimensionRegion->VCFEnabled << ", VCFType=" << pDimensionRegion->VCFType << ", VCFCutoff=" << (int) pDimensionRegion->VCFCutoff << ", VCFResonance=" << (int) pDimensionRegion->VCFResonance << ", VCFCutoffController=" << pDimensionRegion->VCFCutoffController << endl;
438 cout << " VelocityResponseCurve=";
439 switch (pDimensionRegion->VelocityResponseCurve) {
440 case gig::curve_type_nonlinear:
441 cout << "NONLINEAR";
442 break;
443 case gig::curve_type_linear:
444 cout << "LINEAR";
445 break;
446 case gig::curve_type_special:
447 cout << "SPECIAL";
448 break;
449 case gig::curve_type_unknown:
450 default:
451 cout << "UNKNOWN - please report this !";
452 }
453 cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl;
454 cout << " VelocityUpperLimit=" << (int) pDimensionRegion->VelocityUpperLimit << " DimensionUpperLimits[]=" << flush;
455 printIntArray(pDimensionRegion->DimensionUpperLimits, 8);
456 cout << endl;
457 #if 0 // requires access to protected member VelocityTable, so commented out for now
458 if (pDimensionRegion->VelocityTable) {
459 cout << " VelocityTable[]=" << flush;
460 printIntArray(pDimensionRegion->VelocityTable, 127);
461 cout << endl;
462 }
463 #endif
464 cout << " Pan=" << (int) pDimensionRegion->Pan << endl;
465
466 dimensionRegions++;
467 }
468 }
469
470 string Revision() {
471 string s = "$Revision$";
472 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
473 }
474
475 void PrintVersion() {
476 cout << "gigdump revision " << Revision() << endl;
477 cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl;
478 }
479
480 void PrintUsage() {
481 cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
482 cout << endl;
483 cout << "Usage: gigdump [-v] FILE" << endl;
484 cout << endl;
485 cout << " -v Print version and exit." << endl;
486 cout << endl;
487 }

Properties

Name Value
svn:keywords Revision

  ViewVC Help
Powered by ViewVC