Mercurial > hg > svgui
comparison layer/TimeInstantLayer.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 | ca57f70b0e48 |
children | 202d1dca67d2 |
comparison
equal
deleted
inserted
replaced
24:6b794a2af3d9 | 25:dcdb21b62dbb |
---|---|
137 { | 137 { |
138 QPoint discard; | 138 QPoint discard; |
139 return !m_view->shouldIlluminateLocalFeatures(this, discard); | 139 return !m_view->shouldIlluminateLocalFeatures(this, discard); |
140 } | 140 } |
141 | 141 |
142 QRect | |
143 TimeInstantLayer::getFeatureDescriptionRect(QPainter &paint, QPoint pos) const | |
144 { | |
145 return QRect(0, 0, | |
146 std::max(100, paint.fontMetrics().width(tr("No local points"))), | |
147 50); //!!! cruddy | |
148 } | |
149 | |
150 SparseOneDimensionalModel::PointList | 142 SparseOneDimensionalModel::PointList |
151 TimeInstantLayer::getLocalPoints(int x) const | 143 TimeInstantLayer::getLocalPoints(int x) const |
152 { | 144 { |
153 if (!m_model) return SparseOneDimensionalModel::PointList(); | 145 if (!m_model) return SparseOneDimensionalModel::PointList(); |
154 | 146 |
179 } | 171 } |
180 | 172 |
181 return usePoints; | 173 return usePoints; |
182 } | 174 } |
183 | 175 |
184 void | 176 QString |
185 TimeInstantLayer::paintLocalFeatureDescription(QPainter &paint, QRect rect, | 177 TimeInstantLayer::getFeatureDescription(QPoint &pos) const |
186 QPoint pos) const | 178 { |
187 { | |
188 //!!! bleagh | |
189 | |
190 int x = pos.x(); | 179 int x = pos.x(); |
180 | |
181 if (!m_model || !m_model->getSampleRate()) return ""; | |
182 | |
183 SparseOneDimensionalModel::PointList points = getLocalPoints(x); | |
184 | |
185 if (points.empty()) { | |
186 if (!m_model->isReady()) { | |
187 return tr("In progress"); | |
188 } else { | |
189 return tr("No local points"); | |
190 } | |
191 } | |
192 | |
193 long useFrame = points.begin()->frame; | |
194 | |
195 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); | |
191 | 196 |
192 if (!m_model || !m_model->getSampleRate()) return; | 197 QString text; |
193 | 198 |
194 SparseOneDimensionalModel::PointList points = getLocalPoints(x); | 199 if (points.begin()->label == "") { |
195 | 200 text = QString(tr("Time:\t%1\nNo label")) |
196 QFontMetrics metrics = paint.fontMetrics(); | 201 .arg(rt.toText(true).c_str()); |
197 int xbase = rect.x() + 5; | 202 } else { |
198 int ybase = rect.y() + 5; | 203 text = QString(tr("Time:\t%1\nLabel:\t%2")) |
199 | 204 .arg(rt.toText(true).c_str()) |
200 if (points.empty()) { | 205 .arg(points.begin()->label); |
201 QString label = tr("No local points"); | 206 } |
202 if (!m_model->isReady()) { | 207 |
203 label = tr("In progress"); | 208 pos = QPoint(getXForFrame(useFrame), pos.y()); |
204 } | 209 return text; |
205 paint.drawText(xbase + 5, ybase + 5 + metrics.ascent(), label); | |
206 return; | |
207 } | |
208 | |
209 long useFrame = points.begin()->frame; | |
210 | |
211 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); | |
212 QString timeText = QString(tr("Time %1")).arg(rt.toText(true).c_str()); | |
213 | |
214 int timewidth = metrics.width(timeText); | |
215 int labelwidth = metrics.width(points.begin()->label); | |
216 | |
217 int boxheight = metrics.height() * 2 + 3; | |
218 int boxwidth = std::max(timewidth, labelwidth); | |
219 | |
220 paint.drawRect(xbase, ybase, boxwidth + 10, | |
221 boxheight + 10 - metrics.descent() + 1); | |
222 | |
223 paint.drawText(xbase + 5, ybase + 5 + metrics.ascent(), timeText); | |
224 paint.drawText(xbase + 5, ybase + 7 + metrics.ascent() + metrics.height(), | |
225 points.begin()->label); | |
226 } | 210 } |
227 | 211 |
228 int | 212 int |
229 TimeInstantLayer::getNearestFeatureFrame(int frame, | 213 TimeInstantLayer::getNearestFeatureFrame(int frame, |
230 size_t &resolution, | 214 size_t &resolution, |