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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 804 - (show annotations) (download)
Sat Nov 12 19:16:01 2005 UTC (14 years ago) by schoenebeck
File size: 5837 byte(s)
* src/DLS.cpp:
  - further bugfixes regarding DLS write support
* src/dlsdump.cpp:
  - show for every region the name of the referenced sample
  - show file name in quotation marks

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 << "\"\n";
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: ";
127 if (pSample->pInfo->Name != "") {
128 cout << "\"" << pSample->pInfo->Name << "\", ";
129 }
130 cout << pSample->SamplesPerSecond << "Hz, ";
131 }
132 else {
133 cout << "<NO_VALID_SAMPLE_REFERENCE> ";
134 }
135 cout << "KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
136 cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl;
137 cout << " Loops=" << pRegion->SampleLoops << endl;
138
139 pRegion = instr->GetNextRegion();
140 }
141 }
142
143 string Revision() {
144 string s = "$Revision: 1.4 $";
145 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
146 }
147
148 void PrintVersion() {
149 cout << "dlsdump revision " << Revision() << endl;
150 cout << "using " << DLS::libraryName() << " " << DLS::libraryVersion() << endl;
151 }
152
153 void PrintUsage() {
154 cout << "dlsdump - parses DLS (Downloadable Sounds) Level 1 and Level 2 files and prints out the content." << endl;
155 cout << endl;
156 cout << "Usage: dlsdump [-v] FILE" << endl;
157 cout << endl;
158 cout << " -v Print version and exit." << endl;
159 cout << endl;
160 }

  ViewVC Help
Powered by ViewVC