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