From: Scott Wheeler Date: Tue, 27 Apr 2004 02:01:27 +0000 (+0000) Subject: Add native support for the RVA2 (relative volume adjustment) frame. The X-Git-Tag: v1.5~398 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5091aa0b0c3fb50cfd02030c49ac5543285342d9;p=taglib Add native support for the RVA2 (relative volume adjustment) frame. The 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 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@306706 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/mpeg/id3v2/frames/Makefile.am b/mpeg/id3v2/frames/Makefile.am index ea3a8c97..fe4a48f7 100644 --- a/mpeg/id3v2/frames/Makefile.am +++ b/mpeg/id3v2/frames/Makefile.am @@ -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 index 00000000..acbd689a --- /dev/null +++ b/mpeg/id3v2/frames/relativevolumeframe.cpp @@ -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 index 00000000..55d2100e --- /dev/null +++ b/mpeg/id3v2/frames/relativevolumeframe.h @@ -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 + +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 diff --git a/mpeg/id3v2/id3v2framefactory.cpp b/mpeg/id3v2/id3v2framefactory.cpp index d550b29f..2574f960 100644 --- a/mpeg/id3v2/id3v2framefactory.cpp +++ b/mpeg/id3v2/id3v2framefactory.cpp @@ -23,10 +23,11 @@ #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); }