/[svn]/libgig/trunk/src/dlsdump.cpp
ViewVC logotype

Contents of /libgig/trunk/src/dlsdump.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 933 - (show annotations) (download)
Fri Nov 24 12:50:05 2006 UTC (17 years, 4 months ago) by schoenebeck
File size: 5991 byte(s)
* preparations for release 3.1.0

1 /***************************************************************************
2 * *
3 * libgig - C++ cross-platform Gigasampler format file access library *
4 * *
5 * Copyright (C) 2003-2006 by Christian Schoenebeck *
6 * <cuse@users.sourceforge.net> *
7 * *
8 * This program is part of libgig. *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
23 * MA 02111-1307 USA *
24 ***************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #include <iostream>
31 #include <cstdlib>
32 #include <string>
33
34 #include "DLS.h"
35
36 using namespace std;
37
38 string Revision();
39 void PrintVersion();
40 void PrintSamples(DLS::File* dls);
41 void PrintInstruments(DLS::File* dls);
42 void PrintRegions(DLS::Instrument* instr);
43 void PrintUsage();
44
45 int main(int argc, char *argv[])
46 {
47 if (argc <= 1) {
48 PrintUsage();
49 return EXIT_FAILURE;
50 }
51 if (argv[1][0] == '-') {
52 switch (argv[1][1]) {
53 case 'v':
54 PrintVersion();
55 return EXIT_SUCCESS;
56 }
57 }
58 FILE* hFile = fopen(argv[1], "r");
59 if (!hFile) {
60 cout << "Invalid file argument!" << endl;
61 return EXIT_FAILURE;
62 }
63 fclose(hFile);
64 try {
65 RIFF::File* riff = new RIFF::File(argv[1]);
66 DLS::File* dls = new DLS::File(riff);
67 if (dls->pInfo->Name != "") cout << "File Name: \"" << dls->pInfo->Name << "\"\n";
68 PrintSamples(dls);
69 cout << endl;
70 PrintInstruments(dls);
71 delete dls;
72 delete riff;
73 }
74 catch (RIFF::Exception e) {
75 e.PrintMessage();
76 return EXIT_FAILURE;
77 }
78 catch (...) {
79 cout << "Unknown exception while trying to parse file." << endl;
80 return EXIT_FAILURE;
81 }
82
83 return EXIT_SUCCESS;
84 }
85
86 void PrintSamples(DLS::File* dls) {
87 int samples = 0;
88 cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
89 DLS::Sample* pSample = dls->GetFirstSample();
90 while (pSample) {
91 samples++;
92 string name = pSample->pInfo->Name;
93 if (name == "") name = "<NO NAME>";
94 else name = '\"' + name + '\"';
95 cout << " Sample " << samples << ") " << name << ", ";
96 cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels" << endl;
97 pSample = dls->GetNextSample();
98 }
99 }
100
101 void PrintInstruments(DLS::File* dls) {
102 int instruments = 0;
103 cout << "Available Instruments:" << endl;
104 DLS::Instrument* pInstrument = dls->GetFirstInstrument();
105 while (pInstrument) {
106 instruments++;
107 string name = pInstrument->pInfo->Name;
108 if (name == "") name = "<NO NAME>";
109 else name = '\"' + name + '\"';
110 cout << " Instrument " << instruments << ") " << name << ", ";
111
112 cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
113 PrintRegions(pInstrument);
114
115 pInstrument = dls->GetNextInstrument();
116 }
117 }
118
119 void PrintRegions(DLS::Instrument* instr) {
120 int regions = 0;
121 DLS::Region* pRegion = instr->GetFirstRegion();
122 while (pRegion) {
123 regions++;
124
125 cout << " Region " << regions << ") ";
126 DLS::Sample* pSample = pRegion->GetSample();
127 if (pSample) {
128 cout << "Sample: ";
129 if (pSample->pInfo->Name != "") {
130 cout << "\"" << pSample->pInfo->Name << "\", ";
131 }
132 cout << pSample->SamplesPerSecond << "Hz, ";
133 }
134 else {
135 cout << "<NO_VALID_SAMPLE_REFERENCE> ";
136 }
137 cout << "KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
138 cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl;
139 cout << " Loops=" << pRegion->SampleLoops << endl;
140
141 pRegion = instr->GetNextRegion();
142 }
143 }
144
145 string Revision() {
146 string s = "$Revision: 1.5 $";
147 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
148 }
149
150 void PrintVersion() {
151 cout << "dlsdump revision " << Revision() << endl;
152 cout << "using " << DLS::libraryName() << " " << DLS::libraryVersion() << endl;
153 }
154
155 void PrintUsage() {
156 cout << "dlsdump - parses DLS (Downloadable Sounds) Level 1 and Level 2 files and prints out the content." << endl;
157 cout << endl;
158 cout << "Usage: dlsdump [-v] FILE" << endl;
159 cout << endl;
160 cout << " -v Print version and exit." << endl;
161 cout << endl;
162 }

  ViewVC Help
Powered by ViewVC