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