00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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);
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 }