Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

gigdump.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   libgig - C++ cross-platform Gigasampler format file loader library    *
00004  *                                                                         *
00005  *   Copyright (C) 2003-2005 by Christian Schoenebeck                      *
00006  *                              <cuse@users.sourceforge.net>               *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the Free Software           *
00020  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00021  *   MA  02111-1307  USA                                                   *
00022  ***************************************************************************/
00023 
00024 #ifdef HAVE_CONFIG_H
00025 # include <config.h>
00026 #endif
00027 
00028 #include <iostream>
00029 #include <cstdlib>
00030 #include <string>
00031 
00032 #include "gig.h"
00033 
00034 using namespace std;
00035 
00036 string Revision();
00037 void PrintVersion();
00038 void PrintSamples(gig::File* gig);
00039 void PrintInstruments(gig::File* gig);
00040 void PrintRegions(gig::Instrument* instr);
00041 void PrintUsage();
00042 void PrintDimensionRegions(gig::Region* rgn);
00043 
00044 int main(int argc, char *argv[])
00045 {
00046     if (argc <= 1) {
00047         PrintUsage();
00048         return EXIT_FAILURE;
00049     }
00050     if (argv[1][0] == '-') {
00051         switch (argv[1][1]) {
00052             case 'v':
00053                 PrintVersion();
00054                 return EXIT_SUCCESS;
00055         }
00056     }
00057     FILE* hFile = fopen(argv[1], "r");
00058     if (!hFile) {
00059         cout << "Invalid file argument!" << endl;
00060         return EXIT_FAILURE;
00061     }
00062     fclose(hFile);
00063     try {
00064         RIFF::File* riff = new RIFF::File(argv[1]);
00065         gig::File*  gig  = new gig::File(riff);
00066         PrintSamples(gig);
00067         cout << endl;
00068         PrintInstruments(gig);
00069         delete gig;
00070         delete riff;
00071     }
00072     catch (RIFF::Exception e) {
00073         e.PrintMessage();
00074         return EXIT_FAILURE;
00075     }
00076     catch (...) {
00077         cout << "Unknown exception while trying to parse file." << endl;
00078         return EXIT_FAILURE;
00079     }
00080 
00081     return EXIT_SUCCESS;
00082 }
00083 
00084 void PrintSamples(gig::File* gig) {
00085     int samples = 0;
00086     cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
00087     gig::Sample* pSample = gig->GetFirstSample();
00088     while (pSample) {
00089         samples++;
00090         string name = pSample->pInfo->Name;
00091         if (name == "") name = "<NO NAME>";
00092         else            name = '\"' + name + '\"';
00093         cout << "    Sample " << samples << ") " << name << ", ";
00094         cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops";
00095         if (pSample->Loops) {
00096             cout << " (Type: ";
00097             switch (pSample->LoopType) {
00098                 case gig::loop_type_normal:         cout << "normal)";   break;
00099                 case gig::loop_type_bidirectional:  cout << "pingpong)"; break;
00100                 case gig::loop_type_backward:       cout << "reverse)";  break;
00101             }
00102             cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd;
00103             cout << ", LoopPlayCount=" << pSample->LoopPlayCount;
00104         }
00105         cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl;
00106         pSample = gig->GetNextSample();
00107     }
00108 }
00109 
00110 void PrintInstruments(gig::File* gig) {
00111     int instruments = 0;
00112     cout << "Available Instruments:" << endl;
00113     gig::Instrument* pInstrument = gig->GetFirstInstrument();
00114     while (pInstrument) {
00115         instruments++;
00116         string name = pInstrument->pInfo->Name;
00117         if (name == "") name = "<NO NAME>";
00118         else            name = '\"' + name + '\"';
00119         cout << "    Instrument " << instruments << ") " << name << ", ";
00120 
00121         cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
00122         PrintRegions(pInstrument);
00123 
00124         pInstrument = gig->GetNextInstrument();
00125     }
00126 }
00127 
00128 void PrintRegions(gig::Instrument* instr) {
00129     int iRegion = 1;
00130     gig::Region* pRegion = instr->GetFirstRegion();
00131     while (pRegion) {
00132         cout << "        Region " << iRegion++ << ") ";
00133         gig::Sample* pSample = pRegion->GetSample();
00134         if (pSample) {
00135             cout << "Sample: ";
00136             if (pSample->pInfo->Name != "") {
00137                 cout << "\"" << pSample->pInfo->Name << "\", ";
00138             }
00139             cout << pSample->SamplesPerSecond << "Hz, " << endl;
00140         }
00141         else {
00142             cout << "<NO_VALID_SAMPLE_REFERENCE> ";
00143         }
00144         cout << "            KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
00145         cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl;
00146         cout << "            Loops=" << pRegion->SampleLoops << endl;
00147         cout << "            Dimensions=" << pRegion->Dimensions << endl;
00148         for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) {
00149             cout << "            Dimension[" << iDimension << "]: Type=";
00150             gig::dimension_def_t DimensionDef = pRegion->pDimensionDefinitions[iDimension];
00151             switch (DimensionDef.dimension) {
00152                 case gig::dimension_none:
00153                     cout << "NONE";
00154                     break;
00155                 case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono).
00156                     cout << "SAMPLECHANNEL";
00157                     break;
00158                 case gig::dimension_layer: { // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers).
00159                     gig::crossfade_t crossfade = pRegion->pDimensionRegions[iDimension]->Crossfade;
00160                     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 << ")";
00161                     break;
00162                 }
00163                 case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined).
00164                     cout << "VELOCITY";
00165                     break;
00166                 case gig::dimension_channelaftertouch: // Channel Key Pressure
00167                     cout << "AFTERTOUCH";
00168                     break;
00169                 case gig::dimension_releasetrigger: // Special dimension for triggering samples on releasing a key.
00170                     cout << "RELEASETRIGGER";
00171                     break;
00172                 case gig::dimension_keyboard: // Key Position
00173                     cout << "KEYBOARD";
00174                     break;
00175                 case gig::dimension_roundrobin: // Different samples triggered each time a note is played, dimension regions selected in sequence
00176                     cout << "ROUNDROBIN";
00177                     break;
00178                 case gig::dimension_random: // Different samples triggered each time a note is played, random order
00179                     cout << "RANDOM";
00180                     break;
00181                 case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1)
00182                     cout << "MODWHEEL";
00183                     break;
00184                 case gig::dimension_breath: // Breath Controller (Coarse, MIDI Controller 2)
00185                     cout << "BREATH";
00186                     break;
00187                 case gig::dimension_foot: // Foot Pedal (Coarse, MIDI Controller 4)
00188                     cout << "FOOT";
00189                     break;
00190                 case gig::dimension_portamentotime: // Portamento Time (Coarse, MIDI Controller 5)
00191                     cout << "PORTAMENTOTIME";
00192                     break;
00193                 case gig::dimension_effect1: // Effect Controller 1 (Coarse, MIDI Controller 12)
00194                     cout << "EFFECT1";
00195                     break;
00196                 case gig::dimension_effect2: // Effect Controller 2 (Coarse, MIDI Controller 13)
00197                     cout << "EFFECT2";
00198                     break;
00199                 case gig::dimension_genpurpose1: // General Purpose Controller 1 (Slider, MIDI Controller 16)
00200                     cout << "GENPURPOSE1";
00201                     break;
00202                 case gig::dimension_genpurpose2: // General Purpose Controller 2 (Slider, MIDI Controller 17)
00203                     cout << "GENPURPOSE2";
00204                     break;
00205                 case gig::dimension_genpurpose3: // General Purpose Controller 3 (Slider, MIDI Controller 18)
00206                     cout << "GENPURPOSE3";
00207                     break;
00208                 case gig::dimension_genpurpose4: // General Purpose Controller 4 (Slider, MIDI Controller 19)
00209                     cout << "GENPURPOSE4";
00210                     break;
00211                 case gig::dimension_sustainpedal: // Sustain Pedal (MIDI Controller 64)
00212                     cout << "SUSTAINPEDAL";
00213                     break;
00214                 case gig::dimension_portamento: // Portamento (MIDI Controller 65)
00215                     cout << "PORTAMENTO";
00216                     break;
00217                 case gig::dimension_sostenutopedal: // Sostenuto Pedal (MIDI Controller 66)
00218                     cout << "SOSTENUTOPEDAL";
00219                     break;
00220                 case gig::dimension_softpedal: // Soft Pedal (MIDI Controller 67)
00221                     cout << "SOFTPEDAL";
00222                     break;
00223                 case gig::dimension_genpurpose5: // General Purpose Controller 5 (Button, MIDI Controller 80)
00224                     cout << "GENPURPOSE5";
00225                     break;
00226                 case gig::dimension_genpurpose6: // General Purpose Controller 6 (Button, MIDI Controller 81)
00227                     cout << "GENPURPOSE6";
00228                     break;
00229                 case gig::dimension_genpurpose7: // General Purpose Controller 7 (Button, MIDI Controller 82)
00230                     cout << "GENPURPOSE7";
00231                     break;
00232                 case gig::dimension_genpurpose8: // General Purpose Controller 8 (Button, MIDI Controller 83)
00233                     cout << "GENPURPOSE8";
00234                     break;
00235                 case gig::dimension_effect1depth: // Effect 1 Depth (MIDI Controller 91)
00236                     cout << "EFFECT1DEPTH";
00237                     break;
00238                 case gig::dimension_effect2depth: // Effect 2 Depth (MIDI Controller 92)
00239                     cout << "EFFECT2DEPTH";
00240                     break;
00241                 case gig::dimension_effect3depth: // Effect 3 Depth (MIDI Controller 93)
00242                     cout << "EFFECT3DEPTH";
00243                     break;
00244                 case gig::dimension_effect4depth: // Effect 4 Depth (MIDI Controller 94)
00245                     cout << "EFFECT4DEPTH";
00246                     break;
00247                 case gig::dimension_effect5depth:  // Effect 5 Depth (MIDI Controller 95)
00248                     cout << "EFFECT5DEPTH";
00249                     break;
00250                 default:
00251                     cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !";
00252                     break;
00253             }
00254             cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones;
00255             cout << ", SplitType=";
00256             switch (DimensionDef.split_type) {
00257                 case gig::split_type_normal:
00258                     cout << "NORMAL" << endl;
00259                     break;
00260                 case gig::split_type_customvelocity:
00261                     cout << "CUSTOMVELOCITY" << endl;
00262                     break;
00263                 case gig::split_type_bit:
00264                     cout << "BIT" << endl;
00265                     break;
00266                 default:
00267                     cout << "UNKNOWN" << endl;
00268             }
00269         }
00270 
00271         PrintDimensionRegions(pRegion);
00272 
00273         pRegion = instr->GetNextRegion();
00274     }
00275 }
00276 
00277 void PrintDimensionRegions(gig::Region* rgn) {
00278     int dimensionRegions = 0;
00279     gig::DimensionRegion* pDimensionRegion;
00280     while (dimensionRegions < 32) {
00281         pDimensionRegion = rgn->pDimensionRegions[dimensionRegions];
00282         if (!pDimensionRegion) break;
00283 
00284         cout << "            Dimension Region " << dimensionRegions + 1 << ")" << endl;
00285 
00286         gig::Sample* pSample = pDimensionRegion->pSample;
00287         if (pSample) {
00288             cout << "                Sample: ";
00289             if (pSample->pInfo->Name != "") {
00290                 cout << "\"" << pSample->pInfo->Name << "\", ";
00291             }
00292             cout << pSample->SamplesPerSecond << "Hz, ";
00293             cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl;
00294         }
00295         else {
00296             cout << "                Sample: <NO_VALID_SAMPLE_REFERENCE> " << endl;
00297         }
00298         cout << "                LFO1Frequency=" << pDimensionRegion->LFO1Frequency << "Hz, LFO1InternalDepth=" << pDimensionRegion-> LFO1InternalDepth << ", LFO1ControlDepth=" << pDimensionRegion->LFO1ControlDepth << " LFO1Controller=" << pDimensionRegion->LFO1Controller << endl;
00299         cout << "                LFO2Frequency=" << pDimensionRegion->LFO2Frequency << "Hz, LFO2InternalDepth=" << pDimensionRegion-> LFO2InternalDepth << ", LFO2ControlDepth=" << pDimensionRegion->LFO2ControlDepth << " LFO2Controller=" << pDimensionRegion->LFO2Controller << endl;
00300         cout << "                LFO3Frequency=" << pDimensionRegion->LFO3Frequency << "Hz, LFO3InternalDepth=" << pDimensionRegion-> LFO3InternalDepth << ", LFO3ControlDepth=" << pDimensionRegion->LFO3ControlDepth << " LFO3Controller=" << pDimensionRegion->LFO3Controller << endl;
00301         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;
00302         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;
00303         cout << "                VCFEnabled=" << pDimensionRegion->VCFEnabled << ", VCFType=" << pDimensionRegion->VCFType << ", VCFCutoff=" << (int) pDimensionRegion->VCFCutoff << ",  VCFResonance=" << (int) pDimensionRegion->VCFResonance << ", VCFCutoffController=" << pDimensionRegion->VCFCutoffController << endl;
00304         cout << "                VelocityResponseCurve=";
00305         switch (pDimensionRegion->VelocityResponseCurve) {
00306             case gig::curve_type_nonlinear:
00307                 cout << "NONLINEAR";
00308                 break;
00309             case gig::curve_type_linear:
00310                 cout << "LINEAR";
00311                 break;
00312             case gig::curve_type_special:
00313                 cout << "SPECIAL";
00314                 break;
00315             case gig::curve_type_unknown:
00316             default:
00317                 cout << "UNKNOWN - please report this !";
00318         }
00319         cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl;
00320         cout << "                Pan=" << (int) pDimensionRegion->Pan << endl;
00321 
00322         dimensionRegions++;
00323     }
00324 }
00325 
00326 string Revision() {
00327     string s = "$Revision: 1.16 $";
00328     return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
00329 }
00330 
00331 void PrintVersion() {
00332     cout << "gigdump revision " << Revision() << endl;
00333     cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl;
00334 }
00335 
00336 void PrintUsage() {
00337     cout << "gigdump - parses Gigasampler files and prints out the content." << endl;
00338     cout << endl;
00339     cout << "Usage: gigdump [-v] FILE" << endl;
00340     cout << endl;
00341     cout << "   -v  Print version and exit." << endl;
00342     cout << endl;
00343 }

Generated on Wed Nov 23 13:57:08 2005 for libgig by  doxygen 1.4.3-20050530