mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
WavPack support.
CCBUG:114982 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@733568 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
b83bf359fc
commit
5a495c5c11
@ -6,7 +6,9 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/ogg/flac
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/flac
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpeg/id3v2 )
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpeg/id3v2
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/wavpack
|
||||
)
|
||||
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/taglib_c.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib_c.pc )
|
||||
|
@ -8,6 +8,7 @@ INCLUDES = \
|
||||
-I$(top_srcdir)/taglib/flac \
|
||||
-I$(top_srcdir)/taglib/mpc \
|
||||
-I$(top_srcdir)/taglib/mpeg/id3v2 \
|
||||
-I$(top_srcdir)/taglib/wavpack \
|
||||
$(all_includes)
|
||||
|
||||
lib_LTLIBRARIES = libtag_c.la
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <flacfile.h>
|
||||
#include <oggflacfile.h>
|
||||
#include <mpcfile.h>
|
||||
#include <wavpackfile.h>
|
||||
#include <tag.h>
|
||||
#include <string.h>
|
||||
#include <id3v2framefactory.h>
|
||||
@ -71,6 +72,8 @@ TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type)
|
||||
return reinterpret_cast<TagLib_File *>(new MPC::File(filename));
|
||||
case TagLib_File_OggFlac:
|
||||
return reinterpret_cast<TagLib_File *>(new Ogg::FLAC::File(filename));
|
||||
case TagLib_File_WavPack:
|
||||
return reinterpret_cast<TagLib_File *>(new WavPack::File(filename));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -86,7 +86,8 @@ typedef enum {
|
||||
TagLib_File_OggVorbis,
|
||||
TagLib_File_FLAC,
|
||||
TagLib_File_MPC,
|
||||
TagLib_File_OggFlac
|
||||
TagLib_File_OggFlac,
|
||||
TagLib_File_WavPack
|
||||
} TagLib_File_Type;
|
||||
|
||||
/*!
|
||||
|
@ -11,6 +11,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ape
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wavpack
|
||||
${CMAKE_CURRENT_BINARY_DIR}/taglib
|
||||
${CMAKE_CURRENT_BINARY_DIR}/..
|
||||
)
|
||||
@ -24,6 +25,7 @@ ADD_SUBDIRECTORY( ogg )
|
||||
ADD_SUBDIRECTORY( flac )
|
||||
ADD_SUBDIRECTORY( ape )
|
||||
ADD_SUBDIRECTORY( mpc )
|
||||
ADD_SUBDIRECTORY( wavpack )
|
||||
|
||||
|
||||
|
||||
@ -96,6 +98,11 @@ ape/apefooter.cpp
|
||||
ape/apeitem.cpp
|
||||
)
|
||||
|
||||
SET(wavpack_SRCS
|
||||
wavpack/wavpackfile.cpp
|
||||
wavpack/wavpackproperties.cpp
|
||||
)
|
||||
|
||||
SET(toolkit_SRCS
|
||||
toolkit/tstring.cpp
|
||||
toolkit/tstringlist.cpp
|
||||
@ -108,6 +115,7 @@ toolkit/unicode.cpp
|
||||
|
||||
SET(tag_LIB_SRCS ${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS}
|
||||
${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
|
||||
${wavpack_SRCS}
|
||||
tag.cpp
|
||||
fileref.cpp
|
||||
audioproperties.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = toolkit mpeg ogg flac ape mpc
|
||||
SUBDIRS = toolkit mpeg ogg flac ape mpc wavpack
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir)/taglib \
|
||||
@ -9,6 +9,7 @@ INCLUDES = \
|
||||
-I$(top_srcdir)/taglib/flac \
|
||||
-I$(top_srcdir)/taglib/mpc \
|
||||
-I$(top_srcdir)/taglib/ogg/vorbis \
|
||||
-I$(top_srcdir)/taglib/wavpack \
|
||||
$(all_includes)
|
||||
|
||||
lib_LTLIBRARIES = libtag.la
|
||||
@ -18,4 +19,4 @@ taglib_include_HEADERS = tag.h fileref.h audioproperties.h taglib_export.h
|
||||
taglib_includedir = $(includedir)/taglib
|
||||
|
||||
libtag_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 5:0:4
|
||||
libtag_la_LIBADD = ./mpeg/libmpeg.la ./ogg/libogg.la ./flac/libflac.la ./mpc/libmpc.la ./ape/libape.la ./toolkit/libtoolkit.la
|
||||
libtag_la_LIBADD = ./mpeg/libmpeg.la ./ogg/libogg.la ./flac/libflac.la ./mpc/libmpc.la ./ape/libape.la ./toolkit/libtoolkit.la ./wavpack/libwavpack.la
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "flacfile.h"
|
||||
#include "oggflacfile.h"
|
||||
#include "mpcfile.h"
|
||||
#include "wavpackfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
@ -115,6 +116,7 @@ StringList FileRef::defaultFileExtensions()
|
||||
l.append("oga");
|
||||
l.append("mp3");
|
||||
l.append("mpc");
|
||||
l.append("wv");
|
||||
|
||||
return l;
|
||||
}
|
||||
@ -179,6 +181,8 @@ File *FileRef::create(const char *fileName, bool readAudioProperties,
|
||||
return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(s.substr(s.size() - 4, 4).upper() == ".MPC")
|
||||
return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(s.substr(s.size() - 4, 4).upper() == ".WV")
|
||||
return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
1
taglib/wavpack/CMakeLists.txt
Normal file
1
taglib/wavpack/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
INSTALL( FILES wavpackfile.h wavpackproperties.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib)
|
15
taglib/wavpack/Makefile.am
Normal file
15
taglib/wavpack/Makefile.am
Normal file
@ -0,0 +1,15 @@
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir)/taglib \
|
||||
-I$(top_srcdir)/taglib/toolkit \
|
||||
-I$(top_srcdir)/taglib/ape \
|
||||
-I$(top_srcdir)/taglib/mpc \
|
||||
-I$(top_srcdir)/taglib/mpeg/id3v1 \
|
||||
-I$(top_srcdir)/taglib/mpeg/id3v2 \
|
||||
$(all_includes)
|
||||
|
||||
noinst_LTLIBRARIES = libwavpack.la
|
||||
|
||||
libwavpack_la_SOURCES = wavpackfile.cpp wavpackproperties.cpp
|
||||
|
||||
taglib_include_HEADERS = wavpackfile.h wavpackproperties.h
|
||||
taglib_includedir = $(includedir)/taglib
|
311
taglib/wavpack/wavpackfile.cpp
Normal file
311
taglib/wavpack/wavpackfile.cpp
Normal file
@ -0,0 +1,311 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2004 by Allan Sandfeld Jensen
|
||||
email : kde@carewolf.org
|
||||
(original MPC implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tbytevector.h>
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include "wavpackfile.h"
|
||||
#include "id3v1tag.h"
|
||||
#include "id3v2header.h"
|
||||
#include "apetag.h"
|
||||
#include "apefooter.h"
|
||||
#include "combinedtag.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class WavPack::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
APETag(0),
|
||||
APELocation(-1),
|
||||
APESize(0),
|
||||
ID3v1Tag(0),
|
||||
ID3v1Location(-1),
|
||||
tag(0),
|
||||
properties(0),
|
||||
scanned(false),
|
||||
hasAPE(false),
|
||||
hasID3v1(false) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
if (tag != ID3v1Tag && tag != APETag) delete tag;
|
||||
delete ID3v1Tag;
|
||||
delete APETag;
|
||||
delete properties;
|
||||
}
|
||||
|
||||
APE::Tag *APETag;
|
||||
long APELocation;
|
||||
uint APESize;
|
||||
|
||||
ID3v1::Tag *ID3v1Tag;
|
||||
long ID3v1Location;
|
||||
|
||||
Tag *tag;
|
||||
|
||||
Properties *properties;
|
||||
bool scanned;
|
||||
|
||||
// These indicate whether the file *on disk* has these tags, not if
|
||||
// this data structure does. This is used in computing offsets.
|
||||
|
||||
bool hasAPE;
|
||||
bool hasID3v1;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WavPack::File::File(const char *file, bool readProperties,
|
||||
Properties::ReadStyle propertiesStyle) : TagLib::File(file)
|
||||
{
|
||||
d = new FilePrivate;
|
||||
read(readProperties, propertiesStyle);
|
||||
}
|
||||
|
||||
WavPack::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
TagLib::Tag *WavPack::File::tag() const
|
||||
{
|
||||
return d->tag;
|
||||
}
|
||||
|
||||
WavPack::Properties *WavPack::File::audioProperties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
bool WavPack::File::save()
|
||||
{
|
||||
if(readOnly()) {
|
||||
debug("WavPack::File::save() -- File is read only.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update ID3v1 tag
|
||||
|
||||
if(d->ID3v1Tag) {
|
||||
if(d->hasID3v1) {
|
||||
seek(d->ID3v1Location);
|
||||
writeBlock(d->ID3v1Tag->render());
|
||||
}
|
||||
else {
|
||||
seek(0, End);
|
||||
d->ID3v1Location = tell();
|
||||
writeBlock(d->ID3v1Tag->render());
|
||||
d->hasID3v1 = true;
|
||||
}
|
||||
} else
|
||||
if(d->hasID3v1) {
|
||||
removeBlock(d->ID3v1Location, 128);
|
||||
d->hasID3v1 = false;
|
||||
if(d->hasAPE) {
|
||||
if(d->APELocation > d->ID3v1Location)
|
||||
d->APELocation -= 128;
|
||||
}
|
||||
}
|
||||
|
||||
// Update APE tag
|
||||
|
||||
if(d->APETag) {
|
||||
if(d->hasAPE)
|
||||
insert(d->APETag->render(), d->APELocation, d->APESize);
|
||||
else {
|
||||
if(d->hasID3v1) {
|
||||
insert(d->APETag->render(), d->ID3v1Location, 0);
|
||||
d->APESize = d->APETag->footer()->completeTagSize();
|
||||
d->hasAPE = true;
|
||||
d->APELocation = d->ID3v1Location;
|
||||
d->ID3v1Location += d->APESize;
|
||||
}
|
||||
else {
|
||||
seek(0, End);
|
||||
d->APELocation = tell();
|
||||
writeBlock(d->APETag->render());
|
||||
d->APESize = d->APETag->footer()->completeTagSize();
|
||||
d->hasAPE = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if(d->hasAPE) {
|
||||
removeBlock(d->APELocation, d->APESize);
|
||||
d->hasAPE = false;
|
||||
if(d->hasID3v1) {
|
||||
if (d->ID3v1Location > d->APELocation)
|
||||
d->ID3v1Location -= d->APESize;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ID3v1::Tag *WavPack::File::ID3v1Tag(bool create)
|
||||
{
|
||||
if(!create || d->ID3v1Tag)
|
||||
return d->ID3v1Tag;
|
||||
|
||||
// no ID3v1 tag exists and we've been asked to create one
|
||||
|
||||
d->ID3v1Tag = new ID3v1::Tag;
|
||||
|
||||
if(d->APETag)
|
||||
d->tag = new CombinedTag(d->APETag, d->ID3v1Tag);
|
||||
else
|
||||
d->tag = d->ID3v1Tag;
|
||||
|
||||
return d->ID3v1Tag;
|
||||
}
|
||||
|
||||
APE::Tag *WavPack::File::APETag(bool create)
|
||||
{
|
||||
if(!create || d->APETag)
|
||||
return d->APETag;
|
||||
|
||||
// no APE tag exists and we've been asked to create one
|
||||
|
||||
d->APETag = new APE::Tag;
|
||||
|
||||
if(d->ID3v1Tag)
|
||||
d->tag = new CombinedTag(d->APETag, d->ID3v1Tag);
|
||||
else
|
||||
d->tag = d->APETag;
|
||||
|
||||
return d->APETag;
|
||||
}
|
||||
|
||||
void WavPack::File::remove(int tags)
|
||||
{
|
||||
if(tags & ID3v1) {
|
||||
delete d->ID3v1Tag;
|
||||
d->ID3v1Tag = 0;
|
||||
|
||||
if(d->APETag)
|
||||
d->tag = d->APETag;
|
||||
else
|
||||
d->tag = d->APETag = new APE::Tag;
|
||||
}
|
||||
|
||||
if(tags & APE) {
|
||||
delete d->APETag;
|
||||
d->APETag = 0;
|
||||
|
||||
if(d->ID3v1Tag)
|
||||
d->tag = d->ID3v1Tag;
|
||||
else
|
||||
d->tag = d->APETag = new APE::Tag;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertiesStyle */)
|
||||
{
|
||||
// Look for an ID3v1 tag
|
||||
|
||||
d->ID3v1Location = findID3v1();
|
||||
|
||||
if(d->ID3v1Location >= 0) {
|
||||
d->ID3v1Tag = new ID3v1::Tag(this, d->ID3v1Location);
|
||||
d->hasID3v1 = true;
|
||||
}
|
||||
|
||||
// Look for an APE tag
|
||||
|
||||
d->APELocation = findAPE();
|
||||
|
||||
if(d->APELocation >= 0) {
|
||||
d->APETag = new APE::Tag(this, d->APELocation);
|
||||
d->APESize = d->APETag->footer()->completeTagSize();
|
||||
d->APELocation = d->APELocation + d->APETag->footer()->size() - d->APESize;
|
||||
d->hasAPE = true;
|
||||
}
|
||||
|
||||
if(d->hasID3v1 && d->hasAPE)
|
||||
d->tag = new CombinedTag(d->APETag, d->ID3v1Tag);
|
||||
else {
|
||||
if(d->hasID3v1)
|
||||
d->tag = d->ID3v1Tag;
|
||||
else {
|
||||
if(d->hasAPE)
|
||||
d->tag = d->APETag;
|
||||
else
|
||||
d->tag = d->APETag = new APE::Tag;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for WavPack audio properties
|
||||
|
||||
if(readProperties) {
|
||||
seek(0);
|
||||
d->properties = new Properties(readBlock(WavPack::HeaderSize),
|
||||
length() - d->APESize);
|
||||
}
|
||||
}
|
||||
|
||||
long WavPack::File::findAPE()
|
||||
{
|
||||
if(!isValid())
|
||||
return -1;
|
||||
|
||||
if(d->hasID3v1)
|
||||
seek(-160, End);
|
||||
else
|
||||
seek(-32, End);
|
||||
|
||||
long p = tell();
|
||||
|
||||
if(readBlock(8) == APE::Tag::fileIdentifier())
|
||||
return p;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
long WavPack::File::findID3v1()
|
||||
{
|
||||
if(!isValid())
|
||||
return -1;
|
||||
|
||||
seek(-128, End);
|
||||
long p = tell();
|
||||
|
||||
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
|
||||
return p;
|
||||
|
||||
return -1;
|
||||
}
|
164
taglib/wavpack/wavpackfile.h
Normal file
164
taglib/wavpack/wavpackfile.h
Normal file
@ -0,0 +1,164 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2004 by Allan Sandfeld Jensen
|
||||
email : kde@carewolf.org
|
||||
(original MPC implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_WVFILE_H
|
||||
#define TAGLIB_WVFILE_H
|
||||
|
||||
#include <tfile.h>
|
||||
#include "taglib_export.h"
|
||||
#include "wavpackproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
class Tag;
|
||||
|
||||
namespace ID3v1 { class Tag; }
|
||||
namespace APE { class Tag; }
|
||||
|
||||
//! An implementation of WavPack metadata
|
||||
|
||||
/*!
|
||||
* This is implementation of WavPack metadata.
|
||||
*
|
||||
* This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream
|
||||
* properties from the file.
|
||||
*/
|
||||
|
||||
namespace WavPack {
|
||||
|
||||
//! An implementation of TagLib::File with WavPack specific methods
|
||||
|
||||
/*!
|
||||
* This implements and provides an interface for WavPack files to the
|
||||
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
|
||||
* the abstract TagLib::File API as well as providing some additional
|
||||
* information specific to WavPack files.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public TagLib::File
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* This set of flags is used for various operations and is suitable for
|
||||
* being OR-ed together.
|
||||
*/
|
||||
enum TagTypes {
|
||||
//! Empty set. Matches no tag types.
|
||||
NoTags = 0x0000,
|
||||
//! Matches ID3v1 tags.
|
||||
ID3v1 = 0x0001,
|
||||
//! Matches APE tags.
|
||||
APE = 0x0002,
|
||||
//! Matches all tag types.
|
||||
AllTags = 0xffff
|
||||
};
|
||||
|
||||
/*!
|
||||
* Contructs an WavPack file from \a file. If \a readProperties is true the
|
||||
* file's audio properties will also be read using \a propertiesStyle. If
|
||||
* false, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(const char *file, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the File.
|
||||
*/
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the Tag for this file. This will be an APE tag, an ID3v1 tag
|
||||
* or a combination of the two.
|
||||
*/
|
||||
virtual TagLib::Tag *tag() const;
|
||||
|
||||
/*!
|
||||
* Returns the MPC::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual Properties *audioProperties() const;
|
||||
|
||||
/*!
|
||||
* Saves the file.
|
||||
*/
|
||||
virtual bool save();
|
||||
|
||||
/*!
|
||||
* Returns a pointer to the ID3v1 tag of the file.
|
||||
*
|
||||
* If \a create is false (the default) this will return a null pointer
|
||||
* if there is no valid ID3v1 tag. If \a create is true it will create
|
||||
* an ID3v1 tag if one does not exist. If there is already an APE tag, the
|
||||
* new ID3v1 tag will be placed after it.
|
||||
*
|
||||
* \note The Tag <b>is still</b> owned by the APE::File and should not be
|
||||
* deleted by the user. It will be deleted when the file (object) is
|
||||
* destroyed.
|
||||
*/
|
||||
ID3v1::Tag *ID3v1Tag(bool create = false);
|
||||
|
||||
/*!
|
||||
* Returns a pointer to the APE tag of the file.
|
||||
*
|
||||
* If \a create is false (the default) this will return a null pointer
|
||||
* if there is no valid APE tag. If \a create is true it will create
|
||||
* a APE tag if one does not exist.
|
||||
*
|
||||
* \note The Tag <b>is still</b> owned by the APE::File and should not be
|
||||
* deleted by the user. It will be deleted when the file (object) is
|
||||
* destroyed.
|
||||
*/
|
||||
APE::Tag *APETag(bool create = false);
|
||||
|
||||
/*!
|
||||
* This will remove the tags that match the OR-ed together TagTypes from the
|
||||
* file. By default it removes all tags.
|
||||
*
|
||||
* \note This will also invalidate pointers to the tags
|
||||
* as their memory will be freed.
|
||||
* \note In order to make the removal permanent save() still needs to be called
|
||||
*/
|
||||
void remove(int tags = AllTags);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
|
||||
void scan();
|
||||
long findID3v1();
|
||||
long findAPE();
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
143
taglib/wavpack/wavpackproperties.cpp
Normal file
143
taglib/wavpack/wavpackproperties.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2004 by Allan Sandfeld Jensen
|
||||
email : kde@carewolf.org
|
||||
(original MPC implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
#include <bitset>
|
||||
|
||||
#include "wavpackproperties.h"
|
||||
#include "wavpackfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class WavPack::Properties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
|
||||
data(d),
|
||||
streamLength(length),
|
||||
style(s),
|
||||
length(0),
|
||||
bitrate(0),
|
||||
sampleRate(0),
|
||||
channels(0),
|
||||
version(0),
|
||||
bitsPerSample(0) {}
|
||||
|
||||
ByteVector data;
|
||||
long streamLength;
|
||||
ReadStyle style;
|
||||
int length;
|
||||
int bitrate;
|
||||
int sampleRate;
|
||||
int channels;
|
||||
int version;
|
||||
int bitsPerSample;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WavPack::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
|
||||
{
|
||||
d = new PropertiesPrivate(data, streamLength, style);
|
||||
read();
|
||||
}
|
||||
|
||||
WavPack::Properties::~Properties()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
int WavPack::Properties::length() const
|
||||
{
|
||||
return d->length;
|
||||
}
|
||||
|
||||
int WavPack::Properties::bitrate() const
|
||||
{
|
||||
return d->bitrate;
|
||||
}
|
||||
|
||||
int WavPack::Properties::sampleRate() const
|
||||
{
|
||||
return d->sampleRate;
|
||||
}
|
||||
|
||||
int WavPack::Properties::channels() const
|
||||
{
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
int WavPack::Properties::version() const
|
||||
{
|
||||
return d->version;
|
||||
}
|
||||
|
||||
int WavPack::Properties::bitsPerSample() const
|
||||
{
|
||||
return d->bitsPerSample;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const unsigned int sample_rates[] = { 6000, 8000, 9600, 11025, 12000,
|
||||
16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 };
|
||||
|
||||
#define BYTES_STORED 3
|
||||
#define MONO_FLAG 4
|
||||
|
||||
#define SHIFT_LSB 13
|
||||
#define SHIFT_MASK (0x1fL << SHIFT_LSB)
|
||||
|
||||
#define SRATE_LSB 23
|
||||
#define SRATE_MASK (0xfL << SRATE_LSB)
|
||||
|
||||
void WavPack::Properties::read()
|
||||
{
|
||||
if(!d->data.startsWith("wvpk"))
|
||||
return;
|
||||
|
||||
d->version = d->data.mid(8, 2).toShort(false);
|
||||
|
||||
unsigned int flags = d->data.mid(24, 4).toUInt(false);
|
||||
d->bitsPerSample = ((flags & BYTES_STORED) + 1) * 8 -
|
||||
((flags & SHIFT_MASK) >> SHIFT_LSB);
|
||||
d->sampleRate = sample_rates[(flags & SRATE_MASK) >> SRATE_LSB];
|
||||
d->channels = (flags & MONO_FLAG) ? 1 : 2;
|
||||
|
||||
unsigned int samples = d->data.mid(12, 4).toUInt(false);
|
||||
d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
|
||||
|
||||
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
|
||||
}
|
||||
|
91
taglib/wavpack/wavpackproperties.h
Normal file
91
taglib/wavpack/wavpackproperties.h
Normal file
@ -0,0 +1,91 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2004 by Allan Sandfeld Jensen
|
||||
email : kde@carewolf.org
|
||||
(original MPC implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_WVPROPERTIES_H
|
||||
#define TAGLIB_WVPROPERTIES_H
|
||||
|
||||
#include "taglib_export.h"
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace WavPack {
|
||||
|
||||
class File;
|
||||
|
||||
static const uint HeaderSize = 32;
|
||||
|
||||
//! An implementation of audio property reading for WavPack
|
||||
|
||||
/*!
|
||||
* This reads the data from an WavPack stream found in the AudioProperties
|
||||
* API.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT Properties : public AudioProperties
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of WavPack::Properties with the data read from the
|
||||
* ByteVector \a data.
|
||||
*/
|
||||
Properties(const ByteVector &data, long streamLength, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this WavPack::Properties instance.
|
||||
*/
|
||||
virtual ~Properties();
|
||||
|
||||
// Reimplementations.
|
||||
|
||||
virtual int length() const;
|
||||
virtual int bitrate() const;
|
||||
virtual int sampleRate() const;
|
||||
virtual int channels() const;
|
||||
|
||||
/*!
|
||||
* Returns number of bits per sample.
|
||||
*/
|
||||
int bitsPerSample() const;
|
||||
|
||||
/*!
|
||||
* Returns WavPack version.
|
||||
*/
|
||||
int version() const;
|
||||
|
||||
private:
|
||||
void read();
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user