]> granicus.if.org Git - taglib/commitdiff
Add native support for the RVA2 (relative volume adjustment) frame. The
authorScott Wheeler <wheeler@kde.org>
Tue, 27 Apr 2004 02:01:27 +0000 (02:01 +0000)
committerScott Wheeler <wheeler@kde.org>
Tue, 27 Apr 2004 02:01:27 +0000 (02:01 +0000)
docs aren't there yet and this is completely untested, but that will follow
as soon as I find a file actually tagged with one of these.  :-)

CCMAIL:Jorn Baayen <jbaayen@gnome.org>

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@306706 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

mpeg/id3v2/frames/Makefile.am
mpeg/id3v2/frames/relativevolumeframe.cpp [new file with mode: 0644]
mpeg/id3v2/frames/relativevolumeframe.h [new file with mode: 0644]
mpeg/id3v2/id3v2framefactory.cpp

index ea3a8c979cc57f0e4585998e210a0584d7d64577..fe4a48f7a5997f7bd9ad7454d6c23840e4e1518c 100644 (file)
@@ -8,12 +8,14 @@ noinst_LTLIBRARIES = libframes.la
 libframes_la_SOURCES = \
        attachedpictureframe.cpp \
        commentsframe.cpp \
+       relativevolumeframe.cpp \
        textidentificationframe.cpp \
        unknownframe.cpp
 
 taglib_include_HEADERS = \
        attachedpictureframe.h \
        commentsframe.h \
+       relativevolumeframe.h \
        textidentificationframe.h \
        unknownframe.h
 
