dlsdump.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   libgig - C++ cross-platform Gigasampler format file access library    *
00004  *                                                                         *
00005  *   Copyright (C) 2003-2006 by Christian Schoenebeck                      *
00006  *                              <cuse@users.sourceforge.net>               *
00007  *                                                                         *
00008  *   This program is part of libgig.                                       *
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  *   This program is distributed in the hope that it will be useful,       *
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00018  *   GNU General Public License for more details.                          *
00019  *                                                                         *
00020  *   You should have received a copy of the GNU General Public License     *
00021  *   along with this program; if not, write to the Free Software           *
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00023  *   MA  02111-1307  USA                                                   *
00024  ***************************************************************************/
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029 
00030 #include <iostream>
00031 #include <cstdlib>
00032 #include <string>
00033 
00034 #include "DLS.h"
00035 
00036 using namespace std;
00037 
00038 string Revision();
00039 void PrintVersion();
00040 void PrintSamples(DLS::File* dls);
00041 void PrintInstruments(DLS::File* dls);
00042 void PrintRegions(DLS::Instrument* instr);
00043 void PrintUsage();
00044 
00045 int main(int argc, char *argv[])
00046 {
00047     if (argc <= 1) {
00048         PrintUsage();
00049         return EXIT_FAILURE;
00050     }
00051     if (argv[1][0] == '-') {
00052         switch (argv[1][1]) {
00053             case 'v':
00054                 PrintVersion();
00055                 return EXIT_SUCCESS;
00056         }
00057     }
00058     FILE* hFile = fopen(argv[1], "r");
00059     if (!hFile) {
00060         cout << "Invalid file argument!" << endl;
00061         return EXIT_FAILURE;
00062     }
00063     fclose(hFile);
00064     try {
00065         RIFF::File* riff = new RIFF::File(argv[1]);
00066         DLS::File*  dls  = new DLS::File(riff);
00067         if (dls->pInfo->Name != "") cout << "File Name: \"" << dls->pInfo->Name << "\"\n";
00068         PrintSamples(dls);
00069         cout << endl;
00070         PrintInstruments(dls);
00071         delete dls;
00072         delete riff;
00073     }
00074     catch (RIFF::Exception e) {
00075         e.PrintMessage();
00076         return EXIT_FAILURE;
00077     }
00078     catch (...) {
00079         cout << "Unknown exception while trying to parse file." << endl;
00080         return EXIT_FAILURE;
00081     }
00082 
00083     return EXIT_SUCCESS;
00084 }
00085 
00086 void PrintSamples(DLS::File* dls) {
00087     int samples = 0;
00088     cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
00089     DLS::Sample* pSample = dls->GetFirstSample();
00090     while (pSample) {
00091         samples++;
00092         string name = pSample->pInfo->Name;
00093         if (name == "") name = "<NO NAME>";
00094         else            name = '\"' + name + '\"';
00095         cout << "    Sample " << samples << ") " << name << ", ";
00096         cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels" << endl;
00097         pSample = dls->GetNextSample();
00098     }
00099 }
00100 
00101 void PrintInstruments(DLS::File* dls) {
00102     int instruments = 0;
00103     cout << "Available Instruments:" << endl;
00104     DLS::Instrument* pInstrument = dls->GetFirstInstrument();
00105     while (pInstrument) {
00106         instruments++;
00107         string name = pInstrument->pInfo->Name;
00108         if (name == "") name = "<NO NAME>";
00109         else            name = '\"' + name + '\"';
00110         cout << "    Instrument " << instruments << ") " << name << ", ";
00111 
00112         cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
00113         PrintRegions(pInstrument);
00114 
00115         pInstrument = dls->GetNextInstrument();
00116     }
00117 }
00118 
00119 void PrintRegions(DLS::Instrument* instr) {
00120     int regions = 0;
00121     DLS::Region* pRegion = instr->GetFirstRegion();
00122     while (pRegion) {
00123         regions++;
00124 
00125         cout << "        Region " << regions << ") ";
00126         DLS::Sample* pSample = pRegion->GetSample();
00127         if (pSample) {
00128             cout << "Sample: ";
00129             if (pSample->pInfo->Name != "") {
00130                 cout << "\"" << pSample->pInfo->Name << "\", ";
00131             }
00132             cout << pSample->SamplesPerSecond << "Hz, ";
00133         }
00134         else {
00135             cout << "<NO_VALID_SAMPLE_REFERENCE> ";
00136         }
00137         cout << "KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
00138         cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl;
00139         cout << "            Loops=" << pRegion->SampleLoops << endl;
00140 
00141         pRegion = instr->GetNextRegion();
00142     }
00143 }
00144 
00145 string Revision() {
00146     string s = "$Revision: 1.5 $";
00147     return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
00148 }
00149 
00150 void PrintVersion() {
00151     cout << "dlsdump revision " << Revision() << endl;
00152     cout << "using " << DLS::libraryName() << " " << DLS::libraryVersion() << endl;
00153 }
00154 
00155 void PrintUsage() {
00156     cout << "dlsdump - parses DLS (Downloadable Sounds) Level 1 and Level 2 files and prints out the content." << endl;
00157     cout << endl;
00158     cout << "Usage: dlsdump [-v] FILE" << endl;
00159     cout << endl;
00160     cout << "   -v  Print version and exit." << endl;
00161     cout << endl;
00162 }

Generated on Wed Dec 6 19:25:57 2006 for libgig by  doxygen 1.5.1