1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file loader library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Christian Schoenebeck * |
* Copyright (C) 2003-2014 by Christian Schoenebeck * |
6 |
* <cuse@users.sourceforge.net> * |
* <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 * |
* 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 * |
* it under the terms of the GNU General Public License as published by * |
29 |
|
|
30 |
#include <iostream> |
#include <iostream> |
31 |
#include <cstdlib> |
#include <cstdlib> |
32 |
|
#include <string> |
33 |
|
|
34 |
#include "gig.h" |
#include "../gig.h" |
35 |
|
|
36 |
using namespace std; |
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); |
void PrintSamples(gig::File* gig); |
43 |
|
void PrintScripts(gig::File* gig); |
44 |
void PrintInstruments(gig::File* gig); |
void PrintInstruments(gig::File* gig); |
45 |
void PrintRegions(gig::Instrument* instr); |
void PrintRegions(gig::Instrument* instr); |
46 |
void PrintUsage(); |
void PrintUsage(); |
52 |
PrintUsage(); |
PrintUsage(); |
53 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
54 |
} |
} |
55 |
|
if (argv[1][0] == '-') { |
56 |
|
switch (argv[1][1]) { |
57 |
|
case 'v': |
58 |
|
PrintVersion(); |
59 |
|
return EXIT_SUCCESS; |
60 |
|
} |
61 |
|
} |
62 |
FILE* hFile = fopen(argv[1], "r"); |
FILE* hFile = fopen(argv[1], "r"); |
63 |
if (!hFile) { |
if (!hFile) { |
64 |
cout << "Invalid file argument!" << endl; |
cout << "Invalid file argument!" << endl; |
68 |
try { |
try { |
69 |
RIFF::File* riff = new RIFF::File(argv[1]); |
RIFF::File* riff = new RIFF::File(argv[1]); |
70 |
gig::File* gig = new gig::File(riff); |
gig::File* gig = new gig::File(riff); |
71 |
|
PrintFileInformations(gig); |
72 |
|
cout << endl; |
73 |
|
PrintGroups(gig); |
74 |
|
cout << endl; |
75 |
PrintSamples(gig); |
PrintSamples(gig); |
76 |
cout << endl; |
cout << endl; |
77 |
|
PrintScripts(gig); |
78 |
|
cout << endl; |
79 |
PrintInstruments(gig); |
PrintInstruments(gig); |
80 |
delete gig; |
delete gig; |
81 |
delete riff; |
delete riff; |
92 |
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
93 |
} |
} |
94 |
|
|
95 |
|
void PrintFileInformations(gig::File* gig) { |
96 |
|
cout << "Global File Informations:" << endl; |
97 |
|
cout << " Total instruments: " << gig->Instruments << endl; |
98 |
|
if (gig->pVersion) { |
99 |
|
cout << " Version: " << gig->pVersion->major << "." |
100 |
|
<< gig->pVersion->minor << "." |
101 |
|
<< gig->pVersion->release << "." |
102 |
|
<< gig->pVersion->build << endl; |
103 |
|
} |
104 |
|
if (gig->pInfo) { |
105 |
|
if (gig->pInfo->Name.size()) |
106 |
|
cout << " Name: '" << gig->pInfo->Name << "'\n"; |
107 |
|
if (gig->pInfo->ArchivalLocation.size()) |
108 |
|
cout << " ArchivalLocation: '" << gig->pInfo->ArchivalLocation << "'\n"; |
109 |
|
if (gig->pInfo->CreationDate.size()) |
110 |
|
cout << " CreationDate: '" << gig->pInfo->CreationDate << "'\n"; |
111 |
|
if (gig->pInfo->Comments.size()) |
112 |
|
cout << " Comments: '" << gig->pInfo->Comments << "'\n"; |
113 |
|
if (gig->pInfo->Product.size()) |
114 |
|
cout << " Product: '" << gig->pInfo->Product << "'\n"; |
115 |
|
if (gig->pInfo->Copyright.size()) |
116 |
|
cout << " Copyright: '" << gig->pInfo->Copyright << "'\n"; |
117 |
|
if (gig->pInfo->Artists.size()) |
118 |
|
cout << " Artists: '" << gig->pInfo->Artists << "'\n"; |
119 |
|
if (gig->pInfo->Genre.size()) |
120 |
|
cout << " Genre: '" << gig->pInfo->Genre << "'\n"; |
121 |
|
if (gig->pInfo->Keywords.size()) |
122 |
|
cout << " Keywords: '" << gig->pInfo->Keywords << "'\n"; |
123 |
|
if (gig->pInfo->Engineer.size()) |
124 |
|
cout << " Engineer: '" << gig->pInfo->Engineer << "'\n"; |
125 |
|
if (gig->pInfo->Technician.size()) |
126 |
|
cout << " Technician: '" << gig->pInfo->Technician << "'\n"; |
127 |
|
if (gig->pInfo->Software.size()) |
128 |
|
cout << " Software: '" << gig->pInfo->Software << "'\n"; |
129 |
|
if (gig->pInfo->Medium.size()) |
130 |
|
cout << " Medium: '" << gig->pInfo->Medium << "'\n"; |
131 |
|
if (gig->pInfo->Source.size()) |
132 |
|
cout << " Source: '" << gig->pInfo->Source << "'\n"; |
133 |
|
if (gig->pInfo->SourceForm.size()) |
134 |
|
cout << " SourceForm: '" << gig->pInfo->SourceForm << "'\n"; |
135 |
|
if (gig->pInfo->Commissioned.size()) |
136 |
|
cout << " Commissioned: '" << gig->pInfo->Commissioned << "'\n"; |
137 |
|
} |
138 |
|
} |
139 |
|
|
140 |
|
void PrintGroups(gig::File* gig) { |
141 |
|
int groups = 0; |
142 |
|
cout << "ALL defined Groups:" << endl; |
143 |
|
for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup()) { |
144 |
|
groups++; |
145 |
|
string name = pGroup->Name; |
146 |
|
if (name == "") name = "<NO NAME>"; |
147 |
|
else name = '\"' + name + '\"'; |
148 |
|
cout << " Group " << groups << ")" << endl; |
149 |
|
cout << " Name: " << name << endl; |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
void PrintSamples(gig::File* gig) { |
void PrintSamples(gig::File* gig) { |
154 |
int samples = 0; |
int samples = 0; |
155 |
cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl; |
cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl; |
156 |
gig::Sample* pSample = gig->GetFirstSample(); |
gig::Sample* pSample = gig->GetFirstSample(); |
157 |
while (pSample) { |
while (pSample) { |
158 |
samples++; |
samples++; |
159 |
|
// determine sample's name |
160 |
string name = pSample->pInfo->Name; |
string name = pSample->pInfo->Name; |
161 |
if (name == "") name = "<NO NAME>"; |
if (name == "") name = "<NO NAME>"; |
162 |
else name = '\"' + name + '\"'; |
else name = '\"' + name + '\"'; |
163 |
|
// determine group this sample belongs to |
164 |
|
int iGroup = 1; |
165 |
|
for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup(), iGroup++) { |
166 |
|
if (pGroup == pSample->GetGroup()) break; |
167 |
|
} |
168 |
|
// print sample info |
169 |
cout << " Sample " << samples << ") " << name << ", "; |
cout << " Sample " << samples << ") " << name << ", "; |
170 |
|
cout << "Group " << iGroup << ", "; |
171 |
cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops"; |
cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops"; |
172 |
if (pSample->Loops) { |
if (pSample->Loops) { |
173 |
cout << " (Type: "; |
cout << " (Type: "; |
177 |
case gig::loop_type_backward: cout << "reverse)"; break; |
case gig::loop_type_backward: cout << "reverse)"; break; |
178 |
} |
} |
179 |
cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd; |
cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd; |
180 |
|
cout << ", LoopPlayCount=" << pSample->LoopPlayCount; |
181 |
} |
} |
182 |
cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl; |
cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl; |
183 |
pSample = gig->GetNextSample(); |
pSample = gig->GetNextSample(); |
184 |
} |
} |
185 |
} |
} |
186 |
|
|
187 |
|
void PrintScripts(gig::File* gig) { |
188 |
|
cout << "ALL Available Real-Time Instrument Scripts (as there might be more than referenced by Instruments):" << endl; |
189 |
|
for (int g = 0; gig->GetScriptGroup(g); ++g) { |
190 |
|
gig::ScriptGroup* pGroup = gig->GetScriptGroup(g); |
191 |
|
cout << " Group " << g+1 << ") '" << pGroup->Name << "'\n"; |
192 |
|
for (int s = 0; pGroup->GetScript(s); ++s) { |
193 |
|
gig::Script* pScript = pGroup->GetScript(s); |
194 |
|
cout << " Script " << s+1 << ") '" << pScript->Name << "':\n"; |
195 |
|
cout << "[START OF SCRIPT]\n"; |
196 |
|
cout << pScript->GetScriptAsText(); |
197 |
|
cout << "[END OF SCRIPT]\n"; |
198 |
|
} |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
void PrintInstruments(gig::File* gig) { |
void PrintInstruments(gig::File* gig) { |
203 |
int instruments = 0; |
int instruments = 0; |
204 |
cout << "Available Instruments:" << endl; |
cout << "Available Instruments:" << endl; |
211 |
cout << " Instrument " << instruments << ") " << name << ", "; |
cout << " Instrument " << instruments << ") " << name << ", "; |
212 |
|
|
213 |
cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl; |
cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl; |
214 |
|
|
215 |
|
cout << " ScriptSlots=" << pInstrument->ScriptSlotCount() << endl; |
216 |
|
for (int s = 0; s < pInstrument->ScriptSlotCount(); ++s) { |
217 |
|
gig::Script* pScript = pInstrument->GetScriptOfSlot(s); |
218 |
|
string name = pScript->Name; |
219 |
|
cout << " ScriptSlot[" << s << "]='" << name << "'\n"; |
220 |
|
} |
221 |
|
|
222 |
PrintRegions(pInstrument); |
PrintRegions(pInstrument); |
223 |
|
|
224 |
pInstrument = gig->GetNextInstrument(); |
pInstrument = gig->GetNextInstrument(); |
242 |
cout << "<NO_VALID_SAMPLE_REFERENCE> "; |
cout << "<NO_VALID_SAMPLE_REFERENCE> "; |
243 |
} |
} |
244 |
cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", "; |
cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", "; |
245 |
cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl; |
cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl; |
246 |
cout << " Loops=" << pRegion->SampleLoops << endl; |
cout << " Loops=" << pRegion->SampleLoops << endl; |
247 |
cout << " Dimensions=" << pRegion->Dimensions << endl; |
cout << " Dimensions=" << pRegion->Dimensions << endl; |
248 |
for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) { |
for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) { |
255 |
case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono). |
case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono). |
256 |
cout << "SAMPLECHANNEL"; |
cout << "SAMPLECHANNEL"; |
257 |
break; |
break; |
258 |
case gig::dimension_layer: // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers). |
case gig::dimension_layer: { // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers). |
259 |
gig::crossfade_t crossfade = pRegion->pDimensionRegions[iDimension]->Crossfade; |
gig::crossfade_t crossfade = pRegion->pDimensionRegions[iDimension]->Crossfade; |
260 |
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 << ")"; |
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 << ")"; |
261 |
break; |
break; |
262 |
|
} |
263 |
case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined). |
case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined). |
264 |
cout << "VELOCITY"; |
cout << "VELOCITY"; |
265 |
break; |
break; |
272 |
case gig::dimension_keyboard: // Key Position |
case gig::dimension_keyboard: // Key Position |
273 |
cout << "KEYBOARD"; |
cout << "KEYBOARD"; |
274 |
break; |
break; |
275 |
|
case gig::dimension_roundrobin: // Different samples triggered each time a note is played, dimension regions selected in sequence |
276 |
|
cout << "ROUNDROBIN"; |
277 |
|
break; |
278 |
|
case gig::dimension_random: // Different samples triggered each time a note is played, random order |
279 |
|
cout << "RANDOM"; |
280 |
|
break; |
281 |
|
case gig::dimension_smartmidi: // For MIDI tools like legato and repetition mode |
282 |
|
cout << "SMARTMIDI"; |
283 |
|
break; |
284 |
|
case gig::dimension_roundrobinkeyboard: // Different samples triggered each time a note is played, any key advances the counter |
285 |
|
cout << "ROUNDROBINKEYBOARD"; |
286 |
|
break; |
287 |
case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1) |
case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1) |
288 |
cout << "MODWHEEL"; |
cout << "MODWHEEL"; |
289 |
break; |
break; |
354 |
cout << "EFFECT5DEPTH"; |
cout << "EFFECT5DEPTH"; |
355 |
break; |
break; |
356 |
default: |
default: |
357 |
cout << "UNKNOWN - please report this !"; |
cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !"; |
358 |
break; |
break; |
359 |
} |
} |
360 |
cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones; |
cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones; |
363 |
case gig::split_type_normal: |
case gig::split_type_normal: |
364 |
cout << "NORMAL" << endl; |
cout << "NORMAL" << endl; |
365 |
break; |
break; |
|
case gig::split_type_customvelocity: |
|
|
cout << "CUSTOMVELOCITY" << endl; |
|
|
break; |
|
366 |
case gig::split_type_bit: |
case gig::split_type_bit: |
367 |
cout << "BIT" << endl; |
cout << "BIT" << endl; |
368 |
break; |
break; |
377 |
} |
} |
378 |
} |
} |
379 |
|
|
380 |
|
template<typename T_int> |
381 |
|
static void printIntArray(T_int* array, int size) { |
382 |
|
printf("{"); |
383 |
|
for (int i = 0; i < size; ++i) |
384 |
|
printf("[%d]=%d,", i, array[i]); |
385 |
|
printf("}"); |
386 |
|
fflush(stdout); |
387 |
|
} |
388 |
|
|
389 |
void PrintDimensionRegions(gig::Region* rgn) { |
void PrintDimensionRegions(gig::Region* rgn) { |
390 |
int dimensionRegions = 0; |
int dimensionRegions = 0; |
391 |
gig::DimensionRegion* pDimensionRegion; |
gig::DimensionRegion* pDimensionRegion; |
392 |
while (dimensionRegions < 32) { |
while (dimensionRegions < rgn->DimensionRegions) { |
393 |
pDimensionRegion = rgn->pDimensionRegions[dimensionRegions]; |
pDimensionRegion = rgn->pDimensionRegions[dimensionRegions]; |
394 |
if (!pDimensionRegion) break; |
if (!pDimensionRegion) break; |
395 |
|
|
401 |
if (pSample->pInfo->Name != "") { |
if (pSample->pInfo->Name != "") { |
402 |
cout << "\"" << pSample->pInfo->Name << "\", "; |
cout << "\"" << pSample->pInfo->Name << "\", "; |
403 |
} |
} |
404 |
cout << pSample->SamplesPerSecond << "Hz, " << endl; |
cout << pSample->SamplesPerSecond << "Hz, "; |
405 |
|
cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl; |
406 |
} |
} |
407 |
else { |
else { |
408 |
cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl; |
cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl; |
429 |
cout << "UNKNOWN - please report this !"; |
cout << "UNKNOWN - please report this !"; |
430 |
} |
} |
431 |
cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl; |
cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl; |
432 |
|
cout << " VelocityUpperLimit=" << (int) pDimensionRegion->VelocityUpperLimit << " DimensionUpperLimits[]=" << flush; |
433 |
|
printIntArray(pDimensionRegion->DimensionUpperLimits, 8); |
434 |
|
cout << endl; |
435 |
|
#if 0 // requires access to protected member VelocityTable, so commented out for now |
436 |
|
if (pDimensionRegion->VelocityTable) { |
437 |
|
cout << " VelocityTable[]=" << flush; |
438 |
|
printIntArray(pDimensionRegion->VelocityTable, 127); |
439 |
|
cout << endl; |
440 |
|
} |
441 |
|
#endif |
442 |
|
cout << " Pan=" << (int) pDimensionRegion->Pan << endl; |
443 |
|
|
444 |
dimensionRegions++; |
dimensionRegions++; |
445 |
} |
} |
446 |
} |
} |
447 |
|
|
448 |
|
string Revision() { |
449 |
|
string s = "$Revision$"; |
450 |
|
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
451 |
|
} |
452 |
|
|
453 |
|
void PrintVersion() { |
454 |
|
cout << "gigdump revision " << Revision() << endl; |
455 |
|
cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl; |
456 |
|
} |
457 |
|
|
458 |
void PrintUsage() { |
void PrintUsage() { |
459 |
cout << "gigdump - parses Gigasampler files and prints out the content." << endl; |
cout << "gigdump - parses Gigasampler files and prints out the content." << endl; |
460 |
cout << endl; |
cout << endl; |
461 |
cout << "Usage: gigdump FILE" << endl; |
cout << "Usage: gigdump [-v] FILE" << endl; |
462 |
|
cout << endl; |
463 |
|
cout << " -v Print version and exit." << endl; |
464 |
|
cout << endl; |
465 |
} |
} |