Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Annotator
|
Chris@0
|
5 A utility for batch feature extraction from audio files.
|
Chris@0
|
6 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
|
Chris@0
|
7 Copyright 2007-2008 QMUL.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include <vector>
|
Chris@0
|
17 #include <string>
|
Chris@0
|
18 #include <iostream>
|
Chris@0
|
19
|
Chris@0
|
20 #include <QCoreApplication>
|
Chris@0
|
21 #include <QSettings>
|
Chris@0
|
22 #include <QStringList>
|
Chris@0
|
23 #include <QString>
|
Chris@0
|
24 #include <QFileInfo>
|
Chris@0
|
25 #include <QDir>
|
Chris@45
|
26 #include <QSet>
|
Chris@0
|
27
|
Chris@0
|
28 using std::cout;
|
Chris@0
|
29 using std::cerr;
|
Chris@0
|
30 using std::endl;
|
Chris@0
|
31 using std::vector;
|
Chris@0
|
32 using std::string;
|
Chris@0
|
33
|
Chris@2
|
34 #include "../version.h"
|
Chris@2
|
35
|
Chris@0
|
36 #include "base/Exceptions.h"
|
Chris@0
|
37 #include "base/TempDirectory.h"
|
Chris@111
|
38 #include "base/ProgressPrinter.h"
|
Chris@0
|
39
|
Chris@0
|
40 #include "data/fileio/AudioFileReaderFactory.h"
|
Chris@0
|
41 #include "data/fileio/PlaylistFileReader.h"
|
Chris@0
|
42
|
Chris@0
|
43 #include "transform/Transform.h"
|
Chris@0
|
44 #include "transform/TransformFactory.h"
|
Chris@0
|
45
|
Chris@0
|
46 #include "FeatureExtractionManager.h"
|
Chris@0
|
47 #include "transform/FeatureWriter.h"
|
Chris@0
|
48 #include "FeatureWriterFactory.h"
|
Chris@0
|
49
|
Chris@0
|
50 #include "rdf/RDFTransformFactory.h"
|
Chris@0
|
51
|
Chris@0
|
52 #include <vamp-hostsdk/PluginSummarisingAdapter.h>
|
Chris@0
|
53
|
Chris@0
|
54 #ifdef HAVE_FFTW3
|
Chris@0
|
55 #include <fftw3.h>
|
Chris@0
|
56 #endif
|
Chris@0
|
57
|
Chris@0
|
58 // Desired options:
|
Chris@0
|
59 //
|
Chris@0
|
60 // * output preference:
|
Chris@0
|
61 // - all data in one file
|
Chris@0
|
62 // - one file per input file
|
Chris@0
|
63 // - one file per input file per transform
|
Chris@0
|
64 // - (any use for: one file per transform?)
|
Chris@0
|
65 //
|
Chris@0
|
66 // * output location:
|
Chris@0
|
67 // - same directory as input file
|
Chris@0
|
68 // - current directory
|
Chris@0
|
69 //
|
Chris@0
|
70 // * output filename:
|
Chris@0
|
71 // - based on input (obvious choice for one file per input file modes)
|
Chris@0
|
72 // - specified on command line (obvious choice for all in one file mode)
|
Chris@0
|
73 //
|
Chris@0
|
74 // * output format: one or more of
|
Chris@0
|
75 // - RDF
|
Chris@0
|
76 // - AudioDB
|
Chris@0
|
77 // - Vamp Simple Host format
|
Chris@0
|
78 // - CSV
|
Chris@0
|
79 //
|
Chris@0
|
80 // * input handling:
|
Chris@0
|
81 // - run each transform on each input file separately
|
Chris@0
|
82 // - provide all input files to the same transform, one per channel
|
Chris@0
|
83 //
|
Chris@0
|
84 // * format-specific options:
|
Chris@0
|
85 // - RDF format: fancy/plain RDF
|
Chris@0
|
86 // - CSV format: separator, timestamp type
|
Chris@0
|
87 // note: do the output file/location also count as format-specific options?
|
Chris@0
|
88 // an output writer that wrote to a database would have different options...
|
Chris@0
|
89 //
|
Chris@0
|
90 // * debug level and progress output
|
Chris@0
|
91 //
|
Chris@0
|
92 // * other potential options:
|
Chris@0
|
93 // - ignore version mismatches in Transform specifications
|
Chris@0
|
94 // - sample rate: force a given rate; use file rate instead of rate in
|
Chris@0
|
95 // Transform spec
|
Chris@0
|
96 //
|
Chris@0
|
97 // * other potential instructions:
|
Chris@0
|
98 // - write out a skeleton Transform file for a specified plugin
|
Chris@0
|
99 // - write out skeleton RDF for a plugin library (i.e. do the job of
|
Chris@0
|
100 // RDF template_generator)
|
Chris@0
|
101 // - verify that RDF for a plugin library matches the plugin
|
Chris@0
|
102 //
|
Chris@0
|
103 // MAYBE:
|
Chris@0
|
104 // * transform(s) to run:
|
Chris@0
|
105 // - supply transform file names on command line
|
Chris@0
|
106 // - use all transforms found in a given directory?
|
Chris@0
|
107 //
|
Chris@0
|
108 // MAYBE:
|
Chris@0
|
109 // * input files to transform:
|
Chris@0
|
110 // - supply file names or URIs on command line
|
Chris@0
|
111 // - use all files in a given directory or tree
|
Chris@0
|
112
|
Chris@0
|
113 static QString
|
Chris@0
|
114 wrap(QString s, int len, int pfx = 0)
|
Chris@0
|
115 {
|
Chris@0
|
116 QString ws;
|
Chris@0
|
117 QStringList sl(s.split(' '));
|
Chris@0
|
118 int i = 0, c = 0;
|
Chris@0
|
119 while (i < sl.size()) {
|
Chris@0
|
120 int wl = sl[i].length();
|
Chris@0
|
121 if (c + wl < len) {
|
Chris@0
|
122 if (c > 0) {
|
Chris@0
|
123 ws += ' ';
|
Chris@0
|
124 ++c;
|
Chris@0
|
125 }
|
Chris@0
|
126 } else {
|
Chris@0
|
127 if (c > 0) {
|
Chris@0
|
128 ws += '\n';
|
Chris@0
|
129 for (int j = 0; j < pfx; ++j) ws += ' ';
|
Chris@0
|
130 c = 0;
|
Chris@0
|
131 }
|
Chris@0
|
132 }
|
Chris@0
|
133 ws += sl[i];
|
Chris@0
|
134 c += wl;
|
Chris@0
|
135 ++i;
|
Chris@0
|
136 }
|
Chris@0
|
137 return ws;
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 void usage(QString myname)
|
Chris@0
|
141 {
|
Chris@0
|
142 set<string> writers = FeatureWriterFactory::getWriterTags();
|
Chris@0
|
143
|
Chris@0
|
144 cerr << endl;
|
Chris@2
|
145 cerr << "Sonic Annotator v" << RUNNER_VERSION << endl;
|
Chris@0
|
146 cerr << "A utility for batch feature extraction from audio files." << endl;
|
Chris@0
|
147 cerr << "Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London." << endl;
|
Chris@95
|
148 cerr << "Copyright 2007-2014 Queen Mary, University of London." << endl;
|
Chris@0
|
149 cerr << endl;
|
Chris@0
|
150 cerr << "This program is free software. You may redistribute copies of it under the" << endl;
|
Chris@0
|
151 cerr << "terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>." << endl;
|
Chris@0
|
152 cerr << "This program is supplied with NO WARRANTY, to the extent permitted by law." << endl;
|
Chris@0
|
153 cerr << endl;
|
Chris@0
|
154 cerr << " Usage: " << myname.toStdString()
|
Chris@0
|
155 << " [-mr] -t trans.xml [...] -w <writer> [...] <audio> [...]" << endl;
|
Chris@0
|
156 cerr << " " << myname.toStdString()
|
Chris@0
|
157 << " [-mr] -T trans.txt [...] -w <writer> [...] <audio> [...]" << endl;
|
Chris@0
|
158 cerr << " " << myname.toStdString()
|
Chris@0
|
159 << " -s <transform>" << endl;
|
Chris@0
|
160 cerr << " " << myname.toStdString()
|
Chris@46
|
161 << " [-lhv]" << endl;
|
Chris@0
|
162 cerr << endl;
|
Chris@0
|
163 cerr << "Where <audio> is an audio file or URL to use as input: either a local file" << endl;
|
Chris@0
|
164 cerr << "path, local \"file://\" URL, or remote \"http://\" or \"ftp://\" URL." << endl;
|
Chris@0
|
165 cerr << endl;
|
Chris@0
|
166
|
Chris@0
|
167 QString extensions = AudioFileReaderFactory::getKnownExtensions();
|
Chris@0
|
168 QStringList extlist = extensions.split(" ", QString::SkipEmptyParts);
|
Chris@0
|
169 if (!extlist.empty()) {
|
Chris@0
|
170 cerr << "The following audio file extensions are recognised:" << endl;
|
Chris@0
|
171 cerr << " ";
|
Chris@0
|
172 int c = 2;
|
Chris@0
|
173 for (int i = 0; i < extlist.size(); ++i) {
|
Chris@0
|
174 QString ext = extlist[i];
|
Chris@0
|
175 if (ext.startsWith("*.")) ext = ext.right(ext.length()-2);
|
Chris@0
|
176 c += ext.length() + 2;
|
Chris@0
|
177 if (c >= 80) {
|
Chris@0
|
178 cerr << "\n ";
|
Chris@0
|
179 c -= 78;
|
Chris@0
|
180 }
|
Chris@0
|
181 cerr << ext.toStdString();
|
Chris@0
|
182 if (i + 1 == extlist.size()) cerr << ".";
|
Chris@0
|
183 else cerr << ", ";
|
Chris@0
|
184 }
|
Chris@0
|
185 cerr << endl;
|
Chris@0
|
186 }
|
Chris@0
|
187
|
Chris@0
|
188 cerr << "Playlist files in M3U format are also supported." << endl;
|
Chris@0
|
189 cerr << endl;
|
Chris@0
|
190 cerr << "Transformation options:" << endl;
|
Chris@0
|
191 cerr << endl;
|
Chris@0
|
192 cerr << " -t, --transform <T> Apply transform described in transform file <T> to" << endl;
|
Chris@0
|
193 cerr << " all input audio files. You may supply this option" << endl;
|
Chris@0
|
194 cerr << " multiple times. You must supply this option or -T at" << endl;
|
Chris@0
|
195 cerr << " least once for any work to be done. Transform format" << endl;
|
Chris@0
|
196 cerr << " may be SV transform XML or Vamp transform RDF. See" << endl;
|
Chris@0
|
197 cerr << " documentation for examples." << endl;
|
Chris@0
|
198 cerr << endl;
|
Chris@0
|
199 cerr << " -T, --transforms <T> Apply all transforms described in transform files" << endl;
|
Chris@0
|
200 cerr << " whose names are listed in text file <T>. You may supply" << endl;
|
Chris@0
|
201 cerr << " this option multiple times." << endl;
|
Chris@0
|
202 cerr << endl;
|
Chris@0
|
203 cerr << " -d, --default <I> Apply the default transform for transform id <I>. This" << endl;
|
Chris@0
|
204 cerr << " is equivalent to generating a skeleton transform for this" << endl;
|
Chris@0
|
205 cerr << " id (using the -s option, below) and then applying that," << endl;
|
Chris@0
|
206 cerr << " unmodified, with the -t option in the normal way. Note" << endl;
|
Chris@0
|
207 cerr << " that the results may vary as the implementation's default" << endl;
|
Chris@0
|
208 cerr << " processing parameters are not guaranteed. Do not use" << endl;
|
Chris@0
|
209 cerr << " this in production systems. You may supply this option" << endl;
|
Chris@0
|
210 cerr << " multiple times, and mix it with -t and -T." << endl;
|
Chris@0
|
211 cerr << endl;
|
Chris@0
|
212 cerr << " -w, --writer <W> Write output using writer type <W>." << endl;
|
Chris@0
|
213 cerr << " Supported writer types are: ";
|
Chris@0
|
214 for (set<string>::const_iterator i = writers.begin();
|
Chris@0
|
215 i != writers.end(); ) {
|
Chris@0
|
216 cerr << *i;
|
Chris@0
|
217 if (++i != writers.end()) cerr << ", ";
|
Chris@0
|
218 else cerr << ".";
|
Chris@0
|
219 }
|
Chris@0
|
220 cerr << endl;
|
Chris@0
|
221 cerr << " You may supply this option multiple times. You must" << endl;
|
Chris@0
|
222 cerr << " supply this option at least once for any work to be done." << endl;
|
Chris@0
|
223 cerr << endl;
|
Chris@0
|
224 cerr << " -S, --summary <S> In addition to the result features, write summary feature" << endl;
|
Chris@0
|
225 cerr << " of summary type <S>." << endl;
|
Chris@0
|
226 cerr << " Supported summary types are: min, max, mean, median, mode," << endl;
|
Chris@0
|
227 cerr << " sum, variance, sd, count." << endl;
|
Chris@0
|
228 cerr << " You may supply this option multiple times." << endl;
|
Chris@0
|
229 cerr << endl;
|
Chris@0
|
230 cerr << " --summary-only Write only summary features; do not write the regular" << endl;
|
Chris@0
|
231 cerr << " result features." << endl;
|
Chris@0
|
232 cerr << endl;
|
Chris@0
|
233 cerr << " --segments <A>,<B>[,...]" << endl;
|
Chris@0
|
234 cerr << " Summarise in segments, with segment boundaries" << endl;
|
Chris@0
|
235 cerr << " at A, B, ... seconds." << endl;
|
Chris@0
|
236 cerr << endl;
|
Chris@0
|
237
|
Chris@0
|
238 /*!!! This feature not implemented yet (sniff)
|
Chris@0
|
239 cerr << " -m, --multiplex If multiple input audio files are given, use mono" << endl;
|
Chris@0
|
240 cerr << " mixdowns of all files as the input channels for a single" << endl;
|
Chris@0
|
241 cerr << " invocation of each transform, instead of running the" << endl;
|
Chris@0
|
242 cerr << " transform against all files separately." << endl;
|
Chris@0
|
243 cerr << endl;
|
Chris@0
|
244 */
|
Chris@0
|
245
|
Chris@0
|
246 cerr << " -r, --recursive If any of the <audio> arguments is found to be a local" << endl;
|
Chris@0
|
247 cerr << " directory, search the tree starting at that directory" << endl;
|
Chris@0
|
248 cerr << " for all supported audio files and take all of those as" << endl;
|
Chris@0
|
249 cerr << " input instead." << endl;
|
Chris@0
|
250 cerr << endl;
|
Chris@21
|
251 cerr << " -f, --force Continue with subsequent files following an error." << endl;
|
Chris@21
|
252 cerr << endl;
|
Chris@0
|
253 cerr << "Housekeeping options:" << endl;
|
Chris@0
|
254 cerr << endl;
|
Chris@0
|
255 cerr << " -l, --list List all known transform ids to standard output." << endl;
|
Chris@0
|
256 cerr << endl;
|
Chris@0
|
257 cerr << " -s, --skeleton <I> Generate a skeleton transform file for transform id <I>" << endl;
|
Chris@0
|
258 cerr << " and write it to standard output." << endl;
|
Chris@0
|
259 cerr << endl;
|
Chris@46
|
260 cerr << " -v, --version Show the version number and exit." << endl;
|
Chris@0
|
261 cerr << " -h, --help Show this help." << endl;
|
Chris@0
|
262
|
Chris@0
|
263 cerr << endl;
|
Chris@46
|
264 cerr << "If no -w (or --writer) options are supplied, either the -l -s -v or -h option" << endl;
|
Chris@46
|
265 cerr << "(or long equivalent) must be given instead." << endl;
|
Chris@0
|
266
|
Chris@0
|
267 for (set<string>::const_iterator i = writers.begin();
|
Chris@0
|
268 i != writers.end(); ++i) {
|
Chris@0
|
269 FeatureWriter *w = FeatureWriterFactory::createWriter(*i);
|
Chris@0
|
270 if (!w) {
|
Chris@0
|
271 cerr << " (Internal error: failed to create writer of this type)" << endl;
|
Chris@0
|
272 continue;
|
Chris@0
|
273 }
|
Chris@0
|
274 FeatureWriter::ParameterList params = w->getSupportedParameters();
|
Chris@0
|
275 delete w;
|
Chris@0
|
276 if (params.empty()) {
|
Chris@0
|
277 continue;
|
Chris@0
|
278 }
|
Chris@0
|
279 cerr << endl;
|
Chris@0
|
280 cerr << "Additional options for writer type \"" << *i << "\":" << endl;
|
Chris@0
|
281 cerr << endl;
|
Chris@0
|
282 for (FeatureWriter::ParameterList::const_iterator j = params.begin();
|
Chris@0
|
283 j != params.end(); ++j) {
|
Chris@0
|
284 cerr << " --" << *i << "-" << j->name << " ";
|
Chris@0
|
285 int spaceage = 16 - int(i->length()) - int(j->name.length());
|
Chris@0
|
286 if (j->hasArg) { cerr << "<X> "; spaceage -= 4; }
|
Chris@0
|
287 for (int k = 0; k < spaceage; ++k) cerr << " ";
|
Chris@0
|
288 QString s(j->description.c_str());
|
Chris@0
|
289 s = wrap(s, 56, 22);
|
Chris@0
|
290 cerr << s.toStdString() << endl;
|
Chris@0
|
291 }
|
Chris@0
|
292 }
|
Chris@0
|
293
|
Chris@0
|
294 cerr << endl;
|
Chris@0
|
295 exit(0);
|
Chris@0
|
296 }
|
Chris@0
|
297
|
Chris@0
|
298 void
|
Chris@0
|
299 listTransforms()
|
Chris@0
|
300 {
|
Chris@0
|
301 TransformList transforms =
|
Chris@0
|
302 TransformFactory::getInstance()->getAllTransformDescriptions();
|
Chris@0
|
303
|
Chris@0
|
304 for (TransformList::const_iterator iter = transforms.begin();
|
Chris@0
|
305 iter != transforms.end(); ++iter) {
|
Chris@0
|
306 const TransformDescription &transform = *iter;
|
Chris@0
|
307 if (transform.type == TransformDescription::Analysis) {
|
Chris@0
|
308 cout << transform.identifier.toStdString() << endl;
|
Chris@0
|
309 }
|
Chris@0
|
310 }
|
Chris@0
|
311 }
|
Chris@0
|
312
|
Chris@0
|
313 void
|
Chris@0
|
314 printSkeleton(QString id)
|
Chris@0
|
315 {
|
Chris@0
|
316 Transform transform =
|
Chris@0
|
317 TransformFactory::getInstance()->getDefaultTransformFor(id);
|
Chris@0
|
318 cout << "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> ." << endl
|
Chris@0
|
319 << "@prefix vamp: <http://purl.org/ontology/vamp/> ." << endl
|
Chris@0
|
320 << "@prefix : <#> ." << endl << endl;
|
Chris@0
|
321 QString rdf = RDFTransformFactory::writeTransformToRDF
|
Chris@0
|
322 (transform, ":transform");
|
Chris@0
|
323 cout << rdf.toStdString();
|
Chris@0
|
324 }
|
Chris@0
|
325
|
Chris@0
|
326 void
|
Chris@0
|
327 findSourcesRecursive(QString dirname, QStringList &addTo, int &found)
|
Chris@0
|
328 {
|
Chris@0
|
329 QDir dir(dirname);
|
Chris@0
|
330
|
Chris@0
|
331 QString printable = dir.dirName().left(20);
|
Chris@0
|
332 cerr << "\rScanning \"" << printable.toStdString() << "\"..."
|
Chris@0
|
333 << QString(" ").left(20 - printable.length()).toStdString()
|
Chris@0
|
334 << " [" << found << " audio file(s)]";
|
Chris@0
|
335
|
Chris@0
|
336 QString extensions = AudioFileReaderFactory::getKnownExtensions();
|
Chris@0
|
337 QStringList extlist = extensions.split(" ", QString::SkipEmptyParts);
|
Chris@0
|
338
|
Chris@0
|
339 QStringList files = dir.entryList
|
Chris@0
|
340 (extlist, QDir::Files | QDir::Readable);
|
Chris@0
|
341 for (int i = 0; i < files.size(); ++i) {
|
Chris@0
|
342 addTo.push_back(dir.filePath(files[i]));
|
Chris@0
|
343 ++found;
|
Chris@0
|
344 }
|
Chris@0
|
345
|
Chris@0
|
346 QStringList subdirs = dir.entryList
|
Chris@0
|
347 (QStringList(), QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
Chris@0
|
348 for (int i = 0; i < subdirs.size(); ++i) {
|
Chris@0
|
349 findSourcesRecursive(dir.filePath(subdirs[i]), addTo, found);
|
Chris@0
|
350 }
|
Chris@0
|
351 }
|
Chris@0
|
352
|
Chris@111
|
353 QStringList
|
Chris@111
|
354 expandPlaylists(QStringList sources)
|
Chris@111
|
355 {
|
Chris@111
|
356 QStringList expanded;
|
Chris@111
|
357 foreach (QString path, sources) {
|
Chris@111
|
358 cerr << "expandPlaylists: looking at " << path << endl;
|
Chris@111
|
359 if (QFileInfo(path).suffix().toLower() == "m3u") {
|
Chris@111
|
360 ProgressPrinter retrievalProgress("Opening playlist file...");
|
Chris@111
|
361 FileSource source(path, &retrievalProgress);
|
Chris@111
|
362 if (!source.isAvailable()) {
|
Chris@111
|
363 cerr << "ERROR: File or URL \"" << path.toStdString()
|
Chris@111
|
364 << "\" could not be located" << endl;
|
Chris@111
|
365 throw FileNotFound(path);
|
Chris@111
|
366 }
|
Chris@111
|
367 source.waitForData();
|
Chris@111
|
368 PlaylistFileReader reader(source);
|
Chris@111
|
369 if (reader.isOK()) {
|
Chris@111
|
370 vector<QString> files = reader.load();
|
Chris@111
|
371 for (int i = 0; i < (int)files.size(); ++i) {
|
Chris@111
|
372 expanded.push_back(files[i]);
|
Chris@111
|
373 }
|
Chris@111
|
374 }
|
Chris@111
|
375 } else {
|
Chris@111
|
376 // not a playlist
|
Chris@111
|
377 expanded.push_back(path);
|
Chris@111
|
378 }
|
Chris@111
|
379 }
|
Chris@111
|
380 return expanded;
|
Chris@111
|
381 }
|
Chris@0
|
382
|
Chris@0
|
383 int main(int argc, char **argv)
|
Chris@0
|
384 {
|
Chris@0
|
385 QCoreApplication application(argc, argv);
|
Chris@0
|
386
|
Chris@0
|
387 QCoreApplication::setOrganizationName("QMUL");
|
Chris@0
|
388 QCoreApplication::setOrganizationDomain("qmul.ac.uk");
|
Chris@0
|
389 QCoreApplication::setApplicationName("Sonic Annotator");
|
Chris@0
|
390
|
Chris@0
|
391 QStringList args = application.arguments();
|
Chris@0
|
392 set<string> requestedWriterTags;
|
Chris@0
|
393 set<string> requestedTransformFiles;
|
Chris@0
|
394 set<string> requestedTransformListFiles;
|
Chris@0
|
395 set<string> requestedDefaultTransforms;
|
Chris@0
|
396 set<string> requestedSummaryTypes;
|
Chris@21
|
397 bool force = false;
|
Chris@0
|
398 //!!! bool multiplex = false;
|
Chris@0
|
399 bool recursive = false;
|
Chris@0
|
400 bool list = false;
|
Chris@0
|
401 bool summaryOnly = false;
|
Chris@0
|
402 QString skeletonFor = "";
|
Chris@0
|
403 QString myname = args[0];
|
Chris@0
|
404 myname = QFileInfo(myname).baseName();
|
Chris@0
|
405 QStringList otherArgs;
|
Chris@0
|
406 Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries boundaries;
|
Chris@0
|
407
|
Chris@0
|
408 QString helpStr = myname + ": use -h or --help option for help";
|
Chris@0
|
409
|
Chris@0
|
410 for (int i = 1; i < args.size(); ++i) {
|
Chris@0
|
411
|
Chris@0
|
412 QString arg = args[i];
|
Chris@0
|
413 bool last = ((i + 1) == args.size());
|
Chris@0
|
414
|
Chris@0
|
415 if (arg == "-h" || arg == "--help" || arg == "-?") {
|
Chris@0
|
416 usage(myname);
|
Chris@0
|
417 }
|
Chris@0
|
418
|
Chris@46
|
419 if (arg == "-v" || arg == "--version") {
|
Chris@46
|
420 std::cout << RUNNER_VERSION << std::endl;
|
Chris@46
|
421 return 0;
|
Chris@46
|
422 }
|
Chris@46
|
423
|
Chris@0
|
424 if (arg == "-w" || arg == "--writer") {
|
Chris@0
|
425 if (last || args[i+1].startsWith("-")) {
|
Chris@0
|
426 cerr << myname.toStdString() << ": argument expected for \""
|
Chris@0
|
427 << arg.toStdString() << "\" option" << endl;
|
Chris@0
|
428 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
429 exit(2);
|
Chris@0
|
430 } else {
|
Chris@0
|
431 string tag = args[++i].toStdString();
|
Chris@0
|
432 if (requestedWriterTags.find(tag) != requestedWriterTags.end()) {
|
Chris@0
|
433 cerr << myname.toStdString() << ": NOTE: duplicate specification of writer type \"" << tag << "\" ignored" << endl;
|
Chris@0
|
434 } else {
|
Chris@0
|
435 requestedWriterTags.insert(tag);
|
Chris@0
|
436 }
|
Chris@0
|
437 continue;
|
Chris@0
|
438 }
|
Chris@0
|
439 } else if (arg == "-t" || arg == "--transform") {
|
Chris@0
|
440 if (last || args[i+1].startsWith("-")) {
|
Chris@0
|
441 cerr << myname.toStdString() << ": argument expected for \""
|
Chris@0
|
442 << arg.toStdString() << "\" option" << endl;
|
Chris@0
|
443 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
444 exit(2);
|
Chris@0
|
445 } else {
|
Chris@0
|
446 string transform = args[++i].toStdString();
|
Chris@0
|
447 if (requestedTransformFiles.find(transform) !=
|
Chris@0
|
448 requestedTransformFiles.end()) {
|
Chris@0
|
449 cerr << myname.toStdString() << ": NOTE: duplicate specification of transform file \"" << transform << "\" ignored" << endl;
|
Chris@0
|
450 } else {
|
Chris@0
|
451 requestedTransformFiles.insert(transform);
|
Chris@0
|
452 }
|
Chris@0
|
453 continue;
|
Chris@0
|
454 }
|
Chris@0
|
455 } else if (arg == "-T" || arg == "--transforms") {
|
Chris@0
|
456 if (last || args[i+1].startsWith("-")) {
|
Chris@0
|
457 cerr << myname.toStdString() << ": argument expected for \""
|
Chris@0
|
458 << arg.toStdString() << "\" option" << endl;
|
Chris@0
|
459 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
460 exit(2);
|
Chris@0
|
461 } else {
|
Chris@0
|
462 string transform = args[++i].toStdString();
|
Chris@0
|
463 if (requestedTransformListFiles.find(transform) !=
|
Chris@0
|
464 requestedTransformListFiles.end()) {
|
Chris@0
|
465 cerr << myname.toStdString() << ": NOTE: duplicate specification of transform list file \"" << transform << "\" ignored" << endl;
|
Chris@0
|
466 } else {
|
Chris@0
|
467 requestedTransformListFiles.insert(transform);
|
Chris@0
|
468 }
|
Chris@0
|
469 continue;
|
Chris@0
|
470 }
|
Chris@0
|
471 } else if (arg == "-d" || arg == "--default") {
|
Chris@0
|
472 if (last || args[i+1].startsWith("-")) {
|
Chris@0
|
473 cerr << myname.toStdString() << ": argument expected for \""
|
Chris@0
|
474 << arg.toStdString() << "\" option" << endl;
|
Chris@0
|
475 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
476 exit(2);
|
Chris@0
|
477 } else {
|
Chris@0
|
478 string deft = args[++i].toStdString();
|
Chris@0
|
479 if (requestedDefaultTransforms.find(deft) !=
|
Chris@0
|
480 requestedDefaultTransforms.end()) {
|
Chris@0
|
481 cerr << myname.toStdString() << ": NOTE: duplicate specification of default transform \"" << deft << "\" ignored" << endl;
|
Chris@0
|
482 } else {
|
Chris@0
|
483 requestedDefaultTransforms.insert(deft);
|
Chris@0
|
484 }
|
Chris@0
|
485 continue;
|
Chris@0
|
486 }
|
Chris@0
|
487 } else if (arg == "-S" || arg == "--summary") {
|
Chris@0
|
488 if (last || args[i+1].startsWith("-")) {
|
Chris@0
|
489 cerr << myname.toStdString() << ": argument expected for \""
|
Chris@0
|
490 << arg.toStdString() << "\" option" << endl;
|
Chris@0
|
491 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
492 exit(2);
|
Chris@0
|
493 } else {
|
Chris@0
|
494 string summary = args[++i].toStdString();
|
Chris@0
|
495 requestedSummaryTypes.insert(summary);
|
Chris@0
|
496 continue;
|
Chris@0
|
497 }
|
Chris@0
|
498 } else if (arg == "--summary-only") {
|
Chris@0
|
499 summaryOnly = true;
|
Chris@0
|
500 continue;
|
Chris@0
|
501 } else if (arg == "--segments") {
|
Chris@0
|
502 if (last) {
|
Chris@0
|
503 cerr << myname.toStdString() << ": argument expected for \""
|
Chris@0
|
504 << arg.toStdString() << "\" option" << endl;
|
Chris@0
|
505 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
506 exit(2);
|
Chris@0
|
507 } else {
|
Chris@0
|
508 string segmentSpec = args[++i].toStdString();
|
Chris@0
|
509 QStringList segmentStrs = QString(segmentSpec.c_str()).split(',');
|
Chris@0
|
510 for (int j = 0; j < segmentStrs.size(); ++j) {
|
Chris@0
|
511 bool good = false;
|
Chris@0
|
512 boundaries.insert(Vamp::RealTime::fromSeconds
|
Chris@0
|
513 (segmentStrs[j].toDouble(&good)));
|
Chris@0
|
514 if (!good) {
|
Chris@0
|
515 cerr << myname.toStdString() << ": segment boundaries must be numeric" << endl;
|
Chris@0
|
516 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
517 exit(2);
|
Chris@0
|
518 }
|
Chris@0
|
519 }
|
Chris@0
|
520 }
|
Chris@0
|
521 /*!!!
|
Chris@0
|
522 } else if (arg == "-m" || arg == "--multiplex") {
|
Chris@0
|
523 multiplex = true;
|
Chris@0
|
524 cerr << myname.toStdString()
|
Chris@0
|
525 << ": WARNING: Multiplex argument not yet implemented" << endl; //!!!
|
Chris@0
|
526 continue;
|
Chris@0
|
527 */
|
Chris@0
|
528 } else if (arg == "-r" || arg == "--recursive") {
|
Chris@0
|
529 recursive = true;
|
Chris@0
|
530 continue;
|
Chris@21
|
531 } else if (arg == "-f" || arg == "--force") {
|
Chris@21
|
532 force = true;
|
Chris@21
|
533 continue;
|
Chris@0
|
534 } else if (arg == "-l" || arg == "--list") {
|
Chris@0
|
535 list = true;
|
Chris@0
|
536 continue;
|
Chris@0
|
537 } else if (arg == "-s" || arg == "--skeleton") {
|
Chris@0
|
538 if (last || args[i+1].startsWith("-")) {
|
Chris@0
|
539 cerr << myname.toStdString() << ": usage: "
|
Chris@0
|
540 << myname.toStdString() << " " << arg.toStdString()
|
Chris@0
|
541 << " <transform>" << endl;
|
Chris@0
|
542 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
543 exit(2);
|
Chris@0
|
544 } else {
|
Chris@0
|
545 skeletonFor = args[++i];
|
Chris@0
|
546 continue;
|
Chris@0
|
547 }
|
Chris@0
|
548 } else {
|
Chris@0
|
549 otherArgs.push_back(args[i]);
|
Chris@0
|
550 }
|
Chris@0
|
551 }
|
Chris@0
|
552
|
Chris@0
|
553 if (list) {
|
Chris@0
|
554 if (!requestedWriterTags.empty() || skeletonFor != "") {
|
Chris@0
|
555 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
556 exit(2);
|
Chris@0
|
557 }
|
Chris@0
|
558 listTransforms();
|
Chris@0
|
559 exit(0);
|
Chris@0
|
560 }
|
Chris@0
|
561 if (skeletonFor != "") {
|
Chris@0
|
562 if (!requestedWriterTags.empty()) {
|
Chris@0
|
563 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
564 exit(2);
|
Chris@0
|
565 }
|
Chris@0
|
566 printSkeleton(skeletonFor);
|
Chris@0
|
567 exit(0);
|
Chris@0
|
568 }
|
Chris@0
|
569
|
Chris@0
|
570 if (requestedTransformFiles.empty() &&
|
Chris@0
|
571 requestedTransformListFiles.empty() &&
|
Chris@0
|
572 requestedDefaultTransforms.empty()) {
|
Chris@0
|
573 cerr << myname.toStdString()
|
Chris@0
|
574 << ": no transform(s) specified" << endl;
|
Chris@0
|
575 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
576 exit(2);
|
Chris@0
|
577 }
|
Chris@0
|
578
|
Chris@0
|
579 if (requestedWriterTags.empty()) {
|
Chris@0
|
580 cerr << myname.toStdString()
|
Chris@0
|
581 << ": no writer(s) specified" << endl;
|
Chris@0
|
582 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
583 exit(2);
|
Chris@0
|
584 }
|
Chris@0
|
585
|
Chris@0
|
586 if (!boundaries.empty()) {
|
Chris@0
|
587 if (requestedSummaryTypes.empty()) {
|
Chris@0
|
588 cerr << myname.toStdString()
|
Chris@0
|
589 << ": summary segment boundaries provided, but no summary type specified"
|
Chris@0
|
590 << endl;
|
Chris@0
|
591 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
592 exit(2);
|
Chris@0
|
593 }
|
Chris@0
|
594 }
|
Chris@0
|
595
|
Chris@20
|
596 QSettings settings;
|
Chris@20
|
597
|
Chris@0
|
598 #ifdef HAVE_FFTW3
|
Chris@0
|
599 settings.beginGroup("FFTWisdom");
|
Chris@0
|
600 QString wisdom = settings.value("wisdom").toString();
|
Chris@0
|
601 if (wisdom != "") {
|
Chris@0
|
602 fftw_import_wisdom_from_string(wisdom.toLocal8Bit().data());
|
Chris@0
|
603 }
|
Chris@0
|
604 settings.endGroup();
|
Chris@0
|
605 #endif
|
Chris@0
|
606
|
Chris@20
|
607 settings.beginGroup("RDF");
|
Chris@20
|
608 if (!settings.contains("rdf-indices")) {
|
Chris@20
|
609 QStringList list;
|
Chris@20
|
610 list << "http://www.vamp-plugins.org/rdf/plugins/index.txt";
|
Chris@20
|
611 settings.setValue("rdf-indices", list);
|
Chris@20
|
612 }
|
Chris@20
|
613 settings.endGroup();
|
Chris@20
|
614
|
Chris@0
|
615 FeatureExtractionManager manager;
|
Chris@0
|
616
|
Chris@0
|
617 if (!requestedSummaryTypes.empty()) {
|
Chris@0
|
618 if (!manager.setSummaryTypes(requestedSummaryTypes,
|
Chris@0
|
619 boundaries)) {
|
Chris@0
|
620 cerr << myname.toStdString()
|
Chris@0
|
621 << ": failed to set requested summary types" << endl;
|
Chris@0
|
622 exit(1);
|
Chris@0
|
623 }
|
Chris@0
|
624 }
|
Chris@102
|
625
|
Chris@102
|
626 manager.setSummariesOnly(summaryOnly);
|
Chris@0
|
627
|
Chris@0
|
628 vector<FeatureWriter *> writers;
|
Chris@0
|
629
|
Chris@0
|
630 for (set<string>::const_iterator i = requestedWriterTags.begin();
|
Chris@0
|
631 i != requestedWriterTags.end(); ++i) {
|
Chris@0
|
632
|
Chris@0
|
633 FeatureWriter *writer = FeatureWriterFactory::createWriter(*i);
|
Chris@0
|
634
|
Chris@0
|
635 if (!writer) {
|
Chris@0
|
636 cerr << myname.toStdString() << ": unknown feature writer \""
|
Chris@0
|
637 << *i << "\"" << endl;
|
Chris@0
|
638 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
639 exit(2);
|
Chris@0
|
640 }
|
Chris@0
|
641
|
Chris@0
|
642 map<string, string> writerArgs;
|
Chris@0
|
643 FeatureWriter::ParameterList pl(writer->getSupportedParameters());
|
Chris@0
|
644
|
Chris@95
|
645 for (int k = 0; k < (int)pl.size(); ++k) {
|
Chris@0
|
646
|
Chris@0
|
647 string argbase = pl[k].name;
|
Chris@0
|
648 QString literal = QString("--%1-%2")
|
Chris@0
|
649 .arg(i->c_str()).arg(argbase.c_str());
|
Chris@0
|
650
|
Chris@95
|
651 for (int j = 0; j < (int)otherArgs.size(); ) {
|
Chris@0
|
652
|
Chris@0
|
653 if (otherArgs[j] != literal) {
|
Chris@0
|
654 ++j;
|
Chris@0
|
655 continue;
|
Chris@0
|
656 }
|
Chris@0
|
657
|
Chris@0
|
658 otherArgs.removeAt(j);
|
Chris@0
|
659
|
Chris@0
|
660 if (pl[k].hasArg) {
|
Chris@0
|
661 if (j < otherArgs.size()) {
|
Chris@0
|
662 writerArgs[argbase] = otherArgs[j].toStdString();
|
Chris@0
|
663 otherArgs.removeAt(j);
|
Chris@0
|
664 } else {
|
Chris@0
|
665 cerr << myname.toStdString() << ": "
|
Chris@0
|
666 << "argument required for \""
|
Chris@0
|
667 << literal.toStdString() << "\" option"
|
Chris@0
|
668 << endl;
|
Chris@0
|
669 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
670 exit(2);
|
Chris@0
|
671 }
|
Chris@0
|
672 } else {
|
Chris@0
|
673 writerArgs[argbase] = "";
|
Chris@0
|
674 }
|
Chris@0
|
675 }
|
Chris@0
|
676 }
|
Chris@0
|
677
|
Chris@0
|
678 writer->setParameters(writerArgs);
|
Chris@0
|
679
|
Chris@0
|
680 writers.push_back(writer);
|
Chris@0
|
681 }
|
Chris@0
|
682
|
Chris@0
|
683 for (int i = 0; i < otherArgs.size(); ++i) {
|
Chris@0
|
684 if (otherArgs[i].startsWith("-")) {
|
Chris@0
|
685 cerr << myname.toStdString() << ": unknown option \""
|
Chris@0
|
686 << otherArgs[i].toStdString() << "\"" << endl;
|
Chris@0
|
687 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
688 exit(2);
|
Chris@0
|
689 }
|
Chris@0
|
690 }
|
Chris@0
|
691
|
Chris@0
|
692 if (otherArgs.empty()) {
|
Chris@0
|
693 cerr << myname.toStdString() << ": no input(s) specified" << endl;
|
Chris@0
|
694 cerr << helpStr.toStdString() << endl;
|
Chris@0
|
695 exit(2);
|
Chris@0
|
696 }
|
Chris@0
|
697
|
Chris@0
|
698 for (set<string>::const_iterator i = requestedTransformListFiles.begin();
|
Chris@0
|
699 i != requestedTransformListFiles.end(); ++i) {
|
Chris@0
|
700 PlaylistFileReader reader(i->c_str());
|
Chris@0
|
701 if (reader.isOK()) {
|
Chris@0
|
702 vector<QString> files = reader.load();
|
Chris@95
|
703 for (int j = 0; j < (int)files.size(); ++j) {
|
Chris@0
|
704 requestedTransformFiles.insert(files[j].toStdString());
|
Chris@0
|
705 }
|
Chris@0
|
706 } else {
|
Chris@0
|
707 cerr << myname.toStdString() << ": failed to read template list file \"" << *i << "\"" << endl;
|
Chris@0
|
708 exit(2);
|
Chris@0
|
709 }
|
Chris@0
|
710 }
|
Chris@0
|
711
|
Chris@0
|
712 QStringList sources;
|
Chris@0
|
713 if (!recursive) {
|
Chris@0
|
714 sources = otherArgs;
|
Chris@0
|
715 } else {
|
Chris@0
|
716 for (QStringList::const_iterator i = otherArgs.begin();
|
Chris@0
|
717 i != otherArgs.end(); ++i) {
|
Chris@0
|
718 if (QDir(*i).exists()) {
|
Chris@0
|
719 cerr << "Directory found and recursive flag set, scanning for audio files..." << endl;
|
Chris@0
|
720 int found = 0;
|
Chris@0
|
721 findSourcesRecursive(*i, sources, found);
|
Chris@0
|
722 cerr << "\rDone, found " << found << " supported audio file(s) " << endl;
|
Chris@0
|
723 } else {
|
Chris@0
|
724 sources.push_back(*i);
|
Chris@0
|
725 }
|
Chris@0
|
726 }
|
Chris@0
|
727 }
|
Chris@0
|
728
|
Chris@111
|
729 sources = expandPlaylists(sources);
|
Chris@111
|
730
|
Chris@28
|
731 bool good = true;
|
Chris@45
|
732 QSet<QString> badSources;
|
Chris@28
|
733
|
Chris@0
|
734 for (QStringList::const_iterator i = sources.begin();
|
Chris@0
|
735 i != sources.end(); ++i) {
|
Chris@0
|
736 try {
|
Chris@45
|
737 manager.addSource(*i);
|
Chris@22
|
738 } catch (const std::exception &e) {
|
Chris@45
|
739 badSources.insert(*i);
|
Chris@21
|
740 cerr << "ERROR: Failed to process file \"" << i->toStdString()
|
Chris@21
|
741 << "\": " << e.what() << endl;
|
Chris@22
|
742 if (force) {
|
Chris@22
|
743 // print a note only if we have more files to process
|
Chris@22
|
744 QStringList::const_iterator j = i;
|
Chris@22
|
745 if (++j != sources.end()) {
|
Chris@22
|
746 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
|
Chris@22
|
747 }
|
Chris@22
|
748 } else {
|
Chris@45
|
749 cerr << "NOTE: If you want to continue with processing any further files after an" << endl
|
Chris@45
|
750 << "error like this, use the --force option" << endl;
|
Chris@28
|
751 good = false;
|
Chris@22
|
752 break;
|
Chris@22
|
753 }
|
Chris@0
|
754 }
|
Chris@0
|
755 }
|
Chris@45
|
756
|
Chris@45
|
757 if (good) {
|
Chris@45
|
758
|
Chris@45
|
759 bool haveFeatureExtractor = false;
|
Chris@45
|
760
|
Chris@45
|
761 for (set<string>::const_iterator i = requestedTransformFiles.begin();
|
Chris@45
|
762 i != requestedTransformFiles.end(); ++i) {
|
Chris@45
|
763 if (manager.addFeatureExtractorFromFile(i->c_str(), writers)) {
|
Chris@45
|
764 haveFeatureExtractor = true;
|
Chris@45
|
765 }
|
Chris@45
|
766 }
|
Chris@45
|
767
|
Chris@45
|
768 for (set<string>::const_iterator i = requestedDefaultTransforms.begin();
|
Chris@45
|
769 i != requestedDefaultTransforms.end(); ++i) {
|
Chris@45
|
770 if (manager.addDefaultFeatureExtractor(i->c_str(), writers)) {
|
Chris@45
|
771 haveFeatureExtractor = true;
|
Chris@45
|
772 }
|
Chris@45
|
773 }
|
Chris@45
|
774
|
Chris@45
|
775 if (!haveFeatureExtractor) {
|
Chris@45
|
776 cerr << myname.toStdString() << ": no feature extractors added" << endl;
|
Chris@45
|
777 good = false;
|
Chris@45
|
778 }
|
Chris@45
|
779 }
|
Chris@45
|
780
|
Chris@45
|
781 if (good) {
|
Chris@45
|
782 for (QStringList::const_iterator i = sources.begin();
|
Chris@45
|
783 i != sources.end(); ++i) {
|
Chris@45
|
784 if (badSources.contains(*i)) continue;
|
Chris@45
|
785 std::cerr << "Extracting features for: \"" << i->toStdString() << "\"" << std::endl;
|
Chris@45
|
786 try {
|
Chris@47
|
787 manager.extractFeatures(*i, force);
|
Chris@45
|
788 } catch (const std::exception &e) {
|
Chris@45
|
789 cerr << "ERROR: Feature extraction failed for \"" << i->toStdString()
|
Chris@45
|
790 << "\": " << e.what() << endl;
|
Chris@45
|
791 if (force) {
|
Chris@45
|
792 // print a note only if we have more files to process
|
Chris@45
|
793 QStringList::const_iterator j = i;
|
Chris@45
|
794 if (++j != sources.end()) {
|
Chris@45
|
795 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
|
Chris@45
|
796 }
|
Chris@45
|
797 } else {
|
Chris@45
|
798 cerr << "NOTE: If you want to continue with processing any further files after an" << endl
|
Chris@45
|
799 << "error like this, use the --force option" << endl;
|
Chris@45
|
800 good = false;
|
Chris@45
|
801 break;
|
Chris@45
|
802 }
|
Chris@45
|
803 }
|
Chris@45
|
804 }
|
Chris@45
|
805 }
|
Chris@0
|
806
|
Chris@95
|
807 for (int i = 0; i < (int)writers.size(); ++i) delete writers[i];
|
Chris@0
|
808
|
Chris@0
|
809 #ifdef HAVE_FFTW3
|
Chris@0
|
810 settings.beginGroup("FFTWisdom");
|
Chris@0
|
811 char *cwisdom = fftw_export_wisdom_to_string();
|
Chris@0
|
812 if (cwisdom) {
|
Chris@0
|
813 settings.setValue("wisdom", cwisdom);
|
Chris@0
|
814 fftw_free(cwisdom);
|
Chris@0
|
815 }
|
Chris@0
|
816 settings.endGroup();
|
Chris@0
|
817 #endif
|
Chris@0
|
818
|
Chris@0
|
819 TempDirectory::getInstance()->cleanup();
|
Chris@0
|
820
|
Chris@28
|
821 if (good) return 0;
|
Chris@28
|
822 else return 1;
|
Chris@0
|
823 }
|
Chris@0
|
824
|
Chris@0
|
825
|