Chris@74
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@74
|
2
|
Chris@74
|
3 /*
|
Chris@74
|
4 Sonic Visualiser
|
Chris@74
|
5 An audio file viewer and annotation editor.
|
Chris@74
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@74
|
7 This file copyright 2006 Chris Cannam.
|
Chris@74
|
8
|
Chris@74
|
9 This program is free software; you can redistribute it and/or
|
Chris@74
|
10 modify it under the terms of the GNU General Public License as
|
Chris@74
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@74
|
12 License, or (at your option) any later version. See the file
|
Chris@74
|
13 COPYING included with this distribution for more information.
|
Chris@74
|
14 */
|
Chris@74
|
15
|
Chris@74
|
16 #include "Clipboard.h"
|
Chris@74
|
17
|
Chris@74
|
18 Clipboard::Point::Point(long frame, QString label) :
|
Chris@74
|
19 m_haveFrame(true),
|
Chris@74
|
20 m_frame(frame),
|
Chris@74
|
21 m_haveValue(false),
|
Chris@74
|
22 m_haveDuration(false),
|
Chris@74
|
23 m_haveLabel(true),
|
Chris@340
|
24 m_label(label),
|
Chris@340
|
25 m_haveLevel(false),
|
Chris@340
|
26 m_level(0.f),
|
Chris@370
|
27 m_haveReferenceFrame(false),
|
Chris@340
|
28 m_referenceFrame(frame)
|
Chris@74
|
29 {
|
Chris@74
|
30 }
|
Chris@74
|
31
|
Chris@74
|
32 Clipboard::Point::Point(long frame, float value, QString label) :
|
Chris@74
|
33 m_haveFrame(true),
|
Chris@74
|
34 m_frame(frame),
|
Chris@74
|
35 m_haveValue(true),
|
Chris@74
|
36 m_value(value),
|
Chris@74
|
37 m_haveDuration(false),
|
Chris@74
|
38 m_haveLabel(true),
|
Chris@340
|
39 m_label(label),
|
Chris@340
|
40 m_haveLevel(false),
|
Chris@340
|
41 m_level(0.f),
|
Chris@370
|
42 m_haveReferenceFrame(false),
|
Chris@340
|
43 m_referenceFrame(frame)
|
Chris@74
|
44 {
|
Chris@74
|
45 }
|
Chris@74
|
46
|
Chris@74
|
47 Clipboard::Point::Point(long frame, float value, size_t duration, QString label) :
|
Chris@74
|
48 m_haveFrame(true),
|
Chris@74
|
49 m_frame(frame),
|
Chris@74
|
50 m_haveValue(true),
|
Chris@74
|
51 m_value(value),
|
Chris@74
|
52 m_haveDuration(true),
|
Chris@74
|
53 m_duration(duration),
|
Chris@74
|
54 m_haveLabel(true),
|
Chris@340
|
55 m_label(label),
|
Chris@340
|
56 m_haveLevel(false),
|
Chris@340
|
57 m_level(0.f),
|
Chris@370
|
58 m_haveReferenceFrame(false),
|
Chris@340
|
59 m_referenceFrame(frame)
|
Chris@340
|
60 {
|
Chris@340
|
61 }
|
Chris@340
|
62
|
Chris@340
|
63 Clipboard::Point::Point(long frame, float value, size_t duration, float level, QString label) :
|
Chris@340
|
64 m_haveFrame(true),
|
Chris@340
|
65 m_frame(frame),
|
Chris@340
|
66 m_haveValue(true),
|
Chris@340
|
67 m_value(value),
|
Chris@340
|
68 m_haveDuration(true),
|
Chris@340
|
69 m_duration(duration),
|
Chris@340
|
70 m_haveLabel(true),
|
Chris@340
|
71 m_label(label),
|
Chris@340
|
72 m_haveLevel(true),
|
Chris@340
|
73 m_level(level),
|
Chris@370
|
74 m_haveReferenceFrame(false),
|
Chris@340
|
75 m_referenceFrame(frame)
|
Chris@74
|
76 {
|
Chris@74
|
77 }
|
Chris@74
|
78
|
Chris@74
|
79 Clipboard::Point::Point(const Point &point) :
|
Chris@74
|
80 m_haveFrame(point.m_haveFrame),
|
Chris@74
|
81 m_frame(point.m_frame),
|
Chris@74
|
82 m_haveValue(point.m_haveValue),
|
Chris@74
|
83 m_value(point.m_value),
|
Chris@74
|
84 m_haveDuration(point.m_haveDuration),
|
Chris@74
|
85 m_duration(point.m_duration),
|
Chris@74
|
86 m_haveLabel(point.m_haveLabel),
|
Chris@340
|
87 m_label(point.m_label),
|
Chris@340
|
88 m_haveLevel(point.m_haveLevel),
|
Chris@340
|
89 m_level(point.m_level),
|
Chris@370
|
90 m_haveReferenceFrame(point.m_haveReferenceFrame),
|
Chris@340
|
91 m_referenceFrame(point.m_referenceFrame)
|
Chris@74
|
92 {
|
Chris@74
|
93 }
|
Chris@74
|
94
|
Chris@74
|
95 Clipboard::Point &
|
Chris@74
|
96 Clipboard::Point::operator=(const Point &point)
|
Chris@74
|
97 {
|
Chris@74
|
98 if (this == &point) return *this;
|
Chris@74
|
99 m_haveFrame = point.m_haveFrame;
|
Chris@74
|
100 m_frame = point.m_frame;
|
Chris@74
|
101 m_haveValue = point.m_haveValue;
|
Chris@74
|
102 m_value = point.m_value;
|
Chris@74
|
103 m_haveDuration = point.m_haveDuration;
|
Chris@74
|
104 m_duration = point.m_duration;
|
Chris@74
|
105 m_haveLabel = point.m_haveLabel;
|
Chris@74
|
106 m_label = point.m_label;
|
Chris@340
|
107 m_haveLevel = point.m_haveLevel;
|
Chris@340
|
108 m_level = point.m_level;
|
Chris@370
|
109 m_haveReferenceFrame = point.m_haveReferenceFrame;
|
Chris@340
|
110 m_referenceFrame = point.m_referenceFrame;
|
Chris@74
|
111 return *this;
|
Chris@74
|
112 }
|
Chris@74
|
113
|
Chris@74
|
114 bool
|
Chris@74
|
115 Clipboard::Point::haveFrame() const
|
Chris@74
|
116 {
|
Chris@74
|
117 return m_haveFrame;
|
Chris@74
|
118 }
|
Chris@74
|
119
|
Chris@74
|
120 long
|
Chris@74
|
121 Clipboard::Point::getFrame() const
|
Chris@74
|
122 {
|
Chris@74
|
123 return m_frame;
|
Chris@74
|
124 }
|
Chris@74
|
125
|
Chris@872
|
126 Clipboard::Point
|
Chris@872
|
127 Clipboard::Point::withFrame(long frame) const
|
Chris@872
|
128 {
|
Chris@872
|
129 Point p(*this);
|
Chris@872
|
130 p.m_haveFrame = true;
|
Chris@872
|
131 p.m_frame = frame;
|
Chris@872
|
132 return p;
|
Chris@872
|
133 }
|
Chris@872
|
134
|
Chris@74
|
135 bool
|
Chris@74
|
136 Clipboard::Point::haveValue() const
|
Chris@74
|
137 {
|
Chris@74
|
138 return m_haveValue;
|
Chris@74
|
139 }
|
Chris@74
|
140
|
Chris@74
|
141 float
|
Chris@74
|
142 Clipboard::Point::getValue() const
|
Chris@74
|
143 {
|
Chris@74
|
144 return m_value;
|
Chris@74
|
145 }
|
Chris@74
|
146
|
Chris@872
|
147 Clipboard::Point
|
Chris@872
|
148 Clipboard::Point::withValue(float value) const
|
Chris@872
|
149 {
|
Chris@872
|
150 Point p(*this);
|
Chris@872
|
151 p.m_haveValue = true;
|
Chris@872
|
152 p.m_value = value;
|
Chris@872
|
153 return p;
|
Chris@872
|
154 }
|
Chris@872
|
155
|
Chris@74
|
156 bool
|
Chris@74
|
157 Clipboard::Point::haveDuration() const
|
Chris@74
|
158 {
|
Chris@74
|
159 return m_haveDuration;
|
Chris@74
|
160 }
|
Chris@74
|
161
|
Chris@74
|
162 size_t
|
Chris@74
|
163 Clipboard::Point::getDuration() const
|
Chris@74
|
164 {
|
Chris@74
|
165 return m_duration;
|
Chris@74
|
166 }
|
Chris@74
|
167
|
Chris@872
|
168 Clipboard::Point
|
Chris@872
|
169 Clipboard::Point::withDuration(size_t duration) const
|
Chris@872
|
170 {
|
Chris@872
|
171 Point p(*this);
|
Chris@872
|
172 p.m_haveDuration = true;
|
Chris@872
|
173 p.m_duration = duration;
|
Chris@872
|
174 return p;
|
Chris@872
|
175 }
|
Chris@872
|
176
|
Chris@74
|
177 bool
|
Chris@74
|
178 Clipboard::Point::haveLabel() const
|
Chris@74
|
179 {
|
Chris@74
|
180 return m_haveLabel;
|
Chris@74
|
181 }
|
Chris@74
|
182
|
Chris@74
|
183 QString
|
Chris@74
|
184 Clipboard::Point::getLabel() const
|
Chris@74
|
185 {
|
Chris@74
|
186 return m_label;
|
Chris@74
|
187 }
|
Chris@74
|
188
|
Chris@872
|
189 Clipboard::Point
|
Chris@872
|
190 Clipboard::Point::withLabel(QString label) const
|
Chris@872
|
191 {
|
Chris@872
|
192 Point p(*this);
|
Chris@872
|
193 p.m_haveLabel = true;
|
Chris@872
|
194 p.m_label = label;
|
Chris@872
|
195 return p;
|
Chris@872
|
196 }
|
Chris@872
|
197
|
Chris@340
|
198 bool
|
Chris@340
|
199 Clipboard::Point::haveLevel() const
|
Chris@340
|
200 {
|
Chris@340
|
201 return m_haveLevel;
|
Chris@340
|
202 }
|
Chris@340
|
203
|
Chris@340
|
204 float
|
Chris@340
|
205 Clipboard::Point::getLevel() const
|
Chris@340
|
206 {
|
Chris@340
|
207 return m_level;
|
Chris@340
|
208 }
|
Chris@340
|
209
|
Chris@872
|
210 Clipboard::Point
|
Chris@872
|
211 Clipboard::Point::withLevel(float level) const
|
Chris@872
|
212 {
|
Chris@872
|
213 Point p(*this);
|
Chris@872
|
214 p.m_haveLevel = true;
|
Chris@872
|
215 p.m_level = level;
|
Chris@872
|
216 return p;
|
Chris@872
|
217 }
|
Chris@872
|
218
|
Chris@340
|
219 bool
|
Chris@370
|
220 Clipboard::Point::haveReferenceFrame() const
|
Chris@340
|
221 {
|
Chris@370
|
222 return m_haveReferenceFrame;
|
Chris@370
|
223 }
|
Chris@370
|
224
|
Chris@370
|
225 bool
|
Chris@370
|
226 Clipboard::Point::referenceFrameDiffers() const
|
Chris@370
|
227 {
|
Chris@370
|
228 return m_haveReferenceFrame && (m_referenceFrame != m_frame);
|
Chris@340
|
229 }
|
Chris@340
|
230
|
Chris@340
|
231 long
|
Chris@340
|
232 Clipboard::Point::getReferenceFrame() const
|
Chris@340
|
233 {
|
Chris@340
|
234 return m_referenceFrame;
|
Chris@340
|
235 }
|
Chris@340
|
236
|
Chris@340
|
237 void
|
Chris@340
|
238 Clipboard::Point::setReferenceFrame(long f)
|
Chris@340
|
239 {
|
Chris@370
|
240 m_haveReferenceFrame = true;
|
Chris@340
|
241 m_referenceFrame = f;
|
Chris@340
|
242 }
|
Chris@340
|
243
|
Chris@74
|
244 Clipboard::Clipboard() { }
|
Chris@74
|
245 Clipboard::~Clipboard() { }
|
Chris@74
|
246
|
Chris@74
|
247 void
|
Chris@74
|
248 Clipboard::clear()
|
Chris@74
|
249 {
|
Chris@74
|
250 m_points.clear();
|
Chris@74
|
251 }
|
Chris@74
|
252
|
Chris@74
|
253 bool
|
Chris@74
|
254 Clipboard::empty() const
|
Chris@74
|
255 {
|
Chris@74
|
256 return m_points.empty();
|
Chris@74
|
257 }
|
Chris@74
|
258
|
Chris@74
|
259 const Clipboard::PointList &
|
Chris@74
|
260 Clipboard::getPoints() const
|
Chris@74
|
261 {
|
Chris@74
|
262 return m_points;
|
Chris@74
|
263 }
|
Chris@74
|
264
|
Chris@74
|
265 void
|
Chris@74
|
266 Clipboard::setPoints(const PointList &pl)
|
Chris@74
|
267 {
|
Chris@74
|
268 m_points = pl;
|
Chris@74
|
269 }
|
Chris@74
|
270
|
Chris@74
|
271 void
|
Chris@74
|
272 Clipboard::addPoint(const Point &point)
|
Chris@74
|
273 {
|
Chris@74
|
274 m_points.push_back(point);
|
Chris@74
|
275 }
|
Chris@74
|
276
|
Chris@340
|
277 bool
|
Chris@370
|
278 Clipboard::haveReferenceFrames() const
|
Chris@370
|
279 {
|
Chris@370
|
280 for (PointList::const_iterator i = m_points.begin();
|
Chris@370
|
281 i != m_points.end(); ++i) {
|
Chris@370
|
282 if (i->haveReferenceFrame()) return true;
|
Chris@370
|
283 }
|
Chris@370
|
284 return false;
|
Chris@370
|
285 }
|
Chris@370
|
286
|
Chris@370
|
287 bool
|
Chris@369
|
288 Clipboard::referenceFramesDiffer() const
|
Chris@340
|
289 {
|
Chris@340
|
290 for (PointList::const_iterator i = m_points.begin();
|
Chris@340
|
291 i != m_points.end(); ++i) {
|
Chris@370
|
292 if (i->referenceFrameDiffers()) return true;
|
Chris@340
|
293 }
|
Chris@340
|
294 return false;
|
Chris@340
|
295 }
|
Chris@340
|
296
|