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