Additional manual formatting to taglib sources

This commit is contained in:
Jonas Kvinge
2020-06-14 17:01:05 +02:00
parent 577b7d8ec8
commit ef34dce4dc
217 changed files with 7367 additions and 8204 deletions

View File

@@ -56,10 +56,10 @@ class APE::File::FilePrivate {
FilePrivate() : APELocation(-1),
APESize(0),
ID3v1Location(-1),
ID3v2Header(0),
ID3v2Header(nullptr),
ID3v2Location(-1),
ID3v2Size(0),
properties(0) {}
properties(nullptr) {}
~FilePrivate() {
delete ID3v2Header;
@@ -98,16 +98,18 @@ bool APE::File::isSupported(IOStream *) {
// public members
////////////////////////////////////////////////////////////////////////////////
APE::File::File(FileName file, bool readProperties, Properties::ReadStyle) : Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate()) {
APE::File::File(FileName file, bool readProperties, Properties::ReadStyle) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate()) {
if (isOpen())
read(readProperties);
}
APE::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) : Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate()) {
APE::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate()) {
if (isOpen())
read(readProperties);
}
APE::File::~File() {
@@ -127,10 +129,12 @@ void APE::File::removeUnsupportedProperties(const StringList &properties) {
}
PropertyMap APE::File::setProperties(const PropertyMap &properties) {
if (ID3v1Tag())
ID3v1Tag()->setProperties(properties);
return APETag(true)->setProperties(properties);
}
APE::Properties *APE::File::audioProperties() const {
@@ -138,6 +142,7 @@ APE::Properties *APE::File::audioProperties() const {
}
bool APE::File::save() {
if (readOnly()) {
debug("APE::File::save() -- File is read only.");
return false;
@@ -206,6 +211,7 @@ bool APE::File::save() {
}
return true;
}
ID3v1::Tag *APE::File::ID3v1Tag(bool create) {
@@ -217,14 +223,16 @@ APE::Tag *APE::File::APETag(bool create) {
}
void APE::File::strip(int tags) {
if (tags & ID3v1)
d->tag.set(ApeID3v1Index, 0);
d->tag.set(ApeID3v1Index, nullptr);
if (tags & APE)
d->tag.set(ApeAPEIndex, 0);
d->tag.set(ApeAPEIndex, nullptr);
if (!ID3v1Tag())
APETag(true);
}
bool APE::File::hasAPETag() const {
@@ -240,6 +248,7 @@ bool APE::File::hasID3v1Tag() const {
////////////////////////////////////////////////////////////////////////////////
void APE::File::read(bool readProperties) {
// Look for an ID3v2 tag
d->ID3v2Location = Utils::findID3v2(this);
@@ -293,4 +302,5 @@ void APE::File::read(bool readProperties) {
d->properties = new Properties(this, streamLength);
}
}

View File

@@ -53,29 +53,28 @@ class Tag;
//! An implementation of APE metadata
/*!
* This is implementation of APE metadata.
*
* This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream
* properties from the file.
*/
* This is implementation of APE metadata.
*
* This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream properties from the file.
*
*/
namespace APE {
//! An implementation of TagLib::File with APE specific methods
/*!
* This implements and provides an interface for APE 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 APE files.
*/
* This implements and provides an interface for APE 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 APE files.
*
*/
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
public:
/*!
* This set of flags is used for various operations and is suitable for
* being OR-ed together.
*/
* 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,
@@ -88,140 +87,128 @@ class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
};
/*!
* Constructs an APE file from \a file. If \a readProperties is true the
* file's audio properties will also be read.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*/
* Constructs an APE file from \a file.
* If \a readProperties is true the file's audio properties will also be read.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*/
File(FileName file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
/*!
* Constructs an APE file from \a stream. If \a readProperties is true the
* file's audio properties will also be read.
*
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*/
* Constructs an APE file from \a stream.
* If \a readProperties is true the file's audio properties will also be read.
*
* \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*/
File(IOStream *stream, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
/*!
* Destroys this instance of the File.
*/
* 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.
*/
* Returns the Tag for this file. This will be an APE tag, an ID3v1 tag or a combination of the two.
*/
virtual Strawberry_TagLib::TagLib::Tag *tag() const;
/*!
* Implements the unified property interface -- export function.
* If the file contains both an APE and an ID3v1 tag, only APE
* will be converted to the PropertyMap.
*/
* Implements the unified property interface -- export function.
* If the file contains both an APE and an ID3v1 tag, only APE will be converted to the PropertyMap.
*/
PropertyMap properties() const;
/*!
* Removes unsupported properties. Forwards to the actual Tag's
* removeUnsupportedProperties() function.
*/
* Removes unsupported properties. Forwards to the actual Tag's removeUnsupportedProperties() function.
*/
void removeUnsupportedProperties(const StringList &properties);
/*!
* Implements the unified property interface -- import function.
* Creates an APEv2 tag if necessary. A potentially existing ID3v1
* tag will be updated as well.
*/
* Implements the unified property interface -- import function.
* Creates an APEv2 tag if necessary.
* A potentially existing ID3v1 tag will be updated as well.
*/
PropertyMap setProperties(const PropertyMap &);
/*!
* Returns the APE::Properties for this file. If no audio properties
* were read then this will return a null pointer.
*/
* Returns the APE::Properties for this file.
* If no audio properties were read then this will return a null pointer.
*/
virtual Properties *audioProperties() const;
/*!
* Saves the file.
*
* \note According to the official Monkey's Audio SDK, an APE file
* can only have either ID3V1 or APE tags, so a parameter is used here.
*/
* Saves the file.
*
* \note According to the official Monkey's Audio SDK, an APE file
* can only have either ID3V1 or APE tags, so a parameter is used here.
*/
virtual bool save();
/*!
* Returns a pointer to the ID3v1 tag of the file.
*
* If \a create is false (the default) this may 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 and returns a valid pointer.
*
* \note This may return a valid pointer regardless of whether or not the
* file on disk has an ID3v1 tag. Use hasID3v1Tag() to check if the file
* on disk actually has an ID3v1 tag.
*
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be
* deleted by the user. It will be deleted when the file (object) is
* destroyed.
*
* \see hasID3v1Tag()
*/
* Returns a pointer to the ID3v1 tag of the file.
*
* If \a create is false (the default) this may 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 and returns a valid pointer.
*
* \note This may return a valid pointer regardless of whether or not the file on disk has an ID3v1 tag.
* Use hasID3v1Tag() to check if the file on disk actually has an ID3v1 tag.
*
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* It will be deleted when the file (object) is destroyed.
*
* \see hasID3v1Tag()
*/
ID3v1::Tag *ID3v1Tag(bool create = false);
/*!
* Returns a pointer to the APE tag of the file.
*
* If \a create is false (the default) this may return a null pointer
* if there is no valid APE tag. If \a create is true it will create
* an APE tag if one does not exist and returns a valid pointer.
*
* \note This may return a valid pointer regardless of whether or not the
* file on disk has an APE tag. Use hasAPETag() to check if the file
* on disk actually has an APE tag.
*
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be
* deleted by the user. It will be deleted when the file (object) is
* destroyed.
*
* \see hasAPETag()
*/
* Returns a pointer to the APE tag of the file.
*
* If \a create is false (the default) this may return a null pointer if there is no valid APE tag.
* If \a create is true it will create an APE tag if one does not exist and returns a valid pointer.
*
* \note This may return a valid pointer regardless of whether or not the file on disk has an APE tag.
* Use hasAPETag() to check if the file on disk actually has an APE tag.
*
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* It will be deleted when the file (object) is destroyed.
*
* \see hasAPETag()
*/
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
*/
* 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 strip(int tags = AllTags);
/*!
* Returns whether or not the file on disk actually has an APE tag.
*
* \see APETag()
*/
* Returns whether or not the file on disk actually has an APE tag.
*
* \see APETag()
*/
bool hasAPETag() const;
/*!
* Returns whether or not the file on disk actually has an ID3v1 tag.
*
* \see ID3v1Tag()
*/
* Returns whether or not the file on disk actually has an ID3v1 tag.
*
* \see ID3v1Tag()
*/
bool hasID3v1Tag() const;
/*!
* Returns whether or not the given \a stream can be opened as an APE
* file.
*
* \note This method is designed to do a quick check. The result may
* not necessarily be correct.
*/
* Returns whether or not the given \a stream can be opened as an APE file.
*
* \note This method is designed to do a quick check.
* The result may not necessarily be correct.
*/
static bool isSupported(IOStream *stream);
private:

View File

@@ -134,10 +134,12 @@ ByteVector APE::Footer::renderFooter() const {
}
ByteVector APE::Footer::renderHeader() const {
if (!d->headerPresent)
return ByteVector();
else
return render(true);
}
////////////////////////////////////////////////////////////////////////////////
@@ -145,6 +147,7 @@ ByteVector APE::Footer::renderHeader() const {
////////////////////////////////////////////////////////////////////////////////
void APE::Footer::parse(const ByteVector &data) {
if (data.size() < size())
return;
@@ -169,9 +172,11 @@ void APE::Footer::parse(const ByteVector &data) {
d->headerPresent = flags[31];
d->footerPresent = !flags[30];
d->isHeader = flags[29];
}
ByteVector APE::Footer::render(bool isHeader) const {
ByteVector v;
// add the file identifier -- "APETAGEX"
@@ -206,4 +211,5 @@ ByteVector APE::Footer::render(bool isHeader) const {
v.append(ByteVector::fromLongLong(0));
return v;
}

View File

@@ -37,126 +37,127 @@ namespace APE {
//! An implementation of APE footers
/*!
* This class implements APE footers (and headers). It attempts to follow, both
* semantically and programmatically, the structure specified in
* the APE v2.0 standard. The API is based on the properties of APE footer and
* headers specified there.
*/
* This class implements APE footers (and headers).
* It attempts to follow, both semantically and programmatically,
* the structure specified in the APE v2.0 standard.
* The API is based on the properties of APE footer and headers specified there.
*
*/
class TAGLIB_EXPORT Footer {
public:
/*!
* Constructs an empty APE footer.
*/
* Constructs an empty APE footer.
*/
Footer();
/*!
* Constructs an APE footer based on \a data. parse() is called
* immediately.
*/
* Constructs an APE footer based on \a data. parse() is called immediately.
*/
Footer(const ByteVector &data);
/*!
* Destroys the footer.
*/
* Destroys the footer.
*/
virtual ~Footer();
/*!
* Returns the version number. (Note: This is the 1000 or 2000.)
*/
* Returns the version number. (Note: This is the 1000 or 2000.)
*/
unsigned int version() const;
/*!
* Returns true if a header is present in the tag.
*/
* Returns true if a header is present in the tag.
*/
bool headerPresent() const;
/*!
* Returns true if a footer is present in the tag.
*/
* Returns true if a footer is present in the tag.
*/
bool footerPresent() const;
/*!
* Returns true this is actually the header.
*/
* Returns true this is actually the header.
*/
bool isHeader() const;
/*!
* Sets whether the header should be rendered or not
*/
* Sets whether the header should be rendered or not
*/
void setHeaderPresent(bool b) const;
/*!
* Returns the number of items in the tag.
*/
* Returns the number of items in the tag.
*/
unsigned int itemCount() const;
/*!
* Set the item count to \a s.
* \see itemCount()
*/
* Set the item count to \a s.
* \see itemCount()
*/
void setItemCount(unsigned int s);
/*!
* Returns the tag size in bytes. This is the size of the frame content and footer.
* The size of the \e entire tag will be this plus the header size, if present.
*
* \see completeTagSize()
*/
* Returns the tag size in bytes.
* This is the size of the frame content and footer.
* The size of the \e entire tag will be this plus the header size, if present.
*
* \see completeTagSize()
*/
unsigned int tagSize() const;
/*!
* Returns the tag size, including if present, the header
* size.
*
* \see tagSize()
*/
* Returns the tag size, including if present, the header
* size.
*
* \see tagSize()
*/
unsigned int completeTagSize() const;
/*!
* Set the tag size to \a s.
* \see tagSize()
*/
* Set the tag size to \a s.
* \see tagSize()
*/
void setTagSize(unsigned int s);
/*!
* Returns the size of the footer. Presently this is always 32 bytes.
*/
* Returns the size of the footer. Presently this is always 32 bytes.
*/
static unsigned int size();
/*!
* Returns the string used to identify an APE tag inside of a file.
* Presently this is always "APETAGEX".
*/
* Returns the string used to identify an APE tag inside of a file.
* Presently this is always "APETAGEX".
*/
static ByteVector fileIdentifier();
/*!
* Sets the data that will be used as the footer. 32 bytes,
* starting from \a data will be used.
*/
* Sets the data that will be used as the footer. 32 bytes,
* starting from \a data will be used.
*/
void setData(const ByteVector &data);
/*!
* Renders the footer back to binary format.
*/
* Renders the footer back to binary format.
*/
ByteVector renderFooter() const;
/*!
* Renders the header corresponding to the footer. If headerPresent is
* set to false, it returns an empty ByteVector.
*/
* Renders the header corresponding to the footer.
* If headerPresent is set to false, it returns an empty ByteVector.
*/
ByteVector renderHeader() const;
protected:
/*!
* Called by setData() to parse the footer data. It makes this information
* available through the public API.
*/
* Called by setData() to parse the footer data.
* It makes this information available through the public API.
*/
void parse(const ByteVector &data);
/*!
* Called by renderFooter and renderHeader
*/
* Called by renderFooter and renderHeader
*/
ByteVector render(bool isHeader) const;
private:

View File

@@ -33,8 +33,7 @@ using namespace APE;
class APE::Item::ItemPrivate {
public:
ItemPrivate() : type(Text),
readOnly(false) {}
ItemPrivate() : type(Text), readOnly(false) {}
Item::ItemTypes type;
String key;
@@ -47,8 +46,7 @@ class APE::Item::ItemPrivate {
// public members
////////////////////////////////////////////////////////////////////////////////
APE::Item::Item() : d(new ItemPrivate()) {
}
APE::Item::Item() : d(new ItemPrivate()) {}
APE::Item::Item(const String &key, const String &value) : d(new ItemPrivate()) {
d->key = key;
@@ -61,6 +59,7 @@ APE::Item::Item(const String &key, const StringList &values) : d(new ItemPrivate
}
APE::Item::Item(const String &key, const ByteVector &value, bool binary) : d(new ItemPrivate()) {
d->key = key;
if (binary) {
d->type = Binary;
@@ -69,24 +68,28 @@ APE::Item::Item(const String &key, const ByteVector &value, bool binary) : d(new
else {
d->text.append(value);
}
}
APE::Item::Item(const Item &item) : d(new ItemPrivate(*item.d)) {
}
APE::Item::Item(const Item &item) : d(new ItemPrivate(*item.d)) {}
APE::Item::~Item() {
delete d;
}
Item &APE::Item::operator=(const Item &item) {
Item(item).swap(*this);
return *this;
}
void APE::Item::swap(Item &item) {
using std::swap;
swap(d, item.d);
}
void APE::Item::setReadOnly(bool readOnly) {
@@ -114,14 +117,16 @@ ByteVector APE::Item::binaryData() const {
}
void APE::Item::setBinaryData(const ByteVector &value) {
d->type = Binary;
d->value = value;
d->text.clear();
}
ByteVector APE::Item::value() const {
// This seems incorrect as it won't be actually rendering the value to keep it
// up to date.
// This seems incorrect as it won't be actually rendering the value to keep it up to date.
return d->value;
}
@@ -131,30 +136,39 @@ void APE::Item::setKey(const String &key) {
}
void APE::Item::setValue(const String &value) {
d->type = Text;
d->text = value;
d->value.clear();
}
void APE::Item::setValues(const StringList &value) {
d->type = Text;
d->text = value;
d->value.clear();
}
void APE::Item::appendValue(const String &value) {
d->type = Text;
d->text.append(value);
d->value.clear();
}
void APE::Item::appendValues(const StringList &values) {
d->type = Text;
d->text.append(values);
d->value.clear();
}
int APE::Item::size() const {
int result = 8 + d->key.size() + 1;
switch (d->type) {
case Text:
@@ -174,6 +188,7 @@ int APE::Item::size() const {
break;
}
return result;
}
StringList APE::Item::toStringList() const {
@@ -185,13 +200,16 @@ StringList APE::Item::values() const {
}
String APE::Item::toString() const {
if (d->type == Text && !isEmpty())
return d->text.front();
else
return String();
}
bool APE::Item::isEmpty() const {
switch (d->type) {
case Text:
if (d->text.isEmpty())
@@ -205,9 +223,11 @@ bool APE::Item::isEmpty() const {
default:
return false;
}
}
void APE::Item::parse(const ByteVector &data) {
// 11 bytes is the minimum size for an APE item
if (data.size() < 11) {
@@ -232,9 +252,11 @@ void APE::Item::parse(const ByteVector &data) {
d->text = StringList(ByteVectorList::split(value, '\0'), String::UTF8);
else
d->value = value;
}
ByteVector APE::Item::render() const {
ByteVector data;
unsigned int flags = ((d->readOnly) ? 1 : 0) | (d->type << 1);
ByteVector value;
@@ -263,4 +285,5 @@ ByteVector APE::Item::render() const {
data.append(value);
return data;
}

View File

@@ -32,19 +32,18 @@
namespace Strawberry_TagLib {
namespace TagLib {
namespace APE {
//! An implementation of APE-items
/*!
* This class provides the features of items in the APEv2 standard.
*/
* This class provides the features of items in the APEv2 standard.
*/
class TAGLIB_EXPORT Item {
public:
/*!
* Enum of types an Item can have. The value of 3 is reserved.
*/
* Enum of types an Item can have. The value of 3 is reserved.
*/
enum ItemTypes {
//! Item contains text information coded in UTF-8
Text = 0,
@@ -54,62 +53,62 @@ class TAGLIB_EXPORT Item {
Locator = 2
};
/*!
* Constructs an empty item.
*/
* Constructs an empty item.
*/
Item();
/*!
* Constructs a text item with \a key and \a value.
*/
* Constructs a text item with \a key and \a value.
*/
// BIC: Remove this, StringList has a constructor from a single string
Item(const String &key, const String &value);
/*!
* Constructs a text item with \a key and \a values.
*/
* Constructs a text item with \a key and \a values.
*/
Item(const String &key, const StringList &values);
/*!
* Constructs an item with \a key and \a value.
* If \a binary is true a Binary item will be created, otherwise \a value will be interpreted as text
*/
* Constructs an item with \a key and \a value.
* If \a binary is true a Binary item will be created, otherwise \a value will be interpreted as text
*/
Item(const String &key, const ByteVector &value, bool binary);
/*!
* Construct an item as a copy of \a item.
*/
* Construct an item as a copy of \a item.
*/
Item(const Item &item);
/*!
* Destroys the item.
*/
* Destroys the item.
*/
virtual ~Item();
/*!
* Copies the contents of \a item into this item.
*/
* Copies the contents of \a item into this item.
*/
Item &operator=(const Item &item);
/*!
* Exchanges the content of this item by the content of \a item.
*/
* Exchanges the content of this item by the content of \a item.
*/
void swap(Item &item);
/*!
* Returns the key.
*/
* Returns the key.
*/
String key() const;
/*!
* Returns the binary value.
* If the item type is not \a Binary, always returns an empty ByteVector.
*/
* Returns the binary value.
* If the item type is not \a Binary, always returns an empty ByteVector.
*/
ByteVector binaryData() const;
/*!
* Set the binary value to \a value
* The item's type will also be set to \a Binary
*/
* Set the binary value to \a value
* The item's type will also be set to \a Binary
*/
void setBinaryData(const ByteVector &value);
#ifndef DO_NOT_DOCUMENT
@@ -118,97 +117,90 @@ class TAGLIB_EXPORT Item {
#endif
/*!
* Sets the key for the item to \a key.
*/
* Sets the key for the item to \a key.
*/
void setKey(const String &key);
/*!
* Sets the text value of the item to \a value and clears any previous contents.
*
* \see toString()
*/
* Sets the text value of the item to \a value and clears any previous contents.
*
* \see toString()
*/
void setValue(const String &value);
/*!
* Sets the text value of the item to the list of values in \a value and clears
* any previous contents.
*
* \see toStringList()
*/
* Sets the text value of the item to the list of values in \a value and clears any previous contents.
*
* \see toStringList()
*/
void setValues(const StringList &values);
/*!
* Appends \a value to create (or extend) the current list of text values.
*
* \see toString()
*/
* Appends \a value to create (or extend) the current list of text values.
*
* \see toString()
*/
void appendValue(const String &value);
/*!
* Appends \a values to extend the current list of text values.
*
* \see toStringList()
*/
* Appends \a values to extend the current list of text values.
*
* \see toStringList()
*/
void appendValues(const StringList &values);
/*!
* Returns the size of the full item.
*/
* Returns the size of the full item.
*/
int size() const;
/*!
* Returns the value as a single string. In case of multiple strings,
* the first is returned. If the data type is not \a Text, always returns
* an empty String.
*/
* Returns the value as a single string. In case of multiple strings, the first is returned.
* If the data type is not \a Text, always returns an empty String.
*/
String toString() const;
#ifndef DO_NOT_DOCUMENT
/* Remove in next binary incompatible release */
StringList toStringList() const;
#endif
/*!
* Returns the list of text values. If the data type is not \a Text, always
* returns an empty StringList.
*/
* Returns the list of text values. If the data type is not \a Text, always returns an empty StringList.
*/
StringList values() const;
/*!
* Render the item to a ByteVector.
*/
* Render the item to a ByteVector.
*/
ByteVector render() const;
/*!
* Parse the item from the ByteVector \a data.
*/
* Parse the item from the ByteVector \a data.
*/
void parse(const ByteVector &data);
/*!
* Set the item to read-only.
*/
* Set the item to read-only.
*/
void setReadOnly(bool readOnly);
/*!
* Return true if the item is read-only.
*/
* Return true if the item is read-only.
*/
bool isReadOnly() const;
/*!
* Sets the type of the item to \a type.
*
* \see ItemTypes
*/
* Sets the type of the item to \a type.
*
* \see ItemTypes
*/
void setType(ItemTypes type);
/*!
* Returns the type of the item.
*/
* Returns the type of the item.
*/
ItemTypes type() const;
/*!
* Returns if the item has any real content.
*/
* Returns if the item has any real content.
*/
bool isEmpty() const;
private:
@@ -216,7 +208,6 @@ class TAGLIB_EXPORT Item {
ItemPrivate *d;
};
} // namespace APE
} // namespace TagLib
} // namespace Strawberry_TagLib

View File

@@ -61,13 +61,7 @@ class APE::Properties::PropertiesPrivate {
// public members
////////////////////////////////////////////////////////////////////////////////
APE::Properties::Properties(File *, ReadStyle style) : AudioProperties(style),
d(new PropertiesPrivate()) {
debug("APE::Properties::Properties() -- This constructor is no longer used.");
}
APE::Properties::Properties(File *file, long streamLength, ReadStyle style) : AudioProperties(style),
d(new PropertiesPrivate()) {
APE::Properties::Properties(File *file, long streamLength, ReadStyle style) : AudioProperties(style), d(new PropertiesPrivate()) {
read(file, streamLength);
}
@@ -75,10 +69,6 @@ APE::Properties::~Properties() {
delete d;
}
int APE::Properties::length() const {
return lengthInSeconds();
}
int APE::Properties::lengthInSeconds() const {
return d->length / 1000;
}
@@ -125,6 +115,7 @@ int headerVersion(const ByteVector &header) {
} // namespace
void APE::Properties::read(File *file, long streamLength) {
// First, we assume that the file pointer is set at the first descriptor.
long offset = file->tell();
int version = headerVersion(file->readBlock(6));
@@ -153,9 +144,11 @@ void APE::Properties::read(File *file, long streamLength) {
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5);
}
}
void APE::Properties::analyzeCurrent(File *file) {
// Read the descriptor
file->seek(2, File::Current);
const ByteVector descriptor = file->readBlock(44);
@@ -188,9 +181,11 @@ void APE::Properties::analyzeCurrent(File *file) {
const unsigned int blocksPerFrame = header.toUInt(4, false);
const unsigned int finalFrameBlocks = header.toUInt(8, false);
d->sampleFrames = (totalFrames - 1) * blocksPerFrame + finalFrameBlocks;
}
void APE::Properties::analyzeOld(File *file) {
const ByteVector header = file->readBlock(26);
if (header.size() < 26) {
debug("APE::Properties::analyzeOld() -- MAC header is too short.");
@@ -228,4 +223,5 @@ void APE::Properties::analyzeOld(File *file) {
}
d->bitsPerSample = fmt.toShort(26, false);
}

View File

@@ -35,7 +35,6 @@
namespace Strawberry_TagLib {
namespace TagLib {
namespace APE {
class File;
@@ -43,86 +42,66 @@ class File;
//! An implementation of audio property reading for APE
/*!
* This reads the data from an APE stream found in the AudioProperties
* API.
*/
* This reads the data from an APE stream found in the AudioProperties API.
*/
class TAGLIB_EXPORT Properties : public AudioProperties {
public:
/*!
* Create an instance of APE::Properties with the data read from the
* APE::File \a file.
*
* \deprecated
*/
TAGLIB_DEPRECATED Properties(File *file, ReadStyle style = Average);
/*!
* Create an instance of APE::Properties with the data read from the
* APE::File \a file.
*/
* Create an instance of APE::Properties with the data read from the APE::File \a file.
*/
Properties(File *file, long streamLength, ReadStyle style = Average);
/*!
* Destroys this APE::Properties instance.
*/
* Destroys this APE::Properties instance.
*/
virtual ~Properties();
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
*
* \note This method is just an alias of lengthInSeconds().
*
* \deprecated
*/
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
*
* \see lengthInMilliseconds()
*/
* Returns the length of the file in seconds. The length is rounded down to the nearest whole second.
*
* \see lengthInMilliseconds()
*/
// BIC: make virtual
int lengthInSeconds() const;
/*!
* Returns the length of the file in milliseconds.
*
* \see lengthInSeconds()
*/
* Returns the length of the file in milliseconds.
*
* \see lengthInSeconds()
*/
// BIC: make virtual
int lengthInMilliseconds() const;
/*!
* Returns the average bit rate of the file in kb/s.
*/
* Returns the average bit rate of the file in kb/s.
*/
virtual int bitrate() const;
/*!
* Returns the sample rate in Hz.
*/
* Returns the sample rate in Hz.
*/
virtual int sampleRate() const;
/*!
* Returns the number of audio channels.
*/
* Returns the number of audio channels.
*/
virtual int channels() const;
/*!
* Returns the number of bits per audio sample.
*/
* Returns the number of bits per audio sample.
*/
int bitsPerSample() const;
/*!
* Returns the total number of audio samples in file.
*/
* Returns the total number of audio samples in file.
*/
unsigned int sampleFrames() const;
/*!
* Returns APE version.
*/
* Returns APE version.
*/
int version() const;
private:

View File

@@ -51,7 +51,7 @@ const unsigned int MaxKeyLength = 255;
bool isKeyValid(const ByteVector &key) {
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 };
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", nullptr };
// only allow printable ASCII including space (32..126)
@@ -62,7 +62,7 @@ bool isKeyValid(const ByteVector &key) {
}
const String upperKey = String(key).upper();
for (size_t i = 0; invalidKeys[i] != 0; ++i) {
for (size_t i = 0; invalidKeys[i] != nullptr; ++i) {
if (upperKey == invalidKeys[i])
return false;
}
@@ -73,7 +73,7 @@ bool isKeyValid(const ByteVector &key) {
class APE::Tag::TagPrivate {
public:
TagPrivate() : file(0), footerLocation(0) {}
TagPrivate() : file(nullptr), footerLocation(0) {}
File *file;
long footerLocation;
@@ -207,6 +207,7 @@ const size_t keyConversionsSize = sizeof(keyConversions) / sizeof(keyConversions
} // namespace
PropertyMap APE::Tag::properties() const {
PropertyMap properties;
ItemListMap::ConstIterator it = itemListMap().begin();
for (; it != itemListMap().end(); ++it) {
@@ -226,15 +227,19 @@ PropertyMap APE::Tag::properties() const {
}
}
return properties;
}
void APE::Tag::removeUnsupportedProperties(const StringList &properties) {
StringList::ConstIterator it = properties.begin();
for (; it != properties.end(); ++it)
removeItem(*it);
}
PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) {
PropertyMap properties(origProps); // make a local copy that can be modified
// see comment in properties()
@@ -280,10 +285,12 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) {
}
bool APE::Tag::checkKey(const String &key) {
if (key.size() < MinKeyLength || key.size() > MaxKeyLength)
return false;
return isKeyValid(key.data(String::UTF8));
}
APE::Footer *APE::Tag::footer() const {
@@ -299,6 +306,7 @@ void APE::Tag::removeItem(const String &key) {
}
void APE::Tag::addValue(const String &key, const String &value, bool replace) {
if (replace)
removeItem(key);
@@ -314,24 +322,29 @@ void APE::Tag::addValue(const String &key, const String &value, bool replace) {
it->second.appendValue(value);
else
setItem(key, Item(key, value));
}
void APE::Tag::setData(const String &key, const ByteVector &value) {
removeItem(key);
if (value.isEmpty())
return;
setItem(key, Item(key, value, true));
}
void APE::Tag::setItem(const String &key, const Item &item) {
if (!checkKey(key)) {
debug("APE::Tag::setItem() - Couldn't set an item due to an invalid key.");
return;
}
d->itemListMap[key.upper()] = item;
}
bool APE::Tag::isEmpty() const {
@@ -343,6 +356,7 @@ bool APE::Tag::isEmpty() const {
////////////////////////////////////////////////////////////////////////////////
void APE::Tag::read() {
if (d->file && d->file->isValid()) {
d->file->seek(d->footerLocation);
@@ -355,9 +369,11 @@ void APE::Tag::read() {
d->file->seek(d->footerLocation + Footer::size() - d->footer.tagSize());
parse(d->file->readBlock(d->footer.tagSize() - Footer::size()));
}
}
ByteVector APE::Tag::render() const {
ByteVector data;
unsigned int itemCount = 0;
@@ -371,9 +387,11 @@ ByteVector APE::Tag::render() const {
d->footer.setHeaderPresent(true);
return d->footer.renderHeader() + data + d->footer.renderFooter();
}
void APE::Tag::parse(const ByteVector &data) {
// 11 bytes is the minimum size for an APE item
if (data.size() < 11)
@@ -404,4 +422,5 @@ void APE::Tag::parse(const ByteVector &data) {
pos += keyLength + valLegnth + 9;
}
}

View File

@@ -46,10 +46,10 @@ namespace APE {
class Footer;
/*!
* A mapping between a list of item names, or keys, and the associated item.
*
* \see APE::Tag::itemListMap()
*/
* A mapping between a list of item names, or keys, and the associated item.
*
* \see APE::Tag::itemListMap()
*/
typedef Map<const String, Item> ItemListMap;
@@ -58,31 +58,29 @@ typedef Map<const String, Item> ItemListMap;
class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
public:
/*!
* Create an APE tag with default values.
*/
* Create an APE tag with default values.
*/
Tag();
/*!
* Create an APE tag and parse the data in \a file with APE footer at
* \a tagOffset.
*/
* Create an APE tag and parse the data in \a file with APE footer at
* \a tagOffset.
*/
Tag(Strawberry_TagLib::TagLib::File *file, long footerLocation);
/*!
* Destroys this Tag instance.
*/
* Destroys this Tag instance.
*/
virtual ~Tag();
/*!
* Renders the in memory values to a ByteVector suitable for writing to
* the file.
*/
* Renders the in memory values to a ByteVector suitable for writing to the file.
*/
ByteVector render() const;
/*!
* Returns the string "APETAGEX" suitable for usage in locating the tag in a
* file.
*/
* Returns the string "APETAGEX" suitable for usage in locating the tag in a file.
*/
static ByteVector fileIdentifier();
// Reimplementations.
@@ -104,94 +102,91 @@ class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
virtual void setTrack(unsigned int i);
/*!
* Implements the unified tag dictionary interface -- export function.
* APE tags are perfectly compatible with the dictionary interface because they
* support both arbitrary tag names and multiple values. Currently only
* APE items of type *Text* are handled by the dictionary interface; all *Binary*
* and *Locator* items will be put into the unsupportedData list and can be
* deleted on request using removeUnsupportedProperties(). The same happens
* to Text items if their key is invalid for PropertyMap (which should actually
* never happen).
*
* The only conversion done by this export function is to rename the APE tags
* TRACK to TRACKNUMBER, YEAR to DATE, and ALBUM ARTIST to ALBUMARTIST, respectively,
* in order to be compliant with the names used in other formats.
*/
* Implements the unified tag dictionary interface -- export function.
* APE tags are perfectly compatible with the dictionary interface because they
* support both arbitrary tag names and multiple values.
* Currently only APE items of type *Text* are handled by the dictionary interface; all *Binary*
* and *Locator* items will be put into the unsupportedData list and can be
* deleted on request using removeUnsupportedProperties().
* The same happens to Text items if their key is invalid for PropertyMap (which should actually never happen).
*
* The only conversion done by this export function is to rename the APE tags
* TRACK to TRACKNUMBER, YEAR to DATE, and ALBUM ARTIST to ALBUMARTIST,
* respectively, in order to be compliant with the names used in other formats.
*/
PropertyMap properties() const;
void removeUnsupportedProperties(const StringList &properties);
/*!
* Implements the unified tag dictionary interface -- import function. The same
* comments as for the export function apply; additionally note that the APE tag
* specification requires keys to have between 2 and 16 printable ASCII characters
* with the exception of the fixed strings "ID3", "TAG", "OGGS", and "MP+".
*/
* Implements the unified tag dictionary interface -- import function.
* The same comments as for the export function apply; additionally note that the APE tag
* specification requires keys to have between 2 and 16 printable ASCII characters
* with the exception of the fixed strings "ID3", "TAG", "OGGS", and "MP+".
*/
PropertyMap setProperties(const PropertyMap &);
/*!
* Check if the given String is a valid APE tag key.
*/
* Check if the given String is a valid APE tag key.
*/
static bool checkKey(const String &);
/*!
* Returns a pointer to the tag's footer.
*/
* Returns a pointer to the tag's footer.
*/
Footer *footer() const;
/*!
* Returns a reference to the item list map. This is an ItemListMap of
* all of the items in the tag.
*
* This is the most powerful structure for accessing the items of the tag.
*
* APE tags are case-insensitive, all keys in this map have been converted
* to upper case.
*
* \warning You should not modify this data structure directly, instead
* use setItem() and removeItem().
*/
* Returns a reference to the item list map.
* This is an ItemListMap of all of the items in the tag.
*
* This is the most powerful structure for accessing the items of the tag.
*
* APE tags are case-insensitive, all keys in this map have been converted
* to upper case.
*
* \warning You should not modify this data structure directly, instead
* use setItem() and removeItem().
*/
const ItemListMap &itemListMap() const;
/*!
* Removes the \a key item from the tag
*/
* Removes the \a key item from the tag
*/
void removeItem(const String &key);
/*!
* Adds to the text item specified by \a key the data \a value. If \a replace
* is true, then all of the other values on the same key will be removed
* first. If a binary item exists for \a key it will be removed first.
*/
* Adds to the text item specified by \a key the data \a value.
* If \a replace is true, then all of the other values on the same key will be removed first.
* If a binary item exists for \a key it will be removed first.
*/
void addValue(const String &key, const String &value, bool replace = true);
/*!
* Set the binary data for the key specified by \a item to \a value
* This will convert the item to type \a Binary if it isn't already and
* all of the other values on the same key will be removed.
*/
* Set the binary data for the key specified by \a item to \a value
* This will convert the item to type \a Binary if it isn't already and all of the other values on the same key will be removed.
*/
void setData(const String &key, const ByteVector &value);
/*!
* Sets the \a key item to the value of \a item. If an item with the \a key is already
* present, it will be replaced.
*/
* Sets the \a key item to the value of \a item. If an item with the \a key is already present, it will be replaced.
*/
void setItem(const String &key, const Item &item);
/*!
* Returns true if the tag does not contain any data.
*/
* Returns true if the tag does not contain any data.
*/
bool isEmpty() const;
protected:
/*!
* Reads from the file specified in the constructor.
*/
* Reads from the file specified in the constructor.
*/
void read();
/*!
* Parses the body of the tag in \a data.
*/
* Parses the body of the tag in \a data.
*/
void parse(const ByteVector &data);
private: