/[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 2609 - (show annotations) (download)
Sun Jun 8 19:00:30 2014 UTC (6 years, 4 months ago) by schoenebeck
File size: 22030 byte(s)
* gig: Fixed instrument script slot saving/loading.
* gigdump tool: Show scripts and script slots.
* Bumped version (3.3.0.svn17).

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 int main(int argc, char *argv[])
50 {
51 if (argc <= 1) {
52 PrintUsage();
53 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");
63 if (!hFile) {
64 cout << "Invalid file argument!" << endl;
65 return EXIT_FAILURE;
66 }
67 fclose(hFile);
68 try {
69 RIFF::File* riff = new RIFF::File(argv[1]);
70 gig::File* gig = new gig::File(riff);
71 PrintFileInformations(gig);
72 cout << endl;
73 PrintGroups(gig);
74 cout << endl;
75 PrintSamples(gig);
76 cout << endl;
77 PrintScripts(gig);
78 cout << endl;
79 PrintInstruments(gig);
80 delete gig;
81 delete riff;
82 }
83 catch (RIFF::Exception e) {
84 e.PrintMessage();
85 return EXIT_FAILURE;
86 }
87 catch (...) {
88 cout << "Unknown exception while trying to parse file." << endl;
89 return EXIT_FAILURE;
90 }
91
92 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) {
154 int samples = 0;
155 cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
156 gig::Sample* pSample = gig->GetFirstSample();
157 while (pSample) {
158 samples++;
159 // determine sample's name
160 string name = pSample->pInfo->Name;
161 if (name == "") name = "<NO NAME>";
162 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 << ", ";
170 cout << "Group " << iGroup << ", ";
171 cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops";
172 if (pSample->Loops) {
173 cout << " (Type: ";
174 switch (pSample->LoopType) {
175 case gig::loop_type_normal: cout << "normal)"; break;
176 case gig::loop_type_bidirectional: cout << "pingpong)"; break;
177 case gig::loop_type_backward: cout << "reverse)"; break;
178 }
179 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;
183 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) {
203 int instruments = 0;
204 cout << "Available Instruments:" << endl;
205 gig::Instrument* pInstrument = gig->GetFirstInstrument();
206 while (pInstrument) {
207 instruments++;
208 string name = pInstrument->pInfo->Name;
209 if (name == "") name = "<NO NAME>";
210 else name = '\"' + name + '\"';
211 cout << " Instrument " << instruments << ") " << name << ", ";
212
213 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);
223
224 pInstrument = gig->GetNextInstrument();
225 }
226 }
227
228 void PrintRegions(gig::Instrument* instr) {
229 int iRegion = 1;
230 gig::Region* pRegion = instr->GetFirstRegion();
231 while (pRegion) {
232 cout << " Region " << iRegion++ << ") ";
233 gig::Sample* pSample = pRegion->GetSample();
234 if (pSample) {
235 cout << "Sample: ";
236 if (pSample->pInfo->Name != "") {
237 cout << "\"" << pSample->pInfo->Name << "\", ";
238 }
239 cout << pSample->SamplesPerSecond << "Hz, " << endl;
240 }
241 else {
242 cout << "<NO_VALID_SAMPLE_REFERENCE> ";
243 }
244 cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
245 cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl;
246 cout << " Loops=" << pRegion->SampleLoops << endl;
247 cout << " Dimensions=" << pRegion->Dimensions << endl;
248 for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) {
249 cout << " Dimension[" << iDimension << "]: Type=";
250 gig::dimension_def_t DimensionDef = pRegion->pDimensionDefinitions[iDimension];
251 switch (DimensionDef.dimension) {
252 case gig::dimension_none:
253 cout << "NONE";
254 break;
255 case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono).
256 cout << "SAMPLECHANNEL";
257 break;
258 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;
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 << ")";
261 break;
262 }
263 case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined).
264 cout << "VELOCITY";
265 break;
266 case gig::dimension_channelaftertouch: // Channel Key Pressure
267 cout << "AFTERTOUCH";
268 break;
269 case gig::dimension_releasetrigger: // Special dimension for triggering samples on releasing a key.
270 cout << "RELEASETRIGGER";
271 break;
272 case gig::dimension_keyboard: // Key Position
273 cout << "KEYBOARD";
274 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)
288 cout << "MODWHEEL";
289 break;
290 case gig::dimension_breath: // Breath Controller (Coarse, MIDI Controller 2)
291 cout << "BREATH";
292 break;
293 case gig::dimension_foot: // Foot Pedal (Coarse, MIDI Controller 4)
294 cout << "FOOT";
295 break;
296 case gig::dimension_portamentotime: // Portamento Time (Coarse, MIDI Controller 5)
297 cout << "PORTAMENTOTIME";
298 break;
299 case gig::dimension_effect1: // Effect Controller 1 (Coarse, MIDI Controller 12)
300 cout << "EFFECT1";
301 break;
302 case gig::dimension_effect2: // Effect Controller 2 (Coarse, MIDI Controller 13)
303 cout << "EFFECT2";
304 break;
305 case gig::dimension_genpurpose1: // General Purpose Controller 1 (Slider, MIDI Controller 16)
306 cout << "GENPURPOSE1";
307 break;
308 case gig::dimension_genpurpose2: // General Purpose Controller 2 (Slider, MIDI Controller 17)
309 cout << "GENPURPOSE2";
310 break;
311 case gig::dimension_genpurpose3: // General Purpose Controller 3 (Slider, MIDI Controller 18)
312 cout << "GENPURPOSE3";
313 break;
314 case gig::dimension_genpurpose4: // General Purpose Controller 4 (Slider, MIDI Controller 19)
315 cout << "GENPURPOSE4";
316 break;
317 case gig::dimension_sustainpedal: // Sustain Pedal (MIDI Controller 64)
318 cout << "SUSTAINPEDAL";
319 break;
320 case gig::dimension_portamento: // Portamento (MIDI Controller 65)
321 cout << "PORTAMENTO";
322 break;
323 case gig::dimension_sostenutopedal: // Sostenuto Pedal (MIDI Controller 66)
324 cout << "SOSTENUTOPEDAL";
325 break;
326 case gig::dimension_softpedal: // Soft Pedal (MIDI Controller 67)
327 cout << "SOFTPEDAL";
328 break;
329 case gig::dimension_genpurpose5: // General Purpose Controller 5 (Button, MIDI Controller 80)
330 cout << "GENPURPOSE5";
331 break;
332 case gig::dimension_genpurpose6: // General Purpose Controller 6 (Button, MIDI Controller 81)
333 cout << "GENPURPOSE6";
334 break;
335 case gig::dimension_genpurpose7: // General Purpose Controller 7 (Button, MIDI Controller 82)
336 cout << "GENPURPOSE7";
337 break;
338 case gig::dimension_genpurpose8: // General Purpose Controller 8 (Button, MIDI Controller 83)
339 cout << "GENPURPOSE8";
340 break;
341 case gig::dimension_effect1depth: // Effect 1 Depth (MIDI Controller 91)
342 cout << "EFFECT1DEPTH";
343 break;
344 case gig::dimension_effect2depth: // Effect 2 Depth (MIDI Controller 92)
345 cout << "EFFECT2DEPTH";
346 break;
347 case gig::dimension_effect3depth: // Effect 3 Depth (MIDI Controller 93)
348 cout << "EFFECT3DEPTH";
349 break;
350 case gig::dimension_effect4depth: // Effect 4 Depth (MIDI Controller 94)
351 cout << "EFFECT4DEPTH";
352 break;
353 case gig::dimension_effect5depth: // Effect 5 Depth (MIDI Controller 95)
354 cout << "EFFECT5DEPTH";
355 break;
356 default:
357 cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !";
358 break;
359 }
360 cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones;
361 cout << ", SplitType=";
362 switch (DimensionDef.split_type) {
363 case gig::split_type_normal:
364 cout << "NORMAL" << endl;
365 break;
366 case gig::split_type_bit:
367 cout << "BIT" << endl;
368 break;
369 default:
370 cout << "UNKNOWN" << endl;
371 }
372 }
373
374 PrintDimensionRegions(pRegion);
375
376 pRegion = instr->GetNextRegion();
377 }
378 }
379
380 void PrintDimensionRegions(gig::Region* rgn) {
381 int dimensionRegions = 0;
382 gig::DimensionRegion* pDimensionRegion;
383 while (dimensionRegions < rgn->DimensionRegions) {
384 pDimensionRegion = rgn->pDimensionRegions[dimensionRegions];
385 if (!pDimensionRegion) break;
386
387 cout << " Dimension Region " << dimensionRegions + 1 << ")" << endl;
388
389 gig::Sample* pSample = pDimensionRegion->pSample;
390 if (pSample) {
391 cout << " Sample: ";
392 if (pSample->pInfo->Name != "") {
393 cout << "\"" << pSample->pInfo->Name << "\", ";
394 }
395 cout << pSample->SamplesPerSecond << "Hz, ";
396 cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl;
397 }
398 else {
399 cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl;
400 }
401 cout << " LFO1Frequency=" << pDimensionRegion->LFO1Frequency << "Hz, LFO1InternalDepth=" << pDimensionRegion-> LFO1InternalDepth << ", LFO1ControlDepth=" << pDimensionRegion->LFO1ControlDepth << " LFO1Controller=" << pDimensionRegion->LFO1Controller << endl;
402 cout << " LFO2Frequency=" << pDimensionRegion->LFO2Frequency << "Hz, LFO2InternalDepth=" << pDimensionRegion-> LFO2InternalDepth << ", LFO2ControlDepth=" << pDimensionRegion->LFO2ControlDepth << " LFO2Controller=" << pDimensionRegion->LFO2Controller << endl;
403 cout << " LFO3Frequency=" << pDimensionRegion->LFO3Frequency << "Hz, LFO3InternalDepth=" << pDimensionRegion-> LFO3InternalDepth << ", LFO3ControlDepth=" << pDimensionRegion->LFO3ControlDepth << " LFO3Controller=" << pDimensionRegion->LFO3Controller << endl;
404 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;
405 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;
406 cout << " VCFEnabled=" << pDimensionRegion->VCFEnabled << ", VCFType=" << pDimensionRegion->VCFType << ", VCFCutoff=" << (int) pDimensionRegion->VCFCutoff << ", VCFResonance=" << (int) pDimensionRegion->VCFResonance << ", VCFCutoffController=" << pDimensionRegion->VCFCutoffController << endl;
407 cout << " VelocityResponseCurve=";
408 switch (pDimensionRegion->VelocityResponseCurve) {
409 case gig::curve_type_nonlinear:
410 cout << "NONLINEAR";
411 break;
412 case gig::curve_type_linear:
413 cout << "LINEAR";
414 break;
415 case gig::curve_type_special:
416 cout << "SPECIAL";
417 break;
418 case gig::curve_type_unknown:
419 default:
420 cout << "UNKNOWN - please report this !";
421 }
422 cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl;
423 cout << " Pan=" << (int) pDimensionRegion->Pan << endl;
424
425 dimensionRegions++;
426 }
427 }
428
429 string Revision() {
430 string s = "$Revision$";
431 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
432 }
433
434 void PrintVersion() {
435 cout << "gigdump revision " << Revision() << endl;
436 cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl;
437 }
438
439 void PrintUsage() {
440 cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
441 cout << endl;
442 cout << "Usage: gigdump [-v] FILE" << endl;
443 cout << endl;
444 cout << " -v Print version and exit." << endl;
445 cout << endl;
446 }

Properties

Name Value
svn:keywords Revision

  ViewVC Help
Powered by ViewVC