From ef09a707b8ac1b0fb262b1fc6a2a1dd6d641b35b Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 10 Aug 2015 01:10:35 +0900 Subject: [PATCH] Make AudioProperties::lengthInSeconds() and lengthInMilliseconds() virtual. --- taglib/ape/apeproperties.h | 6 +- taglib/asf/asfproperties.h | 6 +- taglib/audioproperties.cpp | 113 +-------------------- taglib/audioproperties.h | 6 +- taglib/dsf/dsfproperties.cpp | 14 ++- taglib/dsf/dsfproperties.h | 2 + taglib/ebml/matroska/ebmlmatroskaaudio.cpp | 30 ++++-- taglib/ebml/matroska/ebmlmatroskaaudio.h | 22 ++-- taglib/flac/flacproperties.h | 6 +- taglib/mp4/mp4properties.h | 6 +- taglib/mpc/mpcproperties.h | 6 +- taglib/mpeg/mpegproperties.h | 6 +- taglib/ogg/opus/opusproperties.h | 6 +- taglib/ogg/speex/speexproperties.h | 6 +- taglib/ogg/vorbis/vorbisproperties.h | 6 +- taglib/riff/aiff/aiffproperties.h | 6 +- taglib/riff/wav/wavproperties.h | 6 +- taglib/trueaudio/trueaudioproperties.h | 6 +- taglib/wavpack/wavpackproperties.h | 6 +- 19 files changed, 75 insertions(+), 190 deletions(-) diff --git a/taglib/ape/apeproperties.h b/taglib/ape/apeproperties.h index 810d593c..b06c69d8 100644 --- a/taglib/ape/apeproperties.h +++ b/taglib/ape/apeproperties.h @@ -76,16 +76,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/asf/asfproperties.h b/taglib/asf/asfproperties.h index 37d0243a..f7e3182f 100644 --- a/taglib/asf/asfproperties.h +++ b/taglib/asf/asfproperties.h @@ -99,16 +99,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/audioproperties.cpp b/taglib/audioproperties.cpp index fc811e98..64a972de 100644 --- a/taglib/audioproperties.cpp +++ b/taglib/audioproperties.cpp @@ -23,24 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include - -#include "aiffproperties.h" -#include "apeproperties.h" -#include "asfproperties.h" -#include "flacproperties.h" -#include "mp4properties.h" -#include "mpcproperties.h" -#include "mpegproperties.h" -#include "opusproperties.h" -#include "speexproperties.h" -#include "trueaudioproperties.h" -#include "vorbisproperties.h" -#include "wavproperties.h" -#include "wavpackproperties.h" +#include #include "audioproperties.h" -#include "tstringlist.h" using namespace TagLib; @@ -61,102 +46,6 @@ String AudioProperties::toString() const return desc.toString(", "); } -int TagLib::AudioProperties::lengthInSeconds() const -{ - // This is an ugly workaround but we can't add a virtual function. - // Should be virtual in taglib2. - - if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if (dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInSeconds(); - - else - return 0; -} - -int TagLib::AudioProperties::lengthInMilliseconds() const -{ - // This is an ugly workaround but we can't add a virtual function. - // Should be virtual in taglib2. - - if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else if(dynamic_cast(this)) - return dynamic_cast(this)->lengthInMilliseconds(); - - else - return 0; -} - //////////////////////////////////////////////////////////////////////////////// // protected methods //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/audioproperties.h b/taglib/audioproperties.h index 86194bb8..c01c4d77 100644 --- a/taglib/audioproperties.h +++ b/taglib/audioproperties.h @@ -76,16 +76,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const = 0; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const = 0; /*! * Returns the most appropriate bit rate for the file in kb/s. For constant diff --git a/taglib/dsf/dsfproperties.cpp b/taglib/dsf/dsfproperties.cpp index 7c8fad6f..498a650b 100644 --- a/taglib/dsf/dsfproperties.cpp +++ b/taglib/dsf/dsfproperties.cpp @@ -79,10 +79,20 @@ DSF::AudioProperties::~AudioProperties() } int DSF::AudioProperties::length() const +{ + return lengthInSeconds(); +} + +int DSF::AudioProperties::lengthInSeconds() const { return d->length; } +int DSF::AudioProperties::lengthInMilliseconds() const +{ + return d->length * 1000; +} + int DSF::AudioProperties::bitrate() const { return d->bitrate; @@ -144,8 +154,8 @@ void DSF::AudioProperties::read(const ByteVector &data) d->sampleCount = data.toInt64LE(24); d->blockSizePerChannel = data.toUInt32LE(32); - d->bitrate + d->bitrate = static_cast((d->samplingFrequency * d->bitsPerSample * d->channelNum) / 1000.0); - d->length + d->length = d->samplingFrequency > 0 ? static_cast(d->sampleCount / d->samplingFrequency) : 0; } diff --git a/taglib/dsf/dsfproperties.h b/taglib/dsf/dsfproperties.h index 0f48663c..982adabc 100644 --- a/taglib/dsf/dsfproperties.h +++ b/taglib/dsf/dsfproperties.h @@ -58,6 +58,8 @@ namespace TagLib { // Reimplementations. virtual int length() const; + virtual int lengthInSeconds() const; + virtual int lengthInMilliseconds() const; virtual int bitrate() const; virtual int sampleRate() const; virtual int channels() const; diff --git a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp index 8c730674..8c956776 100644 --- a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp +++ b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp @@ -41,7 +41,7 @@ public: Element *elem = document->getDocumentRoot()->getChild(Constants::Segment); Element *info = elem->getChild(Constants::SegmentInfo); Element *value; - + if(info && (value = info->getChild(Constants::Duration))) { length = static_cast(value->getAsFloat() / 1000000000.L); if((value = info->getChild(Constants::TimecodeScale))) @@ -49,34 +49,34 @@ public: else length *= 1000000; } - + info = elem->getChild(Constants::Tracks); if(!info || !(info = info->getChild(Constants::TrackEntry)) || !(info = info->getChild(Constants::Audio))) { - + return; } - + // Dirty bitrate: document->seek(0, File::End); bitrate = static_cast(8 * document->tell() / ((length > 0) ? length : 1)); - + if((value = info->getChild(Constants::Channels))) channels = static_cast(value->getAsUnsigned()); - + if((value = info->getChild(Constants::SamplingFrequency))) samplerate = static_cast(value->getAsFloat()); } - + // The length of the file int length; - + // The bitrate int bitrate; - + // The amount of channels int channels; - + // The sample rate int samplerate; }; @@ -96,10 +96,20 @@ EBML::Matroska::AudioProperties::~AudioProperties() } int EBML::Matroska::AudioProperties::length() const +{ + return lengthInSeconds(); +} + +int EBML::Matroska::AudioProperties::lengthInSeconds() const { return d->length; } +int EBML::Matroska::AudioProperties::lengthInMilliseconds() const +{ + return d->length * 1000; +} + int EBML::Matroska::AudioProperties::bitrate() const { return d->bitrate; diff --git a/taglib/ebml/matroska/ebmlmatroskaaudio.h b/taglib/ebml/matroska/ebmlmatroskaaudio.h index de5ecb3e..80d5f5cc 100644 --- a/taglib/ebml/matroska/ebmlmatroskaaudio.h +++ b/taglib/ebml/matroska/ebmlmatroskaaudio.h @@ -33,9 +33,9 @@ namespace TagLib { namespace EBML { - + namespace Matroska { - + /*! * This class represents the audio properties of a matroska file. * Currently all information are read from the container format and @@ -46,41 +46,43 @@ namespace TagLib { public: //! Destructor virtual ~AudioProperties(); - + /*! * Constructs an instance from a file. */ AudioProperties(File *document); - + /*! * Returns the length of the file. */ virtual int length() const; - + virtual int lengthInSeconds() const; + virtual int lengthInMilliseconds() const; + /*! * Returns the bit rate of the file. Since the container format does not * offer a proper value, it ist currently calculated by dividing the * file size by the length. */ virtual int bitrate() const; - + /*! * Returns the amount of channels of the file. */ virtual int channels() const; - + /*! * Returns the sample rate of the file. */ virtual int sampleRate() const; - + private: class AudioPropertiesPrivate; AudioPropertiesPrivate *d; }; - + } - + } } diff --git a/taglib/flac/flacproperties.h b/taglib/flac/flacproperties.h index a36c4477..260d9b02 100644 --- a/taglib/flac/flacproperties.h +++ b/taglib/flac/flacproperties.h @@ -72,16 +72,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/mp4/mp4properties.h b/taglib/mp4/mp4properties.h index 955d8a2c..d5034b57 100644 --- a/taglib/mp4/mp4properties.h +++ b/taglib/mp4/mp4properties.h @@ -65,16 +65,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/mpc/mpcproperties.h b/taglib/mpc/mpcproperties.h index ccce40e6..77cc0c8a 100644 --- a/taglib/mpc/mpcproperties.h +++ b/taglib/mpc/mpcproperties.h @@ -72,16 +72,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/mpeg/mpegproperties.h b/taglib/mpeg/mpegproperties.h index 2abd8185..0cc103af 100644 --- a/taglib/mpeg/mpegproperties.h +++ b/taglib/mpeg/mpegproperties.h @@ -75,16 +75,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/ogg/opus/opusproperties.h b/taglib/ogg/opus/opusproperties.h index 5d4201d3..4c3528af 100644 --- a/taglib/ogg/opus/opusproperties.h +++ b/taglib/ogg/opus/opusproperties.h @@ -77,16 +77,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/ogg/speex/speexproperties.h b/taglib/ogg/speex/speexproperties.h index fb497e44..6ffdff26 100644 --- a/taglib/ogg/speex/speexproperties.h +++ b/taglib/ogg/speex/speexproperties.h @@ -77,16 +77,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/ogg/vorbis/vorbisproperties.h b/taglib/ogg/vorbis/vorbisproperties.h index 49ad3a29..25ba27ce 100644 --- a/taglib/ogg/vorbis/vorbisproperties.h +++ b/taglib/ogg/vorbis/vorbisproperties.h @@ -74,16 +74,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/riff/aiff/aiffproperties.h b/taglib/riff/aiff/aiffproperties.h index 122f4958..e64e3e59 100644 --- a/taglib/riff/aiff/aiffproperties.h +++ b/taglib/riff/aiff/aiffproperties.h @@ -75,16 +75,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/riff/wav/wavproperties.h b/taglib/riff/wav/wavproperties.h index adc33fe2..60af4f10 100644 --- a/taglib/riff/wav/wavproperties.h +++ b/taglib/riff/wav/wavproperties.h @@ -76,16 +76,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/trueaudio/trueaudioproperties.h b/taglib/trueaudio/trueaudioproperties.h index 3a92ce2d..f82f9db2 100644 --- a/taglib/trueaudio/trueaudioproperties.h +++ b/taglib/trueaudio/trueaudioproperties.h @@ -75,16 +75,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s. diff --git a/taglib/wavpack/wavpackproperties.h b/taglib/wavpack/wavpackproperties.h index e62980ea..d3ff0a21 100644 --- a/taglib/wavpack/wavpackproperties.h +++ b/taglib/wavpack/wavpackproperties.h @@ -77,16 +77,14 @@ namespace TagLib { * * \see lengthInMilliseconds() */ - // BIC: make virtual - int lengthInSeconds() const; + virtual int lengthInSeconds() const; /*! * Returns the length of the file in milliseconds. * * \see lengthInSeconds() */ - // BIC: make virtual - int lengthInMilliseconds() const; + virtual int lengthInMilliseconds() const; /*! * Returns the average bit rate of the file in kb/s.