1 /***************************************************************************
2 copyright : (C) 2002 - 2008 by Scott Wheeler
3 email : wheeler@kde.org
4 copyright : (C) 2006 by Urs Fleisch
5 email : ufleisch@users.sourceforge.net
6 ***************************************************************************/
8 /***************************************************************************
9 * This library is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU Lesser General Public License version *
11 * 2.1 as published by the Free Software Foundation. *
13 * This library is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
23 * Alternatively, this file is available under the Mozilla Public *
24 * License Version 1.1. You may obtain a copy of the License at *
25 * http://www.mozilla.org/MPL/ *
26 ***************************************************************************/
28 #include "unsynchronizedlyricsframe.h"
29 #include <tbytevectorlist.h>
32 using namespace TagLib;
33 using namespace ID3v2;
35 class UnsynchronizedLyricsFrame::UnsynchronizedLyricsFramePrivate
38 UnsynchronizedLyricsFramePrivate() : textEncoding(String::Latin1) {}
39 String::Type textEncoding;
45 ////////////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////////////
49 UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(String::Type encoding) :
52 d = new UnsynchronizedLyricsFramePrivate;
53 d->textEncoding = encoding;
56 UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(const ByteVector &data) :
59 d = new UnsynchronizedLyricsFramePrivate;
63 UnsynchronizedLyricsFrame::~UnsynchronizedLyricsFrame()
68 String UnsynchronizedLyricsFrame::toString() const
73 ByteVector UnsynchronizedLyricsFrame::language() const
78 String UnsynchronizedLyricsFrame::description() const
80 return d->description;
83 String UnsynchronizedLyricsFrame::text() const
88 void UnsynchronizedLyricsFrame::setLanguage(const ByteVector &languageEncoding)
90 d->language = languageEncoding.mid(0, 3);
93 void UnsynchronizedLyricsFrame::setDescription(const String &s)
98 void UnsynchronizedLyricsFrame::setText(const String &s)
104 String::Type UnsynchronizedLyricsFrame::textEncoding() const
106 return d->textEncoding;
109 void UnsynchronizedLyricsFrame::setTextEncoding(String::Type encoding)
111 d->textEncoding = encoding;
114 ////////////////////////////////////////////////////////////////////////////////
116 ////////////////////////////////////////////////////////////////////////////////
118 void UnsynchronizedLyricsFrame::parseFields(const ByteVector &data)
120 if(data.size() < 5) {
121 debug("An unsynchronized lyrics frame must contain at least 5 bytes.");
125 d->textEncoding = String::Type(data[0]);
126 d->language = data.mid(1, 3);
129 = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
132 ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2);
135 d->description = String(l.front(), d->textEncoding);
136 d->text = String(l.back(), d->textEncoding);
140 ByteVector UnsynchronizedLyricsFrame::renderFields() const
144 v.append(char(d->textEncoding));
145 v.append(d->language.size() == 3 ? d->language : "XXX");
146 v.append(d->description.data(d->textEncoding));
147 v.append(textDelimiter(d->textEncoding));
148 v.append(d->text.data(d->textEncoding));
153 ////////////////////////////////////////////////////////////////////////////////
155 ////////////////////////////////////////////////////////////////////////////////
157 UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(const ByteVector &data, Header *h)
160 d = new UnsynchronizedLyricsFramePrivate();
161 parseFields(fieldData(data));