comparison layer/TimeValueLayer.cpp @ 66:e9eac9368e29

* basics of selectable vertical scale in time value layer * clear selection when closing session
author Chris Cannam
date Mon, 27 Mar 2006 16:44:12 +0000
parents 705f05ab42e3
children c4fff27cd651
comparison
equal deleted inserted replaced
65:7f608ec9a061 66:e9eac9368e29
20 #include "base/Profiler.h" 20 #include "base/Profiler.h"
21 #include "base/View.h" 21 #include "base/View.h"
22 22
23 #include "model/SparseTimeValueModel.h" 23 #include "model/SparseTimeValueModel.h"
24 24
25 #include "SpectrogramLayer.h" // for optional frequency alignment
26
25 #include <QPainter> 27 #include <QPainter>
26 #include <QPainterPath> 28 #include <QPainterPath>
27 #include <QMouseEvent> 29 #include <QMouseEvent>
28 30
29 #include <iostream> 31 #include <iostream>
35 m_editing(false), 37 m_editing(false),
36 m_originalPoint(0, 0.0, tr("New Point")), 38 m_originalPoint(0, 0.0, tr("New Point")),
37 m_editingPoint(0, 0.0, tr("New Point")), 39 m_editingPoint(0, 0.0, tr("New Point")),
38 m_editingCommand(0), 40 m_editingCommand(0),
39 m_colour(Qt::black), 41 m_colour(Qt::black),
40 m_plotStyle(PlotConnectedPoints) 42 m_plotStyle(PlotConnectedPoints),
43 m_verticalScale(LinearScale)
41 { 44 {
42 45
43 } 46 }
44 47
45 void 48 void
64 TimeValueLayer::getProperties() const 67 TimeValueLayer::getProperties() const
65 { 68 {
66 PropertyList list; 69 PropertyList list;
67 list.push_back(tr("Colour")); 70 list.push_back(tr("Colour"));
68 list.push_back(tr("Plot Type")); 71 list.push_back(tr("Plot Type"));
72 list.push_back(tr("Vertical Scale"));
69 return list; 73 return list;
70 } 74 }
71 75
72 Layer::PropertyType 76 Layer::PropertyType
73 TimeValueLayer::getPropertyType(const PropertyName &name) const 77 TimeValueLayer::getPropertyType(const PropertyName &name) const
99 103
100 if (min) *min = 0; 104 if (min) *min = 0;
101 if (max) *max = 5; 105 if (max) *max = 5;
102 106
103 deft = int(m_plotStyle); 107 deft = int(m_plotStyle);
108
109 } else if (name == tr("Vertical Scale")) {
110
111 if (min) *min = 0;
112 if (max) *max = 3;
113
114 deft = int(m_verticalScale);
104 115
105 } else { 116 } else {
106 117
107 deft = Layer::getPropertyRangeAndValue(name, min, max); 118 deft = Layer::getPropertyRangeAndValue(name, min, max);
108 } 119 }
132 case 2: return tr("Connected Points"); 143 case 2: return tr("Connected Points");
133 case 3: return tr("Lines"); 144 case 3: return tr("Lines");
134 case 4: return tr("Curve"); 145 case 4: return tr("Curve");
135 case 5: return tr("Segmentation"); 146 case 5: return tr("Segmentation");
136 } 147 }
148 } else if (name == tr("Vertical Scale")) {
149 switch (value) {
150 default:
151 case 0: return tr("Linear Scale");
152 case 1: return tr("Log Scale");
153 case 2: return tr("+/-1 Scale");
154 case 3: return tr("Frequency Scale");
155 }
137 } 156 }
138 return tr("<unknown>"); 157 return tr("<unknown>");
139 } 158 }
140 159
141 void 160 void
151 case 4: setBaseColour(QColor(200, 50, 255)); break; 170 case 4: setBaseColour(QColor(200, 50, 255)); break;
152 case 5: setBaseColour(QColor(255, 150, 50)); break; 171 case 5: setBaseColour(QColor(255, 150, 50)); break;
153 } 172 }
154 } else if (name == tr("Plot Type")) { 173 } else if (name == tr("Plot Type")) {
155 setPlotStyle(PlotStyle(value)); 174 setPlotStyle(PlotStyle(value));
175 } else if (name == tr("Vertical Scale")) {
176 setVerticalScale(VerticalScale(value));
156 } 177 }
157 } 178 }
158 179
159 void 180 void
160 TimeValueLayer::setBaseColour(QColor colour) 181 TimeValueLayer::setBaseColour(QColor colour)
167 void 188 void
168 TimeValueLayer::setPlotStyle(PlotStyle style) 189 TimeValueLayer::setPlotStyle(PlotStyle style)
169 { 190 {
170 if (m_plotStyle == style) return; 191 if (m_plotStyle == style) return;
171 m_plotStyle = style; 192 m_plotStyle = style;
193 emit layerParametersChanged();
194 }
195
196 void
197 TimeValueLayer::setVerticalScale(VerticalScale scale)
198 {
199 if (m_verticalScale == scale) return;
200 m_verticalScale = scale;
172 emit layerParametersChanged(); 201 emit layerParametersChanged();
173 } 202 }
174 203
175 bool 204 bool
176 TimeValueLayer::isLayerScrollable(const View *v) const 205 TimeValueLayer::isLayerScrollable(const View *v) const
338 frame = snapped; 367 frame = snapped;
339 return found; 368 return found;
340 } 369 }
341 370
342 int 371 int
343 TimeValueLayer::getYForValue(View *v, float value) const 372 TimeValueLayer::getYForValue(View *v, float val) const
344 { 373 {
345 float min = m_model->getValueMinimum(); 374 float min = m_model->getValueMinimum();
346 float max = m_model->getValueMaximum(); 375 float max = m_model->getValueMaximum();
347 if (max == min) max = min + 1.0; 376 if (max == min) max = min + 1.0;
348 377
349 int h = v->height(); 378 int h = v->height();
350 379
351 return int(h - ((value - min) * h) / (max - min)); 380 if (m_verticalScale == FrequencyScale || m_verticalScale == LogScale) {
381
382 if (m_verticalScale == FrequencyScale) {
383 // If we have a spectrogram layer on the same view as us, align
384 // ourselves with it...
385 for (int i = 0; i < v->getLayerCount(); ++i) {
386 SpectrogramLayer *spectrogram = dynamic_cast<SpectrogramLayer *>
387 (v->getLayer(i));
388 if (spectrogram) {
389 return spectrogram->getYForFrequency(v, val);
390 }
391 }
392 }
393
394 min = (min < 0.0) ? -log10(-min) : (min == 0.0) ? 0.0 : log10(min);
395 max = (max < 0.0) ? -log10(-max) : (max == 0.0) ? 0.0 : log10(max);
396 val = (val < 0.0) ? -log10(-val) : (val == 0.0) ? 0.0 : log10(val);
397
398 } else if (m_verticalScale == PlusMinusOneScale) {
399 min = -1.0;
400 max = 1.0;
401 }
402
403 return int(h - ((val - min) * h) / (max - min));
352 } 404 }
353 405
354 float 406 float
355 TimeValueLayer::getValueForY(View *v, int y) const 407 TimeValueLayer::getValueForY(View *v, int y) const
356 { 408 {
409 //!!!
410
357 float min = m_model->getValueMinimum(); 411 float min = m_model->getValueMinimum();
358 float max = m_model->getValueMaximum(); 412 float max = m_model->getValueMaximum();
359 if (max == min) max = min + 1.0; 413 if (max == min) max = min + 1.0;
360 414
361 int h = v->height(); 415 int h = v->height();