/[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 808 - (show annotations) (download)
Tue Nov 22 09:11:17 2005 UTC (18 years, 4 months ago) by schoenebeck
Original Path: libgig/trunk/src/gigdump.cpp
File size: 17227 byte(s)
* src/RIFF.cpp: compilation error fix for big endian systems
* src/gigdump.cpp: show correct amount of dimension regions instead of 32
(patch by James Wylder)

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

  ViewVC Help
Powered by ViewVC