OSDN Git Service

Merge branch 'master' of github.com:lordmulder/LameXP
[lamexp/LameXP.git] / src / Registry_Decoder.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Registry_Decoder.h"
23
24 #include "Decoder_AAC.h"
25 #include "Decoder_AC3.h"
26 #include "Decoder_ADPCM.h"
27 #include "Decoder_ALAC.h"
28 #include "Decoder_Avisynth.h"
29 #include "Decoder_FLAC.h"
30 #include "Decoder_MAC.h"
31 #include "Decoder_MP3.h"
32 #include "Decoder_Musepack.h"
33 #include "Decoder_Shorten.h"
34 #include "Decoder_Speex.h"
35 #include "Decoder_TTA.h"
36 #include "Decoder_Vorbis.h"
37 #include "Decoder_Wave.h"
38 #include "Decoder_WavPack.h"
39 #include "Decoder_Opus.h"
40 #include "Decoder_WMA.h"
41 #include "PlaylistImporter.h"
42
43 #include <QString>
44 #include <QStringList>
45 #include <QRegExp>
46
47 #define PROBE_DECODER(DEC) if(DEC::isDecoderAvailable() && DEC::isFormatSupported(containerType, containerProfile, formatType, formatProfile, formatVersion)) { return new DEC(); }
48 #define GET_FILETYPES(DEC) (DEC::isDecoderAvailable() ? DEC::supportedTypes() : QStringList())
49
50 AbstractDecoder *DecoderRegistry::lookup(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
51 {
52         PROBE_DECODER(MP3Decoder);
53         PROBE_DECODER(VorbisDecoder);
54         PROBE_DECODER(AACDecoder);
55         PROBE_DECODER(AC3Decoder);
56         PROBE_DECODER(FLACDecoder);
57         PROBE_DECODER(WavPackDecoder);
58         PROBE_DECODER(MusepackDecoder);
59         PROBE_DECODER(ShortenDecoder);
60         PROBE_DECODER(MACDecoder);
61         PROBE_DECODER(TTADecoder);
62         PROBE_DECODER(SpeexDecoder);
63         PROBE_DECODER(ALACDecoder);
64         PROBE_DECODER(WMADecoder);
65         PROBE_DECODER(ADPCMDecoder);
66         PROBE_DECODER(WaveDecoder);
67         PROBE_DECODER(OpusDecoder);
68         PROBE_DECODER(AvisynthDecoder);
69         
70         return NULL;
71 }
72
73 QStringList DecoderRegistry::getSupportedTypes(void)
74 {
75         QStringList types;
76
77         types << GET_FILETYPES(WaveDecoder);
78         types << GET_FILETYPES(MP3Decoder);
79         types << GET_FILETYPES(VorbisDecoder);
80         types << GET_FILETYPES(AACDecoder);
81         types << GET_FILETYPES(AC3Decoder);
82         types << GET_FILETYPES(FLACDecoder);
83         types << GET_FILETYPES(WavPackDecoder);
84         types << GET_FILETYPES(MusepackDecoder);
85         types << GET_FILETYPES(ShortenDecoder);
86         types << GET_FILETYPES(MACDecoder);
87         types << GET_FILETYPES(TTADecoder);
88         types << GET_FILETYPES(SpeexDecoder);
89         types << GET_FILETYPES(ALACDecoder);
90         types << GET_FILETYPES(WMADecoder);
91         types << GET_FILETYPES(ADPCMDecoder);
92         types << GET_FILETYPES(OpusDecoder);
93         types << GET_FILETYPES(AvisynthDecoder);
94
95         QStringList extensions;
96         extensions << QString(PlaylistImporter::supportedExtensions).split(" ", QString::SkipEmptyParts);
97         QRegExp regExp("\\((.+)\\)", Qt::CaseInsensitive);
98
99         for(int i = 0; i < types.count(); i++)
100         {
101                 if(regExp.lastIndexIn(types.at(i)) >= 0)
102                 {
103                         extensions << regExp.cap(1).split(" ", QString::SkipEmptyParts);
104                 }
105         }
106
107         if(!extensions.empty())
108         {
109                 extensions.removeDuplicates();
110                 extensions.sort();
111                 types.prepend(QString("%1 (%2)").arg(tr("All supported types"), extensions.join(" ")));
112         }
113         
114         types << QString("%1 (%2)").arg(tr("Playlists"), PlaylistImporter::supportedExtensions);
115         types << QString("%1 (*.*)").arg(tr("All files"));
116
117         return types;
118 }