Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "TimeValueLayer.h"
|
Chris@0
|
17
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@0
|
19 #include "base/RealTime.h"
|
Chris@0
|
20 #include "base/Profiler.h"
|
Chris@197
|
21 #include "base/LogRange.h"
|
Chris@437
|
22 #include "base/RangeMapper.h"
|
Chris@376
|
23 #include "ColourDatabase.h"
|
Chris@128
|
24 #include "view/View.h"
|
Chris@0
|
25
|
Chris@128
|
26 #include "data/model/SparseTimeValueModel.h"
|
Chris@340
|
27 #include "data/model/Labeller.h"
|
Chris@0
|
28
|
Chris@70
|
29 #include "widgets/ItemEditDialog.h"
|
Chris@125
|
30 #include "widgets/ListInputDialog.h"
|
Chris@70
|
31
|
Chris@376
|
32 #include "ColourMapper.h"
|
Chris@691
|
33 #include "PianoScale.h"
|
Chris@66
|
34
|
Chris@0
|
35 #include <QPainter>
|
Chris@6
|
36 #include <QPainterPath>
|
Chris@21
|
37 #include <QMouseEvent>
|
Chris@125
|
38 #include <QRegExp>
|
Chris@316
|
39 #include <QTextStream>
|
Chris@360
|
40 #include <QMessageBox>
|
Chris@340
|
41 #include <QInputDialog>
|
Chris@0
|
42
|
Chris@0
|
43 #include <iostream>
|
Chris@0
|
44 #include <cmath>
|
Chris@0
|
45
|
Chris@526
|
46 //#define DEBUG_TIME_VALUE_LAYER 1
|
Chris@526
|
47
|
Chris@44
|
48 TimeValueLayer::TimeValueLayer() :
|
Chris@287
|
49 SingleColourLayer(),
|
Chris@0
|
50 m_model(0),
|
Chris@21
|
51 m_editing(false),
|
Chris@23
|
52 m_originalPoint(0, 0.0, tr("New Point")),
|
Chris@21
|
53 m_editingPoint(0, 0.0, tr("New Point")),
|
Chris@22
|
54 m_editingCommand(0),
|
Chris@197
|
55 m_colourMap(0),
|
Chris@66
|
56 m_plotStyle(PlotConnectedPoints),
|
Chris@437
|
57 m_verticalScale(AutoAlignScale),
|
Chris@513
|
58 m_drawSegmentDivisions(true),
|
Chris@553
|
59 m_derivative(false),
|
Chris@437
|
60 m_scaleMinimum(0),
|
Chris@437
|
61 m_scaleMaximum(0)
|
Chris@0
|
62 {
|
Chris@44
|
63
|
Chris@0
|
64 }
|
Chris@0
|
65
|
Chris@0
|
66 void
|
Chris@0
|
67 TimeValueLayer::setModel(SparseTimeValueModel *model)
|
Chris@0
|
68 {
|
Chris@0
|
69 if (m_model == model) return;
|
Chris@0
|
70 m_model = model;
|
Chris@0
|
71
|
Chris@320
|
72 connectSignals(m_model);
|
Chris@0
|
73
|
Chris@438
|
74 m_scaleMinimum = 0;
|
Chris@438
|
75 m_scaleMaximum = 0;
|
Chris@438
|
76
|
Chris@494
|
77 if (m_model && m_model->getRDFTypeURI().endsWith("Segment")) {
|
Chris@494
|
78 setPlotStyle(PlotSegmentation);
|
Chris@494
|
79 }
|
Chris@494
|
80 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) {
|
Chris@494
|
81 setPlotStyle(PlotSegmentation);
|
Chris@494
|
82 }
|
Chris@494
|
83
|
Chris@526
|
84 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
85 cerr << "TimeValueLayer::setModel(" << model << ")" << endl;
|
Chris@526
|
86 #endif
|
Chris@0
|
87
|
Chris@0
|
88 emit modelReplaced();
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 Layer::PropertyList
|
Chris@0
|
92 TimeValueLayer::getProperties() const
|
Chris@0
|
93 {
|
Chris@287
|
94 PropertyList list = SingleColourLayer::getProperties();
|
Chris@87
|
95 list.push_back("Plot Type");
|
Chris@87
|
96 list.push_back("Vertical Scale");
|
Chris@100
|
97 list.push_back("Scale Units");
|
Chris@513
|
98 list.push_back("Draw Segment Division Lines");
|
Chris@553
|
99 list.push_back("Show Derivative");
|
Chris@0
|
100 return list;
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@87
|
103 QString
|
Chris@87
|
104 TimeValueLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@87
|
105 {
|
Chris@87
|
106 if (name == "Plot Type") return tr("Plot Type");
|
Chris@87
|
107 if (name == "Vertical Scale") return tr("Vertical Scale");
|
Chris@100
|
108 if (name == "Scale Units") return tr("Scale Units");
|
Chris@513
|
109 if (name == "Draw Segment Division Lines") return tr("Draw Segment Division Lines");
|
Chris@553
|
110 if (name == "Show Derivative") return tr("Show Derivative");
|
Chris@287
|
111 return SingleColourLayer::getPropertyLabel(name);
|
Chris@87
|
112 }
|
Chris@87
|
113
|
Chris@515
|
114 QString
|
Chris@515
|
115 TimeValueLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@515
|
116 {
|
Chris@515
|
117 if (name == "Draw Segment Division Lines") return "lines";
|
Chris@553
|
118 if (name == "Show Derivative") return "derivative";
|
Chris@515
|
119 return "";
|
Chris@515
|
120 }
|
Chris@515
|
121
|
Chris@0
|
122 Layer::PropertyType
|
Chris@0
|
123 TimeValueLayer::getPropertyType(const PropertyName &name) const
|
Chris@0
|
124 {
|
Chris@287
|
125 if (name == "Plot Type") return ValueProperty;
|
Chris@287
|
126 if (name == "Vertical Scale") return ValueProperty;
|
Chris@100
|
127 if (name == "Scale Units") return UnitsProperty;
|
Chris@287
|
128 if (name == "Colour" && m_plotStyle == PlotSegmentation) return ValueProperty;
|
Chris@513
|
129 if (name == "Draw Segment Division Lines") return ToggleProperty;
|
Chris@553
|
130 if (name == "Show Derivative") return ToggleProperty;
|
Chris@287
|
131 return SingleColourLayer::getPropertyType(name);
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@198
|
134 QString
|
Chris@198
|
135 TimeValueLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@198
|
136 {
|
Chris@198
|
137 if (name == "Vertical Scale" || name == "Scale Units") {
|
Chris@198
|
138 return tr("Scale");
|
Chris@198
|
139 }
|
Chris@553
|
140 if (name == "Plot Type" || name == "Draw Segment Division Lines" ||
|
Chris@553
|
141 name == "Show Derivative") {
|
Chris@513
|
142 return tr("Plot Type");
|
Chris@513
|
143 }
|
Chris@287
|
144 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@198
|
145 }
|
Chris@198
|
146
|
Chris@0
|
147 int
|
Chris@0
|
148 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
149 int *min, int *max, int *deflt) const
|
Chris@0
|
150 {
|
Chris@216
|
151 int val = 0;
|
Chris@0
|
152
|
Chris@287
|
153 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@197
|
154
|
Chris@287
|
155 if (min) *min = 0;
|
Chris@287
|
156 if (max) *max = ColourMapper::getColourMapCount() - 1;
|
Chris@287
|
157 if (deflt) *deflt = 0;
|
Chris@197
|
158
|
Chris@287
|
159 val = m_colourMap;
|
Chris@0
|
160
|
Chris@87
|
161 } else if (name == "Plot Type") {
|
Chris@0
|
162
|
Chris@10
|
163 if (min) *min = 0;
|
Chris@615
|
164 if (max) *max = 6;
|
Chris@216
|
165 if (deflt) *deflt = int(PlotConnectedPoints);
|
Chris@0
|
166
|
Chris@216
|
167 val = int(m_plotStyle);
|
Chris@0
|
168
|
Chris@87
|
169 } else if (name == "Vertical Scale") {
|
Chris@66
|
170
|
Chris@66
|
171 if (min) *min = 0;
|
Chris@66
|
172 if (max) *max = 3;
|
Chris@216
|
173 if (deflt) *deflt = int(AutoAlignScale);
|
Chris@66
|
174
|
Chris@216
|
175 val = int(m_verticalScale);
|
Chris@66
|
176
|
Chris@100
|
177 } else if (name == "Scale Units") {
|
Chris@100
|
178
|
Chris@216
|
179 if (deflt) *deflt = 0;
|
Chris@100
|
180 if (m_model) {
|
Chris@216
|
181 val = UnitDatabase::getInstance()->getUnitId
|
Chris@100
|
182 (m_model->getScaleUnits());
|
Chris@100
|
183 }
|
Chris@100
|
184
|
Chris@513
|
185 } else if (name == "Draw Segment Division Lines") {
|
Chris@513
|
186
|
Chris@513
|
187 if (min) *min = 0;
|
Chris@513
|
188 if (max) *max = 0;
|
Chris@513
|
189 if (deflt) *deflt = 1;
|
Chris@513
|
190 val = (m_drawSegmentDivisions ? 1.0 : 0.0);
|
Chris@513
|
191
|
Chris@553
|
192 } else if (name == "Show Derivative") {
|
Chris@553
|
193
|
Chris@553
|
194 if (min) *min = 0;
|
Chris@553
|
195 if (max) *max = 0;
|
Chris@553
|
196 if (deflt) *deflt = 0;
|
Chris@553
|
197 val = (m_derivative ? 1.0 : 0.0);
|
Chris@553
|
198
|
Chris@0
|
199 } else {
|
Chris@0
|
200
|
Chris@287
|
201 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@0
|
202 }
|
Chris@0
|
203
|
Chris@216
|
204 return val;
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 QString
|
Chris@0
|
208 TimeValueLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@0
|
209 int value) const
|
Chris@0
|
210 {
|
Chris@287
|
211 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@287
|
212 return ColourMapper::getColourMapName(value);
|
Chris@87
|
213 } else if (name == "Plot Type") {
|
Chris@0
|
214 switch (value) {
|
Chris@0
|
215 default:
|
Chris@0
|
216 case 0: return tr("Points");
|
Chris@0
|
217 case 1: return tr("Stems");
|
Chris@6
|
218 case 2: return tr("Connected Points");
|
Chris@6
|
219 case 3: return tr("Lines");
|
Chris@6
|
220 case 4: return tr("Curve");
|
Chris@26
|
221 case 5: return tr("Segmentation");
|
Chris@615
|
222 case 6: return tr("Discrete Curves");
|
Chris@0
|
223 }
|
Chris@87
|
224 } else if (name == "Vertical Scale") {
|
Chris@66
|
225 switch (value) {
|
Chris@66
|
226 default:
|
Chris@101
|
227 case 0: return tr("Auto-Align");
|
Chris@198
|
228 case 1: return tr("Linear");
|
Chris@198
|
229 case 2: return tr("Log");
|
Chris@198
|
230 case 3: return tr("+/-1");
|
Chris@66
|
231 }
|
Chris@0
|
232 }
|
Chris@287
|
233 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@0
|
234 }
|
Chris@0
|
235
|
Chris@0
|
236 void
|
Chris@0
|
237 TimeValueLayer::setProperty(const PropertyName &name, int value)
|
Chris@0
|
238 {
|
Chris@287
|
239 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@287
|
240 setFillColourMap(value);
|
Chris@87
|
241 } else if (name == "Plot Type") {
|
Chris@0
|
242 setPlotStyle(PlotStyle(value));
|
Chris@87
|
243 } else if (name == "Vertical Scale") {
|
Chris@66
|
244 setVerticalScale(VerticalScale(value));
|
Chris@100
|
245 } else if (name == "Scale Units") {
|
Chris@100
|
246 if (m_model) {
|
Chris@100
|
247 m_model->setScaleUnits
|
Chris@100
|
248 (UnitDatabase::getInstance()->getUnitById(value));
|
Chris@100
|
249 emit modelChanged();
|
Chris@100
|
250 }
|
Chris@513
|
251 } else if (name == "Draw Segment Division Lines") {
|
Chris@513
|
252 setDrawSegmentDivisions(value > 0.5);
|
Chris@553
|
253 } else if (name == "Show Derivative") {
|
Chris@553
|
254 setShowDerivative(value > 0.5);
|
Chris@287
|
255 } else {
|
Chris@287
|
256 SingleColourLayer::setProperty(name, value);
|
Chris@0
|
257 }
|
Chris@0
|
258 }
|
Chris@0
|
259
|
Chris@0
|
260 void
|
Chris@197
|
261 TimeValueLayer::setFillColourMap(int map)
|
Chris@197
|
262 {
|
Chris@197
|
263 if (m_colourMap == map) return;
|
Chris@197
|
264 m_colourMap = map;
|
Chris@197
|
265 emit layerParametersChanged();
|
Chris@197
|
266 }
|
Chris@197
|
267
|
Chris@197
|
268 void
|
Chris@0
|
269 TimeValueLayer::setPlotStyle(PlotStyle style)
|
Chris@0
|
270 {
|
Chris@0
|
271 if (m_plotStyle == style) return;
|
Chris@197
|
272 bool colourTypeChanged = (style == PlotSegmentation ||
|
Chris@197
|
273 m_plotStyle == PlotSegmentation);
|
Chris@0
|
274 m_plotStyle = style;
|
Chris@197
|
275 if (colourTypeChanged) {
|
Chris@197
|
276 emit layerParameterRangesChanged();
|
Chris@197
|
277 }
|
Chris@0
|
278 emit layerParametersChanged();
|
Chris@0
|
279 }
|
Chris@0
|
280
|
Chris@66
|
281 void
|
Chris@66
|
282 TimeValueLayer::setVerticalScale(VerticalScale scale)
|
Chris@66
|
283 {
|
Chris@66
|
284 if (m_verticalScale == scale) return;
|
Chris@66
|
285 m_verticalScale = scale;
|
Chris@66
|
286 emit layerParametersChanged();
|
Chris@66
|
287 }
|
Chris@66
|
288
|
Chris@513
|
289 void
|
Chris@513
|
290 TimeValueLayer::setDrawSegmentDivisions(bool draw)
|
Chris@513
|
291 {
|
Chris@513
|
292 if (m_drawSegmentDivisions == draw) return;
|
Chris@513
|
293 m_drawSegmentDivisions = draw;
|
Chris@513
|
294 emit layerParametersChanged();
|
Chris@513
|
295 }
|
Chris@513
|
296
|
Chris@553
|
297 void
|
Chris@553
|
298 TimeValueLayer::setShowDerivative(bool show)
|
Chris@553
|
299 {
|
Chris@553
|
300 if (m_derivative == show) return;
|
Chris@553
|
301 m_derivative = show;
|
Chris@553
|
302 emit layerParametersChanged();
|
Chris@553
|
303 }
|
Chris@553
|
304
|
Chris@0
|
305 bool
|
Chris@44
|
306 TimeValueLayer::isLayerScrollable(const View *v) const
|
Chris@0
|
307 {
|
Chris@6
|
308 // We don't illuminate sections in the line or curve modes, so
|
Chris@6
|
309 // they're always scrollable
|
Chris@6
|
310
|
Chris@6
|
311 if (m_plotStyle == PlotLines ||
|
Chris@615
|
312 m_plotStyle == PlotCurve ||
|
Chris@615
|
313 m_plotStyle == PlotDiscreteCurves) return true;
|
Chris@6
|
314
|
Chris@0
|
315 QPoint discard;
|
Chris@44
|
316 return !v->shouldIlluminateLocalFeatures(this, discard);
|
Chris@0
|
317 }
|
Chris@0
|
318
|
Chris@79
|
319 bool
|
Chris@101
|
320 TimeValueLayer::getValueExtents(float &min, float &max,
|
Chris@101
|
321 bool &logarithmic, QString &unit) const
|
Chris@79
|
322 {
|
Chris@101
|
323 if (!m_model) return false;
|
Chris@668
|
324
|
Chris@79
|
325 min = m_model->getValueMinimum();
|
Chris@79
|
326 max = m_model->getValueMaximum();
|
Chris@668
|
327
|
Chris@101
|
328 logarithmic = (m_verticalScale == LogScale);
|
Chris@668
|
329
|
Chris@79
|
330 unit = m_model->getScaleUnits();
|
Chris@668
|
331
|
Chris@553
|
332 if (m_derivative) {
|
Chris@553
|
333 max = std::max(fabsf(min), fabsf(max));
|
Chris@553
|
334 min = -max;
|
Chris@553
|
335 }
|
Chris@629
|
336
|
Chris@629
|
337 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
338 cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << endl;
|
Chris@629
|
339 #endif
|
Chris@629
|
340
|
Chris@668
|
341 if (!shouldAutoAlign() && !logarithmic && !m_derivative) {
|
Chris@668
|
342
|
Chris@668
|
343 if (max == min) {
|
Chris@668
|
344 max = max + 0.5;
|
Chris@668
|
345 min = min - 0.5;
|
Chris@668
|
346 } else {
|
Chris@668
|
347 float margin = (max - min) / 10.0;
|
Chris@668
|
348 max = max + margin;
|
Chris@668
|
349 min = min - margin;
|
Chris@668
|
350 }
|
Chris@668
|
351
|
Chris@668
|
352 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
353 cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << endl;
|
Chris@668
|
354 #endif
|
Chris@668
|
355 }
|
Chris@668
|
356
|
Chris@79
|
357 return true;
|
Chris@79
|
358 }
|
Chris@79
|
359
|
Chris@101
|
360 bool
|
Chris@101
|
361 TimeValueLayer::getDisplayExtents(float &min, float &max) const
|
Chris@101
|
362 {
|
Chris@296
|
363 if (!m_model || shouldAutoAlign()) return false;
|
Chris@101
|
364
|
Chris@437
|
365 if (m_scaleMinimum == m_scaleMaximum) {
|
Chris@668
|
366 bool log;
|
Chris@668
|
367 QString unit;
|
Chris@668
|
368 getValueExtents(min, max, log, unit);
|
Chris@553
|
369 } else {
|
Chris@553
|
370 min = m_scaleMinimum;
|
Chris@553
|
371 max = m_scaleMaximum;
|
Chris@437
|
372 }
|
Chris@437
|
373
|
Chris@553
|
374 if (m_derivative) {
|
Chris@553
|
375 max = std::max(fabsf(min), fabsf(max));
|
Chris@553
|
376 min = -max;
|
Chris@553
|
377 }
|
Chris@437
|
378
|
Chris@526
|
379 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
380 cerr << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << endl;
|
Chris@526
|
381 #endif
|
Chris@437
|
382
|
Chris@101
|
383 return true;
|
Chris@101
|
384 }
|
Chris@101
|
385
|
Chris@437
|
386 bool
|
Chris@437
|
387 TimeValueLayer::setDisplayExtents(float min, float max)
|
Chris@437
|
388 {
|
Chris@437
|
389 if (!m_model) return false;
|
Chris@437
|
390
|
Chris@437
|
391 if (min == max) {
|
Chris@437
|
392 if (min == 0.f) {
|
Chris@437
|
393 max = 1.f;
|
Chris@437
|
394 } else {
|
Chris@437
|
395 max = min * 1.0001;
|
Chris@437
|
396 }
|
Chris@437
|
397 }
|
Chris@437
|
398
|
Chris@437
|
399 m_scaleMinimum = min;
|
Chris@437
|
400 m_scaleMaximum = max;
|
Chris@437
|
401
|
Chris@526
|
402 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
403 cerr << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << endl;
|
Chris@526
|
404 #endif
|
Chris@437
|
405
|
Chris@437
|
406 emit layerParametersChanged();
|
Chris@437
|
407 return true;
|
Chris@437
|
408 }
|
Chris@437
|
409
|
Chris@437
|
410 int
|
Chris@437
|
411 TimeValueLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@437
|
412 {
|
Chris@437
|
413 if (shouldAutoAlign()) return 0;
|
Chris@437
|
414 if (!m_model) return 0;
|
Chris@437
|
415
|
Chris@439
|
416 defaultStep = 0;
|
Chris@437
|
417 return 100;
|
Chris@437
|
418 }
|
Chris@437
|
419
|
Chris@437
|
420 int
|
Chris@437
|
421 TimeValueLayer::getCurrentVerticalZoomStep() const
|
Chris@437
|
422 {
|
Chris@437
|
423 if (shouldAutoAlign()) return 0;
|
Chris@437
|
424 if (!m_model) return 0;
|
Chris@437
|
425
|
Chris@437
|
426 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@437
|
427 if (!mapper) return 0;
|
Chris@437
|
428
|
Chris@437
|
429 float dmin, dmax;
|
Chris@437
|
430 getDisplayExtents(dmin, dmax);
|
Chris@437
|
431
|
Chris@437
|
432 int nr = mapper->getPositionForValue(dmax - dmin);
|
Chris@526
|
433
|
Chris@526
|
434 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
435 cerr << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", nr = " << nr << endl;
|
Chris@526
|
436 #endif
|
Chris@526
|
437
|
Chris@437
|
438 delete mapper;
|
Chris@437
|
439
|
Chris@437
|
440 return 100 - nr;
|
Chris@437
|
441 }
|
Chris@437
|
442
|
Chris@437
|
443 void
|
Chris@437
|
444 TimeValueLayer::setVerticalZoomStep(int step)
|
Chris@437
|
445 {
|
Chris@437
|
446 if (shouldAutoAlign()) return;
|
Chris@437
|
447 if (!m_model) return;
|
Chris@437
|
448
|
Chris@437
|
449 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@437
|
450 if (!mapper) return;
|
Chris@437
|
451
|
Chris@437
|
452 float min, max;
|
Chris@437
|
453 bool logarithmic;
|
Chris@437
|
454 QString unit;
|
Chris@437
|
455 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
456
|
Chris@437
|
457 float dmin, dmax;
|
Chris@437
|
458 getDisplayExtents(dmin, dmax);
|
Chris@437
|
459
|
Chris@437
|
460 float newdist = mapper->getValueForPosition(100 - step);
|
Chris@437
|
461
|
Chris@437
|
462 float newmin, newmax;
|
Chris@437
|
463
|
Chris@437
|
464 if (logarithmic) {
|
Chris@437
|
465
|
Chris@437
|
466 // see SpectrogramLayer::setVerticalZoomStep
|
Chris@437
|
467
|
Chris@437
|
468 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
|
Chris@437
|
469 newmin = newmax - newdist;
|
Chris@437
|
470
|
Chris@526
|
471 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
472 cerr << "newmin = " << newmin << ", newmax = " << newmax << endl;
|
Chris@526
|
473 #endif
|
Chris@437
|
474
|
Chris@437
|
475 } else {
|
Chris@437
|
476 float dmid = (dmax + dmin) / 2;
|
Chris@437
|
477 newmin = dmid - newdist / 2;
|
Chris@437
|
478 newmax = dmid + newdist / 2;
|
Chris@437
|
479 }
|
Chris@437
|
480
|
Chris@437
|
481 if (newmin < min) {
|
Chris@437
|
482 newmax += (min - newmin);
|
Chris@437
|
483 newmin = min;
|
Chris@437
|
484 }
|
Chris@437
|
485 if (newmax > max) {
|
Chris@437
|
486 newmax = max;
|
Chris@437
|
487 }
|
Chris@437
|
488
|
Chris@526
|
489 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
490 cerr << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl;
|
Chris@526
|
491 #endif
|
Chris@437
|
492
|
Chris@437
|
493 setDisplayExtents(newmin, newmax);
|
Chris@437
|
494 }
|
Chris@437
|
495
|
Chris@437
|
496 RangeMapper *
|
Chris@437
|
497 TimeValueLayer::getNewVerticalZoomRangeMapper() const
|
Chris@437
|
498 {
|
Chris@437
|
499 if (!m_model) return 0;
|
Chris@437
|
500
|
Chris@437
|
501 RangeMapper *mapper;
|
Chris@437
|
502
|
Chris@437
|
503 float min, max;
|
Chris@437
|
504 bool logarithmic;
|
Chris@437
|
505 QString unit;
|
Chris@437
|
506 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
507
|
Chris@437
|
508 if (min == max) return 0;
|
Chris@437
|
509
|
Chris@437
|
510 if (logarithmic) {
|
Chris@437
|
511 mapper = new LogRangeMapper(0, 100, min, max, unit);
|
Chris@437
|
512 } else {
|
Chris@437
|
513 mapper = new LinearRangeMapper(0, 100, min, max, unit);
|
Chris@437
|
514 }
|
Chris@437
|
515
|
Chris@437
|
516 return mapper;
|
Chris@437
|
517 }
|
Chris@437
|
518
|
Chris@0
|
519 SparseTimeValueModel::PointList
|
Chris@44
|
520 TimeValueLayer::getLocalPoints(View *v, int x) const
|
Chris@0
|
521 {
|
Chris@0
|
522 if (!m_model) return SparseTimeValueModel::PointList();
|
Chris@0
|
523
|
Chris@44
|
524 long frame = v->getFrameForX(x);
|
Chris@0
|
525
|
Chris@0
|
526 SparseTimeValueModel::PointList onPoints =
|
Chris@0
|
527 m_model->getPoints(frame);
|
Chris@0
|
528
|
Chris@0
|
529 if (!onPoints.empty()) {
|
Chris@0
|
530 return onPoints;
|
Chris@0
|
531 }
|
Chris@0
|
532
|
Chris@0
|
533 SparseTimeValueModel::PointList prevPoints =
|
Chris@0
|
534 m_model->getPreviousPoints(frame);
|
Chris@0
|
535 SparseTimeValueModel::PointList nextPoints =
|
Chris@0
|
536 m_model->getNextPoints(frame);
|
Chris@0
|
537
|
Chris@0
|
538 SparseTimeValueModel::PointList usePoints = prevPoints;
|
Chris@0
|
539
|
Chris@0
|
540 if (prevPoints.empty()) {
|
Chris@0
|
541 usePoints = nextPoints;
|
Chris@631
|
542 } else if (nextPoints.empty()) {
|
Chris@631
|
543 // stick with prevPoints
|
Chris@248
|
544 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
|
Chris@44
|
545 !(nextPoints.begin()->frame > v->getEndFrame())) {
|
Chris@0
|
546 usePoints = nextPoints;
|
Chris@0
|
547 } else if (nextPoints.begin()->frame - frame <
|
Chris@0
|
548 frame - prevPoints.begin()->frame) {
|
Chris@0
|
549 usePoints = nextPoints;
|
Chris@0
|
550 }
|
Chris@0
|
551
|
Chris@28
|
552 if (!usePoints.empty()) {
|
Chris@28
|
553 int fuzz = 2;
|
Chris@44
|
554 int px = v->getXForFrame(usePoints.begin()->frame);
|
Chris@28
|
555 if ((px > x && px - x > fuzz) ||
|
Chris@631
|
556 (px < x && x - px > fuzz + 3)) {
|
Chris@28
|
557 usePoints.clear();
|
Chris@28
|
558 }
|
Chris@28
|
559 }
|
Chris@28
|
560
|
Chris@0
|
561 return usePoints;
|
Chris@0
|
562 }
|
Chris@0
|
563
|
Chris@25
|
564 QString
|
Chris@552
|
565 TimeValueLayer::getLabelPreceding(size_t frame) const
|
Chris@552
|
566 {
|
Chris@552
|
567 if (!m_model) return "";
|
Chris@552
|
568 SparseTimeValueModel::PointList points = m_model->getPreviousPoints(frame);
|
Chris@552
|
569 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@552
|
570 i != points.end(); ++i) {
|
Chris@552
|
571 if (i->label != "") return i->label;
|
Chris@552
|
572 }
|
Chris@552
|
573 return "";
|
Chris@552
|
574 }
|
Chris@552
|
575
|
Chris@552
|
576 QString
|
Chris@44
|
577 TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const
|
Chris@0
|
578 {
|
Chris@25
|
579 int x = pos.x();
|
Chris@0
|
580
|
Chris@25
|
581 if (!m_model || !m_model->getSampleRate()) return "";
|
Chris@0
|
582
|
Chris@44
|
583 SparseTimeValueModel::PointList points = getLocalPoints(v, x);
|
Chris@0
|
584
|
Chris@0
|
585 if (points.empty()) {
|
Chris@0
|
586 if (!m_model->isReady()) {
|
Chris@25
|
587 return tr("In progress");
|
Chris@25
|
588 } else {
|
Chris@25
|
589 return tr("No local points");
|
Chris@0
|
590 }
|
Chris@0
|
591 }
|
Chris@0
|
592
|
Chris@0
|
593 long useFrame = points.begin()->frame;
|
Chris@0
|
594
|
Chris@0
|
595 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate());
|
Chris@25
|
596
|
Chris@25
|
597 QString text;
|
Chris@101
|
598 QString unit = m_model->getScaleUnits();
|
Chris@101
|
599 if (unit != "") unit = " " + unit;
|
Chris@0
|
600
|
Chris@25
|
601 if (points.begin()->label == "") {
|
Chris@101
|
602 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label"))
|
Chris@25
|
603 .arg(rt.toText(true).c_str())
|
Chris@25
|
604 .arg(points.begin()->value)
|
Chris@101
|
605 .arg(unit);
|
Chris@101
|
606 } else {
|
Chris@101
|
607 text = QString(tr("Time:\t%1\nValue:\t%2%3\nLabel:\t%4"))
|
Chris@101
|
608 .arg(rt.toText(true).c_str())
|
Chris@101
|
609 .arg(points.begin()->value)
|
Chris@101
|
610 .arg(unit)
|
Chris@25
|
611 .arg(points.begin()->label);
|
Chris@25
|
612 }
|
Chris@0
|
613
|
Chris@44
|
614 pos = QPoint(v->getXForFrame(useFrame),
|
Chris@44
|
615 getYForValue(v, points.begin()->value));
|
Chris@25
|
616 return text;
|
Chris@0
|
617 }
|
Chris@0
|
618
|
Chris@28
|
619 bool
|
Chris@44
|
620 TimeValueLayer::snapToFeatureFrame(View *v, int &frame,
|
Chris@28
|
621 size_t &resolution,
|
Chris@28
|
622 SnapType snap) const
|
Chris@13
|
623 {
|
Chris@13
|
624 if (!m_model) {
|
Chris@44
|
625 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@13
|
626 }
|
Chris@13
|
627
|
Chris@13
|
628 resolution = m_model->getResolution();
|
Chris@28
|
629 SparseTimeValueModel::PointList points;
|
Chris@13
|
630
|
Chris@28
|
631 if (snap == SnapNeighbouring) {
|
Chris@28
|
632
|
Chris@44
|
633 points = getLocalPoints(v, v->getXForFrame(frame));
|
Chris@28
|
634 if (points.empty()) return false;
|
Chris@28
|
635 frame = points.begin()->frame;
|
Chris@28
|
636 return true;
|
Chris@28
|
637 }
|
Chris@28
|
638
|
Chris@28
|
639 points = m_model->getPoints(frame, frame);
|
Chris@28
|
640 int snapped = frame;
|
Chris@28
|
641 bool found = false;
|
Chris@13
|
642
|
Chris@13
|
643 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@13
|
644 i != points.end(); ++i) {
|
Chris@13
|
645
|
Chris@28
|
646 if (snap == SnapRight) {
|
Chris@28
|
647
|
Chris@13
|
648 if (i->frame > frame) {
|
Chris@28
|
649 snapped = i->frame;
|
Chris@28
|
650 found = true;
|
Chris@13
|
651 break;
|
Chris@13
|
652 }
|
Chris@28
|
653
|
Chris@28
|
654 } else if (snap == SnapLeft) {
|
Chris@28
|
655
|
Chris@13
|
656 if (i->frame <= frame) {
|
Chris@28
|
657 snapped = i->frame;
|
Chris@28
|
658 found = true; // don't break, as the next may be better
|
Chris@28
|
659 } else {
|
Chris@28
|
660 break;
|
Chris@28
|
661 }
|
Chris@28
|
662
|
Chris@28
|
663 } else { // nearest
|
Chris@28
|
664
|
Chris@28
|
665 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@28
|
666 ++j;
|
Chris@28
|
667
|
Chris@28
|
668 if (j == points.end()) {
|
Chris@28
|
669
|
Chris@28
|
670 snapped = i->frame;
|
Chris@28
|
671 found = true;
|
Chris@28
|
672 break;
|
Chris@28
|
673
|
Chris@28
|
674 } else if (j->frame >= frame) {
|
Chris@28
|
675
|
Chris@28
|
676 if (j->frame - frame < frame - i->frame) {
|
Chris@28
|
677 snapped = j->frame;
|
Chris@28
|
678 } else {
|
Chris@28
|
679 snapped = i->frame;
|
Chris@28
|
680 }
|
Chris@28
|
681 found = true;
|
Chris@28
|
682 break;
|
Chris@13
|
683 }
|
Chris@13
|
684 }
|
Chris@13
|
685 }
|
Chris@13
|
686
|
Chris@28
|
687 frame = snapped;
|
Chris@28
|
688 return found;
|
Chris@13
|
689 }
|
Chris@13
|
690
|
Chris@517
|
691 bool
|
Chris@517
|
692 TimeValueLayer::snapToSimilarFeature(View *v, int &frame,
|
Chris@517
|
693 size_t &resolution,
|
Chris@517
|
694 SnapType snap) const
|
Chris@517
|
695 {
|
Chris@517
|
696 if (!m_model) {
|
Chris@517
|
697 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
|
Chris@517
|
698 }
|
Chris@517
|
699
|
Chris@517
|
700 resolution = m_model->getResolution();
|
Chris@517
|
701
|
Chris@517
|
702 const SparseTimeValueModel::PointList &points = m_model->getPoints();
|
Chris@517
|
703 SparseTimeValueModel::PointList close = m_model->getPoints(frame, frame);
|
Chris@517
|
704
|
Chris@517
|
705 SparseTimeValueModel::PointList::const_iterator i;
|
Chris@517
|
706
|
Chris@517
|
707 int matchframe = frame;
|
Chris@517
|
708 float matchvalue = 0.f;
|
Chris@517
|
709
|
Chris@517
|
710 for (i = close.begin(); i != close.end(); ++i) {
|
Chris@517
|
711 if (i->frame > frame) break;
|
Chris@517
|
712 matchvalue = i->value;
|
Chris@517
|
713 matchframe = i->frame;
|
Chris@517
|
714 }
|
Chris@517
|
715
|
Chris@517
|
716 int snapped = frame;
|
Chris@517
|
717 bool found = false;
|
Chris@517
|
718 bool distant = false;
|
Chris@517
|
719 float epsilon = 0.0001;
|
Chris@517
|
720
|
Chris@517
|
721 i = close.begin();
|
Chris@517
|
722
|
Chris@517
|
723 // Scan through the close points first, then the more distant ones
|
Chris@517
|
724 // if no suitable close one is found
|
Chris@517
|
725
|
Chris@517
|
726 while (i != points.end()) {
|
Chris@517
|
727
|
Chris@517
|
728 if (i == close.end()) {
|
Chris@517
|
729 i = points.begin();
|
Chris@517
|
730 distant = true;
|
Chris@517
|
731 }
|
Chris@517
|
732
|
Chris@517
|
733 if (snap == SnapRight) {
|
Chris@517
|
734
|
Chris@517
|
735 if (i->frame > matchframe &&
|
Chris@517
|
736 fabsf(i->value - matchvalue) < epsilon) {
|
Chris@517
|
737 snapped = i->frame;
|
Chris@517
|
738 found = true;
|
Chris@517
|
739 break;
|
Chris@517
|
740 }
|
Chris@517
|
741
|
Chris@517
|
742 } else if (snap == SnapLeft) {
|
Chris@517
|
743
|
Chris@517
|
744 if (i->frame < matchframe) {
|
Chris@517
|
745 if (fabsf(i->value - matchvalue) < epsilon) {
|
Chris@517
|
746 snapped = i->frame;
|
Chris@517
|
747 found = true; // don't break, as the next may be better
|
Chris@517
|
748 }
|
Chris@517
|
749 } else if (found || distant) {
|
Chris@517
|
750 break;
|
Chris@517
|
751 }
|
Chris@517
|
752
|
Chris@517
|
753 } else {
|
Chris@517
|
754 // no other snap types supported
|
Chris@517
|
755 }
|
Chris@517
|
756
|
Chris@517
|
757 ++i;
|
Chris@517
|
758 }
|
Chris@517
|
759
|
Chris@517
|
760 frame = snapped;
|
Chris@517
|
761 return found;
|
Chris@517
|
762 }
|
Chris@517
|
763
|
Chris@101
|
764 void
|
Chris@101
|
765 TimeValueLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
|
Chris@101
|
766 {
|
Chris@101
|
767 min = 0.0;
|
Chris@101
|
768 max = 0.0;
|
Chris@101
|
769 log = false;
|
Chris@101
|
770
|
Chris@296
|
771 if (shouldAutoAlign()) {
|
Chris@101
|
772
|
Chris@101
|
773 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) {
|
Chris@101
|
774 min = m_model->getValueMinimum();
|
Chris@101
|
775 max = m_model->getValueMaximum();
|
Chris@668
|
776 } else if (log) {
|
Chris@668
|
777 LogRange::mapRange(min, max);
|
Chris@101
|
778 }
|
Chris@101
|
779
|
Chris@101
|
780 } else if (m_verticalScale == PlusMinusOneScale) {
|
Chris@101
|
781
|
Chris@101
|
782 min = -1.0;
|
Chris@101
|
783 max = 1.0;
|
Chris@101
|
784
|
Chris@101
|
785 } else {
|
Chris@101
|
786
|
Chris@437
|
787 getDisplayExtents(min, max);
|
Chris@632
|
788
|
Chris@101
|
789 if (m_verticalScale == LogScale) {
|
Chris@197
|
790 LogRange::mapRange(min, max);
|
Chris@101
|
791 log = true;
|
Chris@101
|
792 }
|
Chris@101
|
793 }
|
Chris@101
|
794
|
Chris@629
|
795 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
796 cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << endl;
|
Chris@629
|
797 #endif
|
Chris@101
|
798 }
|
Chris@101
|
799
|
Chris@21
|
800 int
|
Chris@66
|
801 TimeValueLayer::getYForValue(View *v, float val) const
|
Chris@21
|
802 {
|
Chris@79
|
803 float min = 0.0, max = 0.0;
|
Chris@101
|
804 bool logarithmic = false;
|
Chris@79
|
805 int h = v->height();
|
Chris@79
|
806
|
Chris@101
|
807 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
808
|
Chris@526
|
809 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
810 cerr << "getYForValue(" << val << "): min " << min << ", max "
|
Chris@682
|
811 << max << ", log " << logarithmic << endl;
|
Chris@526
|
812 #endif
|
Chris@101
|
813
|
Chris@101
|
814 if (logarithmic) {
|
Chris@197
|
815 val = LogRange::map(val);
|
Chris@79
|
816 }
|
Chris@79
|
817
|
Chris@66
|
818 return int(h - ((val - min) * h) / (max - min));
|
Chris@21
|
819 }
|
Chris@21
|
820
|
Chris@21
|
821 float
|
Chris@44
|
822 TimeValueLayer::getValueForY(View *v, int y) const
|
Chris@21
|
823 {
|
Chris@101
|
824 float min = 0.0, max = 0.0;
|
Chris@101
|
825 bool logarithmic = false;
|
Chris@44
|
826 int h = v->height();
|
Chris@21
|
827
|
Chris@101
|
828 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
829
|
Chris@101
|
830 float val = min + (float(h - y) * float(max - min)) / h;
|
Chris@101
|
831
|
Chris@101
|
832 if (logarithmic) {
|
Chris@437
|
833 val = LogRange::map(val);
|
Chris@101
|
834 }
|
Chris@101
|
835
|
Chris@101
|
836 return val;
|
Chris@21
|
837 }
|
Chris@21
|
838
|
Chris@296
|
839 bool
|
Chris@296
|
840 TimeValueLayer::shouldAutoAlign() const
|
Chris@296
|
841 {
|
Chris@296
|
842 if (!m_model) return false;
|
Chris@296
|
843 QString unit = m_model->getScaleUnits();
|
Chris@296
|
844 return (m_verticalScale == AutoAlignScale && unit != "");
|
Chris@296
|
845 }
|
Chris@296
|
846
|
Chris@68
|
847 QColor
|
Chris@101
|
848 TimeValueLayer::getColourForValue(View *v, float val) const
|
Chris@68
|
849 {
|
Chris@101
|
850 float min, max;
|
Chris@101
|
851 bool log;
|
Chris@101
|
852 getScaleExtents(v, min, max, log);
|
Chris@68
|
853
|
Chris@197
|
854 if (min > max) std::swap(min, max);
|
Chris@197
|
855 if (max == min) max = min + 1;
|
Chris@197
|
856
|
Chris@101
|
857 if (log) {
|
Chris@197
|
858 val = LogRange::map(val);
|
Chris@68
|
859 }
|
Chris@68
|
860
|
Chris@526
|
861 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
862 cerr << "TimeValueLayer::getColourForValue: min " << min << ", max "
|
Chris@682
|
863 << max << ", log " << log << ", value " << val << endl;
|
Chris@526
|
864 #endif
|
Chris@68
|
865
|
Chris@197
|
866 QColor solid = ColourMapper(m_colourMap, min, max).map(val);
|
Chris@197
|
867 return QColor(solid.red(), solid.green(), solid.blue(), 120);
|
Chris@68
|
868 }
|
Chris@68
|
869
|
Chris@287
|
870 int
|
Chris@287
|
871 TimeValueLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
872 {
|
Chris@287
|
873 impose = false;
|
Chris@287
|
874 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
875 (QString(darkbg ? "Bright Green" : "Green"));
|
Chris@287
|
876 }
|
Chris@287
|
877
|
Chris@0
|
878 void
|
Chris@44
|
879 TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const
|
Chris@0
|
880 {
|
Chris@0
|
881 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
882
|
Chris@0
|
883 int sampleRate = m_model->getSampleRate();
|
Chris@0
|
884 if (!sampleRate) return;
|
Chris@0
|
885
|
Chris@353
|
886 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@353
|
887
|
Chris@0
|
888 // Profiler profiler("TimeValueLayer::paint", true);
|
Chris@0
|
889
|
Chris@0
|
890 int x0 = rect.left(), x1 = rect.right();
|
Chris@44
|
891 long frame0 = v->getFrameForX(x0);
|
Chris@44
|
892 long frame1 = v->getFrameForX(x1);
|
Chris@553
|
893 if (m_derivative) --frame0;
|
Chris@0
|
894
|
Chris@0
|
895 SparseTimeValueModel::PointList points(m_model->getPoints
|
Chris@0
|
896 (frame0, frame1));
|
Chris@11
|
897 if (points.empty()) return;
|
Chris@0
|
898
|
Chris@287
|
899 paint.setPen(getBaseQColor());
|
Chris@0
|
900
|
Chris@287
|
901 QColor brushColour(getBaseQColor());
|
Chris@0
|
902 brushColour.setAlpha(80);
|
Chris@0
|
903 paint.setBrush(brushColour);
|
Chris@0
|
904
|
Chris@526
|
905 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
906 cerr << "TimeValueLayer::paint: resolution is "
|
Chris@682
|
907 << m_model->getResolution() << " frames" << endl;
|
Chris@526
|
908 #endif
|
Chris@0
|
909
|
Chris@0
|
910 float min = m_model->getValueMinimum();
|
Chris@0
|
911 float max = m_model->getValueMaximum();
|
Chris@0
|
912 if (max == min) max = min + 1.0;
|
Chris@0
|
913
|
Chris@44
|
914 int origin = int(nearbyint(v->height() -
|
Chris@44
|
915 (-min * v->height()) / (max - min)));
|
Chris@0
|
916
|
Chris@0
|
917 QPoint localPos;
|
Chris@0
|
918 long illuminateFrame = -1;
|
Chris@0
|
919
|
Chris@44
|
920 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
|
Chris@0
|
921 SparseTimeValueModel::PointList localPoints =
|
Chris@44
|
922 getLocalPoints(v, localPos.x());
|
Chris@526
|
923 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
924 cerr << "TimeValueLayer: " << localPoints.size() << " local points" << endl;
|
Chris@526
|
925 #endif
|
Chris@0
|
926 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
|
Chris@0
|
927 }
|
Chris@6
|
928
|
Chris@20
|
929 int w =
|
Chris@44
|
930 v->getXForFrame(frame0 + m_model->getResolution()) -
|
Chris@44
|
931 v->getXForFrame(frame0);
|
Chris@7
|
932
|
Chris@629
|
933 if (m_plotStyle == PlotStems) {
|
Chris@629
|
934 if (w < 2) w = 2;
|
Chris@629
|
935 } else {
|
Chris@629
|
936 if (w < 1) w = 1;
|
Chris@629
|
937 }
|
Chris@629
|
938
|
Chris@6
|
939 paint.save();
|
Chris@6
|
940
|
Chris@6
|
941 QPainterPath path;
|
Chris@55
|
942 int pointCount = 0;
|
Chris@79
|
943
|
Chris@79
|
944 int textY = 0;
|
Chris@79
|
945 if (m_plotStyle == PlotSegmentation) {
|
Chris@79
|
946 textY = v->getTextLabelHeight(this, paint);
|
Chris@554
|
947 } else {
|
Chris@554
|
948 int originY = getYForValue(v, 0.f);
|
Chris@554
|
949 if (originY > 0 && originY < v->height()) {
|
Chris@554
|
950 paint.save();
|
Chris@554
|
951 paint.setPen(getPartialShades(v)[1]);
|
Chris@554
|
952 paint.drawLine(x0, originY, x1, originY);
|
Chris@554
|
953 paint.restore();
|
Chris@554
|
954 }
|
Chris@79
|
955 }
|
Chris@6
|
956
|
Chris@615
|
957 int prevFrame = 0;
|
Chris@615
|
958
|
Chris@0
|
959 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@0
|
960 i != points.end(); ++i) {
|
Chris@0
|
961
|
Chris@553
|
962 if (m_derivative && i == points.begin()) continue;
|
Chris@553
|
963
|
Chris@0
|
964 const SparseTimeValueModel::Point &p(*i);
|
Chris@0
|
965
|
Chris@553
|
966 float value = p.value;
|
Chris@553
|
967 if (m_derivative) {
|
Chris@553
|
968 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@553
|
969 --j;
|
Chris@553
|
970 value -= j->value;
|
Chris@553
|
971 }
|
Chris@553
|
972
|
Chris@44
|
973 int x = v->getXForFrame(p.frame);
|
Chris@553
|
974 int y = getYForValue(v, value);
|
Chris@0
|
975
|
Chris@615
|
976 bool gap = false;
|
Chris@615
|
977 if (m_plotStyle == PlotDiscreteCurves) {
|
Chris@615
|
978 gap = (p.frame > prevFrame &&
|
Chris@615
|
979 (p.frame - prevFrame >= m_model->getResolution() * 2));
|
Chris@615
|
980 }
|
Chris@615
|
981
|
Chris@79
|
982 if (m_plotStyle != PlotSegmentation) {
|
Chris@79
|
983 textY = y - paint.fontMetrics().height()
|
Chris@631
|
984 + paint.fontMetrics().ascent() - 1;
|
Chris@372
|
985 if (textY < paint.fontMetrics().ascent() + 1) {
|
Chris@372
|
986 textY = paint.fontMetrics().ascent() + 1;
|
Chris@372
|
987 }
|
Chris@79
|
988 }
|
Chris@79
|
989
|
Chris@34
|
990 bool haveNext = false;
|
Chris@615
|
991 int nf = v->getModelsEndFrame();
|
Chris@615
|
992 int nx = v->getXForFrame(nf);
|
Chris@34
|
993 int ny = y;
|
Chris@34
|
994
|
Chris@34
|
995 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@34
|
996 ++j;
|
Chris@34
|
997
|
Chris@34
|
998 if (j != points.end()) {
|
Chris@34
|
999 const SparseTimeValueModel::Point &q(*j);
|
Chris@553
|
1000 float nvalue = q.value;
|
Chris@553
|
1001 if (m_derivative) nvalue -= p.value;
|
Chris@615
|
1002 nf = q.frame;
|
Chris@615
|
1003 nx = v->getXForFrame(nf);
|
Chris@553
|
1004 ny = getYForValue(v, nvalue);
|
Chris@34
|
1005 haveNext = true;
|
Chris@76
|
1006 }
|
Chris@76
|
1007
|
Chris@682
|
1008 // cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext
|
Chris@682
|
1009 // << ", nx = " << nx << endl;
|
Chris@34
|
1010
|
Chris@615
|
1011 if (m_plotStyle == PlotDiscreteCurves) {
|
Chris@615
|
1012 paint.setPen(QPen(getBaseQColor(), 3));
|
Chris@615
|
1013 paint.setBrush(Qt::NoBrush);
|
Chris@615
|
1014 } else if (m_plotStyle == PlotSegmentation) {
|
Chris@287
|
1015 paint.setPen(getForegroundQColor(v));
|
Chris@553
|
1016 paint.setBrush(getColourForValue(v, value));
|
Chris@26
|
1017 } else if (m_plotStyle == PlotLines ||
|
Chris@26
|
1018 m_plotStyle == PlotCurve) {
|
Chris@615
|
1019 paint.setPen(getBaseQColor());
|
Chris@6
|
1020 paint.setBrush(Qt::NoBrush);
|
Chris@3
|
1021 } else {
|
Chris@615
|
1022 paint.setPen(getBaseQColor());
|
Chris@6
|
1023 paint.setBrush(brushColour);
|
Chris@3
|
1024 }
|
Chris@0
|
1025
|
Chris@0
|
1026 if (m_plotStyle == PlotStems) {
|
Chris@430
|
1027 /*
|
Chris@0
|
1028 paint.setPen(brushColour);
|
Chris@0
|
1029 if (y < origin - 1) {
|
Chris@0
|
1030 paint.drawRect(x + w/2, y + 1, 1, origin - y);
|
Chris@0
|
1031 } else if (y > origin + 1) {
|
Chris@0
|
1032 paint.drawRect(x + w/2, origin, 1, y - origin - 1);
|
Chris@0
|
1033 }
|
Chris@430
|
1034 */
|
Chris@287
|
1035 paint.setPen(getBaseQColor());
|
Chris@430
|
1036 if (y < origin - 1) {
|
Chris@430
|
1037 paint.drawLine(x + w/2, y + 1, x + w/2, origin);
|
Chris@430
|
1038 } else if (y > origin + 1) {
|
Chris@430
|
1039 paint.drawLine(x + w/2, origin, x + w/2, y - 1);
|
Chris@430
|
1040 }
|
Chris@0
|
1041 }
|
Chris@0
|
1042
|
Chris@631
|
1043 bool illuminate = false;
|
Chris@631
|
1044
|
Chris@0
|
1045 if (illuminateFrame == p.frame) {
|
Chris@6
|
1046
|
Chris@631
|
1047 // not equipped to illuminate the right section in line
|
Chris@631
|
1048 // or curve mode
|
Chris@6
|
1049
|
Chris@6
|
1050 if (m_plotStyle != PlotCurve &&
|
Chris@615
|
1051 m_plotStyle != PlotDiscreteCurves &&
|
Chris@6
|
1052 m_plotStyle != PlotLines) {
|
Chris@631
|
1053 illuminate = true;
|
Chris@631
|
1054 }
|
Chris@631
|
1055 }
|
Chris@0
|
1056
|
Chris@6
|
1057 if (m_plotStyle != PlotLines &&
|
Chris@26
|
1058 m_plotStyle != PlotCurve &&
|
Chris@615
|
1059 m_plotStyle != PlotDiscreteCurves &&
|
Chris@26
|
1060 m_plotStyle != PlotSegmentation) {
|
Chris@631
|
1061 if (illuminate) {
|
Chris@631
|
1062 paint.save();
|
Chris@631
|
1063 paint.setPen(getForegroundQColor(v));
|
Chris@631
|
1064 paint.setBrush(getForegroundQColor(v));
|
Chris@631
|
1065 }
|
Chris@326
|
1066 if (m_plotStyle != PlotStems ||
|
Chris@326
|
1067 w > 1) {
|
Chris@326
|
1068 paint.drawRect(x, y - 1, w, 2);
|
Chris@326
|
1069 }
|
Chris@631
|
1070 if (illuminate) {
|
Chris@631
|
1071 paint.restore();
|
Chris@631
|
1072 }
|
Chris@3
|
1073 }
|
Chris@0
|
1074
|
Chris@6
|
1075 if (m_plotStyle == PlotConnectedPoints ||
|
Chris@6
|
1076 m_plotStyle == PlotLines ||
|
Chris@615
|
1077 m_plotStyle == PlotDiscreteCurves ||
|
Chris@6
|
1078 m_plotStyle == PlotCurve) {
|
Chris@0
|
1079
|
Chris@34
|
1080 if (haveNext) {
|
Chris@3
|
1081
|
Chris@6
|
1082 if (m_plotStyle == PlotConnectedPoints) {
|
Chris@34
|
1083
|
Chris@79
|
1084 paint.save();
|
Chris@3
|
1085 paint.setPen(brushColour);
|
Chris@3
|
1086 paint.drawLine(x + w, y, nx, ny);
|
Chris@79
|
1087 paint.restore();
|
Chris@6
|
1088
|
Chris@6
|
1089 } else if (m_plotStyle == PlotLines) {
|
Chris@430
|
1090
|
Chris@430
|
1091 if (pointCount == 0) {
|
Chris@430
|
1092 path.moveTo(x + w/2, y);
|
Chris@430
|
1093 }
|
Chris@6
|
1094
|
Chris@430
|
1095 // paint.drawLine(x + w/2, y, nx + w/2, ny);
|
Chris@430
|
1096 path.lineTo(nx + w/2, ny);
|
Chris@6
|
1097
|
Chris@3
|
1098 } else {
|
Chris@6
|
1099
|
Chris@55
|
1100 float x0 = x + float(w)/2;
|
Chris@55
|
1101 float x1 = nx + float(w)/2;
|
Chris@55
|
1102
|
Chris@55
|
1103 float y0 = y;
|
Chris@55
|
1104 float y1 = ny;
|
Chris@55
|
1105
|
Chris@615
|
1106 if (m_plotStyle == PlotDiscreteCurves) {
|
Chris@615
|
1107 bool nextGap = nf - p.frame >= m_model->getResolution() * 2;
|
Chris@615
|
1108 if (nextGap) {
|
Chris@615
|
1109 x1 = x0;
|
Chris@615
|
1110 y1 = y0;
|
Chris@615
|
1111 }
|
Chris@615
|
1112 }
|
Chris@615
|
1113
|
Chris@615
|
1114 if (pointCount == 0 || gap) {
|
Chris@55
|
1115 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@6
|
1116 }
|
Chris@6
|
1117
|
Chris@6
|
1118 if (nx - x > 5) {
|
Chris@55
|
1119 path.cubicTo(x0, y0,
|
Chris@55
|
1120 x0, y0,
|
Chris@55
|
1121 (x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@55
|
1122
|
Chris@55
|
1123 // // or
|
Chris@55
|
1124 // path.quadTo(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@55
|
1125
|
Chris@6
|
1126 } else {
|
Chris@55
|
1127 path.lineTo((x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@6
|
1128 }
|
Chris@3
|
1129 }
|
Chris@0
|
1130 }
|
Chris@0
|
1131 }
|
Chris@0
|
1132
|
Chris@26
|
1133 if (m_plotStyle == PlotSegmentation) {
|
Chris@76
|
1134
|
Chris@526
|
1135 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1136 cerr << "drawing rect" << endl;
|
Chris@526
|
1137 #endif
|
Chris@26
|
1138
|
Chris@27
|
1139 if (nx <= x) continue;
|
Chris@26
|
1140
|
Chris@559
|
1141 paint.setPen(QPen(getForegroundQColor(v), 2));
|
Chris@559
|
1142
|
Chris@631
|
1143 if (!illuminate) {
|
Chris@513
|
1144 if (!m_drawSegmentDivisions ||
|
Chris@513
|
1145 nx < x + 5 ||
|
Chris@513
|
1146 x >= v->width() - 1) {
|
Chris@513
|
1147 paint.setPen(Qt::NoPen);
|
Chris@513
|
1148 }
|
Chris@27
|
1149 }
|
Chris@26
|
1150
|
Chris@44
|
1151 paint.drawRect(x, -1, nx - x, v->height() + 1);
|
Chris@26
|
1152 }
|
Chris@26
|
1153
|
Chris@629
|
1154 QString label = p.label;
|
Chris@630
|
1155 bool italic = false;
|
Chris@629
|
1156
|
Chris@629
|
1157 if (label == "" &&
|
Chris@629
|
1158 (m_plotStyle == PlotPoints ||
|
Chris@631
|
1159 m_plotStyle == PlotSegmentation ||
|
Chris@631
|
1160 m_plotStyle == PlotConnectedPoints)) {
|
Chris@632
|
1161 char lc[20];
|
Chris@632
|
1162 snprintf(lc, 20, "%.3g", p.value);
|
Chris@632
|
1163 label = lc;
|
Chris@630
|
1164 italic = true;
|
Chris@629
|
1165 }
|
Chris@629
|
1166
|
Chris@629
|
1167 if (label != "") {
|
Chris@632
|
1168 bool haveRoom = nx > x + 6 + paint.fontMetrics().width(label);
|
Chris@632
|
1169 if (haveRoom ||
|
Chris@632
|
1170 (!haveNext &&
|
Chris@632
|
1171 (pointCount == 0 || !italic))) {
|
Chris@630
|
1172 v->drawVisibleText(paint, x + 5, textY, label,
|
Chris@630
|
1173 italic ?
|
Chris@630
|
1174 View::OutlinedItalicText :
|
Chris@630
|
1175 View::OutlinedText);
|
Chris@79
|
1176 }
|
Chris@55
|
1177 }
|
Chris@615
|
1178
|
Chris@615
|
1179 prevFrame = p.frame;
|
Chris@632
|
1180 ++pointCount;
|
Chris@0
|
1181 }
|
Chris@6
|
1182
|
Chris@691
|
1183 if (m_plotStyle == PlotDiscreteCurves) {
|
Chris@691
|
1184 paint.setRenderHint(QPainter::Antialiasing, true);
|
Chris@691
|
1185 paint.drawPath(path);
|
Chris@691
|
1186 } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines)
|
Chris@691
|
1187 && !path.isEmpty()) {
|
Chris@55
|
1188 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width());
|
Chris@6
|
1189 paint.drawPath(path);
|
Chris@6
|
1190 }
|
Chris@6
|
1191
|
Chris@6
|
1192 paint.restore();
|
Chris@6
|
1193
|
Chris@6
|
1194 // looks like save/restore doesn't deal with this:
|
Chris@6
|
1195 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@6
|
1196 }
|
Chris@6
|
1197
|
Chris@42
|
1198 int
|
Chris@607
|
1199 TimeValueLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const
|
Chris@42
|
1200 {
|
Chris@68
|
1201 int w = paint.fontMetrics().width("-000.000");
|
Chris@68
|
1202 if (m_plotStyle == PlotSegmentation) return w + 20;
|
Chris@68
|
1203 else return w + 10;
|
Chris@42
|
1204 }
|
Chris@42
|
1205
|
Chris@42
|
1206 void
|
Chris@607
|
1207 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const
|
Chris@42
|
1208 {
|
Chris@42
|
1209 if (!m_model) return;
|
Chris@42
|
1210
|
Chris@68
|
1211 int h = v->height();
|
Chris@68
|
1212
|
Chris@68
|
1213 int n = 10;
|
Chris@68
|
1214
|
Chris@437
|
1215 float min, max;
|
Chris@437
|
1216 bool logarithmic;
|
Chris@437
|
1217 getScaleExtents(v, min, max, logarithmic);
|
Chris@437
|
1218
|
Chris@437
|
1219 if (m_plotStyle == PlotSegmentation) {
|
Chris@437
|
1220 QString unit;
|
Chris@437
|
1221 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
1222 if (logarithmic) {
|
Chris@437
|
1223 LogRange::mapRange(min, max);
|
Chris@437
|
1224 }
|
Chris@437
|
1225 }
|
Chris@437
|
1226
|
Chris@68
|
1227 float val = min;
|
Chris@68
|
1228 float inc = (max - val) / n;
|
Chris@42
|
1229
|
Chris@55
|
1230 char buffer[40];
|
Chris@55
|
1231
|
Chris@607
|
1232 int w = getVerticalScaleWidth(v, false, paint);
|
Chris@55
|
1233
|
Chris@68
|
1234 int tx = 5;
|
Chris@68
|
1235
|
Chris@68
|
1236 int boxx = 5, boxy = 5;
|
Chris@68
|
1237 if (m_model->getScaleUnits() != "") {
|
Chris@68
|
1238 boxy += paint.fontMetrics().height();
|
Chris@68
|
1239 }
|
Chris@68
|
1240 int boxw = 10, boxh = h - boxy - 5;
|
Chris@68
|
1241
|
Chris@68
|
1242 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1243 tx += boxx + boxw;
|
Chris@68
|
1244 paint.drawRect(boxx, boxy, boxw, boxh);
|
Chris@68
|
1245 }
|
Chris@68
|
1246
|
Chris@68
|
1247 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1248 paint.save();
|
Chris@68
|
1249 for (int y = 0; y < boxh; ++y) {
|
Chris@68
|
1250 float val = ((boxh - y) * (max - min)) / boxh + min;
|
Chris@437
|
1251 if (logarithmic) {
|
Chris@437
|
1252 paint.setPen(getColourForValue(v, LogRange::unmap(val)));
|
Chris@437
|
1253 } else {
|
Chris@437
|
1254 paint.setPen(getColourForValue(v, val));
|
Chris@437
|
1255 }
|
Chris@68
|
1256 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1);
|
Chris@68
|
1257 }
|
Chris@68
|
1258 paint.restore();
|
Chris@68
|
1259 }
|
Chris@434
|
1260
|
Chris@434
|
1261 float round = 1.f;
|
Chris@434
|
1262 int dp = 0;
|
Chris@434
|
1263 if (inc > 0) {
|
Chris@434
|
1264 int prec = trunc(log10f(inc));
|
Chris@434
|
1265 prec -= 1;
|
Chris@434
|
1266 if (prec < 0) dp = -prec;
|
Chris@434
|
1267 round = powf(10.f, prec);
|
Chris@526
|
1268 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1269 cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl;
|
Chris@526
|
1270 #endif
|
Chris@434
|
1271 }
|
Chris@68
|
1272
|
Chris@434
|
1273 int prevy = -1;
|
Chris@434
|
1274
|
Chris@68
|
1275 for (int i = 0; i < n; ++i) {
|
Chris@68
|
1276
|
Chris@68
|
1277 int y, ty;
|
Chris@68
|
1278 bool drawText = true;
|
Chris@68
|
1279
|
Chris@434
|
1280 float dispval = val;
|
Chris@434
|
1281
|
Chris@68
|
1282 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1283 y = boxy + int(boxh - ((val - min) * boxh) / (max - min));
|
Chris@68
|
1284 ty = y;
|
Chris@68
|
1285 } else {
|
Chris@437
|
1286 if (i == n-1 &&
|
Chris@437
|
1287 v->height() < paint.fontMetrics().height() * (n*2)) {
|
Chris@68
|
1288 if (m_model->getScaleUnits() != "") drawText = false;
|
Chris@68
|
1289 }
|
Chris@434
|
1290 dispval = lrintf(val / round) * round;
|
Chris@526
|
1291 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1292 cerr << "val = " << val << ", dispval = " << dispval << endl;
|
Chris@526
|
1293 #endif
|
Chris@437
|
1294 if (logarithmic) {
|
Chris@437
|
1295 y = getYForValue(v, LogRange::unmap(dispval));
|
Chris@437
|
1296 } else {
|
Chris@437
|
1297 y = getYForValue(v, dispval);
|
Chris@437
|
1298 }
|
Chris@68
|
1299 ty = y - paint.fontMetrics().height() +
|
Chris@434
|
1300 paint.fontMetrics().ascent() + 2;
|
Chris@434
|
1301
|
Chris@434
|
1302 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) {
|
Chris@434
|
1303 val += inc;
|
Chris@434
|
1304 continue;
|
Chris@434
|
1305 }
|
Chris@68
|
1306 }
|
Chris@68
|
1307
|
Chris@437
|
1308 if (logarithmic) {
|
Chris@665
|
1309 double dv = LogRange::unmap(dispval);
|
Chris@665
|
1310 int digits = trunc(log10f(dv));
|
Chris@665
|
1311 int sf = dp + (digits > 0 ? digits : 0);
|
Chris@665
|
1312 if (sf < 2) sf = 2;
|
Chris@665
|
1313 sprintf(buffer, "%.*g", sf, dv);
|
Chris@437
|
1314 } else {
|
Chris@437
|
1315 sprintf(buffer, "%.*f", dp, dispval);
|
Chris@437
|
1316 }
|
Chris@55
|
1317 QString label = QString(buffer);
|
Chris@68
|
1318
|
Chris@68
|
1319 if (m_plotStyle != PlotSegmentation) {
|
Chris@68
|
1320 paint.drawLine(w - 5, y, w, y);
|
Chris@68
|
1321 } else {
|
Chris@68
|
1322 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
|
Chris@68
|
1323 }
|
Chris@68
|
1324
|
Chris@434
|
1325 if (drawText) {
|
Chris@435
|
1326 if (m_plotStyle != PlotSegmentation) {
|
Chris@435
|
1327 paint.drawText(tx + w - paint.fontMetrics().width(label) - 8,
|
Chris@435
|
1328 ty, label);
|
Chris@435
|
1329 } else {
|
Chris@435
|
1330 paint.drawText(tx, ty, label);
|
Chris@435
|
1331 }
|
Chris@434
|
1332 }
|
Chris@434
|
1333
|
Chris@434
|
1334 prevy = y;
|
Chris@44
|
1335 val += inc;
|
Chris@42
|
1336 }
|
Chris@68
|
1337
|
Chris@67
|
1338 if (m_model->getScaleUnits() != "") {
|
Chris@67
|
1339 paint.drawText(5, 5 + paint.fontMetrics().ascent(),
|
Chris@67
|
1340 m_model->getScaleUnits());
|
Chris@67
|
1341 }
|
Chris@691
|
1342
|
Chris@691
|
1343 if (logarithmic &&
|
Chris@691
|
1344 (m_model->getScaleUnits() == "Hz") &&
|
Chris@691
|
1345 (m_plotStyle != PlotSegmentation)) {
|
Chris@691
|
1346 float fmin, fmax;
|
Chris@691
|
1347 getDisplayExtents(fmin, fmax);
|
Chris@691
|
1348 PianoScale().paintPianoVertical
|
Chris@691
|
1349 (v, paint, QRect(w, 0, 10, h), fmin, fmax);
|
Chris@691
|
1350 paint.drawLine(w + 10, 0, w + 10, h);
|
Chris@691
|
1351 }
|
Chris@42
|
1352 }
|
Chris@42
|
1353
|
Chris@21
|
1354 void
|
Chris@44
|
1355 TimeValueLayer::drawStart(View *v, QMouseEvent *e)
|
Chris@21
|
1356 {
|
Chris@526
|
1357 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1358 cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@526
|
1359 #endif
|
Chris@21
|
1360
|
Chris@21
|
1361 if (!m_model) return;
|
Chris@21
|
1362
|
Chris@44
|
1363 long frame = v->getFrameForX(e->x());
|
Chris@76
|
1364 long resolution = m_model->getResolution();
|
Chris@21
|
1365 if (frame < 0) frame = 0;
|
Chris@76
|
1366 frame = (frame / resolution) * resolution;
|
Chris@21
|
1367
|
Chris@44
|
1368 float value = getValueForY(v, e->y());
|
Chris@21
|
1369
|
Chris@76
|
1370 bool havePoint = false;
|
Chris@76
|
1371
|
Chris@76
|
1372 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@76
|
1373 if (!points.empty()) {
|
Chris@76
|
1374 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1375 i != points.end(); ++i) {
|
Chris@76
|
1376 if (((i->frame / resolution) * resolution) != frame) {
|
Chris@526
|
1377 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1378 cerr << "ignoring out-of-range frame at " << i->frame << endl;
|
Chris@526
|
1379 #endif
|
Chris@76
|
1380 continue;
|
Chris@76
|
1381 }
|
Chris@76
|
1382 m_editingPoint = *i;
|
Chris@76
|
1383 havePoint = true;
|
Chris@76
|
1384 }
|
Chris@76
|
1385 }
|
Chris@76
|
1386
|
Chris@76
|
1387 if (!havePoint) {
|
Chris@76
|
1388 m_editingPoint = SparseTimeValueModel::Point
|
Chris@76
|
1389 (frame, value, tr("New Point"));
|
Chris@76
|
1390 }
|
Chris@76
|
1391
|
Chris@23
|
1392 m_originalPoint = m_editingPoint;
|
Chris@22
|
1393
|
Chris@376
|
1394 if (m_editingCommand) finish(m_editingCommand);
|
Chris@22
|
1395 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
|
Chris@22
|
1396 tr("Draw Point"));
|
Chris@76
|
1397 if (!havePoint) {
|
Chris@76
|
1398 m_editingCommand->addPoint(m_editingPoint);
|
Chris@76
|
1399 }
|
Chris@22
|
1400
|
Chris@21
|
1401 m_editing = true;
|
Chris@21
|
1402 }
|
Chris@21
|
1403
|
Chris@21
|
1404 void
|
Chris@44
|
1405 TimeValueLayer::drawDrag(View *v, QMouseEvent *e)
|
Chris@21
|
1406 {
|
Chris@526
|
1407 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1408 cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@526
|
1409 #endif
|
Chris@21
|
1410
|
Chris@21
|
1411 if (!m_model || !m_editing) return;
|
Chris@21
|
1412
|
Chris@44
|
1413 long frame = v->getFrameForX(e->x());
|
Chris@76
|
1414 long resolution = m_model->getResolution();
|
Chris@21
|
1415 if (frame < 0) frame = 0;
|
Chris@76
|
1416 frame = (frame / resolution) * resolution;
|
Chris@21
|
1417
|
Chris@44
|
1418 float value = getValueForY(v, e->y());
|
Chris@21
|
1419
|
Chris@76
|
1420 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@76
|
1421
|
Chris@526
|
1422 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1423 cerr << points.size() << " points" << endl;
|
Chris@526
|
1424 #endif
|
Chris@76
|
1425
|
Chris@76
|
1426 bool havePoint = false;
|
Chris@76
|
1427
|
Chris@76
|
1428 if (!points.empty()) {
|
Chris@76
|
1429 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1430 i != points.end(); ++i) {
|
Chris@76
|
1431 if (i->frame == m_editingPoint.frame &&
|
Chris@76
|
1432 i->value == m_editingPoint.value) {
|
Chris@526
|
1433 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1434 cerr << "ignoring current editing point at " << i->frame << ", " << i->value << endl;
|
Chris@526
|
1435 #endif
|
Chris@76
|
1436 continue;
|
Chris@76
|
1437 }
|
Chris@76
|
1438 if (((i->frame / resolution) * resolution) != frame) {
|
Chris@526
|
1439 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1440 cerr << "ignoring out-of-range frame at " << i->frame << endl;
|
Chris@526
|
1441 #endif
|
Chris@76
|
1442 continue;
|
Chris@76
|
1443 }
|
Chris@526
|
1444 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1445 cerr << "adjusting to new point at " << i->frame << ", " << i->value << endl;
|
Chris@526
|
1446 #endif
|
Chris@76
|
1447 m_editingPoint = *i;
|
Chris@76
|
1448 m_originalPoint = m_editingPoint;
|
Chris@76
|
1449 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@76
|
1450 havePoint = true;
|
Chris@76
|
1451 }
|
Chris@76
|
1452 }
|
Chris@76
|
1453
|
Chris@76
|
1454 if (!havePoint) {
|
Chris@76
|
1455 if (frame == m_editingPoint.frame) {
|
Chris@76
|
1456 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@76
|
1457 }
|
Chris@76
|
1458 }
|
Chris@76
|
1459
|
Chris@76
|
1460 // m_editingCommand->deletePoint(m_editingPoint);
|
Chris@21
|
1461 m_editingPoint.frame = frame;
|
Chris@21
|
1462 m_editingPoint.value = value;
|
Chris@22
|
1463 m_editingCommand->addPoint(m_editingPoint);
|
Chris@21
|
1464 }
|
Chris@21
|
1465
|
Chris@21
|
1466 void
|
Chris@248
|
1467 TimeValueLayer::drawEnd(View *, QMouseEvent *)
|
Chris@21
|
1468 {
|
Chris@526
|
1469 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1470 cerr << "TimeValueLayer::drawEnd" << endl;
|
Chris@526
|
1471 #endif
|
Chris@21
|
1472 if (!m_model || !m_editing) return;
|
Chris@376
|
1473 finish(m_editingCommand);
|
Chris@22
|
1474 m_editingCommand = 0;
|
Chris@21
|
1475 m_editing = false;
|
Chris@21
|
1476 }
|
Chris@21
|
1477
|
Chris@21
|
1478 void
|
Chris@335
|
1479 TimeValueLayer::eraseStart(View *v, QMouseEvent *e)
|
Chris@335
|
1480 {
|
Chris@335
|
1481 if (!m_model) return;
|
Chris@335
|
1482
|
Chris@335
|
1483 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@335
|
1484 if (points.empty()) return;
|
Chris@335
|
1485
|
Chris@335
|
1486 m_editingPoint = *points.begin();
|
Chris@335
|
1487
|
Chris@335
|
1488 if (m_editingCommand) {
|
Chris@376
|
1489 finish(m_editingCommand);
|
Chris@335
|
1490 m_editingCommand = 0;
|
Chris@335
|
1491 }
|
Chris@335
|
1492
|
Chris@335
|
1493 m_editing = true;
|
Chris@335
|
1494 }
|
Chris@335
|
1495
|
Chris@335
|
1496 void
|
Chris@335
|
1497 TimeValueLayer::eraseDrag(View *v, QMouseEvent *e)
|
Chris@335
|
1498 {
|
Chris@335
|
1499 }
|
Chris@335
|
1500
|
Chris@335
|
1501 void
|
Chris@335
|
1502 TimeValueLayer::eraseEnd(View *v, QMouseEvent *e)
|
Chris@335
|
1503 {
|
Chris@335
|
1504 if (!m_model || !m_editing) return;
|
Chris@335
|
1505
|
Chris@335
|
1506 m_editing = false;
|
Chris@335
|
1507
|
Chris@335
|
1508 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@335
|
1509 if (points.empty()) return;
|
Chris@335
|
1510 if (points.begin()->frame != m_editingPoint.frame ||
|
Chris@335
|
1511 points.begin()->value != m_editingPoint.value) return;
|
Chris@335
|
1512
|
Chris@335
|
1513 m_editingCommand = new SparseTimeValueModel::EditCommand
|
Chris@335
|
1514 (m_model, tr("Erase Point"));
|
Chris@335
|
1515
|
Chris@335
|
1516 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@335
|
1517
|
Chris@376
|
1518 finish(m_editingCommand);
|
Chris@335
|
1519 m_editingCommand = 0;
|
Chris@335
|
1520 m_editing = false;
|
Chris@335
|
1521 }
|
Chris@335
|
1522
|
Chris@335
|
1523 void
|
Chris@44
|
1524 TimeValueLayer::editStart(View *v, QMouseEvent *e)
|
Chris@21
|
1525 {
|
Chris@526
|
1526 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1527 cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@526
|
1528 #endif
|
Chris@21
|
1529
|
Chris@21
|
1530 if (!m_model) return;
|
Chris@21
|
1531
|
Chris@44
|
1532 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@21
|
1533 if (points.empty()) return;
|
Chris@21
|
1534
|
Chris@21
|
1535 m_editingPoint = *points.begin();
|
Chris@23
|
1536 m_originalPoint = m_editingPoint;
|
Chris@22
|
1537
|
Chris@22
|
1538 if (m_editingCommand) {
|
Chris@376
|
1539 finish(m_editingCommand);
|
Chris@22
|
1540 m_editingCommand = 0;
|
Chris@22
|
1541 }
|
Chris@22
|
1542
|
Chris@21
|
1543 m_editing = true;
|
Chris@21
|
1544 }
|
Chris@21
|
1545
|
Chris@21
|
1546 void
|
Chris@44
|
1547 TimeValueLayer::editDrag(View *v, QMouseEvent *e)
|
Chris@21
|
1548 {
|
Chris@526
|
1549 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1550 cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@526
|
1551 #endif
|
Chris@21
|
1552
|
Chris@21
|
1553 if (!m_model || !m_editing) return;
|
Chris@21
|
1554
|
Chris@44
|
1555 long frame = v->getFrameForX(e->x());
|
Chris@21
|
1556 if (frame < 0) frame = 0;
|
Chris@21
|
1557 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@21
|
1558
|
Chris@44
|
1559 float value = getValueForY(v, e->y());
|
Chris@21
|
1560
|
Chris@22
|
1561 if (!m_editingCommand) {
|
Chris@22
|
1562 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
|
Chris@22
|
1563 tr("Drag Point"));
|
Chris@22
|
1564 }
|
Chris@22
|
1565
|
Chris@22
|
1566 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@21
|
1567 m_editingPoint.frame = frame;
|
Chris@21
|
1568 m_editingPoint.value = value;
|
Chris@22
|
1569 m_editingCommand->addPoint(m_editingPoint);
|
Chris@21
|
1570 }
|
Chris@21
|
1571
|
Chris@21
|
1572 void
|
Chris@248
|
1573 TimeValueLayer::editEnd(View *, QMouseEvent *)
|
Chris@21
|
1574 {
|
Chris@526
|
1575 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1576 cerr << "TimeValueLayer::editEnd" << endl;
|
Chris@526
|
1577 #endif
|
Chris@21
|
1578 if (!m_model || !m_editing) return;
|
Chris@23
|
1579
|
Chris@23
|
1580 if (m_editingCommand) {
|
Chris@23
|
1581
|
Chris@23
|
1582 QString newName = m_editingCommand->getName();
|
Chris@23
|
1583
|
Chris@23
|
1584 if (m_editingPoint.frame != m_originalPoint.frame) {
|
Chris@23
|
1585 if (m_editingPoint.value != m_originalPoint.value) {
|
Chris@23
|
1586 newName = tr("Edit Point");
|
Chris@23
|
1587 } else {
|
Chris@23
|
1588 newName = tr("Relocate Point");
|
Chris@23
|
1589 }
|
Chris@23
|
1590 } else {
|
Chris@23
|
1591 newName = tr("Change Point Value");
|
Chris@23
|
1592 }
|
Chris@23
|
1593
|
Chris@23
|
1594 m_editingCommand->setName(newName);
|
Chris@376
|
1595 finish(m_editingCommand);
|
Chris@23
|
1596 }
|
Chris@23
|
1597
|
Chris@22
|
1598 m_editingCommand = 0;
|
Chris@21
|
1599 m_editing = false;
|
Chris@21
|
1600 }
|
Chris@21
|
1601
|
Chris@255
|
1602 bool
|
Chris@70
|
1603 TimeValueLayer::editOpen(View *v, QMouseEvent *e)
|
Chris@70
|
1604 {
|
Chris@255
|
1605 if (!m_model) return false;
|
Chris@70
|
1606
|
Chris@70
|
1607 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@255
|
1608 if (points.empty()) return false;
|
Chris@70
|
1609
|
Chris@70
|
1610 SparseTimeValueModel::Point point = *points.begin();
|
Chris@70
|
1611
|
Chris@70
|
1612 ItemEditDialog *dialog = new ItemEditDialog
|
Chris@70
|
1613 (m_model->getSampleRate(),
|
Chris@70
|
1614 ItemEditDialog::ShowTime |
|
Chris@70
|
1615 ItemEditDialog::ShowValue |
|
Chris@73
|
1616 ItemEditDialog::ShowText,
|
Chris@73
|
1617 m_model->getScaleUnits());
|
Chris@70
|
1618
|
Chris@70
|
1619 dialog->setFrameTime(point.frame);
|
Chris@70
|
1620 dialog->setValue(point.value);
|
Chris@70
|
1621 dialog->setText(point.label);
|
Chris@70
|
1622
|
Chris@70
|
1623 if (dialog->exec() == QDialog::Accepted) {
|
Chris@70
|
1624
|
Chris@70
|
1625 SparseTimeValueModel::Point newPoint = point;
|
Chris@70
|
1626 newPoint.frame = dialog->getFrameTime();
|
Chris@70
|
1627 newPoint.value = dialog->getValue();
|
Chris@70
|
1628 newPoint.label = dialog->getText();
|
Chris@70
|
1629
|
Chris@70
|
1630 SparseTimeValueModel::EditCommand *command =
|
Chris@70
|
1631 new SparseTimeValueModel::EditCommand(m_model, tr("Edit Point"));
|
Chris@70
|
1632 command->deletePoint(point);
|
Chris@70
|
1633 command->addPoint(newPoint);
|
Chris@376
|
1634 finish(command);
|
Chris@70
|
1635 }
|
Chris@70
|
1636
|
Chris@70
|
1637 delete dialog;
|
Chris@255
|
1638 return true;
|
Chris@70
|
1639 }
|
Chris@70
|
1640
|
Chris@70
|
1641 void
|
Chris@43
|
1642 TimeValueLayer::moveSelection(Selection s, size_t newStartFrame)
|
Chris@43
|
1643 {
|
Chris@99
|
1644 if (!m_model) return;
|
Chris@99
|
1645
|
Chris@43
|
1646 SparseTimeValueModel::EditCommand *command =
|
Chris@43
|
1647 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@43
|
1648 tr("Drag Selection"));
|
Chris@43
|
1649
|
Chris@43
|
1650 SparseTimeValueModel::PointList points =
|
Chris@43
|
1651 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1652
|
Chris@43
|
1653 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@43
|
1654 i != points.end(); ++i) {
|
Chris@43
|
1655
|
Chris@43
|
1656 if (s.contains(i->frame)) {
|
Chris@43
|
1657 SparseTimeValueModel::Point newPoint(*i);
|
Chris@43
|
1658 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
|
Chris@43
|
1659 command->deletePoint(*i);
|
Chris@43
|
1660 command->addPoint(newPoint);
|
Chris@43
|
1661 }
|
Chris@43
|
1662 }
|
Chris@43
|
1663
|
Chris@376
|
1664 finish(command);
|
Chris@43
|
1665 }
|
Chris@43
|
1666
|
Chris@43
|
1667 void
|
Chris@43
|
1668 TimeValueLayer::resizeSelection(Selection s, Selection newSize)
|
Chris@43
|
1669 {
|
Chris@99
|
1670 if (!m_model) return;
|
Chris@99
|
1671
|
Chris@43
|
1672 SparseTimeValueModel::EditCommand *command =
|
Chris@43
|
1673 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@43
|
1674 tr("Resize Selection"));
|
Chris@43
|
1675
|
Chris@43
|
1676 SparseTimeValueModel::PointList points =
|
Chris@43
|
1677 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1678
|
Chris@43
|
1679 double ratio =
|
Chris@43
|
1680 double(newSize.getEndFrame() - newSize.getStartFrame()) /
|
Chris@43
|
1681 double(s.getEndFrame() - s.getStartFrame());
|
Chris@43
|
1682
|
Chris@43
|
1683 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@43
|
1684 i != points.end(); ++i) {
|
Chris@43
|
1685
|
Chris@43
|
1686 if (s.contains(i->frame)) {
|
Chris@43
|
1687
|
Chris@43
|
1688 double target = i->frame;
|
Chris@43
|
1689 target = newSize.getStartFrame() +
|
Chris@43
|
1690 double(target - s.getStartFrame()) * ratio;
|
Chris@43
|
1691
|
Chris@43
|
1692 SparseTimeValueModel::Point newPoint(*i);
|
Chris@43
|
1693 newPoint.frame = lrint(target);
|
Chris@43
|
1694 command->deletePoint(*i);
|
Chris@43
|
1695 command->addPoint(newPoint);
|
Chris@43
|
1696 }
|
Chris@43
|
1697 }
|
Chris@43
|
1698
|
Chris@376
|
1699 finish(command);
|
Chris@43
|
1700 }
|
Chris@43
|
1701
|
Chris@76
|
1702 void
|
Chris@76
|
1703 TimeValueLayer::deleteSelection(Selection s)
|
Chris@76
|
1704 {
|
Chris@99
|
1705 if (!m_model) return;
|
Chris@99
|
1706
|
Chris@76
|
1707 SparseTimeValueModel::EditCommand *command =
|
Chris@76
|
1708 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@76
|
1709 tr("Delete Selected Points"));
|
Chris@76
|
1710
|
Chris@76
|
1711 SparseTimeValueModel::PointList points =
|
Chris@76
|
1712 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1713
|
Chris@76
|
1714 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1715 i != points.end(); ++i) {
|
Chris@76
|
1716
|
Chris@76
|
1717 if (s.contains(i->frame)) {
|
Chris@76
|
1718 command->deletePoint(*i);
|
Chris@76
|
1719 }
|
Chris@76
|
1720 }
|
Chris@76
|
1721
|
Chris@376
|
1722 finish(command);
|
Chris@76
|
1723 }
|
Chris@76
|
1724
|
Chris@76
|
1725 void
|
Chris@359
|
1726 TimeValueLayer::copy(View *v, Selection s, Clipboard &to)
|
Chris@76
|
1727 {
|
Chris@99
|
1728 if (!m_model) return;
|
Chris@99
|
1729
|
Chris@76
|
1730 SparseTimeValueModel::PointList points =
|
Chris@76
|
1731 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1732
|
Chris@76
|
1733 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1734 i != points.end(); ++i) {
|
Chris@76
|
1735 if (s.contains(i->frame)) {
|
Chris@83
|
1736 Clipboard::Point point(i->frame, i->value, i->label);
|
Chris@360
|
1737 point.setReferenceFrame(alignToReference(v, i->frame));
|
Chris@76
|
1738 to.addPoint(point);
|
Chris@76
|
1739 }
|
Chris@76
|
1740 }
|
Chris@76
|
1741 }
|
Chris@76
|
1742
|
Chris@125
|
1743 bool
|
Chris@359
|
1744 TimeValueLayer::paste(View *v, const Clipboard &from, int frameOffset,
|
Chris@125
|
1745 bool interactive)
|
Chris@76
|
1746 {
|
Chris@125
|
1747 if (!m_model) return false;
|
Chris@99
|
1748
|
Chris@76
|
1749 const Clipboard::PointList &points = from.getPoints();
|
Chris@76
|
1750
|
Chris@360
|
1751 bool realign = false;
|
Chris@360
|
1752
|
Chris@360
|
1753 if (clipboardHasDifferentAlignment(v, from)) {
|
Chris@360
|
1754
|
Chris@360
|
1755 QMessageBox::StandardButton button =
|
Chris@360
|
1756 QMessageBox::question(v, tr("Re-align pasted items?"),
|
Chris@360
|
1757 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
|
Chris@360
|
1758 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
Chris@360
|
1759 QMessageBox::Yes);
|
Chris@360
|
1760
|
Chris@360
|
1761 if (button == QMessageBox::Cancel) {
|
Chris@360
|
1762 return false;
|
Chris@360
|
1763 }
|
Chris@360
|
1764
|
Chris@360
|
1765 if (button == QMessageBox::Yes) {
|
Chris@360
|
1766 realign = true;
|
Chris@360
|
1767 }
|
Chris@360
|
1768 }
|
Chris@360
|
1769
|
Chris@76
|
1770 SparseTimeValueModel::EditCommand *command =
|
Chris@76
|
1771 new SparseTimeValueModel::EditCommand(m_model, tr("Paste"));
|
Chris@76
|
1772
|
Chris@125
|
1773 enum ValueAvailability {
|
Chris@125
|
1774 UnknownAvailability,
|
Chris@125
|
1775 NoValues,
|
Chris@125
|
1776 SomeValues,
|
Chris@125
|
1777 AllValues
|
Chris@125
|
1778 };
|
Chris@125
|
1779
|
Chris@340
|
1780 Labeller::ValueType generation = Labeller::ValueNone;
|
Chris@125
|
1781
|
Chris@125
|
1782 bool haveUsableLabels = false;
|
Chris@125
|
1783 bool haveExistingItems = !(m_model->isEmpty());
|
Chris@340
|
1784 Labeller labeller;
|
Chris@340
|
1785 labeller.setSampleRate(m_model->getSampleRate());
|
Chris@125
|
1786
|
Chris@125
|
1787 if (interactive) {
|
Chris@125
|
1788
|
Chris@125
|
1789 ValueAvailability availability = UnknownAvailability;
|
Chris@125
|
1790
|
Chris@125
|
1791 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@125
|
1792 i != points.end(); ++i) {
|
Chris@125
|
1793
|
Chris@125
|
1794 if (!i->haveFrame()) continue;
|
Chris@125
|
1795
|
Chris@125
|
1796 if (availability == UnknownAvailability) {
|
Chris@125
|
1797 if (i->haveValue()) availability = AllValues;
|
Chris@125
|
1798 else availability = NoValues;
|
Chris@125
|
1799 continue;
|
Chris@125
|
1800 }
|
Chris@125
|
1801
|
Chris@125
|
1802 if (i->haveValue()) {
|
Chris@125
|
1803 if (availability == NoValues) {
|
Chris@125
|
1804 availability = SomeValues;
|
Chris@125
|
1805 }
|
Chris@125
|
1806 } else {
|
Chris@125
|
1807 if (availability == AllValues) {
|
Chris@125
|
1808 availability = SomeValues;
|
Chris@125
|
1809 }
|
Chris@125
|
1810 }
|
Chris@125
|
1811
|
Chris@125
|
1812 if (!haveUsableLabels) {
|
Chris@125
|
1813 if (i->haveLabel()) {
|
Chris@125
|
1814 if (i->getLabel().contains(QRegExp("[0-9]"))) {
|
Chris@125
|
1815 haveUsableLabels = true;
|
Chris@125
|
1816 }
|
Chris@125
|
1817 }
|
Chris@125
|
1818 }
|
Chris@125
|
1819
|
Chris@125
|
1820 if (availability == SomeValues && haveUsableLabels) break;
|
Chris@125
|
1821 }
|
Chris@125
|
1822
|
Chris@125
|
1823 if (availability == NoValues || availability == SomeValues) {
|
Chris@125
|
1824
|
Chris@125
|
1825 QString text;
|
Chris@125
|
1826 if (availability == NoValues) {
|
Chris@125
|
1827 text = tr("The items you are pasting do not have values.\nWhat values do you want to use for these items?");
|
Chris@125
|
1828 } else {
|
Chris@125
|
1829 text = tr("Some of the items you are pasting do not have values.\nWhat values do you want to use for these items?");
|
Chris@125
|
1830 }
|
Chris@125
|
1831
|
Chris@340
|
1832 Labeller::TypeNameMap names = labeller.getTypeNames();
|
Chris@340
|
1833
|
Chris@125
|
1834 QStringList options;
|
Chris@340
|
1835 std::vector<Labeller::ValueType> genopts;
|
Chris@125
|
1836
|
Chris@340
|
1837 for (Labeller::TypeNameMap::const_iterator i = names.begin();
|
Chris@340
|
1838 i != names.end(); ++i) {
|
Chris@340
|
1839 if (i->first == Labeller::ValueNone) options << tr("Zero for all items");
|
Chris@340
|
1840 else options << i->second;
|
Chris@340
|
1841 genopts.push_back(i->first);
|
Chris@125
|
1842 }
|
Chris@125
|
1843
|
Chris@125
|
1844 static int prevSelection = 0;
|
Chris@125
|
1845
|
Chris@125
|
1846 bool ok = false;
|
Chris@125
|
1847 QString selected = ListInputDialog::getItem
|
Chris@125
|
1848 (0, tr("Choose value calculation"),
|
Chris@125
|
1849 text, options, prevSelection, &ok);
|
Chris@125
|
1850
|
Chris@125
|
1851 if (!ok) return false;
|
Chris@125
|
1852 int selection = 0;
|
Chris@340
|
1853 generation = Labeller::ValueNone;
|
Chris@125
|
1854
|
Chris@125
|
1855 for (QStringList::const_iterator i = options.begin();
|
Chris@125
|
1856 i != options.end(); ++i) {
|
Chris@125
|
1857 if (selected == *i) {
|
Chris@340
|
1858 generation = genopts[selection];
|
Chris@125
|
1859 break;
|
Chris@125
|
1860 }
|
Chris@125
|
1861 ++selection;
|
Chris@125
|
1862 }
|
Chris@340
|
1863
|
Chris@340
|
1864 labeller.setType(generation);
|
Chris@340
|
1865
|
Chris@340
|
1866 if (generation == Labeller::ValueFromCyclicalCounter ||
|
Chris@340
|
1867 generation == Labeller::ValueFromTwoLevelCounter) {
|
Chris@616
|
1868 int cycleSize = QInputDialog::getInt
|
Chris@340
|
1869 (0, tr("Select cycle size"),
|
Chris@340
|
1870 tr("Cycle size:"), 4, 2, 16, 1);
|
Chris@340
|
1871 labeller.setCounterCycleSize(cycleSize);
|
Chris@340
|
1872 }
|
Chris@125
|
1873
|
Chris@125
|
1874 prevSelection = selection;
|
Chris@125
|
1875 }
|
Chris@125
|
1876 }
|
Chris@125
|
1877
|
Chris@372
|
1878 SparseTimeValueModel::Point prevPoint(0);
|
Chris@125
|
1879
|
Chris@76
|
1880 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@76
|
1881 i != points.end(); ++i) {
|
Chris@76
|
1882
|
Chris@76
|
1883 if (!i->haveFrame()) continue;
|
Chris@360
|
1884
|
Chris@76
|
1885 size_t frame = 0;
|
Chris@360
|
1886
|
Chris@360
|
1887 if (!realign) {
|
Chris@360
|
1888
|
Chris@360
|
1889 frame = i->getFrame();
|
Chris@360
|
1890
|
Chris@360
|
1891 } else {
|
Chris@360
|
1892
|
Chris@360
|
1893 if (i->haveReferenceFrame()) {
|
Chris@360
|
1894 frame = i->getReferenceFrame();
|
Chris@360
|
1895 frame = alignFromReference(v, frame);
|
Chris@360
|
1896 } else {
|
Chris@360
|
1897 frame = i->getFrame();
|
Chris@360
|
1898 }
|
Chris@76
|
1899 }
|
Chris@360
|
1900
|
Chris@76
|
1901 SparseTimeValueModel::Point newPoint(frame);
|
Chris@76
|
1902
|
Chris@125
|
1903 if (i->haveLabel()) {
|
Chris@125
|
1904 newPoint.label = i->getLabel();
|
Chris@125
|
1905 } else if (i->haveValue()) {
|
Chris@125
|
1906 newPoint.label = QString("%1").arg(i->getValue());
|
Chris@125
|
1907 }
|
Chris@125
|
1908
|
Chris@372
|
1909 bool usePrev = false;
|
Chris@372
|
1910 SparseTimeValueModel::Point formerPrevPoint = prevPoint;
|
Chris@372
|
1911
|
Chris@125
|
1912 if (i->haveValue()) {
|
Chris@125
|
1913 newPoint.value = i->getValue();
|
Chris@125
|
1914 } else {
|
Chris@526
|
1915 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1916 cerr << "Setting value on point at " << newPoint.frame << " from labeller";
|
Chris@526
|
1917 if (i == points.begin()) {
|
Chris@682
|
1918 cerr << ", no prev point" << endl;
|
Chris@526
|
1919 } else {
|
Chris@682
|
1920 cerr << ", prev point is at " << prevPoint.frame << endl;
|
Chris@526
|
1921 }
|
Chris@526
|
1922 #endif
|
Chris@340
|
1923 labeller.setValue<SparseTimeValueModel::Point>
|
Chris@371
|
1924 (newPoint, (i == points.begin()) ? 0 : &prevPoint);
|
Chris@526
|
1925 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1926 cerr << "New point value = " << newPoint.value << endl;
|
Chris@526
|
1927 #endif
|
Chris@372
|
1928 if (labeller.actingOnPrevPoint() && i != points.begin()) {
|
Chris@372
|
1929 usePrev = true;
|
Chris@372
|
1930 }
|
Chris@372
|
1931 }
|
Chris@372
|
1932
|
Chris@372
|
1933 if (usePrev) {
|
Chris@372
|
1934 command->deletePoint(formerPrevPoint);
|
Chris@372
|
1935 command->addPoint(prevPoint);
|
Chris@340
|
1936 }
|
Chris@125
|
1937
|
Chris@340
|
1938 prevPoint = newPoint;
|
Chris@76
|
1939 command->addPoint(newPoint);
|
Chris@76
|
1940 }
|
Chris@76
|
1941
|
Chris@376
|
1942 finish(command);
|
Chris@125
|
1943 return true;
|
Chris@360
|
1944 }
|
Chris@76
|
1945
|
Chris@316
|
1946 void
|
Chris@316
|
1947 TimeValueLayer::toXml(QTextStream &stream,
|
Chris@316
|
1948 QString indent, QString extraAttributes) const
|
Chris@6
|
1949 {
|
Chris@316
|
1950 SingleColourLayer::toXml(stream, indent,
|
Chris@316
|
1951 extraAttributes +
|
Chris@553
|
1952 QString(" colourMap=\"%1\" plotStyle=\"%2\" verticalScale=\"%3\" scaleMinimum=\"%4\" scaleMaximum=\"%5\" drawDivisions=\"%6\" derivative=\"%7\" ")
|
Chris@316
|
1953 .arg(m_colourMap)
|
Chris@316
|
1954 .arg(m_plotStyle)
|
Chris@445
|
1955 .arg(m_verticalScale)
|
Chris@445
|
1956 .arg(m_scaleMinimum)
|
Chris@513
|
1957 .arg(m_scaleMaximum)
|
Chris@553
|
1958 .arg(m_drawSegmentDivisions ? "true" : "false")
|
Chris@553
|
1959 .arg(m_derivative ? "true" : "false"));
|
Chris@0
|
1960 }
|
Chris@0
|
1961
|
Chris@11
|
1962 void
|
Chris@11
|
1963 TimeValueLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@11
|
1964 {
|
Chris@287
|
1965 SingleColourLayer::setProperties(attributes);
|
Chris@11
|
1966
|
Chris@445
|
1967 bool ok, alsoOk;
|
Chris@287
|
1968
|
Chris@287
|
1969 int cmap = attributes.value("colourMap").toInt(&ok);
|
Chris@287
|
1970 if (ok) setFillColourMap(cmap);
|
Chris@287
|
1971
|
Chris@11
|
1972 PlotStyle style = (PlotStyle)
|
Chris@11
|
1973 attributes.value("plotStyle").toInt(&ok);
|
Chris@11
|
1974 if (ok) setPlotStyle(style);
|
Chris@286
|
1975
|
Chris@286
|
1976 VerticalScale scale = (VerticalScale)
|
Chris@286
|
1977 attributes.value("verticalScale").toInt(&ok);
|
Chris@286
|
1978 if (ok) setVerticalScale(scale);
|
Chris@445
|
1979
|
Chris@513
|
1980 bool draw = (attributes.value("drawDivisions").trimmed() == "true");
|
Chris@513
|
1981 setDrawSegmentDivisions(draw);
|
Chris@513
|
1982
|
Chris@553
|
1983 bool derivative = (attributes.value("derivative").trimmed() == "true");
|
Chris@553
|
1984 setShowDerivative(derivative);
|
Chris@553
|
1985
|
Chris@445
|
1986 float min = attributes.value("scaleMinimum").toFloat(&ok);
|
Chris@445
|
1987 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
|
Chris@526
|
1988 #ifdef DEBUG_TIME_VALUE_LAYER
|
Chris@682
|
1989 cerr << "from properties: min = " << min << ", max = " << max << endl;
|
Chris@526
|
1990 #endif
|
Chris@526
|
1991 if (ok && alsoOk && min != max) setDisplayExtents(min, max);
|
Chris@11
|
1992 }
|
Chris@11
|
1993
|