~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to src/core/formats/taglibext/unsynchronizedlyricsframe.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Patrick Matthäi, Mark Purcell
  • Date: 2013-11-30 15:44:59 UTC
  • mfrom: (1.1.16) (2.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20131130154459-s6lpalx8yy2zq7gx
Tags: 3.0.2-1
* New upstream release 

[ Patrick Matthäi ]
* New upstream release.
  - Add new libreadline-dev build dependency.
* Don't explicitly request xz compression - dpkg 1.17 does this by default.
* Bump Standards-Version to 3.9.5 (no changes needed).
* Fix Vcs-Browser control field.

[ Mark Purcell ]
* Switch to dh - reduce debian/rules bloat
* kid3 Replaces kid3-qt - low popcon, reduce archive bloat
* Fix vcs-field-not-canonical
* debian/compat -> 9
* Update Description:

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 ***************************************************************************/
7
 
 
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.                     *
12
 
 *                                                                         *
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.                       *
17
 
 *                                                                         *
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  *
21
 
 *   USA                                                                   *
22
 
 ***************************************************************************/
23
 
 
24
 
#include "unsynchronizedlyricsframe.h"
25
 
#include <tbytevectorlist.h>
26
 
#include <tdebug.h>
27
 
 
28
 
using namespace TagLib;
29
 
using namespace ID3v2;
30
 
 
31
 
class UnsynchronizedLyricsFrame::UnsynchronizedLyricsFramePrivate
32
 
{
33
 
public:
34
 
  UnsynchronizedLyricsFramePrivate() : textEncoding(String::Latin1) {}
35
 
  String::Type textEncoding;
36
 
  ByteVector language;
37
 
  String description;
38
 
  String text;
39
 
};
40
 
 
41
 
////////////////////////////////////////////////////////////////////////////////
42
 
// public members
43
 
////////////////////////////////////////////////////////////////////////////////
44
 
 
45
 
UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(String::Type encoding) : Frame("USLT")
46
 
{
47
 
  d = new UnsynchronizedLyricsFramePrivate;
48
 
  d->textEncoding = encoding;
49
 
}
50
 
 
51
 
UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(const ByteVector &data) : Frame(data)
52
 
{
53
 
  d = new UnsynchronizedLyricsFramePrivate;
54
 
  setData(data);
55
 
}
56
 
 
57
 
UnsynchronizedLyricsFrame::~UnsynchronizedLyricsFrame()
58
 
{
59
 
  delete d;
60
 
}
61
 
 
62
 
String UnsynchronizedLyricsFrame::toString() const
63
 
{
64
 
  return d->text;
65
 
}
66
 
 
67
 
ByteVector UnsynchronizedLyricsFrame::language() const
68
 
{
69
 
  return d->language;
70
 
}
71
 
 
72
 
String UnsynchronizedLyricsFrame::description() const
73
 
{
74
 
  return d->description;
75
 
}
76
 
 
77
 
String UnsynchronizedLyricsFrame::text() const
78
 
{
79
 
  return d->text;
80
 
}
81
 
 
82
 
void UnsynchronizedLyricsFrame::setLanguage(const ByteVector &languageEncoding)
83
 
{
84
 
  d->language = languageEncoding.mid(0, 3);
85
 
}
86
 
 
87
 
void UnsynchronizedLyricsFrame::setDescription(const String &s)
88
 
{
89
 
  d->description = s;
90
 
}
91
 
 
92
 
void UnsynchronizedLyricsFrame::setText(const String &s)
93
 
{
94
 
  d->text = s;
95
 
}
96
 
 
97
 
 
98
 
String::Type UnsynchronizedLyricsFrame::textEncoding() const
99
 
{
100
 
  return d->textEncoding;
101
 
}
102
 
 
103
 
void UnsynchronizedLyricsFrame::setTextEncoding(String::Type encoding)
104
 
{
105
 
  d->textEncoding = encoding;
106
 
}
107
 
 
108
 
////////////////////////////////////////////////////////////////////////////////
109
 
// protected members
110
 
////////////////////////////////////////////////////////////////////////////////
111
 
 
112
 
void UnsynchronizedLyricsFrame::parseFields(const ByteVector &data)
113
 
{
114
 
  if(data.size() < 5) {
115
 
    debug("An unsynchronized lyrics frame must contain at least 5 bytes.");
116
 
    return;
117
 
  }
118
 
 
119
 
  d->textEncoding = String::Type(data[0]);
120
 
  d->language = data.mid(1, 3);
121
 
 
122
 
  int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
123
 
 
124
 
  ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2);
125
 
 
126
 
  if(l.size() == 2) {
127
 
    d->description = String(l.front(), d->textEncoding);
128
 
    d->text = String(l.back(), d->textEncoding);
129
 
  }
130
 
}
131
 
 
132
 
ByteVector UnsynchronizedLyricsFrame::renderFields() const
133
 
{
134
 
  ByteVector v;
135
 
 
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));
141
 
 
142
 
  return v;
143
 
}
144
 
 
145
 
////////////////////////////////////////////////////////////////////////////////
146
 
// private members
147
 
////////////////////////////////////////////////////////////////////////////////
148
 
 
149
 
UnsynchronizedLyricsFrame::UnsynchronizedLyricsFrame(const ByteVector &data, Header *h) : Frame(h)
150
 
{
151
 
  d = new UnsynchronizedLyricsFramePrivate();
152
 
  parseFields(fieldData(data));
153
 
}