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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations) (download)
Fri Dec 26 16:15:31 2003 UTC (15 years, 7 months ago) by schoenebeck
Original Path: libgig/trunk/src/gigdump.cpp
File size: 8587 byte(s)
* src/gig.cpp, src/gig.h: added ReadAndLoop() method to class 'Sample'
  which is an extension to the normal Read() method to honor the sample's
  looping information while streaming from disk
* src/RIFF.cpp: minor fix in Chunk::Read() method (only a minor efficiency
  issue)
* src/gigdump.cpp: added printout of samples' looping informations

1 schoenebeck 2 /***************************************************************************
2     * *
3     * libgig - C++ cross-platform Gigasampler format file loader library *
4     * *
5     * Copyright (C) 2003 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 schoenebeck 24 # include <config.h>
26 schoenebeck 2 #endif
27    
28     #include <iostream>
29     #include <cstdlib>
30    
31     #include "gig.h"
32    
33     using namespace std;
34    
35     void PrintSamples(gig::File* gig);
36     void PrintInstruments(gig::File* gig);
37     void PrintRegions(gig::Instrument* instr);
38     void PrintUsage();
39     void PrintDimensionRegions(gig::Region* rgn);
40    
41     int main(int argc, char *argv[])
42     {
43     if (argc <= 1) {
44     PrintUsage();
45     return EXIT_FAILURE;
46     }
47     FILE* hFile = fopen(argv[1], "r");
48     if (!hFile) {
49     cout << "Invalid file argument!" << endl;
50     return EXIT_FAILURE;
51     }
52     fclose(hFile);
53     try {
54     RIFF::File* riff = new RIFF::File(argv[1]);
55     gig::File* gig = new gig::File(riff);
56     PrintSamples(gig);
57     cout << endl;
58     PrintInstruments(gig);
59     delete gig;
60     delete riff;
61     }
62     catch (RIFF::Exception e) {
63     e.PrintMessage();
64     return EXIT_FAILURE;
65     }
66     catch (...) {
67     cout << "Unknown exception while trying to parse file." << endl;
68     return EXIT_FAILURE;
69     }
70    
71     return EXIT_SUCCESS;
72     }
73    
74     void PrintSamples(gig::File* gig) {
75     int samples = 0;
76     cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
77     gig::Sample* pSample = gig->GetFirstSample();
78     while (pSample) {
79     samples++;
80     string name = pSample->pInfo->Name;
81     if (name == "") name = "<NO NAME>";
82     else name = '\"' + name + '\"';
83     cout << " Sample " << samples << ") " << name << ", ";
84 schoenebeck 24 cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops";
85     if (pSample->Loops) {
86     cout << " (Type: ";
87     switch (pSample->LoopType) {
88     case gig::loop_type_normal: cout << "normal)"; break;
89     case gig::loop_type_bidirectional: cout << "pingpong)"; break;
90     case gig::loop_type_backward: cout << "reverse)"; break;
91     }
92     cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd;
93     }
94     cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl;
95 schoenebeck 2 pSample = gig->GetNextSample();
96     }
97     }
98    
99     void PrintInstruments(gig::File* gig) {
100     int instruments = 0;
101     cout << "Available Instruments:" << endl;
102     gig::Instrument* pInstrument = gig->GetFirstInstrument();
103     while (pInstrument) {
104     instruments++;
105     string name = pInstrument->pInfo->Name;
106     if (name == "") name = "<NO NAME>";
107     else name = '\"' + name + '\"';
108     cout << " Instrument " << instruments << ") " << name << ", ";
109    
110     cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
111     PrintRegions(pInstrument);
112    
113     pInstrument = gig->GetNextInstrument();
114     }
115     }
116    
117     void PrintRegions(gig::Instrument* instr) {
118     int iRegion = 1;
119     gig::Region* pRegion = instr->GetFirstRegion();
120     while (pRegion) {
121     cout << " Region " << iRegion++ << ") ";
122     gig::Sample* pSample = pRegion->GetSample();
123     if (pSample) {
124     cout << "Sample: ";
125     if (pSample->pInfo->Name != "") {
126     cout << "\"" << pSample->pInfo->Name << "\", ";
127     }
128     cout << pSample->SamplesPerSecond << "Hz, " << endl;
129     }
130     else {
131     cout << "<NO_VALID_SAMPLE_REFERENCE> ";
132     }
133     cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
134     cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl;
135     cout << " Loops=" << pRegion->SampleLoops << endl;
136     PrintDimensionRegions(pRegion);
137    
138     pRegion = instr->GetNextRegion();
139     }
140     }
141    
142     void PrintDimensionRegions(gig::Region* rgn) {
143     int dimensionRegions = 0;
144     gig::DimensionRegion* pDimensionRegion;
145     while (dimensionRegions < 32) {
146     pDimensionRegion = rgn->pDimensionRegions[dimensionRegions];
147     if (!pDimensionRegion) break;
148    
149     cout << " Dimension Region " << dimensionRegions + 1 << ")" << endl;
150    
151     gig::Sample* pSample = pDimensionRegion->pSample;
152     if (pSample) {
153     cout << " Sample: ";
154     if (pSample->pInfo->Name != "") {
155     cout << "\"" << pSample->pInfo->Name << "\", ";
156     }
157     cout << pSample->SamplesPerSecond << "Hz, " << endl;
158     }
159     else {
160     cout << " Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl;
161     }
162     cout << " LFO1Frequency=" << pDimensionRegion->LFO1Frequency << "Hz, LFO1InternalDepth=" << pDimensionRegion-> LFO1InternalDepth << ", LFO1ControlDepth=" << pDimensionRegion->LFO1ControlDepth << " LFO1Controller=" << pDimensionRegion->LFO1Controller << endl;
163     cout << " LFO2Frequency=" << pDimensionRegion->LFO2Frequency << "Hz, LFO2InternalDepth=" << pDimensionRegion-> LFO2InternalDepth << ", LFO2ControlDepth=" << pDimensionRegion->LFO2ControlDepth << " LFO2Controller=" << pDimensionRegion->LFO2Controller << endl;
164     cout << " LFO3Frequency=" << pDimensionRegion->LFO3Frequency << "Hz, LFO3InternalDepth=" << pDimensionRegion-> LFO3InternalDepth << ", LFO3ControlDepth=" << pDimensionRegion->LFO3ControlDepth << " LFO3Controller=" << pDimensionRegion->LFO3Controller << endl;
165     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;
166     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;
167     cout << " VCFEnabled=" << pDimensionRegion->VCFEnabled << ", VCFType=" << pDimensionRegion->VCFType << ", VCFCutoff=" << (int) pDimensionRegion->VCFCutoff << ", VCFResonance=" << (int) pDimensionRegion->VCFResonance << ", VCFCutoffController=" << pDimensionRegion->VCFCutoffController << endl;
168    
169     dimensionRegions++;
170     }
171     }
172    
173     void PrintUsage() {
174     cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
175     cout << endl;
176     cout << "Usage: gigdump FILE" << endl;
177     }

  ViewVC Help
Powered by ViewVC