Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 25:dcdb21b62dbb
* Refactor sparse models. Previously the 1D and time-value models duplicated
a lot of code; now there is a base class (SparseModel) templated on the
stored point type, and the subclasses define point types with the necessary
characteristics.
* Add NoteModel, a new SparseModel subclass.
* Reorganise local feature description display. Instead of asking the layer
to draw its own, just query it for a textual description and draw that in
Pane. Greatly simplifies this part of the layer code.
* Add local feature descriptions to colour 3D plot and waveform layers.
* Add pitch in MIDI-pitch-and-cents to spectrogram layer.
* Give AudioGenerator its own mutex to shorten lock times in CallbackPlaySource.
* Minor adjustments to layers menu &c
author | Chris Cannam |
---|---|
date | Thu, 02 Feb 2006 16:10:19 +0000 |
parents | 6b794a2af3d9 |
children | 94381052a6c9 |
comparison
equal
deleted
inserted
replaced
24:6b794a2af3d9 | 25:dcdb21b62dbb |
---|---|
62 | 62 |
63 void | 63 void |
64 Colour3DPlotLayer::cacheInvalid(size_t, size_t) | 64 Colour3DPlotLayer::cacheInvalid(size_t, size_t) |
65 { | 65 { |
66 cacheInvalid(); | 66 cacheInvalid(); |
67 } | |
68 | |
69 bool | |
70 Colour3DPlotLayer::isLayerScrollable() const | |
71 { | |
72 QPoint discard; | |
73 return !m_view->shouldIlluminateLocalFeatures(this, discard); | |
74 } | |
75 | |
76 QString | |
77 Colour3DPlotLayer::getFeatureDescription(QPoint &pos) const | |
78 { | |
79 if (!m_model) return ""; | |
80 | |
81 int x = pos.x(); | |
82 int y = pos.y(); | |
83 | |
84 size_t modelStart = m_model->getStartFrame(); | |
85 size_t modelWindow = m_model->getWindowSize(); | |
86 | |
87 int sx0 = modelWindow * | |
88 int((getFrameForX(x) - long(modelStart)) / long(modelWindow)); | |
89 int sx1 = sx0 + modelWindow; | |
90 | |
91 float binHeight = float(m_view->height()) / m_model->getYBinCount(); | |
92 int sy = (m_view->height() - y) / binHeight; | |
93 | |
94 float value = m_model->getBinValue(sx0, sy); | |
95 | |
96 QString binName = m_model->getBinName(sy); | |
97 if (binName == "") binName = QString("[%1]").arg(sy + 1); | |
98 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1); | |
99 | |
100 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4") | |
101 .arg(RealTime::frame2RealTime(sx0, m_model->getSampleRate()) | |
102 .toText(true).c_str()) | |
103 .arg(RealTime::frame2RealTime(sx1, m_model->getSampleRate()) | |
104 .toText(true).c_str()) | |
105 .arg(binName) | |
106 .arg(value); | |
107 | |
108 return text; | |
109 } | |
110 | |
111 int | |
112 Colour3DPlotLayer::getVerticalScaleWidth(QPainter &paint) const | |
113 { | |
114 if (!m_model) return 0; | |
115 | |
116 QString sampleText("123"); | |
117 int tw = paint.fontMetrics().width(sampleText); | |
118 | |
119 for (size_t i = 0; i < m_model->getYBinCount(); ++i) { | |
120 if (m_model->getBinName(i).length() > sampleText.length()) { | |
121 sampleText = m_model->getBinName(i); | |
122 } | |
123 } | |
124 if (sampleText != "123") { | |
125 tw = std::max(tw, paint.fontMetrics().width(sampleText)); | |
126 } | |
127 | |
128 return tw + 13; | |
129 } | |
130 | |
131 void | |
132 Colour3DPlotLayer::paintVerticalScale(QPainter &paint, QRect rect) const | |
133 { | |
134 if (!m_model) return; | |
135 | |
136 int h = rect.height(), w = rect.width(); | |
137 float binHeight = float(m_view->height()) / m_model->getYBinCount(); | |
138 | |
139 // int textHeight = paint.fontMetrics().height(); | |
140 // int toff = -textHeight + paint.fontMetrics().ascent() + 2; | |
141 | |
142 for (size_t i = 0; i < m_model->getYBinCount(); ++i) { | |
143 | |
144 int y0 = m_view->height() - (i * binHeight) - 1; | |
145 | |
146 QString text = m_model->getBinName(i); | |
147 if (text == "") text = QString("[%1]").arg(i + 1); | |
148 | |
149 paint.drawLine(0, y0, w, y0); | |
150 | |
151 int cy = y0 - binHeight/2; | |
152 int ty = cy + paint.fontMetrics().ascent()/2; | |
153 | |
154 // int tx = w - 10 - paint.fontMetrics().width(text); | |
155 paint.drawText(10, ty, text); | |
156 } | |
67 } | 157 } |
68 | 158 |
69 void | 159 void |
70 Colour3DPlotLayer::paint(QPainter &paint, QRect rect) const | 160 Colour3DPlotLayer::paint(QPainter &paint, QRect rect) const |
71 { | 161 { |
191 /* | 281 /* |
192 std::cerr << "Colour3DPlotLayer::paint: w " << w << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sw << ", sh " << sh << std::endl; | 282 std::cerr << "Colour3DPlotLayer::paint: w " << w << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sw << ", sh " << sh << std::endl; |
193 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", window size " << m_model->getWindowSize() << std::endl; | 283 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", window size " << m_model->getWindowSize() << std::endl; |
194 */ | 284 */ |
195 | 285 |
286 QPoint illuminatePos; | |
287 bool illuminate = m_view->shouldIlluminateLocalFeatures(this, illuminatePos); | |
288 | |
196 for (int sx = sx0 - 1; sx <= sx1; ++sx) { | 289 for (int sx = sx0 - 1; sx <= sx1; ++sx) { |
197 | 290 |
198 int fx = sx * int(modelWindow); | 291 int fx = sx * int(modelWindow); |
199 | 292 |
200 if (fx + modelWindow < int(modelStart) || | 293 if (fx + modelWindow < int(modelStart) || |
221 paint.setPen(Qt::NoPen); | 314 paint.setPen(Qt::NoPen); |
222 paint.setBrush(brush); | 315 paint.setBrush(brush); |
223 | 316 |
224 int w = rx1 - rx0; | 317 int w = rx1 - rx0; |
225 if (w < 1) w = 1; | 318 if (w < 1) w = 1; |
226 paint.drawRect(rx0, ry0 - h / sh - 1, w, h / sh + 1); | 319 |
320 QRect r(rx0, ry0 - h / sh - 1, w, h / sh + 1); | |
321 | |
322 if (illuminate) { | |
323 if (r.contains(illuminatePos)) { | |
324 paint.setPen(Qt::black);//!!! | |
325 } | |
326 } | |
327 | |
328 paint.drawRect(r); | |
227 | 329 |
228 if (sx >= 0 && sx < m_cache->width() && | 330 if (sx >= 0 && sx < m_cache->width() && |
229 sy >= 0 && sy < m_cache->height()) { | 331 sy >= 0 && sy < m_cache->height()) { |
230 if (w > 10) { | 332 if (w > 10) { |
231 int dv = m_cache->pixelIndex(sx, sy); | 333 int dv = m_cache->pixelIndex(sx, sy); |