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 <jbaayen@gnome.org>


git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@306706 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Scott Wheeler 2004-04-27 02:01:27 +00:00
parent de4bd42ef0
commit 5091aa0b0c
4 changed files with 231 additions and 3 deletions

View 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

View File

@ -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()));
}

View File

@ -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

View File

@ -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);
}