1 /***************************************************************************
2 copyright : (C) 2002 - 2008 by Scott Wheeler
3 email : wheeler@kde.org
4 ***************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
37 #include "vorbisfile.h"
39 #include "oggflacfile.h"
42 #include "wavpackfile.h"
43 #include "speexfile.h"
44 #include "trueaudiofile.h"
48 using namespace TagLib;
50 class FileRef::FileRefPrivate : public RefCounter
53 FileRefPrivate(File *f) : RefCounter(), file(f) {}
59 static List<const FileTypeResolver *> fileTypeResolvers;
62 List<const FileRef::FileTypeResolver *> FileRef::FileRefPrivate::fileTypeResolvers;
64 ////////////////////////////////////////////////////////////////////////////////
66 ////////////////////////////////////////////////////////////////////////////////
70 d = new FileRefPrivate(0);
73 FileRef::FileRef(FileName fileName, bool readAudioProperties,
74 AudioProperties::ReadStyle audioPropertiesStyle)
76 d = new FileRefPrivate(create(fileName, readAudioProperties, audioPropertiesStyle));
79 FileRef::FileRef(File *file)
81 d = new FileRefPrivate(file);
84 FileRef::FileRef(const FileRef &ref) : d(ref.d)
95 Tag *FileRef::tag() const
98 debug("FileRef::tag() - Called without a valid file.");
101 return d->file->tag();
104 AudioProperties *FileRef::audioProperties() const
107 debug("FileRef::audioProperties() - Called without a valid file.");
110 return d->file->audioProperties();
113 File *FileRef::file() const
121 debug("FileRef::save() - Called without a valid file.");
124 return d->file->save();
127 const FileRef::FileTypeResolver *FileRef::addFileTypeResolver(const FileRef::FileTypeResolver *resolver) // static
129 FileRefPrivate::fileTypeResolvers.prepend(resolver);
133 StringList FileRef::defaultFileExtensions()
145 #ifdef TAGLIB_WITH_MP4
152 #ifdef TAGLIB_WITH_ASF
163 bool FileRef::isNull() const
165 return !d->file || !d->file->isValid();
168 FileRef &FileRef::operator=(const FileRef &ref)
182 bool FileRef::operator==(const FileRef &ref) const
184 return ref.d->file == d->file;
187 bool FileRef::operator!=(const FileRef &ref) const
189 return ref.d->file != d->file;
192 File *FileRef::create(FileName fileName, bool readAudioProperties,
193 AudioProperties::ReadStyle audioPropertiesStyle) // static
196 List<const FileTypeResolver *>::ConstIterator it = FileRefPrivate::fileTypeResolvers.begin();
198 for(; it != FileRefPrivate::fileTypeResolvers.end(); ++it) {
199 File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle);
204 // Ok, this is really dumb for now, but it works for testing.
209 s = (wcslen((const wchar_t *) fileName) > 0) ? String((const wchar_t *) fileName) : String((const char *) fileName);
214 // If this list is updated, the method defaultFileExtensions() should also be
215 // updated. However at some point that list should be created at the same time
216 // that a default file type resolver is created.
218 int pos = s.rfind(".");
220 String ext = s.substr(pos + 1).upper();
222 return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle);
224 return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
226 /* .oga can be any audio in the Ogg container. First try FLAC, then Vorbis. */
227 File *file = new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
231 return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
234 return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
236 return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
238 return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
240 return new Ogg::Speex::File(fileName, readAudioProperties, audioPropertiesStyle);
242 return new TrueAudio::File(fileName, readAudioProperties, audioPropertiesStyle);
243 #ifdef TAGLIB_WITH_MP4
244 if(ext == "M4A" || ext == "M4B" || ext == "M4P" || ext == "MP4" || ext == "3G2")
245 return new MP4::File(fileName, readAudioProperties, audioPropertiesStyle);
247 #ifdef TAGLIB_WITH_ASF
248 if(ext == "WMA" || ext == "ASF")
249 return new ASF::File(fileName, readAudioProperties, audioPropertiesStyle);
252 return new RIFF::AIFF::File(fileName, readAudioProperties, audioPropertiesStyle);
254 return new RIFF::WAV::File(fileName, readAudioProperties, audioPropertiesStyle);
256 return new RIFF::AIFF::File(fileName, readAudioProperties, audioPropertiesStyle);