From b44cee48f4afd3ca938aece09654d70a2dc8f7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Sat, 10 Nov 2007 21:32:32 +0000 Subject: [PATCH] Add methods RelativeVolumeFrame::identification and RelativeVolumeFrame::setIdentification. BUG:150481 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@735098 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- .../mpeg/id3v2/frames/relativevolumeframe.cpp | 18 ++++++++++----- .../mpeg/id3v2/frames/relativevolumeframe.h | 12 ++++++++++ tests/test_id3v2.cpp | 22 +++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp b/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp index 2dac623a..8b9f85bf 100644 --- a/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp +++ b/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp @@ -162,20 +162,28 @@ void RelativeVolumeFrame::setPeakVolume(const PeakVolume &peak) setPeakVolume(peak, MasterVolume); } +String RelativeVolumeFrame::identification() const +{ + return d->identification; +} + +void RelativeVolumeFrame::setIdentification(const String &s) +{ + d->identification = s; +} + //////////////////////////////////////////////////////////////////////////////// // protected members //////////////////////////////////////////////////////////////////////////////// void RelativeVolumeFrame::parseFields(const ByteVector &data) { - ByteVector delimiter = textDelimiter(String::Latin1); - uint pos = data.find(delimiter); - d->identification = String(data.mid(0, pos), String::Latin1); - pos += delimiter.size(); + int pos = 0; + d->identification = readStringField(data, String::Latin1, &pos); // Each channel is at least 4 bytes. - while(pos <= data.size() - 4) { + while(pos <= (int)data.size() - 4) { ChannelType type = ChannelType(data[pos]); diff --git a/taglib/mpeg/id3v2/frames/relativevolumeframe.h b/taglib/mpeg/id3v2/frames/relativevolumeframe.h index fbba54bc..29c7d9e8 100644 --- a/taglib/mpeg/id3v2/frames/relativevolumeframe.h +++ b/taglib/mpeg/id3v2/frames/relativevolumeframe.h @@ -244,6 +244,18 @@ namespace TagLib { #endif + /*! + * Returns the identification for this frame. + */ + String identification() const; + + /*! + * Sets the identification of the frame to \a s. The string + * is used to identify the situation and/or device where this + * adjustment should apply. + */ + void setIdentification(const String &s); + protected: virtual void parseFields(const ByteVector &data); virtual ByteVector renderFields() const; diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 9a07765d..e4ead22a 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; using namespace TagLib; @@ -32,6 +33,7 @@ class TestID3v2 : public CppUnit::TestFixture CPPUNIT_TEST(testReadStringField); CPPUNIT_TEST(testParseAPIC); CPPUNIT_TEST(testParseGEOB); + CPPUNIT_TEST(testParseRelativeVolumeFrame); CPPUNIT_TEST(testBrokenFrame1); //CPPUNIT_TEST(testItunes24FrameSize); CPPUNIT_TEST_SUITE_END(); @@ -112,6 +114,26 @@ public: CPPUNIT_ASSERT_EQUAL(String("d"), f.description()); } + // http://bugs.kde.org/show_bug.cgi?id=150481 + void testParseRelativeVolumeFrame() + { + ID3v2::RelativeVolumeFrame f( + ByteVector("RVA2" // Frame ID + "\x00\x00\x00\x0B" // Frame size + "\x00\x00" // Frame flags + "ident\x00" // Identification + "\x02" // Type of channel + "\x00\x0F" // Volume adjustment + "\x08" // Bits representing peak + "\x45", 21)); // Peak volume + CPPUNIT_ASSERT_EQUAL(String("ident"), f.identification()); + CPPUNIT_ASSERT_EQUAL(15.0f / 512.0f, + f.volumeAdjustment(ID3v2::RelativeVolumeFrame::FrontRight)); + CPPUNIT_ASSERT_EQUAL((uchar)8, + f.peakVolume(ID3v2::RelativeVolumeFrame::FrontRight).bitsRepresentingPeak); + CPPUNIT_ASSERT_EQUAL(ByteVector("\x45"), + f.peakVolume(ID3v2::RelativeVolumeFrame::FrontRight).peakVolume); + } /*void testItunes24FrameSize() {