/[svn]/libgig/trunk/src/tools/korgdump.cpp
ViewVC logotype

Annotation of /libgig/trunk/src/tools/korgdump.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3175 - (hide annotations) (download)
Thu May 11 11:34:19 2017 UTC (6 years, 11 months ago) by schoenebeck
File size: 6146 byte(s)
* Fixed potential crash in command line tools gig2stereo, korg2gig,
  korgdump and sf2extract.

1 schoenebeck 2543 /***************************************************************************
2     * *
3 schoenebeck 3175 * Copyright (C) 2014 - 2017 Christian Schoenebeck *
4 schoenebeck 2543 * <cuse@users.sourceforge.net> *
5     * *
6     * This program is part of libgig. *
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     #include <set>
32    
33 schoenebeck 2573 #include "../Korg.h"
34 schoenebeck 2543
35     using namespace std;
36    
37     static string Revision() {
38     string s = "$Revision$";
39     return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
40     }
41    
42     static void printVersion() {
43     cout << "korgdump revision " << Revision() << endl;
44     cout << "using " << Korg::libraryName() << " " << Korg::libraryVersion() << endl;
45     }
46    
47     static void printUsage() {
48     cout << "korgdump - parses Korg sound files and prints out their content." << endl;
49     cout << endl;
50     cout << "Usage: korgdump [-v] FILE" << endl;
51     cout << endl;
52     cout << " -v Print version and exit." << endl;
53     cout << endl;
54     }
55    
56     static bool endsWith(const string& haystack, const string& needle) {
57 schoenebeck 3175 if (haystack.size() < needle.size()) return false;
58 schoenebeck 2543 return haystack.substr(haystack.size() - needle.size(), needle.size()) == needle;
59     }
60    
61     static void printSample(const string& filename, int i = -1) {
62     Korg::KSFSample* smpl = new Korg::KSFSample(filename);
63     cout << " ";
64     if (i != -1) cout << (i+1) << ". ";
65     cout << "Sample SampleFile='" << smpl->FileName() << "'" << endl;
66     cout << " Name='" << smpl->Name << "'" << endl;
67     cout << " Start=" << smpl->Start << ", Start2=" << smpl->Start2 << ", LoopStart=" << smpl->LoopStart << ", LoopEnd=" << smpl->LoopEnd << endl;
68     cout << " SampleRate=" << smpl->SampleRate << ", LoopTune=" << (int)smpl->LoopTune << ", Channels=" << (int)smpl->Channels << ", BitDepth=" << (int)smpl->BitDepth << ", SamplePoints=" << smpl->SamplePoints << endl;
69     cout << " IsCompressed=" << smpl->IsCompressed() << ", CompressionID=" << (int)smpl->CompressionID() << ", Use2ndStart=" << (int)smpl->Use2ndStart() << endl;
70     cout << endl;
71     delete smpl;
72     }
73    
74     static void printRegion(int i, Korg::KMPRegion* rgn) {
75     cout << " " << (i+1) << ". Region SampleFile='" << rgn->FullSampleFileName() << "'" << endl;
76     cout << " OriginalKey=" << (int)rgn->OriginalKey << ", TopKey=" << (int)rgn->TopKey << endl;
77     cout << " Transpose=" << rgn->Transpose << ", Tune=" << (int)rgn->Tune << ", Level=" << (int)rgn->Level << ", Pan=" << (int)rgn->Pan << endl;
78     cout << " FilterCutoff=" << (int)rgn->FilterCutoff << endl;
79     cout << endl;
80     }
81    
82     static void printInstrument(Korg::KMPInstrument* instr) {
83     cout << "Instrument '" << instr->Name() << "'" << endl;
84     cout << " Use2ndStart=" << instr->Use2ndStart() << endl;
85     cout << endl;
86     set<string> sampleFileNames;
87     for (int i = 0; i < instr->GetRegionCount(); ++i) {
88     Korg::KMPRegion* rgn = instr->GetRegion(i);
89     printRegion(i, rgn);
90     sampleFileNames.insert(rgn->FullSampleFileName());
91     }
92    
93     cout << "Samples referenced by instrument:" << endl;
94     cout << endl;
95    
96     int i = 0;
97     for (set<string>::iterator it = sampleFileNames.begin();
98     it != sampleFileNames.end(); ++it, ++i)
99     {
100     printSample(*it, i);
101     }
102     }
103    
104     int main(int argc, char *argv[]) {
105     if (argc <= 1) {
106     printUsage();
107     return EXIT_FAILURE;
108     }
109     if (argv[1][0] == '-') {
110     switch (argv[1][1]) {
111     case 'v':
112     printVersion();
113     return EXIT_SUCCESS;
114     }
115     }
116     const char* filename = argv[1];
117     FILE* hFile = fopen(filename, "r");
118     if (!hFile) {
119     cout << "Invalid file argument (could not open given file for reading)!" << endl;
120     return EXIT_FAILURE;
121     }
122     fclose(hFile);
123     try {
124     if (endsWith(filename, ".KMP")) {
125     Korg::KMPInstrument* instr = new Korg::KMPInstrument(filename);
126     printInstrument(instr);
127     delete instr;
128     } else if (endsWith(filename, ".KSF")) {
129     printSample(filename);
130     } else if (endsWith(filename, ".PCG")) {
131     cout << "There is no support for .PCG files in this version of korgdump yet." << endl;
132     return EXIT_FAILURE;
133     } else {
134     cout << "Unknown file type (file name postfix)" << endl;
135     return EXIT_FAILURE;
136     }
137     }
138     catch (RIFF::Exception e) {
139     e.PrintMessage();
140     return EXIT_FAILURE;
141     }
142     catch (...) {
143     cout << "Unknown exception while trying to parse file." << endl;
144     return EXIT_FAILURE;
145     }
146    
147     return EXIT_SUCCESS;
148     }

Properties

Name Value
svn:keywords Revision

  ViewVC Help
Powered by ViewVC