Replace raw buffers with std containers (#1101)

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2023-08-06 15:46:59 -07:00 committed by GitHub
parent 868f4eef3d
commit dcef356e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 444 additions and 438 deletions

View File

@ -43,6 +43,8 @@
#include "apefooter.h"
#include "apeitem.h"
#include <array>
using namespace TagLib;
using namespace APE;
@ -53,7 +55,7 @@ namespace
bool isKeyValid(const ByteVector &key)
{
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", nullptr };
static constexpr std::array invalidKeys { "ID3", "TAG", "OGGS", "MP+" };
// only allow printable ASCII including space (32..126)
@ -64,8 +66,8 @@ namespace
}
const String upperKey = String(key).upper();
for(size_t i = 0; invalidKeys[i] != nullptr; ++i) {
if(upperKey == invalidKeys[i])
for(auto k : invalidKeys) {
if(upperKey == k)
return false;
}
@ -203,16 +205,15 @@ namespace
// conversions of tag keys between what we use in PropertyMap and what's usual
// for APE tags
// usual, APE
const std::pair<const char *, const char *> keyConversions[] = {
std::make_pair("TRACKNUMBER", "TRACK"),
std::make_pair("DATE", "YEAR"),
std::make_pair("ALBUMARTIST", "ALBUM ARTIST"),
std::make_pair("DISCNUMBER", "DISC"),
std::make_pair("REMIXER", "MIXARTIST"),
std::make_pair("RELEASESTATUS", "MUSICBRAINZ_ALBUMSTATUS"),
std::make_pair("RELEASETYPE", "MUSICBRAINZ_ALBUMTYPE"),
constexpr std::array keyConversions {
std::pair("TRACKNUMBER", "TRACK"),
std::pair("DATE", "YEAR"),
std::pair("ALBUMARTIST", "ALBUM ARTIST"),
std::pair("DISCNUMBER", "DISC"),
std::pair("REMIXER", "MIXARTIST"),
std::pair("RELEASESTATUS", "MUSICBRAINZ_ALBUMSTATUS"),
std::pair("RELEASETYPE", "MUSICBRAINZ_ALBUMTYPE"),
};
const size_t keyConversionsSize = sizeof(keyConversions) / sizeof(keyConversions[0]);
} // namespace
PropertyMap APE::Tag::properties() const
@ -228,9 +229,9 @@ PropertyMap APE::Tag::properties() const
}
else {
// Some tags need to be handled specially
for(size_t i = 0; i < keyConversionsSize; ++i) {
if(tagName == keyConversions[i].second)
tagName = keyConversions[i].first;
for(const auto &[k, t] : keyConversions) {
if(tagName == t)
tagName = k;
}
properties[tagName].append(it->second.toStringList());
}
@ -249,10 +250,10 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps)
PropertyMap properties(origProps); // make a local copy that can be modified
// see comment in properties()
for(size_t i = 0; i < keyConversionsSize; ++i)
if(properties.contains(keyConversions[i].first)) {
properties.insert(keyConversions[i].second, properties[keyConversions[i].first]);
properties.erase(keyConversions[i].first);
for(const auto &[k, t] : keyConversions)
if(properties.contains(k)) {
properties.insert(t, properties[k]);
properties.erase(k);
}
// first check if tags need to be removed completely

View File

@ -26,6 +26,8 @@
#include "asftag.h"
#include "tpropertymap.h"
#include <array>
using namespace TagLib;
class ASF::Tag::TagPrivate
@ -210,60 +212,59 @@ bool ASF::Tag::isEmpty() const
namespace
{
const std::pair<const char *, const char *> keyTranslation[] = {
std::make_pair("WM/AlbumTitle", "ALBUM"),
std::make_pair("WM/AlbumArtist", "ALBUMARTIST"),
std::make_pair("WM/Composer", "COMPOSER"),
std::make_pair("WM/Writer", "LYRICIST"),
std::make_pair("WM/Conductor", "CONDUCTOR"),
std::make_pair("WM/ModifiedBy", "REMIXER"),
std::make_pair("WM/Year", "DATE"),
std::make_pair("WM/OriginalReleaseYear", "ORIGINALDATE"),
std::make_pair("WM/Producer", "PRODUCER"),
std::make_pair("WM/ContentGroupDescription", "WORK"),
std::make_pair("WM/SubTitle", "SUBTITLE"),
std::make_pair("WM/SetSubTitle", "DISCSUBTITLE"),
std::make_pair("WM/TrackNumber", "TRACKNUMBER"),
std::make_pair("WM/PartOfSet", "DISCNUMBER"),
std::make_pair("WM/Genre", "GENRE"),
std::make_pair("WM/BeatsPerMinute", "BPM"),
std::make_pair("WM/Mood", "MOOD"),
std::make_pair("WM/ISRC", "ISRC"),
std::make_pair("WM/Lyrics", "LYRICS"),
std::make_pair("WM/Media", "MEDIA"),
std::make_pair("WM/Publisher", "LABEL"),
std::make_pair("WM/CatalogNo", "CATALOGNUMBER"),
std::make_pair("WM/Barcode", "BARCODE"),
std::make_pair("WM/EncodedBy", "ENCODEDBY"),
std::make_pair("WM/AlbumSortOrder", "ALBUMSORT"),
std::make_pair("WM/AlbumArtistSortOrder", "ALBUMARTISTSORT"),
std::make_pair("WM/ArtistSortOrder", "ARTISTSORT"),
std::make_pair("WM/TitleSortOrder", "TITLESORT"),
std::make_pair("WM/Script", "SCRIPT"),
std::make_pair("WM/Language", "LANGUAGE"),
std::make_pair("WM/ARTISTS", "ARTISTS"),
std::make_pair("ASIN", "ASIN"),
std::make_pair("MusicBrainz/Track Id", "MUSICBRAINZ_TRACKID"),
std::make_pair("MusicBrainz/Artist Id", "MUSICBRAINZ_ARTISTID"),
std::make_pair("MusicBrainz/Album Id", "MUSICBRAINZ_ALBUMID"),
std::make_pair("MusicBrainz/Album Artist Id", "MUSICBRAINZ_ALBUMARTISTID"),
std::make_pair("MusicBrainz/Album Release Country", "RELEASECOUNTRY"),
std::make_pair("MusicBrainz/Album Status", "RELEASESTATUS"),
std::make_pair("MusicBrainz/Album Type", "RELEASETYPE"),
std::make_pair("MusicBrainz/Release Group Id", "MUSICBRAINZ_RELEASEGROUPID"),
std::make_pair("MusicBrainz/Release Track Id", "MUSICBRAINZ_RELEASETRACKID"),
std::make_pair("MusicBrainz/Work Id", "MUSICBRAINZ_WORKID"),
std::make_pair("MusicIP/PUID", "MUSICIP_PUID"),
std::make_pair("Acoustid/Id", "ACOUSTID_ID"),
std::make_pair("Acoustid/Fingerprint", "ACOUSTID_FINGERPRINT"),
constexpr std::array keyTranslation {
std::pair("WM/AlbumTitle", "ALBUM"),
std::pair("WM/AlbumArtist", "ALBUMARTIST"),
std::pair("WM/Composer", "COMPOSER"),
std::pair("WM/Writer", "LYRICIST"),
std::pair("WM/Conductor", "CONDUCTOR"),
std::pair("WM/ModifiedBy", "REMIXER"),
std::pair("WM/Year", "DATE"),
std::pair("WM/OriginalReleaseYear", "ORIGINALDATE"),
std::pair("WM/Producer", "PRODUCER"),
std::pair("WM/ContentGroupDescription", "WORK"),
std::pair("WM/SubTitle", "SUBTITLE"),
std::pair("WM/SetSubTitle", "DISCSUBTITLE"),
std::pair("WM/TrackNumber", "TRACKNUMBER"),
std::pair("WM/PartOfSet", "DISCNUMBER"),
std::pair("WM/Genre", "GENRE"),
std::pair("WM/BeatsPerMinute", "BPM"),
std::pair("WM/Mood", "MOOD"),
std::pair("WM/ISRC", "ISRC"),
std::pair("WM/Lyrics", "LYRICS"),
std::pair("WM/Media", "MEDIA"),
std::pair("WM/Publisher", "LABEL"),
std::pair("WM/CatalogNo", "CATALOGNUMBER"),
std::pair("WM/Barcode", "BARCODE"),
std::pair("WM/EncodedBy", "ENCODEDBY"),
std::pair("WM/AlbumSortOrder", "ALBUMSORT"),
std::pair("WM/AlbumArtistSortOrder", "ALBUMARTISTSORT"),
std::pair("WM/ArtistSortOrder", "ARTISTSORT"),
std::pair("WM/TitleSortOrder", "TITLESORT"),
std::pair("WM/Script", "SCRIPT"),
std::pair("WM/Language", "LANGUAGE"),
std::pair("WM/ARTISTS", "ARTISTS"),
std::pair("ASIN", "ASIN"),
std::pair("MusicBrainz/Track Id", "MUSICBRAINZ_TRACKID"),
std::pair("MusicBrainz/Artist Id", "MUSICBRAINZ_ARTISTID"),
std::pair("MusicBrainz/Album Id", "MUSICBRAINZ_ALBUMID"),
std::pair("MusicBrainz/Album Artist Id", "MUSICBRAINZ_ALBUMARTISTID"),
std::pair("MusicBrainz/Album Release Country", "RELEASECOUNTRY"),
std::pair("MusicBrainz/Album Status", "RELEASESTATUS"),
std::pair("MusicBrainz/Album Type", "RELEASETYPE"),
std::pair("MusicBrainz/Release Group Id", "MUSICBRAINZ_RELEASEGROUPID"),
std::pair("MusicBrainz/Release Track Id", "MUSICBRAINZ_RELEASETRACKID"),
std::pair("MusicBrainz/Work Id", "MUSICBRAINZ_WORKID"),
std::pair("MusicIP/PUID", "MUSICIP_PUID"),
std::pair("Acoustid/Id", "ACOUSTID_ID"),
std::pair("Acoustid/Fingerprint", "ACOUSTID_FINGERPRINT"),
};
const size_t keyTranslationSize = sizeof(keyTranslation) / sizeof(keyTranslation[0]);
String translateKey(const String &key)
{
for(size_t i = 0; i < keyTranslationSize; ++i) {
if(key == keyTranslation[i].first)
return keyTranslation[i].second;
for(const auto &[k, t] : keyTranslation) {
if(key == k)
return t;
}
return String();
@ -319,8 +320,8 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props)
{
static Map<String, String> reverseKeyMap;
if(reverseKeyMap.isEmpty()) {
for(size_t i = 0; i < keyTranslationSize; i++) {
reverseKeyMap[keyTranslation[i].second] = keyTranslation[i].first;
for(const auto &[k, t] : keyTranslation) {
reverseKeyMap[t] = k;
}
}

View File

@ -32,11 +32,13 @@
using namespace TagLib;
const char *const MP4::Atom::containers[11] = {
namespace {
constexpr std::array containers {
"moov", "udta", "mdia", "meta", "ilst",
"stbl", "minf", "moof", "traf", "trak",
"stsd"
};
};
} // namespace
MP4::Atom::Atom(File *file)
: offset(file->tell())
@ -91,19 +93,17 @@ MP4::Atom::Atom(File *file)
}
}
for(int i = 0; i < numContainers; i++) {
if(name == containers[i]) {
for(auto c : containers) {
if(name == c) {
if(name == "meta") {
offset_t posAfterMeta = file->tell();
ByteVector nextSize = file->readBlock(8).mid(4, 4);
static const char *const metaChildrenNames[] = {
"hdlr", "ilst", "mhdr", "ctry", "lang"
static constexpr std::array metaChildrenNames {
"hdlr", "ilst", "mhdr", "ctry", "lang"
};
bool metaIsFullAtom = true;
for(size_t j = 0;
j < sizeof(metaChildrenNames) / sizeof(metaChildrenNames[0]);
++j) {
if(nextSize == metaChildrenNames[j]) {
for(auto child : metaChildrenNames) {
if(nextSize == child) {
// meta is not a full atom (i.e. not followed by version, flags). It
// is followed by the size and type of the first child atom.
metaIsFullAtom = false;

View File

@ -25,21 +25,22 @@
// This file is not part of the public API!
#ifndef DO_NOT_DOCUMENT
#ifndef TAGLIB_MP4ATOM_H
#define TAGLIB_MP4ATOM_H
#include "tfile.h"
#include "tlist.h"
#include <array>
#ifndef DO_NOT_DOCUMENT
namespace TagLib {
namespace MP4 {
class Atom;
typedef TagLib::List<Atom *> AtomList;
enum AtomDataType
{
enum AtomDataType {
TypeImplicit = 0, // for use with tags for which no type needs to be indicated because only one type is allowed
TypeUTF8 = 1, // without any count or null terminator
TypeUTF16 = 2, // also known as UTF-16BE
@ -85,9 +86,6 @@ namespace TagLib {
offset_t length;
TagLib::ByteVector name;
AtomList children;
private:
static const int numContainers = 11;
static const char *const containers[11];
};
//! Root-level atoms
@ -100,8 +98,8 @@ namespace TagLib {
AtomList path(const char *name1, const char *name2 = nullptr, const char *name3 = nullptr, const char *name4 = nullptr);
AtomList atoms;
};
} // namespace MP4
} // namespace TagLib
} // namespace MP4
} // namespace TagLib
#endif

View File

@ -30,6 +30,8 @@
#include "mp4atom.h"
#include "id3v1genres.h"
#include <array>
using namespace TagLib;
class MP4::Tag::TagPrivate
@ -899,84 +901,83 @@ bool MP4::Tag::contains(const String &key) const
namespace
{
const std::pair<const char *, const char *> keyTranslation[] = {
std::make_pair("\251nam", "TITLE"),
std::make_pair("\251ART", "ARTIST"),
std::make_pair("\251alb", "ALBUM"),
std::make_pair("\251cmt", "COMMENT"),
std::make_pair("\251gen", "GENRE"),
std::make_pair("\251day", "DATE"),
std::make_pair("\251wrt", "COMPOSER"),
std::make_pair("\251grp", "GROUPING"),
std::make_pair("aART", "ALBUMARTIST"),
std::make_pair("trkn", "TRACKNUMBER"),
std::make_pair("disk", "DISCNUMBER"),
std::make_pair("cpil", "COMPILATION"),
std::make_pair("tmpo", "BPM"),
std::make_pair("cprt", "COPYRIGHT"),
std::make_pair("\251lyr", "LYRICS"),
std::make_pair("\251too", "ENCODEDBY"),
std::make_pair("soal", "ALBUMSORT"),
std::make_pair("soaa", "ALBUMARTISTSORT"),
std::make_pair("soar", "ARTISTSORT"),
std::make_pair("sonm", "TITLESORT"),
std::make_pair("soco", "COMPOSERSORT"),
std::make_pair("sosn", "SHOWSORT"),
std::make_pair("shwm", "SHOWWORKMOVEMENT"),
std::make_pair("pgap", "GAPLESSPLAYBACK"),
std::make_pair("pcst", "PODCAST"),
std::make_pair("catg", "PODCASTCATEGORY"),
std::make_pair("desc", "PODCASTDESC"),
std::make_pair("egid", "PODCASTID"),
std::make_pair("purl", "PODCASTURL"),
std::make_pair("tves", "TVEPISODE"),
std::make_pair("tven", "TVEPISODEID"),
std::make_pair("tvnn", "TVNETWORK"),
std::make_pair("tvsn", "TVSEASON"),
std::make_pair("tvsh", "TVSHOW"),
std::make_pair("\251wrk", "WORK"),
std::make_pair("\251mvn", "MOVEMENTNAME"),
std::make_pair("\251mvi", "MOVEMENTNUMBER"),
std::make_pair("\251mvc", "MOVEMENTCOUNT"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Track Id", "MUSICBRAINZ_TRACKID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Artist Id", "MUSICBRAINZ_ARTISTID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Album Id", "MUSICBRAINZ_ALBUMID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Album Artist Id", "MUSICBRAINZ_ALBUMARTISTID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Release Group Id", "MUSICBRAINZ_RELEASEGROUPID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Release Track Id", "MUSICBRAINZ_RELEASETRACKID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Work Id", "MUSICBRAINZ_WORKID"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Album Release Country", "RELEASECOUNTRY"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Album Status", "RELEASESTATUS"),
std::make_pair("----:com.apple.iTunes:MusicBrainz Album Type", "RELEASETYPE"),
std::make_pair("----:com.apple.iTunes:ARTISTS", "ARTISTS"),
std::make_pair("----:com.apple.iTunes:originaldate", "ORIGINALDATE"),
std::make_pair("----:com.apple.iTunes:ASIN", "ASIN"),
std::make_pair("----:com.apple.iTunes:LABEL", "LABEL"),
std::make_pair("----:com.apple.iTunes:LYRICIST", "LYRICIST"),
std::make_pair("----:com.apple.iTunes:CONDUCTOR", "CONDUCTOR"),
std::make_pair("----:com.apple.iTunes:REMIXER", "REMIXER"),
std::make_pair("----:com.apple.iTunes:ENGINEER", "ENGINEER"),
std::make_pair("----:com.apple.iTunes:PRODUCER", "PRODUCER"),
std::make_pair("----:com.apple.iTunes:DJMIXER", "DJMIXER"),
std::make_pair("----:com.apple.iTunes:MIXER", "MIXER"),
std::make_pair("----:com.apple.iTunes:SUBTITLE", "SUBTITLE"),
std::make_pair("----:com.apple.iTunes:DISCSUBTITLE", "DISCSUBTITLE"),
std::make_pair("----:com.apple.iTunes:MOOD", "MOOD"),
std::make_pair("----:com.apple.iTunes:ISRC", "ISRC"),
std::make_pair("----:com.apple.iTunes:CATALOGNUMBER", "CATALOGNUMBER"),
std::make_pair("----:com.apple.iTunes:BARCODE", "BARCODE"),
std::make_pair("----:com.apple.iTunes:SCRIPT", "SCRIPT"),
std::make_pair("----:com.apple.iTunes:LANGUAGE", "LANGUAGE"),
std::make_pair("----:com.apple.iTunes:LICENSE", "LICENSE"),
std::make_pair("----:com.apple.iTunes:MEDIA", "MEDIA"),
constexpr std::array keyTranslation {
std::pair("\251nam", "TITLE"),
std::pair("\251ART", "ARTIST"),
std::pair("\251alb", "ALBUM"),
std::pair("\251cmt", "COMMENT"),
std::pair("\251gen", "GENRE"),
std::pair("\251day", "DATE"),
std::pair("\251wrt", "COMPOSER"),
std::pair("\251grp", "GROUPING"),
std::pair("aART", "ALBUMARTIST"),
std::pair("trkn", "TRACKNUMBER"),
std::pair("disk", "DISCNUMBER"),
std::pair("cpil", "COMPILATION"),
std::pair("tmpo", "BPM"),
std::pair("cprt", "COPYRIGHT"),
std::pair("\251lyr", "LYRICS"),
std::pair("\251too", "ENCODEDBY"),
std::pair("soal", "ALBUMSORT"),
std::pair("soaa", "ALBUMARTISTSORT"),
std::pair("soar", "ARTISTSORT"),
std::pair("sonm", "TITLESORT"),
std::pair("soco", "COMPOSERSORT"),
std::pair("sosn", "SHOWSORT"),
std::pair("shwm", "SHOWWORKMOVEMENT"),
std::pair("pgap", "GAPLESSPLAYBACK"),
std::pair("pcst", "PODCAST"),
std::pair("catg", "PODCASTCATEGORY"),
std::pair("desc", "PODCASTDESC"),
std::pair("egid", "PODCASTID"),
std::pair("purl", "PODCASTURL"),
std::pair("tves", "TVEPISODE"),
std::pair("tven", "TVEPISODEID"),
std::pair("tvnn", "TVNETWORK"),
std::pair("tvsn", "TVSEASON"),
std::pair("tvsh", "TVSHOW"),
std::pair("\251wrk", "WORK"),
std::pair("\251mvn", "MOVEMENTNAME"),
std::pair("\251mvi", "MOVEMENTNUMBER"),
std::pair("\251mvc", "MOVEMENTCOUNT"),
std::pair("----:com.apple.iTunes:MusicBrainz Track Id", "MUSICBRAINZ_TRACKID"),
std::pair("----:com.apple.iTunes:MusicBrainz Artist Id", "MUSICBRAINZ_ARTISTID"),
std::pair("----:com.apple.iTunes:MusicBrainz Album Id", "MUSICBRAINZ_ALBUMID"),
std::pair("----:com.apple.iTunes:MusicBrainz Album Artist Id", "MUSICBRAINZ_ALBUMARTISTID"),
std::pair("----:com.apple.iTunes:MusicBrainz Release Group Id", "MUSICBRAINZ_RELEASEGROUPID"),
std::pair("----:com.apple.iTunes:MusicBrainz Release Track Id", "MUSICBRAINZ_RELEASETRACKID"),
std::pair("----:com.apple.iTunes:MusicBrainz Work Id", "MUSICBRAINZ_WORKID"),
std::pair("----:com.apple.iTunes:MusicBrainz Album Release Country", "RELEASECOUNTRY"),
std::pair("----:com.apple.iTunes:MusicBrainz Album Status", "RELEASESTATUS"),
std::pair("----:com.apple.iTunes:MusicBrainz Album Type", "RELEASETYPE"),
std::pair("----:com.apple.iTunes:ARTISTS", "ARTISTS"),
std::pair("----:com.apple.iTunes:originaldate", "ORIGINALDATE"),
std::pair("----:com.apple.iTunes:ASIN", "ASIN"),
std::pair("----:com.apple.iTunes:LABEL", "LABEL"),
std::pair("----:com.apple.iTunes:LYRICIST", "LYRICIST"),
std::pair("----:com.apple.iTunes:CONDUCTOR", "CONDUCTOR"),
std::pair("----:com.apple.iTunes:REMIXER", "REMIXER"),
std::pair("----:com.apple.iTunes:ENGINEER", "ENGINEER"),
std::pair("----:com.apple.iTunes:PRODUCER", "PRODUCER"),
std::pair("----:com.apple.iTunes:DJMIXER", "DJMIXER"),
std::pair("----:com.apple.iTunes:MIXER", "MIXER"),
std::pair("----:com.apple.iTunes:SUBTITLE", "SUBTITLE"),
std::pair("----:com.apple.iTunes:DISCSUBTITLE", "DISCSUBTITLE"),
std::pair("----:com.apple.iTunes:MOOD", "MOOD"),
std::pair("----:com.apple.iTunes:ISRC", "ISRC"),
std::pair("----:com.apple.iTunes:CATALOGNUMBER", "CATALOGNUMBER"),
std::pair("----:com.apple.iTunes:BARCODE", "BARCODE"),
std::pair("----:com.apple.iTunes:SCRIPT", "SCRIPT"),
std::pair("----:com.apple.iTunes:LANGUAGE", "LANGUAGE"),
std::pair("----:com.apple.iTunes:LICENSE", "LICENSE"),
std::pair("----:com.apple.iTunes:MEDIA", "MEDIA"),
};
const size_t keyTranslationSize = sizeof(keyTranslation) / sizeof(keyTranslation[0]);
String translateKey(const String &key)
{
for(size_t i = 0; i < keyTranslationSize; ++i) {
if(key == keyTranslation[i].first)
return keyTranslation[i].second;
for(const auto &[k, t] : keyTranslation) {
if(key == k)
return t;
}
return String();
@ -1026,8 +1027,8 @@ PropertyMap MP4::Tag::setProperties(const PropertyMap &props)
{
static Map<String, String> reverseKeyMap;
if(reverseKeyMap.isEmpty()) {
for(size_t i = 0; i < keyTranslationSize; i++) {
reverseKeyMap[keyTranslation[i].second] = keyTranslation[i].first;
for(const auto &[k, t] : keyTranslation) {
reverseKeyMap[t] = k;
}
}

View File

@ -25,8 +25,9 @@
#include "mpcproperties.h"
#include "tstring.h"
#include "tdebug.h"
#include "tstring.h"
#include <array>
#include <bitset>
#include <cmath>
@ -184,7 +185,7 @@ namespace
// This array looks weird, but the same as original MusePack code found at:
// https://www.musepack.net/index.php?pg=src
const unsigned short sftable [8] = { 44100, 48000, 37800, 32000, 0, 0, 0, 0 };
constexpr std::array sftable { 44100, 48000, 37800, 32000, 0, 0, 0, 0 };
} // namespace
void MPC::Properties::readSV8(File *file, offset_t streamLength)

View File

@ -25,11 +25,13 @@
#include "id3v1genres.h"
#include <array>
using namespace TagLib;
namespace
{
const wchar_t *const genres[] = {
constexpr std::array genres {
L"Blues",
L"Classic Rock",
L"Country",
@ -223,14 +225,13 @@ namespace
L"Garage Rock",
L"Psybient"
};
const int genresSize = sizeof(genres) / sizeof(genres[0]);
} // namespace
StringList ID3v1::genreList()
{
StringList l;
for(int i = 0; i < genresSize; i++) {
l.append(genres[i]);
for(auto g : genres) {
l.append(g);
}
return l;
@ -239,7 +240,7 @@ StringList ID3v1::genreList()
ID3v1::GenreMap ID3v1::genreMap()
{
GenreMap m;
for(int i = 0; i < genresSize; i++) {
for(size_t i = 0; i < genres.size(); i++) {
m.insert(genres[i], i);
}
@ -248,37 +249,32 @@ ID3v1::GenreMap ID3v1::genreMap()
String ID3v1::genre(int i)
{
if(i >= 0 && i < genresSize)
if(i >= 0 && i < genres.size())
return String(genres[i]); // always make a copy
return String();
}
int ID3v1::genreIndex(const String &name)
{
for(int i = 0; i < genresSize; ++i) {
for(size_t i = 0; i < genres.size(); ++i) {
if(name == genres[i])
return i;
return static_cast<int>(i);
}
// If the name was not found, try the names which have been changed
static const struct {
const wchar_t *genre;
int code;
} fixUpGenres[] = {
{ L"Jazz+Funk", 29 },
{ L"Folk/Rock", 81 },
{ L"Bebob", 85 },
{ L"Avantgarde", 90 },
{ L"Dance Hall", 125 },
{ L"Hardcore", 129 },
{ L"BritPop", 132 },
{ L"Negerpunk", 133 }
static constexpr std::array fixUpGenres {
std::pair(L"Jazz+Funk", 29),
std::pair(L"Folk/Rock", 81),
std::pair(L"Bebob", 85),
std::pair(L"Avantgarde", 90),
std::pair(L"Dance Hall", 125),
std::pair(L"Hardcore", 129),
std::pair(L"BritPop", 132),
std::pair(L"Negerpunk", 133),
};
static const int fixUpGenresSize =
sizeof(fixUpGenres) / sizeof(fixUpGenres[0]);
for(int i = 0; i < fixUpGenresSize; ++i) {
if(name == fixUpGenres[i].genre)
return fixUpGenres[i].code;
for(const auto &[genre, code] : fixUpGenres) {
if(name == genre)
return code;
}
return 255;

View File

@ -29,6 +29,8 @@
#include "tpropertymap.h"
#include "id3v1genres.h"
#include <array>
using namespace TagLib;
using namespace ID3v2;
@ -125,22 +127,21 @@ void TextIdentificationFrame::setTextEncoding(String::Type encoding)
namespace
{
// array of allowed TIPL prefixes and their corresponding key value
const std::pair<const char *, const char *> involvedPeople[] = {
std::make_pair("ARRANGER", "ARRANGER"),
std::make_pair("ENGINEER", "ENGINEER"),
std::make_pair("PRODUCER", "PRODUCER"),
std::make_pair("DJ-MIX", "DJMIXER"),
std::make_pair("MIX", "MIXER"),
constexpr std::array involvedPeople {
std::pair("ARRANGER", "ARRANGER"),
std::pair("ENGINEER", "ENGINEER"),
std::pair("PRODUCER", "PRODUCER"),
std::pair("DJ-MIX", "DJMIXER"),
std::pair("MIX", "MIXER"),
};
const size_t involvedPeopleSize = sizeof(involvedPeople) / sizeof(involvedPeople[0]);
} // namespace
const KeyConversionMap &TextIdentificationFrame::involvedPeopleMap() // static
{
static KeyConversionMap m;
if(m.isEmpty()) {
for(size_t i = 0; i < involvedPeopleSize; ++i)
m.insert(involvedPeople[i].second, involvedPeople[i].first);
for(const auto &[o, t] : involvedPeople)
m.insert(t, o);
}
return m;
}
@ -293,9 +294,9 @@ PropertyMap TextIdentificationFrame::makeTIPLProperties() const
const StringList l = fieldList();
for(auto it = l.begin(); it != l.end(); ++it) {
bool found = false;
for(size_t i = 0; i < involvedPeopleSize; ++i)
if(*it == involvedPeople[i].first) {
map.insert(involvedPeople[i].second, (++it)->split(","));
for(const auto &[o, t] : involvedPeople)
if(*it == o) {
map.insert(t, (++it)->split(","));
found = true;
break;
}

View File

@ -25,6 +25,7 @@
#include "id3v2frame.h"
#include <array>
#include <bitset>
#include "tdebug.h"
@ -307,122 +308,119 @@ String::Type Frame::checkTextEncoding(const StringList &fields, String::Type enc
namespace
{
const std::pair<const char *, const char *> frameTranslation[] = {
constexpr std::array frameTranslation {
// Text information frames
std::make_pair("TALB", "ALBUM"),
std::make_pair("TBPM", "BPM"),
std::make_pair("TCOM", "COMPOSER"),
std::make_pair("TCON", "GENRE"),
std::make_pair("TCOP", "COPYRIGHT"),
std::make_pair("TDEN", "ENCODINGTIME"),
std::make_pair("TDLY", "PLAYLISTDELAY"),
std::make_pair("TDOR", "ORIGINALDATE"),
std::make_pair("TDRC", "DATE"),
// std::make_pair("TRDA", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
// std::make_pair("TDAT", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
// std::make_pair("TYER", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
// std::make_pair("TIME", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
std::make_pair("TDRL", "RELEASEDATE"),
std::make_pair("TDTG", "TAGGINGDATE"),
std::make_pair("TENC", "ENCODEDBY"),
std::make_pair("TEXT", "LYRICIST"),
std::make_pair("TFLT", "FILETYPE"),
//std::make_pair("TIPL", "INVOLVEDPEOPLE"), handled separately
std::make_pair("TIT1", "WORK"), // 'Work' in iTunes
std::make_pair("TIT2", "TITLE"),
std::make_pair("TIT3", "SUBTITLE"),
std::make_pair("TKEY", "INITIALKEY"),
std::make_pair("TLAN", "LANGUAGE"),
std::make_pair("TLEN", "LENGTH"),
//std::make_pair("TMCL", "MUSICIANCREDITS"), handled separately
std::make_pair("TMED", "MEDIA"),
std::make_pair("TMOO", "MOOD"),
std::make_pair("TOAL", "ORIGINALALBUM"),
std::make_pair("TOFN", "ORIGINALFILENAME"),
std::make_pair("TOLY", "ORIGINALLYRICIST"),
std::make_pair("TOPE", "ORIGINALARTIST"),
std::make_pair("TOWN", "OWNER"),
std::make_pair("TPE1", "ARTIST"),
std::make_pair("TPE2", "ALBUMARTIST"), // id3's spec says 'PERFORMER', but most programs use 'ALBUMARTIST'
std::make_pair("TPE3", "CONDUCTOR"),
std::make_pair("TPE4", "REMIXER"), // could also be ARRANGER
std::make_pair("TPOS", "DISCNUMBER"),
std::make_pair("TPRO", "PRODUCEDNOTICE"),
std::make_pair("TPUB", "LABEL"),
std::make_pair("TRCK", "TRACKNUMBER"),
std::make_pair("TRSN", "RADIOSTATION"),
std::make_pair("TRSO", "RADIOSTATIONOWNER"),
std::make_pair("TSOA", "ALBUMSORT"),
std::make_pair("TSOC", "COMPOSERSORT"),
std::make_pair("TSOP", "ARTISTSORT"),
std::make_pair("TSOT", "TITLESORT"),
std::make_pair("TSO2", "ALBUMARTISTSORT"), // non-standard, used by iTunes
std::make_pair("TSRC", "ISRC"),
std::make_pair("TSSE", "ENCODING"),
std::make_pair("TSST", "DISCSUBTITLE"),
std::pair("TALB", "ALBUM"),
std::pair("TBPM", "BPM"),
std::pair("TCOM", "COMPOSER"),
std::pair("TCON", "GENRE"),
std::pair("TCOP", "COPYRIGHT"),
std::pair("TDEN", "ENCODINGTIME"),
std::pair("TDLY", "PLAYLISTDELAY"),
std::pair("TDOR", "ORIGINALDATE"),
std::pair("TDRC", "DATE"),
// std::pair("TRDA", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
// std::pair("TDAT", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
// std::pair("TYER", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
// std::pair("TIME", "DATE"), // id3 v2.3, replaced by TDRC in v2.4
std::pair("TDRL", "RELEASEDATE"),
std::pair("TDTG", "TAGGINGDATE"),
std::pair("TENC", "ENCODEDBY"),
std::pair("TEXT", "LYRICIST"),
std::pair("TFLT", "FILETYPE"),
// std::pair("TIPL", "INVOLVEDPEOPLE"), handled separately
std::pair("TIT1", "WORK"), // 'Work' in iTunes
std::pair("TIT2", "TITLE"),
std::pair("TIT3", "SUBTITLE"),
std::pair("TKEY", "INITIALKEY"),
std::pair("TLAN", "LANGUAGE"),
std::pair("TLEN", "LENGTH"),
// std::pair("TMCL", "MUSICIANCREDITS"), handled separately
std::pair("TMED", "MEDIA"),
std::pair("TMOO", "MOOD"),
std::pair("TOAL", "ORIGINALALBUM"),
std::pair("TOFN", "ORIGINALFILENAME"),
std::pair("TOLY", "ORIGINALLYRICIST"),
std::pair("TOPE", "ORIGINALARTIST"),
std::pair("TOWN", "OWNER"),
std::pair("TPE1", "ARTIST"),
std::pair("TPE2", "ALBUMARTIST"), // id3's spec says 'PERFORMER', but most programs use 'ALBUMARTIST'
std::pair("TPE3", "CONDUCTOR"),
std::pair("TPE4", "REMIXER"), // could also be ARRANGER
std::pair("TPOS", "DISCNUMBER"),
std::pair("TPRO", "PRODUCEDNOTICE"),
std::pair("TPUB", "LABEL"),
std::pair("TRCK", "TRACKNUMBER"),
std::pair("TRSN", "RADIOSTATION"),
std::pair("TRSO", "RADIOSTATIONOWNER"),
std::pair("TSOA", "ALBUMSORT"),
std::pair("TSOC", "COMPOSERSORT"),
std::pair("TSOP", "ARTISTSORT"),
std::pair("TSOT", "TITLESORT"),
std::pair("TSO2", "ALBUMARTISTSORT"), // non-standard, used by iTunes
std::pair("TSRC", "ISRC"),
std::pair("TSSE", "ENCODING"),
std::pair("TSST", "DISCSUBTITLE"),
// URL frames
std::make_pair("WCOP", "COPYRIGHTURL"),
std::make_pair("WOAF", "FILEWEBPAGE"),
std::make_pair("WOAR", "ARTISTWEBPAGE"),
std::make_pair("WOAS", "AUDIOSOURCEWEBPAGE"),
std::make_pair("WORS", "RADIOSTATIONWEBPAGE"),
std::make_pair("WPAY", "PAYMENTWEBPAGE"),
std::make_pair("WPUB", "PUBLISHERWEBPAGE"),
//std::make_pair("WXXX", "URL"), handled specially
std::pair("WCOP", "COPYRIGHTURL"),
std::pair("WOAF", "FILEWEBPAGE"),
std::pair("WOAR", "ARTISTWEBPAGE"),
std::pair("WOAS", "AUDIOSOURCEWEBPAGE"),
std::pair("WORS", "RADIOSTATIONWEBPAGE"),
std::pair("WPAY", "PAYMENTWEBPAGE"),
std::pair("WPUB", "PUBLISHERWEBPAGE"),
// std::pair("WXXX", "URL"), handled specially
// Other frames
std::make_pair("COMM", "COMMENT"),
//std::make_pair("USLT", "LYRICS"), handled specially
std::pair("COMM", "COMMENT"),
// std::pair("USLT", "LYRICS"), handled specially
// Apple iTunes proprietary frames
std::make_pair("PCST", "PODCAST"),
std::make_pair("TCAT", "PODCASTCATEGORY"),
std::make_pair("TDES", "PODCASTDESC"),
std::make_pair("TGID", "PODCASTID"),
std::make_pair("WFED", "PODCASTURL"),
std::make_pair("MVNM", "MOVEMENTNAME"),
std::make_pair("MVIN", "MOVEMENTNUMBER"),
std::make_pair("GRP1", "GROUPING"),
std::make_pair("TCMP", "COMPILATION"),
std::pair("PCST", "PODCAST"),
std::pair("TCAT", "PODCASTCATEGORY"),
std::pair("TDES", "PODCASTDESC"),
std::pair("TGID", "PODCASTID"),
std::pair("WFED", "PODCASTURL"),
std::pair("MVNM", "MOVEMENTNAME"),
std::pair("MVIN", "MOVEMENTNUMBER"),
std::pair("GRP1", "GROUPING"),
std::pair("TCMP", "COMPILATION"),
};
const size_t frameTranslationSize = sizeof(frameTranslation) / sizeof(frameTranslation[0]);
const std::pair<const char *, const char *> txxxFrameTranslation[] = {
std::make_pair("MUSICBRAINZ ALBUM ID", "MUSICBRAINZ_ALBUMID"),
std::make_pair("MUSICBRAINZ ARTIST ID", "MUSICBRAINZ_ARTISTID"),
std::make_pair("MUSICBRAINZ ALBUM ARTIST ID", "MUSICBRAINZ_ALBUMARTISTID"),
std::make_pair("MUSICBRAINZ ALBUM RELEASE COUNTRY", "RELEASECOUNTRY"),
std::make_pair("MUSICBRAINZ ALBUM STATUS", "RELEASESTATUS"),
std::make_pair("MUSICBRAINZ ALBUM TYPE", "RELEASETYPE"),
std::make_pair("MUSICBRAINZ RELEASE GROUP ID", "MUSICBRAINZ_RELEASEGROUPID"),
std::make_pair("MUSICBRAINZ RELEASE TRACK ID", "MUSICBRAINZ_RELEASETRACKID"),
std::make_pair("MUSICBRAINZ WORK ID", "MUSICBRAINZ_WORKID"),
std::make_pair("ACOUSTID ID", "ACOUSTID_ID"),
std::make_pair("ACOUSTID FINGERPRINT", "ACOUSTID_FINGERPRINT"),
std::make_pair("MUSICIP PUID", "MUSICIP_PUID"),
constexpr std::array txxxFrameTranslation {
std::pair("MUSICBRAINZ ALBUM ID", "MUSICBRAINZ_ALBUMID"),
std::pair("MUSICBRAINZ ARTIST ID", "MUSICBRAINZ_ARTISTID"),
std::pair("MUSICBRAINZ ALBUM ARTIST ID", "MUSICBRAINZ_ALBUMARTISTID"),
std::pair("MUSICBRAINZ ALBUM RELEASE COUNTRY", "RELEASECOUNTRY"),
std::pair("MUSICBRAINZ ALBUM STATUS", "RELEASESTATUS"),
std::pair("MUSICBRAINZ ALBUM TYPE", "RELEASETYPE"),
std::pair("MUSICBRAINZ RELEASE GROUP ID", "MUSICBRAINZ_RELEASEGROUPID"),
std::pair("MUSICBRAINZ RELEASE TRACK ID", "MUSICBRAINZ_RELEASETRACKID"),
std::pair("MUSICBRAINZ WORK ID", "MUSICBRAINZ_WORKID"),
std::pair("ACOUSTID ID", "ACOUSTID_ID"),
std::pair("ACOUSTID FINGERPRINT", "ACOUSTID_FINGERPRINT"),
std::pair("MUSICIP PUID", "MUSICIP_PUID"),
};
const size_t txxxFrameTranslationSize = sizeof(txxxFrameTranslation) / sizeof(txxxFrameTranslation[0]);
// list of deprecated frames and their successors
const std::pair<const char *, const char *> deprecatedFrames[] = {
std::make_pair("TRDA", "TDRC"), // 2.3 -> 2.4 (http://en.wikipedia.org/wiki/ID3)
std::make_pair("TDAT", "TDRC"), // 2.3 -> 2.4
std::make_pair("TYER", "TDRC"), // 2.3 -> 2.4
std::make_pair("TIME", "TDRC"), // 2.3 -> 2.4
constexpr std::array deprecatedFrames {
std::pair("TRDA", "TDRC"), // 2.3 -> 2.4 (http://en.wikipedia.org/wiki/ID3)
std::pair("TDAT", "TDRC"), // 2.3 -> 2.4
std::pair("TYER", "TDRC"), // 2.3 -> 2.4
std::pair("TIME", "TDRC"), // 2.3 -> 2.4
};
const size_t deprecatedFramesSize = sizeof(deprecatedFrames) / sizeof(deprecatedFrames[0]);
} // namespace
String Frame::frameIDToKey(const ByteVector &id)
{
ByteVector id24 = id;
for(size_t i = 0; i < deprecatedFramesSize; ++i) {
if(id24 == deprecatedFrames[i].first) {
id24 = deprecatedFrames[i].second;
for(const auto &[o, t] : deprecatedFrames) {
if(id24 == o) {
id24 = t;
break;
}
}
for(size_t i = 0; i < frameTranslationSize; ++i) {
if(id24 == frameTranslation[i].first)
return frameTranslation[i].second;
for(const auto &[o, t] : frameTranslation) {
if(id24 == o)
return t;
}
return String();
}
@ -430,9 +428,9 @@ String Frame::frameIDToKey(const ByteVector &id)
ByteVector Frame::keyToFrameID(const String &s)
{
const String key = s.upper();
for(size_t i = 0; i < frameTranslationSize; ++i) {
if(key == frameTranslation[i].second)
return frameTranslation[i].first;
for(const auto &[o, t] : frameTranslation) {
if(key == t)
return o;
}
return ByteVector();
}
@ -440,9 +438,9 @@ ByteVector Frame::keyToFrameID(const String &s)
String Frame::txxxToKey(const String &description)
{
const String d = description.upper();
for(size_t i = 0; i < txxxFrameTranslationSize; ++i) {
if(d == txxxFrameTranslation[i].first)
return txxxFrameTranslation[i].second;
for(const auto &[o, t] : txxxFrameTranslation) {
if(d == o)
return t;
}
return d;
}
@ -450,9 +448,9 @@ String Frame::txxxToKey(const String &description)
String Frame::keyToTXXX(const String &s)
{
const String key = s.upper();
for(size_t i = 0; i < txxxFrameTranslationSize; ++i) {
if(key == txxxFrameTranslation[i].second)
return txxxFrameTranslation[i].first;
for(const auto &[o, t] : txxxFrameTranslation) {
if(key == t)
return o;
}
return s;
}

View File

@ -49,6 +49,8 @@
#include "frames/tableofcontentsframe.h"
#include "frames/podcastframe.h"
#include <array>
using namespace TagLib;
using namespace ID3v2;
@ -392,89 +394,87 @@ FrameFactory::~FrameFactory()
namespace
{
// Frame conversion table ID3v2.2 -> 2.4
const std::pair<const char *, const char *> frameConversion2[] = {
std::make_pair("BUF", "RBUF"),
std::make_pair("CNT", "PCNT"),
std::make_pair("COM", "COMM"),
std::make_pair("CRA", "AENC"),
std::make_pair("ETC", "ETCO"),
std::make_pair("GEO", "GEOB"),
std::make_pair("IPL", "TIPL"),
std::make_pair("MCI", "MCDI"),
std::make_pair("MLL", "MLLT"),
std::make_pair("POP", "POPM"),
std::make_pair("REV", "RVRB"),
std::make_pair("SLT", "SYLT"),
std::make_pair("STC", "SYTC"),
std::make_pair("TAL", "TALB"),
std::make_pair("TBP", "TBPM"),
std::make_pair("TCM", "TCOM"),
std::make_pair("TCO", "TCON"),
std::make_pair("TCP", "TCMP"),
std::make_pair("TCR", "TCOP"),
std::make_pair("TDY", "TDLY"),
std::make_pair("TEN", "TENC"),
std::make_pair("TFT", "TFLT"),
std::make_pair("TKE", "TKEY"),
std::make_pair("TLA", "TLAN"),
std::make_pair("TLE", "TLEN"),
std::make_pair("TMT", "TMED"),
std::make_pair("TOA", "TOAL"),
std::make_pair("TOF", "TOFN"),
std::make_pair("TOL", "TOLY"),
std::make_pair("TOR", "TDOR"),
std::make_pair("TOT", "TOAL"),
std::make_pair("TP1", "TPE1"),
std::make_pair("TP2", "TPE2"),
std::make_pair("TP3", "TPE3"),
std::make_pair("TP4", "TPE4"),
std::make_pair("TPA", "TPOS"),
std::make_pair("TPB", "TPUB"),
std::make_pair("TRC", "TSRC"),
std::make_pair("TRD", "TDRC"),
std::make_pair("TRK", "TRCK"),
std::make_pair("TS2", "TSO2"),
std::make_pair("TSA", "TSOA"),
std::make_pair("TSC", "TSOC"),
std::make_pair("TSP", "TSOP"),
std::make_pair("TSS", "TSSE"),
std::make_pair("TST", "TSOT"),
std::make_pair("TT1", "TIT1"),
std::make_pair("TT2", "TIT2"),
std::make_pair("TT3", "TIT3"),
std::make_pair("TXT", "TOLY"),
std::make_pair("TXX", "TXXX"),
std::make_pair("TYE", "TDRC"),
std::make_pair("UFI", "UFID"),
std::make_pair("ULT", "USLT"),
std::make_pair("WAF", "WOAF"),
std::make_pair("WAR", "WOAR"),
std::make_pair("WAS", "WOAS"),
std::make_pair("WCM", "WCOM"),
std::make_pair("WCP", "WCOP"),
std::make_pair("WPB", "WPUB"),
std::make_pair("WXX", "WXXX"),
constexpr std::array frameConversion2 {
std::pair("BUF", "RBUF"),
std::pair("CNT", "PCNT"),
std::pair("COM", "COMM"),
std::pair("CRA", "AENC"),
std::pair("ETC", "ETCO"),
std::pair("GEO", "GEOB"),
std::pair("IPL", "TIPL"),
std::pair("MCI", "MCDI"),
std::pair("MLL", "MLLT"),
std::pair("POP", "POPM"),
std::pair("REV", "RVRB"),
std::pair("SLT", "SYLT"),
std::pair("STC", "SYTC"),
std::pair("TAL", "TALB"),
std::pair("TBP", "TBPM"),
std::pair("TCM", "TCOM"),
std::pair("TCO", "TCON"),
std::pair("TCP", "TCMP"),
std::pair("TCR", "TCOP"),
std::pair("TDY", "TDLY"),
std::pair("TEN", "TENC"),
std::pair("TFT", "TFLT"),
std::pair("TKE", "TKEY"),
std::pair("TLA", "TLAN"),
std::pair("TLE", "TLEN"),
std::pair("TMT", "TMED"),
std::pair("TOA", "TOAL"),
std::pair("TOF", "TOFN"),
std::pair("TOL", "TOLY"),
std::pair("TOR", "TDOR"),
std::pair("TOT", "TOAL"),
std::pair("TP1", "TPE1"),
std::pair("TP2", "TPE2"),
std::pair("TP3", "TPE3"),
std::pair("TP4", "TPE4"),
std::pair("TPA", "TPOS"),
std::pair("TPB", "TPUB"),
std::pair("TRC", "TSRC"),
std::pair("TRD", "TDRC"),
std::pair("TRK", "TRCK"),
std::pair("TS2", "TSO2"),
std::pair("TSA", "TSOA"),
std::pair("TSC", "TSOC"),
std::pair("TSP", "TSOP"),
std::pair("TSS", "TSSE"),
std::pair("TST", "TSOT"),
std::pair("TT1", "TIT1"),
std::pair("TT2", "TIT2"),
std::pair("TT3", "TIT3"),
std::pair("TXT", "TOLY"),
std::pair("TXX", "TXXX"),
std::pair("TYE", "TDRC"),
std::pair("UFI", "UFID"),
std::pair("ULT", "USLT"),
std::pair("WAF", "WOAF"),
std::pair("WAR", "WOAR"),
std::pair("WAS", "WOAS"),
std::pair("WCM", "WCOM"),
std::pair("WCP", "WCOP"),
std::pair("WPB", "WPUB"),
std::pair("WXX", "WXXX"),
// Apple iTunes nonstandard frames
std::make_pair("PCS", "PCST"),
std::make_pair("TCT", "TCAT"),
std::make_pair("TDR", "TDRL"),
std::make_pair("TDS", "TDES"),
std::make_pair("TID", "TGID"),
std::make_pair("WFD", "WFED"),
std::make_pair("MVN", "MVNM"),
std::make_pair("MVI", "MVIN"),
std::make_pair("GP1", "GRP1"),
std::pair("PCS", "PCST"),
std::pair("TCT", "TCAT"),
std::pair("TDR", "TDRL"),
std::pair("TDS", "TDES"),
std::pair("TID", "TGID"),
std::pair("WFD", "WFED"),
std::pair("MVN", "MVNM"),
std::pair("MVI", "MVIN"),
std::pair("GP1", "GRP1"),
};
const size_t frameConversion2Size = sizeof(frameConversion2) / sizeof(frameConversion2[0]);
// Frame conversion table ID3v2.3 -> 2.4
const std::pair<const char *, const char *> frameConversion3[] = {
std::make_pair("TORY", "TDOR"),
std::make_pair("TYER", "TDRC"),
std::make_pair("IPLS", "TIPL"),
constexpr std::array frameConversion3 {
std::pair("TORY", "TDOR"),
std::pair("TYER", "TDRC"),
std::pair("IPLS", "TIPL"),
};
const size_t frameConversion3Size = sizeof(frameConversion3) / sizeof(frameConversion3[0]);
} // namespace
bool FrameFactory::updateFrame(Frame::Header *header) const
@ -501,9 +501,9 @@ bool FrameFactory::updateFrame(Frame::Header *header) const
// ID3v2.2 only used 3 bytes for the frame ID, so we need to convert all of
// the frames to their 4 byte ID3v2.4 equivalent.
for(size_t i = 0; i < frameConversion2Size; ++i) {
if(frameID == frameConversion2[i].first) {
header->setFrameID(frameConversion2[i].second);
for(const auto &[o, t] : frameConversion2) {
if(frameID == o) {
header->setFrameID(t);
break;
}
}
@ -525,9 +525,9 @@ bool FrameFactory::updateFrame(Frame::Header *header) const
return false;
}
for(size_t i = 0; i < frameConversion3Size; ++i) {
if(frameID == frameConversion3[i].first) {
header->setFrameID(frameConversion3[i].second);
for(const auto &[o, t] : frameConversion3) {
if(frameID == o) {
header->setFrameID(t);
break;
}
}

View File

@ -33,6 +33,8 @@
#include "mpegutils.h"
#include <array>
using namespace TagLib;
class MPEG::Header::HeaderPrivate : public RefCounter
@ -212,17 +214,19 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
// Set the bitrate
static const int bitrates[2][3][16] = {
{ // Version 1
{ 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 }, // layer 1
{ 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 }, // layer 2
{ 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0 } // layer 3
static constexpr std::array bitrates {
std::array {
// Version 1
std::array { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 }, // layer 1
std::array { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 }, // layer 2
std::array { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0 } // layer 3
},
std::array {
// Version 2 or 2.5
std::array { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0 }, // layer 1
std::array { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 }, // layer 2
std::array { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 } // layer 3
},
{ // Version 2 or 2.5
{ 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0 }, // layer 1
{ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 }, // layer 2
{ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 } // layer 3
}
};
const int versionIndex = (d->version == Version1) ? 0 : 1;
@ -240,10 +244,10 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
// Set the sample rate
static const int sampleRates[3][4] = {
{ 44100, 48000, 32000, 0 }, // Version 1
{ 22050, 24000, 16000, 0 }, // Version 2
{ 11025, 12000, 8000, 0 } // Version 2.5
static constexpr std::array sampleRates {
std::array { 44100, 48000, 32000, 0 }, // Version 1
std::array { 22050, 24000, 16000, 0 }, // Version 2
std::array { 11025, 12000, 8000, 0 } // Version 2.5
};
// The sample rate index is encoded as two bits in the 3nd byte, i.e. xxxx11xx
@ -269,18 +273,18 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
// Samples per frame
static const int samplesPerFrame[3][2] = {
static constexpr std::array samplesPerFrame {
// MPEG1, 2/2.5
{ 384, 384 }, // Layer I
{ 1152, 1152 }, // Layer II
{ 1152, 576 } // Layer III
std::pair(384, 384), // Layer I
std::pair(1152, 1152), // Layer II
std::pair(1152, 576), // Layer III
};
d->samplesPerFrame = samplesPerFrame[layerIndex][versionIndex];
d->samplesPerFrame = versionIndex ? samplesPerFrame[layerIndex].second : samplesPerFrame[layerIndex].first;
// Calculate the frame length
static const int paddingSize[3] = { 4, 1, 1 };
static constexpr std::array paddingSize { 4, 1, 1 };
d->frameLength = d->samplesPerFrame * d->bitrate * 125 / d->sampleRate;

View File

@ -26,6 +26,7 @@
#include "oggpage.h"
#include <algorithm>
#include <array>
#include "tstring.h"
#include "tdebug.h"
@ -44,7 +45,7 @@ namespace {
*/
unsigned int pageChecksum(const ByteVector &data)
{
static const unsigned int crcTable[256] = {
static constexpr std::array<unsigned int, 256> crcTable {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,

View File

@ -26,11 +26,12 @@
#include "tbytevector.h"
#include <algorithm>
#include <iostream>
#include <limits>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include "tstring.h"
#include "tdebug.h"
@ -845,23 +846,23 @@ ByteVector ByteVector::toHex() const
ByteVector ByteVector::fromBase64(const ByteVector & input)
{
static const unsigned char base64[256] = {
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x3e,0x80,0x80,0x80,0x3f,
0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,
0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x80,0x80,0x80,0x80,0x80,
0x80,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80
static constexpr std::array<unsigned char, 256> base64 {
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x3e, 0x80, 0x80, 0x80, 0x3f,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
};
unsigned int len = input.size();

View File

@ -35,6 +35,8 @@
#include "wavpackfile.h"
#include <array>
// Implementation of this class is based on the information at:
// http://www.wavpack.com/file_format.txt
@ -149,9 +151,10 @@ unsigned int WavPack::Properties::sampleFrames() const
namespace
{
const unsigned int sampleRates[] = {
6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000,
32000, 44100, 48000, 64000, 88200, 96000, 192000, 0 };
constexpr std::array sampleRates {
6000U, 8000U, 9600U, 11025U, 12000U, 16000U, 22050U, 24000U,
32000U, 44100U, 48000U, 64000U, 88200U, 96000U, 192000U, 0U
};
/*!
* Given a WavPack \a block (complete, but not including the 32-byte header),