1
/***************************************************************************
2
copyright : (C) 2002, 2003 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 *
22
***************************************************************************/
24
#include "unsynchronizedlyricsframe.h"
25
#include <tbytevectorlist.h>
28
using namespace TagLib;
29
using namespace ID3v2;
31
class UnsynchronizedLyricsFrame::UnsynchronizedLyricsFramePrivate
34
UnsynchronizedLyricsFramePrivate() : textEncoding(String::Latin1) {}
35
String::Type textEncoding;
41
////////////////////////////////////////////////////////////////////////////////
43
////////////////////////////////////////////////////////////////////////////////
45
UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(String::Type encoding) : Frame("USLT")
47
d = new UnsynchronizedLyricsFramePrivate;
48
d->textEncoding = encoding;
51
UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(const ByteVector &data) : Frame(data)
53
d = new UnsynchronizedLyricsFramePrivate;
57
UnsynchronizedLyricsFrame::~UnsynchronizedLyricsFrame()
62
String UnsynchronizedLyricsFrame::toString() const
67
ByteVector UnsynchronizedLyricsFrame::language() const
72
String UnsynchronizedLyricsFrame::description() const
74
return d->description;
77
String UnsynchronizedLyricsFrame::text() const
82
void UnsynchronizedLyricsFrame::setLanguage(const ByteVector &languageEncoding)
84
d->language = languageEncoding.mid(0, 3);
87
void UnsynchronizedLyricsFrame::setDescription(const String &s)
92
void UnsynchronizedLyricsFrame::setText(const String &s)
98
String::Type UnsynchronizedLyricsFrame::textEncoding() const
100
return d->textEncoding;
103
void UnsynchronizedLyricsFrame::setTextEncoding(String::Type encoding)
105
d->textEncoding = encoding;
108
////////////////////////////////////////////////////////////////////////////////
110
////////////////////////////////////////////////////////////////////////////////
112
void UnsynchronizedLyricsFrame::parseFields(const ByteVector &data)
114
if(data.size() < 5) {
115
debug("An unsynchronized lyrics frame must contain at least 5 bytes.");
119
d->textEncoding = String::Type(data[0]);
120
d->language = data.mid(1, 3);
122
int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
124
ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2);
127
d->description = String(l.front(), d->textEncoding);
128
d->text = String(l.back(), d->textEncoding);
132
ByteVector UnsynchronizedLyricsFrame::renderFields() const
136
v.append(char(d->textEncoding));
137
v.append(d->language.size() == 3 ? d->language : " ");
138
v.append(d->description.data(d->textEncoding));
139
v.append(textDelimiter(d->textEncoding));
140
v.append(d->text.data(d->textEncoding));
145
////////////////////////////////////////////////////////////////////////////////
147
////////////////////////////////////////////////////////////////////////////////
149
UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(const ByteVector &data, Header *h) : Frame(h)
151
d = new UnsynchronizedLyricsFramePrivate();
152
parseFields(fieldData(data));