1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-24 15:30:40 +01:00
strawberry-audio-player-win.../3rdparty/taglib/tagunion.cpp

221 lines
6.4 KiB
C++
Raw Normal View History

2018-05-10 15:29:28 +02:00
/***************************************************************************
copyright : (C) 2002 - 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* 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., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 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 <tagunion.h>
#include <tstringlist.h>
#include <tpropertymap.h>
#include "id3v1tag.h"
#include "id3v2tag.h"
#include "apetag.h"
#include "xiphcomment.h"
#include "infotag.h"
using namespace Strawberry_TagLib::TagLib;
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
#define stringUnion(method) \
if (tag(0) && !tag(0)->method().isEmpty()) \
return tag(0)->method(); \
if (tag(1) && !tag(1)->method().isEmpty()) \
return tag(1)->method(); \
if (tag(2) && !tag(2)->method().isEmpty()) \
return tag(2)->method(); \
return String();
#define numberUnion(method) \
if (tag(0) && tag(0)->method() > 0) \
return tag(0)->method(); \
if (tag(1) && tag(1)->method() > 0) \
return tag(1)->method(); \
if (tag(2) && tag(2)->method() > 0) \
return tag(2)->method(); \
2018-05-10 15:29:28 +02:00
return 0
2020-06-13 19:02:42 +02:00
#define setUnion(method, value) \
if (tag(0)) \
tag(0)->set##method(value); \
if (tag(1)) \
tag(1)->set##method(value); \
if (tag(2)) \
tag(2)->set##method(value);
class TagUnion::TagUnionPrivate {
public:
TagUnionPrivate() : tags(3, static_cast<Tag *>(0)) {
2018-05-10 15:29:28 +02:00
}
2020-06-13 19:02:42 +02:00
~TagUnionPrivate() {
2018-05-10 15:29:28 +02:00
delete tags[0];
delete tags[1];
delete tags[2];
}
std::vector<Tag *> tags;
};
2020-06-13 19:02:42 +02:00
TagUnion::TagUnion(Tag *first, Tag *second, Tag *third) : d(new TagUnionPrivate()) {
2018-05-10 15:29:28 +02:00
d->tags[0] = first;
d->tags[1] = second;
d->tags[2] = third;
}
2020-06-13 19:02:42 +02:00
TagUnion::~TagUnion() {
2018-05-10 15:29:28 +02:00
delete d;
}
2020-06-13 19:02:42 +02:00
Tag *TagUnion::operator[](int index) const {
2018-05-10 15:29:28 +02:00
return tag(index);
}
2020-06-13 19:02:42 +02:00
Tag *TagUnion::tag(int index) const {
2018-05-10 15:29:28 +02:00
return d->tags[index];
}
2020-06-13 19:02:42 +02:00
void TagUnion::set(int index, Tag *tag) {
2018-05-10 15:29:28 +02:00
delete d->tags[index];
d->tags[index] = tag;
}
2020-06-13 19:02:42 +02:00
PropertyMap TagUnion::properties() const {
2018-05-10 15:29:28 +02:00
// This is an ugly workaround but we can't add a virtual function.
// Should be virtual in taglib2.
2020-06-13 19:02:42 +02:00
for (size_t i = 0; i < 3; ++i) {
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
if (d->tags[i] && !d->tags[i]->isEmpty()) {
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
if (dynamic_cast<const ID3v1::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
return dynamic_cast<const ID3v1::Tag *>(d->tags[i])->properties();
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<const ID3v2::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
return dynamic_cast<const ID3v2::Tag *>(d->tags[i])->properties();
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<const APE::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
return dynamic_cast<const APE::Tag *>(d->tags[i])->properties();
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<const Ogg::XiphComment *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
return dynamic_cast<const Ogg::XiphComment *>(d->tags[i])->properties();
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<const RIFF::Info::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
return dynamic_cast<const RIFF::Info::Tag *>(d->tags[i])->properties();
}
}
return PropertyMap();
}
2020-06-13 19:02:42 +02:00
void TagUnion::removeUnsupportedProperties(const StringList &unsupported) {
2018-05-10 15:29:28 +02:00
// This is an ugly workaround but we can't add a virtual function.
// Should be virtual in taglib2.
2020-06-13 19:02:42 +02:00
for (size_t i = 0; i < 3; ++i) {
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
if (d->tags[i]) {
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
if (dynamic_cast<ID3v1::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
dynamic_cast<ID3v1::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<ID3v2::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
dynamic_cast<ID3v2::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<APE::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
dynamic_cast<APE::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<Ogg::XiphComment *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
dynamic_cast<Ogg::XiphComment *>(d->tags[i])->removeUnsupportedProperties(unsupported);
2020-06-13 19:02:42 +02:00
else if (dynamic_cast<RIFF::Info::Tag *>(d->tags[i]))
2018-05-10 15:29:28 +02:00
dynamic_cast<RIFF::Info::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
}
}
}
2020-06-13 19:02:42 +02:00
String TagUnion::title() const {
2018-05-10 15:29:28 +02:00
stringUnion(title);
}
2020-06-13 19:02:42 +02:00
String TagUnion::artist() const {
2018-05-10 15:29:28 +02:00
stringUnion(artist);
}
2020-06-13 19:02:42 +02:00
String TagUnion::album() const {
2018-05-10 15:29:28 +02:00
stringUnion(album);
}
2020-06-13 19:02:42 +02:00
String TagUnion::comment() const {
2018-05-10 15:29:28 +02:00
stringUnion(comment);
}
2020-06-13 19:02:42 +02:00
String TagUnion::genre() const {
2018-05-10 15:29:28 +02:00
stringUnion(genre);
}
2020-06-13 19:02:42 +02:00
unsigned int TagUnion::year() const {
2018-05-10 15:29:28 +02:00
numberUnion(year);
}
2020-06-13 19:02:42 +02:00
unsigned int TagUnion::track() const {
2018-05-10 15:29:28 +02:00
numberUnion(track);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setTitle(const String &s) {
2018-05-10 15:29:28 +02:00
setUnion(Title, s);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setArtist(const String &s) {
2018-05-10 15:29:28 +02:00
setUnion(Artist, s);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setAlbum(const String &s) {
2018-05-10 15:29:28 +02:00
setUnion(Album, s);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setComment(const String &s) {
2018-05-10 15:29:28 +02:00
setUnion(Comment, s);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setGenre(const String &s) {
2018-05-10 15:29:28 +02:00
setUnion(Genre, s);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setYear(unsigned int i) {
2018-05-10 15:29:28 +02:00
setUnion(Year, i);
}
2020-06-13 19:02:42 +02:00
void TagUnion::setTrack(unsigned int i) {
2018-05-10 15:29:28 +02:00
setUnion(Track, i);
}
2020-06-13 19:02:42 +02:00
bool TagUnion::isEmpty() const {
if (d->tags[0] && !d->tags[0]->isEmpty())
2018-05-10 15:29:28 +02:00
return false;
2020-06-13 19:02:42 +02:00
if (d->tags[1] && !d->tags[1]->isEmpty())
2018-05-10 15:29:28 +02:00
return false;
2020-06-13 19:02:42 +02:00
if (d->tags[2] && !d->tags[2]->isEmpty())
2018-05-10 15:29:28 +02:00
return false;
return true;
}