1 /*************************************************************************** 2 copyright : (C) 2004 by Allan Sandfeld Jensen 3 email : kde@carewolf.org 4 ***************************************************************************/ 5 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. * 10 * * 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. * 15 * * 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., 51 Franklin Street, Fifth Floor, Boston, MA * 19 * 02110-1301 USA * 20 * * 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 ***************************************************************************/ 25 26 #ifndef TAGLIB_OGGFLACFILE_H 27 #define TAGLIB_OGGFLACFILE_H 28 29 #include "taglib_export.h" 30 #include "oggfile.h" 31 #include "xiphcomment.h" 32 33 #include "flacproperties.h" 34 35 namespace TagLib { 36 37 class Tag; 38 39 namespace Ogg { 40 41 //! An implementation of Ogg FLAC metadata 42 43 /*! 44 * This is implementation of FLAC metadata for Ogg FLAC files. For "pure" 45 * FLAC files look under the FLAC hierarchy. 46 * 47 * Unlike "pure" FLAC-files, Ogg FLAC only supports Xiph-comments, 48 * while the audio-properties are the same. 49 */ 50 namespace FLAC { 51 52 using TagLib::FLAC::Properties; 53 54 //! An implementation of TagLib::File with Ogg/FLAC specific methods 55 56 /*! 57 * This implements and provides an interface for Ogg/FLAC files to the 58 * TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing 59 * the abstract TagLib::File API as well as providing some additional 60 * information specific to Ogg FLAC files. 61 */ 62 63 class TAGLIB_EXPORT File : public Ogg::File 64 { 65 public: 66 /*! 67 * Constructs an Ogg/FLAC file from \a file. If \a readProperties is true 68 * the file's audio properties will also be read. 69 * 70 * \note In the current implementation, \a propertiesStyle is ignored. 71 */ 72 File(FileName file, bool readProperties = true, 73 Properties::ReadStyle propertiesStyle = Properties::Average); 74 75 /*! 76 * Constructs an Ogg/FLAC file from \a stream. If \a readProperties is true 77 * the file's audio properties will also be read. 78 * 79 * \note TagLib will *not* take ownership of the stream, the caller is 80 * responsible for deleting it after the File object. 81 * 82 * \note In the current implementation, \a propertiesStyle is ignored. 83 */ 84 File(IOStream *stream, bool readProperties = true, 85 Properties::ReadStyle propertiesStyle = Properties::Average); 86 87 /*! 88 * Destroys this instance of the File. 89 */ 90 virtual ~File(); 91 92 /*! 93 * Returns the Tag for this file. This will always be a XiphComment. 94 * 95 * \note This always returns a valid pointer regardless of whether or not 96 * the file on disk has a XiphComment. Use hasXiphComment() to check if 97 * the file on disk actually has a XiphComment. 98 * 99 * \note The Tag <b>is still</b> owned by the FLAC::File and should not be 100 * deleted by the user. It will be deleted when the file (object) is 101 * destroyed. 102 * 103 * \see hasXiphComment() 104 */ 105 virtual XiphComment *tag() const; 106 107 /*! 108 * Returns the FLAC::Properties for this file. If no audio properties 109 * were read then this will return a null pointer. 110 */ 111 virtual Properties *audioProperties() const; 112 113 114 /*! 115 * Implements the unified property interface -- export function. 116 * This forwards directly to XiphComment::properties(). 117 */ 118 PropertyMap properties() const; 119 120 /*! 121 * Implements the unified tag dictionary interface -- import function. 122 * Like properties(), this is a forwarder to the file's XiphComment. 123 */ 124 PropertyMap setProperties(const PropertyMap &); 125 126 127 /*! 128 * Save the file. This will primarily save and update the XiphComment. 129 * Returns true if the save is successful. 130 */ 131 virtual bool save(); 132 133 /*! 134 * Returns the length of the audio-stream, used by FLAC::Properties for 135 * calculating the bitrate. 136 */ 137 long streamLength(); 138 139 /*! 140 * Returns whether or not the file on disk actually has a XiphComment. 141 * 142 * \see tag() 143 */ 144 bool hasXiphComment() const; 145 146 /*! 147 * Check if the given \a stream can be opened as an Ogg FLAC file. 148 * 149 * \note This method is designed to do a quick check. The result may 150 * not necessarily be correct. 151 */ 152 static bool isSupported(IOStream *stream); 153 154 private: 155 File(const File &); 156 File &operator=(const File &); 157 158 void read(bool readProperties, Properties::ReadStyle propertiesStyle); 159 void scan(); 160 ByteVector streamInfoData(); 161 ByteVector xiphCommentData(); 162 163 class FilePrivate; 164 FilePrivate *d; 165 }; 166 } // namespace FLAC 167 } // namespace Ogg 168 } // namespace TagLib 169 170 #endif 171