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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2543 - (hide annotations) (download)
Sat May 10 02:06:58 2014 UTC (9 years, 11 months ago) by schoenebeck
File size: 7816 byte(s)
* Initial support for sample based instruments in KORG's file format (.KMP
  and .KSF files) -> Korg.h, Korg.cpp.
* Added new command line tool "korgdump" (and a man page for it).
* Added new command line tool "korg2gig" (and a man page for it), for
  converting KORG sounds to Giga format.
* riftree tool: Added more command line options for being able to also dump
  other kind of file formats similar but not equal to the RIFF format.
* gig.h/.cpp: Added new method File::GetGroup(String name) for retrieving
  group by name.
* RIFF.h/.cpp: Added support for loading RIFF-like files with a bit
  different layout than "real" RIFF files (used for KORG format support).
* RIFF.h/.cpp: Added new method Chunk::GetFile().
* RIFF.h/.cpp: Added new method Chunk::GetLayout().
* Bumped version (3.3.0.svn9).

1 schoenebeck 2 /***************************************************************************
2     * *
3 schoenebeck 933 * libgig - C++ cross-platform Gigasampler format file access library *
4 schoenebeck 2 * *
5 schoenebeck 2543 * Copyright (C) 2003-2014 by Christian Schoenebeck *
6 schoenebeck 518 * <cuse@users.sourceforge.net> *
7 schoenebeck 2 * *
8 schoenebeck 933 * This program is part of libgig. *
9     * *
10 schoenebeck 2 * 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 schoenebeck 55
26 schoenebeck 2 #ifdef HAVE_CONFIG_H
27     #include <config.h>
28     #endif
29    
30     #include <stdio.h>
31     #include <iostream>
32 schoenebeck 518 #include <string>
33 schoenebeck 2 #include <cstdlib>
34    
35     #include "RIFF.h"
36    
37     using namespace std;
38    
39 schoenebeck 518 string Revision();
40     void PrintVersion();
41 schoenebeck 2 void PrintUsage();
42     void PrintChunkList(RIFF::List* list, bool PrintSize);
43 schoenebeck 2543 static uint32_t strToChunkID(string s);
44 schoenebeck 2
45     int main(int argc, char *argv[])
46     {
47 schoenebeck 2543 bool bPrintSize = false;
48     RIFF::endian_t endian = RIFF::endian_native;
49     RIFF::layout_t layout = RIFF::layout_standard;
50     bool bExpectFirstChunkID = false;
51     uint32_t uiExpectedFirstChunkID;
52 schoenebeck 2
53 schoenebeck 2543 // validate & parse arguments provided to this program
54 schoenebeck 2 if (argc <= 1) {
55     PrintUsage();
56     return EXIT_FAILURE;
57     }
58 schoenebeck 2543 int iArg;
59     for (iArg = 1; iArg < argc; ++iArg) {
60     const string opt = argv[iArg];
61     if (opt == "--") { // common for all command line tools: separator between initial option arguments and i.e. subsequent file arguments
62     iArg++;
63     break;
64     }
65     if (opt.substr(0, 1) != "-") break;
66    
67     if (opt == "-v") {
68     PrintVersion();
69     return EXIT_SUCCESS;
70     } else if (opt == "-s") {
71     bPrintSize = true;
72     } else if (opt == "--big-endian") {
73     endian = RIFF::endian_big;
74     } else if (opt == "--little-endian") {
75     endian = RIFF::endian_little;
76     } else if (opt == "--flat") {
77     layout = RIFF::layout_flat;
78     } else if (opt == "--first-chunk-id") {
79     iArg++;
80     if (iArg >= argc) {
81 schoenebeck 518 PrintVersion();
82     return EXIT_SUCCESS;
83 schoenebeck 2543 }
84     bExpectFirstChunkID = true;
85     uiExpectedFirstChunkID = strToChunkID(argv[iArg]);
86     } else {
87     cerr << "Unknown option '" << opt << "'" << endl;
88     cerr << endl;
89     PrintUsage();
90     return EXIT_FAILURE;
91 schoenebeck 2 }
92     }
93 schoenebeck 2543
94     const int nFileArguments = argc - iArg;
95     if (nFileArguments != 1) {
96     cerr << "You must provide a file argument." << endl;
97 schoenebeck 518 return EXIT_FAILURE;
98     }
99 schoenebeck 2543 const int FileArgIndex = iArg;
100    
101 schoenebeck 2 FILE* hFile = fopen(argv[FileArgIndex], "r");
102     if (!hFile) {
103 schoenebeck 2543 cerr << "Invalid file argument!" << endl;
104 schoenebeck 2 return EXIT_FAILURE;
105     }
106     fclose(hFile);
107     try {
108 schoenebeck 2543 RIFF::File* riff = NULL;
109     switch (layout) {
110     case RIFF::layout_standard:
111     riff = new RIFF::File(argv[FileArgIndex]);
112     cout << "RIFF(" << riff->GetListTypeString() << ")->";
113     break;
114     case RIFF::layout_flat:
115     if (!bExpectFirstChunkID) {
116     cerr << "If you are using '--flat' then you must also use '--first-chunk-id'." << endl;
117     return EXIT_FAILURE;
118     }
119     riff = new RIFF::File(
120     argv[FileArgIndex], uiExpectedFirstChunkID, endian, layout
121     );
122     cout << "Flat RIFF-alike file";
123     break;
124     }
125 schoenebeck 2 if (bPrintSize) cout << " (" << riff->GetSize() << " Bytes)";
126     cout << endl;
127     PrintChunkList(riff, bPrintSize);
128     delete riff;
129     }
130     catch (RIFF::Exception e) {
131     e.PrintMessage();
132     return EXIT_FAILURE;
133     }
134     catch (...) {
135 schoenebeck 2543 cerr << "Unknown exception while trying to parse file." << endl;
136 schoenebeck 2 return EXIT_FAILURE;
137     }
138    
139     return EXIT_SUCCESS;
140     }
141    
142     void PrintChunkList(RIFF::List* list, bool PrintSize) {
143     RIFF::Chunk* ck = list->GetFirstSubChunk();
144     while (ck != NULL) {
145     RIFF::Chunk* ckParent = ck;
146     while (ckParent->GetParent() != NULL) {
147     cout << " "; // e.g. 'LIST(INFO)->'
148     ckParent = ckParent->GetParent();
149     }
150     cout << ck->GetChunkIDString();
151     switch (ck->GetChunkID()) {
152     case CHUNK_ID_LIST: case CHUNK_ID_RIFF:
153     {
154     RIFF::List* l = (RIFF::List*) ck;
155     cout << "(" << l->GetListTypeString() << ")->";
156     if (PrintSize) cout << " (" << l->GetSize() << " Bytes)";
157     cout << endl;
158     PrintChunkList(l, PrintSize);
159     break;
160     }
161     default:
162     cout << ";";
163     if (PrintSize) cout << " (" << ck->GetSize() << " Bytes)";
164     cout << endl;
165     }
166     ck = list->GetNextSubChunk();
167     }
168     }
169    
170 schoenebeck 2543 static uint32_t strToChunkID(string s) {
171     if (s.size() != 4) {
172     cerr << "Argument after '--first-chunk-id' must be exactly 4 characters long." << endl;
173     exit(-1);
174     }
175     uint32_t result = 0;
176     for (int i = 0; i < 4; ++i) {
177     uint32_t byte = s[i];
178     result |= byte << i*8;
179     }
180     return result;
181     }
182    
183 schoenebeck 518 string Revision() {
184 schoenebeck 2493 string s = "$Revision$";
185 schoenebeck 518 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
186     }
187    
188     void PrintVersion() {
189     cout << "rifftree revision " << Revision() << endl;
190     cout << "using " << RIFF::libraryName() << " " << RIFF::libraryVersion() << endl;
191     }
192    
193 schoenebeck 2 void PrintUsage() {
194     cout << "rifftree - parses an arbitrary RIFF file and prints out the RIFF tree structure." << endl;
195     cout << endl;
196 schoenebeck 2543 cout << "Usage: rifftree [OPTIONS] FILE" << endl;
197 schoenebeck 2 cout << endl;
198 schoenebeck 2543 cout << "Options:" << endl;
199 schoenebeck 2 cout << endl;
200 schoenebeck 2543 cout << " -v Print version and exit." << endl;
201     cout << endl;
202     cout << " -s Print the size of each chunk." << endl;
203     cout << endl;
204     cout << " --flat" << endl;
205     cout << " First chunk of file is not a list (container) chunk." << endl;
206     cout << endl;
207     cout << " --first-chunk-id CKID" << endl;
208     cout << " 32 bit chunk ID of very first chunk in file." << endl;
209     cout << endl;
210     cout << " --big-endian" << endl;
211     cout << " File is in big endian format." << endl;
212     cout << endl;
213     cout << " --little-endian" << endl;
214     cout << " File is in little endian format." << endl;
215     cout << endl;
216 schoenebeck 2 }

Properties

Name Value
svn:keywords Revision

  ViewVC Help
Powered by ViewVC