mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Make AudioProperties::lengthInSeconds() and lengthInMilliseconds() virtual.
This commit is contained in:
parent
400fa04b1c
commit
ef09a707b8
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -23,24 +23,9 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tbytevector.h>
|
||||
|
||||
#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 <tstringlist.h>
|
||||
|
||||
#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<const APE::AudioProperties*>(this))
|
||||
return dynamic_cast<const APE::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const ASF::AudioProperties*>(this))
|
||||
return dynamic_cast<const ASF::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const FLAC::AudioProperties*>(this))
|
||||
return dynamic_cast<const FLAC::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const MP4::AudioProperties*>(this))
|
||||
return dynamic_cast<const MP4::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const MPC::AudioProperties*>(this))
|
||||
return dynamic_cast<const MPC::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const MPEG::AudioProperties*>(this))
|
||||
return dynamic_cast<const MPEG::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const Ogg::Opus::AudioProperties*>(this))
|
||||
return dynamic_cast<const Ogg::Opus::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const Ogg::Speex::AudioProperties*>(this))
|
||||
return dynamic_cast<const Ogg::Speex::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const TrueAudio::AudioProperties*>(this))
|
||||
return dynamic_cast<const TrueAudio::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if (dynamic_cast<const RIFF::AIFF::AudioProperties*>(this))
|
||||
return dynamic_cast<const RIFF::AIFF::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const RIFF::WAV::AudioProperties*>(this))
|
||||
return dynamic_cast<const RIFF::WAV::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const Ogg::Vorbis::AudioProperties*>(this))
|
||||
return dynamic_cast<const Ogg::Vorbis::AudioProperties*>(this)->lengthInSeconds();
|
||||
|
||||
else if(dynamic_cast<const WavPack::AudioProperties*>(this))
|
||||
return dynamic_cast<const WavPack::AudioProperties*>(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<const APE::AudioProperties*>(this))
|
||||
return dynamic_cast<const APE::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const ASF::AudioProperties*>(this))
|
||||
return dynamic_cast<const ASF::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const FLAC::AudioProperties*>(this))
|
||||
return dynamic_cast<const FLAC::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const MP4::AudioProperties*>(this))
|
||||
return dynamic_cast<const MP4::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const MPC::AudioProperties*>(this))
|
||||
return dynamic_cast<const MPC::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const MPEG::AudioProperties*>(this))
|
||||
return dynamic_cast<const MPEG::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const Ogg::Opus::AudioProperties*>(this))
|
||||
return dynamic_cast<const Ogg::Opus::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const Ogg::Speex::AudioProperties*>(this))
|
||||
return dynamic_cast<const Ogg::Speex::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const TrueAudio::AudioProperties*>(this))
|
||||
return dynamic_cast<const TrueAudio::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const RIFF::AIFF::AudioProperties*>(this))
|
||||
return dynamic_cast<const RIFF::AIFF::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const RIFF::WAV::AudioProperties*>(this))
|
||||
return dynamic_cast<const RIFF::WAV::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const Ogg::Vorbis::AudioProperties*>(this))
|
||||
return dynamic_cast<const Ogg::Vorbis::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else if(dynamic_cast<const WavPack::AudioProperties*>(this))
|
||||
return dynamic_cast<const WavPack::AudioProperties*>(this)->lengthInMilliseconds();
|
||||
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// protected methods
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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
|
||||
|
@ -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<uint>((d->samplingFrequency * d->bitsPerSample * d->channelNum) / 1000.0);
|
||||
d->length
|
||||
d->length
|
||||
= d->samplingFrequency > 0 ? static_cast<uint>(d->sampleCount / d->samplingFrequency) : 0;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<int>(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<int>(8 * document->tell() / ((length > 0) ? length : 1));
|
||||
|
||||
|
||||
if((value = info->getChild(Constants::Channels)))
|
||||
channels = static_cast<int>(value->getAsUnsigned());
|
||||
|
||||
|
||||
if((value = info->getChild(Constants::SamplingFrequency)))
|
||||
samplerate = static_cast<int>(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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user