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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 55 - (hide annotations) (download)
Tue Apr 27 09:06:07 2004 UTC (19 years, 11 months ago) by schoenebeck
File size: 5062 byte(s)
updated copyright header for 2004

1 schoenebeck 2 /***************************************************************************
2     * *
3     * libgig - C++ cross-platform Gigasampler format file loader library *
4     * *
5 schoenebeck 55 * Copyright (C) 2003, 2004 by Christian Schoenebeck *
6     * <cuse@users.sourceforge.net> *
7 schoenebeck 2 * *
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 schoenebeck 55
24 schoenebeck 2 #ifdef HAVE_CONFIG_H
25     #include <config.h>
26     #endif
27    
28     #include <iostream>
29     #include <cstdlib>
30    
31     #include "DLS.h"
32    
33     using namespace std;
34    
35     void PrintSamples(DLS::File* dls);
36     void PrintInstruments(DLS::File* dls);
37     void PrintRegions(DLS::Instrument* instr);
38     void PrintUsage();
39    
40     int main(int argc, char *argv[])
41     {
42     if (argc <= 1) {
43     PrintUsage();
44     return EXIT_FAILURE;
45     }
46     FILE* hFile = fopen(argv[1], "r");
47     if (!hFile) {
48     cout << "Invalid file argument!" << endl;
49     return EXIT_FAILURE;
50     }
51     fclose(hFile);
52     try {
53     RIFF::File* riff = new RIFF::File(argv[1]);
54     DLS::File* dls = new DLS::File(riff);
55     if (dls->pInfo->Name != "") cout << "File Name: " << dls->pInfo->Name << endl;
56     PrintSamples(dls);
57     cout << endl;
58     PrintInstruments(dls);
59     delete dls;
60     delete riff;
61     }
62     catch (RIFF::Exception e) {
63     e.PrintMessage();
64     return EXIT_FAILURE;
65     }
66     catch (...) {
67     cout << "Unknown exception while trying to parse file." << endl;
68     return EXIT_FAILURE;
69     }
70    
71     return EXIT_SUCCESS;
72     }
73    
74     void PrintSamples(DLS::File* dls) {
75     int samples = 0;
76     cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl;
77     DLS::Sample* pSample = dls->GetFirstSample();
78     while (pSample) {
79     samples++;
80     string name = pSample->pInfo->Name;
81     if (name == "") name = "<NO NAME>";
82     else name = '\"' + name + '\"';
83     cout << " Sample " << samples << ") " << name << ", ";
84     cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels" << endl;
85     pSample = dls->GetNextSample();
86     }
87     }
88    
89     void PrintInstruments(DLS::File* dls) {
90     int instruments = 0;
91     cout << "Available Instruments:" << endl;
92     DLS::Instrument* pInstrument = dls->GetFirstInstrument();
93     while (pInstrument) {
94     instruments++;
95     string name = pInstrument->pInfo->Name;
96     if (name == "") name = "<NO NAME>";
97     else name = '\"' + name + '\"';
98     cout << " Instrument " << instruments << ") " << name << ", ";
99    
100     cout << " MIDIBank=" << pInstrument->MIDIBank << ", MIDIProgram=" << pInstrument->MIDIProgram << endl;
101     PrintRegions(pInstrument);
102    
103     pInstrument = dls->GetNextInstrument();
104     }
105     }
106    
107     void PrintRegions(DLS::Instrument* instr) {
108     int regions = 0;
109     DLS::Region* pRegion = instr->GetFirstRegion();
110     while (pRegion) {
111     regions++;
112    
113     cout << " Region " << regions << ") ";
114     DLS::Sample* pSample = pRegion->GetSample();
115     if (pSample) {
116     cout << "Sample: " << pSample->SamplesPerSecond << "Hz, ";
117     }
118     else {
119     cout << "<NO_VALID_SAMPLE_REFERENCE> ";
120     }
121     cout << "KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", ";
122     cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl;
123     cout << " Loops=" << pRegion->SampleLoops << endl;
124    
125     pRegion = instr->GetNextRegion();
126     }
127     }
128    
129     void PrintUsage() {
130     cout << "dlsdump - parses DLS (Downloadable Sounds) Level 1 and Level 2 files and prints out the content." << endl;
131     cout << endl;
132     cout << "Usage: dlsdump FILE" << endl;
133     }

  ViewVC Help
Powered by ViewVC