Use ID3v2::FrameFactory also for WAV and DSDIFF (#1172)

* Use ID3v2::FrameFactory also for WAV and DSDIFF

* Apply suggestions from code review

Co-authored-by: Kevin André <[email protected]>

---------

Co-authored-by: Kevin André <[email protected]>
This commit is contained in:
Urs Fleisch
2023-11-09 18:58:51 +01:00
committed by GitHub
co-authored by Kevin André
parent 52b245f015
commit 0e395f4ec4
8 changed files with 41 additions and 19 deletions
+4 -2
View File
@@ -812,7 +812,8 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
}
else if(d->chunks[i].name == "ID3 " || d->chunks[i].name == "id3 ") {
d->id3v2TagChunkID = d->chunks[i].name;
d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->chunks[i].offset));
d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->chunks[i].offset,
d->ID3v2FrameFactory));
d->isID3InPropChunk = false;
d->hasID3v2 = true;
}
@@ -841,7 +842,8 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
continue;
}
d->id3v2TagChunkID = d->childChunks[PROPChunk][i].name;
d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->childChunks[PROPChunk][i].offset));
d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->childChunks[PROPChunk][i].offset,
d->ID3v2FrameFactory));
d->isID3InPropChunk = true;
d->hasID3v2 = true;
}
+2 -2
View File
@@ -83,7 +83,7 @@ namespace TagLib {
*
* \note In the current implementation, \a propertiesStyle is ignored.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*/
File(FileName file, bool readProperties = true,
@@ -94,7 +94,7 @@ namespace TagLib {
* Constructs an DSDIFF file from \a stream. If \a readProperties is true
* the file's audio properties will also be read.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*
* \note TagLib will *not* take ownership of the stream, the caller is
+2 -2
View File
@@ -46,7 +46,7 @@ namespace TagLib {
* \a propertiesStyle are ignored. The audio properties are always
* read.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*/
File(FileName file, bool readProperties = true,
@@ -61,7 +61,7 @@ namespace TagLib {
* \a propertiesStyle are ignored. The audio properties are always
* read.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*
* \note TagLib will *not* take ownership of the stream, the caller is
+2 -2
View File
@@ -98,7 +98,7 @@ namespace TagLib {
* Constructs an FLAC file from \a file. If \a readProperties is true the
* file's audio properties will also be read.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* \note In the current implementation, \a propertiesStyle is ignored.
@@ -115,7 +115,7 @@ namespace TagLib {
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* \note In the current implementation, \a propertiesStyle is ignored.
+2 -2
View File
@@ -87,7 +87,7 @@ namespace TagLib {
* Constructs an MPEG file from \a file. If \a readProperties is true the
* file's audio properties will also be read.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* If \a propertiesStyle is not Fast, the file will be scanned
@@ -105,7 +105,7 @@ namespace TagLib {
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* If \a propertiesStyle is not Fast, the file will be scanned
+17 -5
View File
@@ -41,6 +41,15 @@ namespace
class RIFF::WAV::File::FilePrivate
{
public:
FilePrivate(ID3v2::FrameFactory *frameFactory)
: ID3v2FrameFactory(frameFactory ? frameFactory
: ID3v2::FrameFactory::instance())
{
}
~FilePrivate() = default;
const ID3v2::FrameFactory *ID3v2FrameFactory;
std::unique_ptr<Properties> properties;
TagUnion tag;
@@ -64,17 +73,19 @@ bool RIFF::WAV::File::isSupported(IOStream *stream)
// public members
////////////////////////////////////////////////////////////////////////////////
RIFF::WAV::File::File(FileName file, bool readProperties, Properties::ReadStyle) :
RIFF::WAV::File::File(FileName file, bool readProperties, Properties::ReadStyle,
ID3v2::FrameFactory *frameFactory) :
RIFF::File(file, LittleEndian),
d(std::make_unique<FilePrivate>())
d(std::make_unique<FilePrivate>(frameFactory))
{
if(isOpen())
read(readProperties);
}
RIFF::WAV::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) :
RIFF::WAV::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle,
ID3v2::FrameFactory *frameFactory) :
RIFF::File(stream, LittleEndian),
d(std::make_unique<FilePrivate>())
d(std::make_unique<FilePrivate>(frameFactory))
{
if(isOpen())
read(readProperties);
@@ -190,7 +201,8 @@ void RIFF::WAV::File::read(bool readProperties)
const ByteVector name = chunkName(i);
if(name == "ID3 " || name == "id3 ") {
if(!d->tag[ID3v2Index]) {
d->tag.set(ID3v2Index, new ID3v2::Tag(this, chunkOffset(i)));
d->tag.set(ID3v2Index, new ID3v2::Tag(this, chunkOffset(i),
d->ID3v2FrameFactory));
d->hasID3v2 = true;
}
else {
+10 -2
View File
@@ -74,9 +74,13 @@ namespace TagLib {
* file's audio properties will also be read.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*/
File(FileName file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average,
ID3v2::FrameFactory *frameFactory = nullptr);
/*!
* Constructs a WAV file from \a stream. If \a readProperties is true the
@@ -86,9 +90,13 @@ namespace TagLib {
* responsible for deleting it after the File object.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory (default if null).
*/
File(IOStream *stream, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average,
ID3v2::FrameFactory *frameFactory = nullptr);
/*!
* Destroys this instance of the File.
+2 -2
View File
@@ -91,7 +91,7 @@ namespace TagLib {
* Constructs a TrueAudio file from \a file. If \a readProperties is true
* the file's audio properties will also be read.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* \note In the current implementation, \a propertiesStyle is ignored.
@@ -119,7 +119,7 @@ namespace TagLib {
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*
* If this file contains and ID3v2 tag the frames will be created using
* If this file contains an ID3v2 tag, the frames will be created using
* \a frameFactory.
*
* \note In the current implementation, \a propertiesStyle is ignored.