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

dlsdump.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 "DLS.h"
00033 
00034 using namespace std;
00035 
00036 string Revision();
00037 void PrintVersion();
00038 void PrintSamples(DLS::File* dls);
00039 void PrintInstruments(DLS::File* dls);
00040 void PrintRegions(DLS::Instrument* instr);
00041 void PrintUsage();
00042 
00043 int main(int argc, char *argv[])
00044 {
00045     if (argc <= 1) {
00046         PrintUsage();
00047         return EXIT_FAILURE;
00048     }
00049     if (argv[1][0] == '-') {
00050         switch (argv[1][1]) {
00051             case 'v':
00052                 PrintVersion();
00053                 return EXIT_SUCCESS;
00054         }
00055     }
00056     FILE* hFile = fopen(argv[1], "r");
00057     if (!hFile) {
00058         cout << "Invalid file argument!" << endl;
00059         return EXIT_FAILURE;
00060     }
00061     fclose(hFile);
00062     try {
00063         RIFF::File* riff = new RIFF::File(argv[1]);
00064         DLS::File*  dls  = new DLS::File(riff);
00065         if (dls->pInfo->Name != "") cout << "File Name: " << dls->pInfo->Name << endl;
00066         PrintSamples(dls);
00067         cout << endl;
00068         PrintInstruments(dls);
00069         delete dls;
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(DLS::File* dls) {
00085     int samples = 0;
00086     cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
00087     DLS::Sample* pSample = dls->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" << endl;
00095         pSample = dls->GetNextSample();
00096     }
00097 }
00098 
00099 void PrintInstruments(DLS::File* dls) {
00100     int instruments = 0;
00101     cout << "Available Instruments:" << endl;
00102     DLS::Instrument* pInstrument = dls->GetFirstInstrument();
00103     while (pInstrument) {
00104         instruments++;
00105         string name = pInstrument->pInfo->Name;
00106         if (name == "") name = "<NO NAME>";
00107         else            name = '\"' + name + '\"';
00108         cout << "    Instrument " << instruments << ") " << name << ", ";
00109 
00110         cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
00111         PrintRegions(pInstrument);
00112 
00113         pInstrument = dls->GetNextInstrument();
00114     }
00115 }
00116 
00117 void PrintRegions(DLS::Instrument* instr) {
00118     int regions = 0;
00119     DLS::Region* pRegion = instr->GetFirstRegion();
00120     while (pRegion) {
00121         regions++;
00122 
00123         cout << "        Region " << regions << ") ";
00124         DLS::Sample* pSample = pRegion->GetSample();
00125         if (pSample) {
00126             cout << "Sample: " << pSample->SamplesPerSecond << "Hz, ";
00127         }
00128         else {
00129             cout << "<NO_VALID_SAMPLE_REFERENCE> ";
00130         }
00131         cout << "KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
00132         cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl;
00133         cout << "            Loops=" << pRegion->SampleLoops << endl;
00134 
00135         pRegion = instr->GetNextRegion();
00136     }
00137 }
00138 
00139 string Revision() {
00140     string s = "$Revision: 1.3 $";
00141     return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
00142 }
00143 
00144 void PrintVersion() {
00145     cout << "dlsdump revision " << Revision() << endl;
00146     cout << "using " << DLS::libraryName() << " " << DLS::libraryVersion() << endl;
00147 }
00148 
00149 void PrintUsage() {
00150     cout << "dlsdump - parses DLS (Downloadable Sounds) Level 1 and Level 2 files and prints out the content." << endl;
00151     cout << endl;
00152     cout << "Usage: dlsdump [-v] FILE" << endl;
00153     cout << endl;
00154     cout << "   -v  Print version and exit." << endl;
00155     cout << endl;
00156 }

Generated on Wed May 25 23:48:22 2005 for libgig by  doxygen 1.4.2