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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 518 - (show annotations) (download)
Sun May 8 16:19:34 2005 UTC (18 years, 11 months ago) by schoenebeck
File size: 5691 byte(s)
* added functions libraryName() and libraryVersion() to each of the three
  library units (RIFF,DLS,gig)
* all tools now offer a command line switch -v to show the tools revision
  and the used libgig version
* man pages are now auto generated with the correct libgig version

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

  ViewVC Help
Powered by ViewVC