diff --git a/mpeg/id3v2/frames/relativevolumeframe.cpp b/mpeg/id3v2/frames/relativevolumeframe.cpp
new file mode 100644 (file)
index 0000000..acbd689
--- /dev/null
@@ -0,0 +1,137 @@
+/***************************************************************************
+    copyright            : (C) 2004 by Scott Wheeler
+    email                : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it  under the terms of the GNU Lesser General Public License version  *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+ *   USA                                                                   *
+ ***************************************************************************/
+
+#include "relativevolumeframe.h"
+
+using namespace TagLib;
+using namespace ID3v2;
+
+class RelativeVolumeFrame::RelativeVolumeFramePrivate
+{
+public:
+  RelativeVolumeFramePrivate() : channelType(Other), volumeAdjustment(0) {}
+
+  String identification;
+  ChannelType channelType;
+  short volumeAdjustment;
+  PeakVolume peakVolume;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+RelativeVolumeFrame::RelativeVolumeFrame(const ByteVector &data) : Frame(data)
+{
+  d = new RelativeVolumeFramePrivate;
+  setData(data);
+}
+
+RelativeVolumeFrame::~RelativeVolumeFrame()
+{
+  delete d;
+}
+
+String RelativeVolumeFrame::toString() const
+{
+  return d->identification;
+}
+
+RelativeVolumeFrame::ChannelType RelativeVolumeFrame::channelType() const
+{
+  return d->channelType;
+}
+
+void RelativeVolumeFrame::setChannelType(ChannelType t)
+{
+  d->channelType = t;
+}
+
+short RelativeVolumeFrame::volumeAdjustmentIndex() const
+{
+  return d->volumeAdjustment;
+}
+
+void RelativeVolumeFrame::setVolumeAdjustmentIndex(short index)
+{
+  d->volumeAdjustment = index;
+}
+
+float RelativeVolumeFrame::volumeAdjustment() const
+{
+  return float(d->volumeAdjustment) / float(512);
+}
+
+void RelativeVolumeFrame::setVolumeAdjustment(float adjustment)
+{
+  d->volumeAdjustment = short(adjustment / float(512));
+}
+
+RelativeVolumeFrame::PeakVolume RelativeVolumeFrame::peakVolume() const
+{
+  return d->peakVolume;
+}
+
+void RelativeVolumeFrame::setPeakVolume(const PeakVolume &peak)
+{
+  d->peakVolume = peak;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// protected members
+////////////////////////////////////////////////////////////////////////////////
+
+void RelativeVolumeFrame::parseFields(const ByteVector &data)
+{
+  int pos = data.find(textDelimiter(String::Latin1));
+  d->identification = String(data.mid(0, pos), String::Latin1);
+
+  d->volumeAdjustment = data.mid(pos, 2).toShort();
+  pos += 2;
+
+  d->peakVolume.bitsRepresentingPeak = data[pos];
+  pos += 1;
+
+  d->peakVolume.peakVolume = data.mid(pos, d->peakVolume.bitsRepresentingPeak);
+}
+
+ByteVector RelativeVolumeFrame::renderFields() const
+{
+  ByteVector data;
+
+  data.append(d->identification.data(String::Latin1));
+  data.append(textDelimiter(String::Latin1));
+  data.append(ByteVector::fromShort(d->volumeAdjustment));
+  data.append(char(d->peakVolume.bitsRepresentingPeak));
+  data.append(d->peakVolume.peakVolume);
+
+  return data;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+RelativeVolumeFrame::RelativeVolumeFrame(const ByteVector &data, Header *h) : Frame(h)
+{
+  d = new RelativeVolumeFramePrivate;
+  parseFields(data.mid(Header::size(h->version()), size()));
+}
diff --git a/mpeg/id3v2/frames/relativevolumeframe.h b/mpeg/id3v2/frames/relativevolumeframe.h
new file mode 100644 (file)
index 0000000..55d2100
--- /dev/null
@@ -0,0 +1,85 @@
+/***************************************************************************
+    copyright            : (C) 2004 by Scott Wheeler
+    email                : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it  under the terms of the GNU Lesser General Public License version  *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+ *   USA                                                                   *
+ ***************************************************************************/
+
+#ifndef TAGLIB_RELATIVEVOLUMEFRAME_H
+#define TAGLIB_RELATIVEVOLUMEFRAME_H
+
+#include <id3v2frame.h>
+
+namespace TagLib {
+
+  namespace ID3v2 {
+
+    class RelativeVolumeFrame : public Frame
+    {
+      friend class FrameFactory;
+
+    public:
+
+      enum ChannelType {
+        Other        = 0x00,
+        MasterVolume = 0x01,
+        FrontRight   = 0x02,
+        FrontLeft    = 0x03,
+        BackRight    = 0x04,
+        BackLeft     = 0x05,
+        FrontCentre  = 0x06,
+        BackCentre   = 0x07,
+        Subwoofer    = 0x08
+      };
+
+      struct PeakVolume
+      {
+        PeakVolume() : bitsRepresentingPeak(0) {}
+        unsigned char bitsRepresentingPeak;
+        ByteVector peakVolume;
+      };
+
+      RelativeVolumeFrame(const ByteVector &data);
+      virtual ~RelativeVolumeFrame();
+
+      virtual String toString() const;
+
+      ChannelType channelType() const;
+      void setChannelType(ChannelType t);
+      short volumeAdjustmentIndex() const;
+      void setVolumeAdjustmentIndex(short index);
+      float volumeAdjustment() const;
+      void setVolumeAdjustment(float adjustment);
+      PeakVolume peakVolume() const;
+      void setPeakVolume(const PeakVolume &peak);
+
+    protected:
+      virtual void parseFields(const ByteVector &data);
+      virtual ByteVector renderFields() const;
+
+    private:
+      RelativeVolumeFrame(const ByteVector &data, Header *h);
+      RelativeVolumeFrame(const RelativeVolumeFrame &);
+      RelativeVolumeFrame &operator=(const RelativeVolumeFrame &);
+
+      class RelativeVolumeFramePrivate;
+      RelativeVolumeFramePrivate *d;
+    };
+
+  }
+}
+#endif
index d550b29f24aa57c16ce59b62a2d1057a16be4978..2574f960b7ef84193b030a9e28426807541f21b7 100644 (file)
 
 #include "id3v2framefactory.h"
 
-#include "frames/unknownframe.h"
-#include "frames/textidentificationframe.h"
-#include "frames/commentsframe.h"
 #include "frames/attachedpictureframe.h"
+#include "frames/commentsframe.h"
+#include "frames/relativevolumeframe.h"
+#include "frames/textidentificationframe.h"
+#include "frames/unknownframe.h"
 
 using namespace TagLib;
 using namespace ID3v2;
@@ -118,6 +119,9 @@ Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const
     return f;
   }
 
+  if(frameID == "RVA2")
+    return new RelativeVolumeFrame(data, header);
+
   return new UnknownFrame(data, header);
 }