Chris@235
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@235
|
2
|
Chris@235
|
3 /*
|
Chris@235
|
4 Sonic Visualiser
|
Chris@235
|
5 An audio file viewer and annotation editor.
|
Chris@235
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@235
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@235
|
8
|
Chris@235
|
9 This program is free software; you can redistribute it and/or
|
Chris@235
|
10 modify it under the terms of the GNU General Public License as
|
Chris@235
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@235
|
12 License, or (at your option) any later version. See the file
|
Chris@235
|
13 COPYING included with this distribution for more information.
|
Chris@235
|
14 */
|
Chris@235
|
15
|
Chris@235
|
16 #include "AudioFileReaderFactory.h"
|
Chris@235
|
17
|
Chris@235
|
18 #include "WavFileReader.h"
|
Chris@235
|
19 #include "OggVorbisFileReader.h"
|
Chris@235
|
20 #include "MP3FileReader.h"
|
Chris@235
|
21
|
Chris@235
|
22 #include <QString>
|
Chris@235
|
23 #include <iostream>
|
Chris@235
|
24
|
Chris@235
|
25 QString
|
Chris@235
|
26 AudioFileReaderFactory::getKnownExtensions()
|
Chris@235
|
27 {
|
Chris@235
|
28 std::set<QString> extensions;
|
Chris@235
|
29
|
Chris@235
|
30 WavFileReader::getSupportedExtensions(extensions);
|
Chris@235
|
31 #ifdef HAVE_MAD
|
Chris@235
|
32 MP3FileReader::getSupportedExtensions(extensions);
|
Chris@235
|
33 #endif
|
Chris@235
|
34 #ifdef HAVE_OGGZ
|
Chris@235
|
35 #ifdef HAVE_FISHSOUND
|
Chris@235
|
36 OggVorbisFileReader::getSupportedExtensions(extensions);
|
Chris@235
|
37 #endif
|
Chris@235
|
38 #endif
|
Chris@235
|
39
|
Chris@235
|
40 QString rv;
|
Chris@235
|
41 for (std::set<QString>::const_iterator i = extensions.begin();
|
Chris@235
|
42 i != extensions.end(); ++i) {
|
Chris@235
|
43 if (i != extensions.begin()) rv += " ";
|
Chris@235
|
44 rv += "*." + *i;
|
Chris@235
|
45 }
|
Chris@235
|
46
|
Chris@235
|
47 return rv;
|
Chris@235
|
48 }
|
Chris@235
|
49
|
Chris@235
|
50 AudioFileReader *
|
Chris@235
|
51 AudioFileReaderFactory::createReader(QString path)
|
Chris@235
|
52 {
|
Chris@235
|
53 QString err;
|
Chris@235
|
54
|
Chris@235
|
55 AudioFileReader *reader = 0;
|
Chris@235
|
56
|
Chris@235
|
57 reader = new WavFileReader(path);
|
Chris@235
|
58 if (reader->isOK()) return reader;
|
Chris@235
|
59 if (reader->getError() != "") err = reader->getError();
|
Chris@235
|
60 delete reader;
|
Chris@235
|
61
|
Chris@235
|
62 if (err != "") {
|
Chris@235
|
63 std::cerr << "AudioFileReaderFactory: WAV file reader error: \""
|
Chris@235
|
64 << err.toStdString() << "\"" << std::endl;
|
Chris@235
|
65 }
|
Chris@235
|
66
|
Chris@235
|
67
|
Chris@235
|
68 #ifdef HAVE_OGGZ
|
Chris@235
|
69 #ifdef HAVE_FISHSOUND
|
Chris@235
|
70 reader = new OggVorbisFileReader(path, true,
|
Chris@235
|
71 OggVorbisFileReader::CacheInTemporaryFile);
|
Chris@235
|
72 if (reader->isOK()) return reader;
|
Chris@235
|
73 if (reader->getError() != "") err = reader->getError();
|
Chris@235
|
74 delete reader;
|
Chris@235
|
75
|
Chris@235
|
76 if (err != "") {
|
Chris@235
|
77 std::cerr << "AudioFileReaderFactory: Ogg file reader error: \""
|
Chris@235
|
78 << err.toStdString() << "\"" << std::endl;
|
Chris@235
|
79 }
|
Chris@235
|
80
|
Chris@235
|
81 #endif
|
Chris@235
|
82 #endif
|
Chris@235
|
83
|
Chris@235
|
84 #ifdef HAVE_MAD
|
Chris@235
|
85 reader = new MP3FileReader(path, true,
|
Chris@235
|
86 MP3FileReader::CacheInTemporaryFile);
|
Chris@235
|
87 if (reader->isOK()) return reader;
|
Chris@235
|
88 if (reader->getError() != "") err = reader->getError();
|
Chris@235
|
89 delete reader;
|
Chris@235
|
90
|
Chris@235
|
91 if (err != "") {
|
Chris@235
|
92 std::cerr << "AudioFileReaderFactory: mp3 file reader error: \""
|
Chris@235
|
93 << err.toStdString() << "\"" << std::endl;
|
Chris@235
|
94 }
|
Chris@235
|
95
|
Chris@235
|
96 #endif
|
Chris@235
|
97
|
Chris@235
|
98 return 0;
|
Chris@235
|
99 }
|
Chris@235
|
100
|