]> granicus.if.org Git - taglib/commitdiff
Add AudioProperties::lengthInSeconds() and lengthInMilliseconds() functions to emulat...
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 31 Jul 2015 17:23:18 +0000 (02:23 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 31 Jul 2015 17:23:18 +0000 (02:23 +0900)
taglib/audioproperties.cpp
taglib/audioproperties.h

index 298b97da12973e2693435eee042ddf2656052e56..4598164cc922ab9261dc9cbec21d793e585733fe 100644 (file)
  *   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 "audioproperties.h"
 
 using namespace TagLib;
@@ -41,11 +57,108 @@ AudioProperties::~AudioProperties()
 
 }
 
+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::Properties*>(this))
+    return dynamic_cast<const APE::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const ASF::Properties*>(this))
+    return dynamic_cast<const ASF::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const FLAC::Properties*>(this))
+    return dynamic_cast<const FLAC::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const MP4::Properties*>(this))
+    return dynamic_cast<const MP4::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const MPC::Properties*>(this))
+    return dynamic_cast<const MPC::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const MPEG::Properties*>(this))
+    return dynamic_cast<const MPEG::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const Ogg::Opus::Properties*>(this))
+    return dynamic_cast<const Ogg::Opus::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const Ogg::Speex::Properties*>(this))
+    return dynamic_cast<const Ogg::Speex::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const TrueAudio::Properties*>(this))
+    return dynamic_cast<const TrueAudio::Properties*>(this)->lengthInSeconds();
+
+  else if (dynamic_cast<const RIFF::AIFF::Properties*>(this))
+    return dynamic_cast<const RIFF::AIFF::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const RIFF::WAV::Properties*>(this))
+    return dynamic_cast<const RIFF::WAV::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const Vorbis::Properties*>(this))
+    return dynamic_cast<const Vorbis::Properties*>(this)->lengthInSeconds();
+
+  else if(dynamic_cast<const WavPack::Properties*>(this))
+    return dynamic_cast<const WavPack::Properties*>(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::Properties*>(this))
+    return dynamic_cast<const APE::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const ASF::Properties*>(this))
+    return dynamic_cast<const ASF::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const FLAC::Properties*>(this))
+    return dynamic_cast<const FLAC::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const MP4::Properties*>(this))
+    return dynamic_cast<const MP4::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const MPC::Properties*>(this))
+    return dynamic_cast<const MPC::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const MPEG::Properties*>(this))
+    return dynamic_cast<const MPEG::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const Ogg::Opus::Properties*>(this))
+    return dynamic_cast<const Ogg::Opus::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const Ogg::Speex::Properties*>(this))
+    return dynamic_cast<const Ogg::Speex::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const TrueAudio::Properties*>(this))
+    return dynamic_cast<const TrueAudio::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const RIFF::AIFF::Properties*>(this))
+    return dynamic_cast<const RIFF::AIFF::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const RIFF::WAV::Properties*>(this))
+    return dynamic_cast<const RIFF::WAV::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const Vorbis::Properties*>(this))
+    return dynamic_cast<const Vorbis::Properties*>(this)->lengthInMilliseconds();
+
+  else if(dynamic_cast<const WavPack::Properties*>(this))
+    return dynamic_cast<const WavPack::Properties*>(this)->lengthInMilliseconds();
+
+  else
+    return 0;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // protected methods
 ////////////////////////////////////////////////////////////////////////////////
 
-AudioProperties::AudioProperties(ReadStyle)
+AudioProperties::AudioProperties(ReadStyle) :
+  d(0)
 {
 
 }
index 4648dcc23d578aeef81097e5a6bdf41d43670e2f..f27aefca8c3220a5a7aa047a343057f4bef837c1 100644 (file)
@@ -69,6 +69,23 @@ namespace TagLib {
      */
     virtual int length() const = 0;
 
+    /*!
+     * Returns the length of the file in seconds.  The length is rounded down to
+     * the nearest whole second.
+     *
+     * \see lengthInMilliseconds()
+     */
+    // BIC: make virtual
+    int lengthInSeconds() const;
+
+    /*!
+     * Returns the length of the file in milliseconds.
+     *
+     * \see lengthInSeconds()
+     */
+    // BIC: make virtual
+    int lengthInMilliseconds() const;
+
     /*!
      * Returns the most appropriate bit rate for the file in kb/s.  For constant
      * bitrate formats this is simply the bitrate of the file.  For variable