comparison layer/SliceLayer.cpp @ 274:b9380f679f70

* Fix centre line position * Fix failure to update overview when generating peaks from wav file * Provide y-coordinate scale values and differences for spectrum measurement mode, and fix values for waveform (inc dB for both) * Add Printer colour scheme (may be futile)
author Chris Cannam
date Mon, 02 Jul 2007 13:04:17 +0000
parents a2ae3d93c645
children 3c402c6052f6
comparison
equal deleted inserted replaced
273:e954c00cbe55 274:b9380f679f70
223 } 223 }
224 224
225 return bin; 225 return bin;
226 } 226 }
227 227
228 float
229 SliceLayer::getYForValue(float value, const View *v, float &norm) const
230 {
231 norm = 0.f;
232
233 if (m_yorigins.find(v) == m_yorigins.end()) return 0;
234
235 value *= m_gain;
236
237 int yorigin = m_yorigins[v];
238 int h = m_heights[v];
239 float thresh = -80.f;
240
241 float y = 0.f;
242
243 if (h <= 0) return y;
244
245 switch (m_energyScale) {
246
247 case dBScale:
248 {
249 float db = thresh;
250 if (value > 0.f) db = 10.f * log10f(value);
251 if (db < thresh) db = thresh;
252 norm = (db - thresh) / -thresh;
253 y = yorigin - (float(h) * norm);
254 break;
255 }
256
257 case MeterScale:
258 y = AudioLevel::multiplier_to_preview(value, h);
259 norm = float(y) / float(h);
260 y = yorigin - y;
261 break;
262
263 default:
264 norm = value;
265 y = yorigin - (float(h) * value);
266 break;
267 }
268
269 return y;
270 }
271
272 float
273 SliceLayer::getValueForY(float y, const View *v) const
274 {
275 float value = 0.f;
276
277 if (m_yorigins.find(v) == m_yorigins.end()) return value;
278
279 int yorigin = m_yorigins[v];
280 int h = m_heights[v];
281 float thresh = -80.f;
282
283 if (h <= 0) return value;
284
285 y = yorigin - y;
286
287 switch (m_energyScale) {
288
289 case dBScale:
290 {
291 float db = ((y / h) * -thresh) + thresh;
292 value = powf(10.f, db/10.f);
293 break;
294 }
295
296 case MeterScale:
297 value = AudioLevel::preview_to_multiplier(lrintf(y), h);
298 break;
299
300 default:
301 value = y / h;
302 }
303
304 return value / m_gain;
305 }
306
228 void 307 void
229 SliceLayer::paint(View *v, QPainter &paint, QRect rect) const 308 SliceLayer::paint(View *v, QPainter &paint, QRect rect) const
230 { 309 {
231 if (!m_sliceableModel || !m_sliceableModel->isOK() || 310 if (!m_sliceableModel || !m_sliceableModel->isOK() ||
232 !m_sliceableModel->isReady()) return; 311 !m_sliceableModel->isReady()) return;
243 } 322 }
244 } 323 }
245 324
246 paint.setPen(m_colour); 325 paint.setPen(m_colour);
247 326
248 // int w = (v->width() * 2) / 3; 327 int xorigin = getVerticalScaleWidth(v, paint) + 1;
249 int xorigin = getVerticalScaleWidth(v, paint) + 1; //!!! (v->width() / 2) - (w / 2);
250 int w = v->width() - xorigin - 1; 328 int w = v->width() - xorigin - 1;
251 329
252 m_xorigins[v] = xorigin; // for use in getFeatureDescription 330 m_xorigins[v] = xorigin; // for use in getFeatureDescription
253 331
254 int yorigin = v->height() - 20 - paint.fontMetrics().height() - 7; 332 int yorigin = v->height() - 20 - paint.fontMetrics().height() - 7;
255 int h = yorigin - paint.fontMetrics().height() - 8; 333 int h = yorigin - paint.fontMetrics().height() - 8;
256 if (h < 0) return; 334
257 335 m_yorigins[v] = yorigin; // for getYForValue etc
258 // int h = (v->height() * 3) / 4; 336 m_heights[v] = h;
259 // int yorigin = (v->height() / 2) + (h / 2); 337
260 338 if (h <= 0) return;
339
261 QPainterPath path; 340 QPainterPath path;
262 float thresh = -80.f;
263 341
264 size_t mh = m_sliceableModel->getHeight(); 342 size_t mh = m_sliceableModel->getHeight();
265 343
266 int divisor = 0; 344 int divisor = 0;
267 345
274 int f0x = v->getXForFrame(f0); 352 int f0x = v->getXForFrame(f0);
275 f0 = v->getFrameForX(f0x); 353 f0 = v->getFrameForX(f0x);
276 size_t f1 = v->getFrameForX(f0x + 1); 354 size_t f1 = v->getFrameForX(f0x + 1);
277 if (f1 > f0) --f1; 355 if (f1 > f0) --f1;
278 356
279 size_t col0 = f0 / m_sliceableModel->getResolution(); 357 std::cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << std::endl;
358
359 size_t res = m_sliceableModel->getResolution();
360 size_t col0 = f0 / res;
280 size_t col1 = col0; 361 size_t col1 = col0;
281 if (m_samplingMode != NearestSample) { 362 if (m_samplingMode != NearestSample) col1 = f1 / res;
282 col1 = f1 / m_sliceableModel->getResolution(); 363 f0 = col0 * res;
283 } 364 f1 = (col1 + 1) * res - 1;
284 f0 = col0 * m_sliceableModel->getResolution(); 365
285 f1 = (col1 + 1) * m_sliceableModel->getResolution() - 1; 366 std::cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << std::endl;
286 367
287 m_currentf0 = f0; 368 m_currentf0 = f0;
288 m_currentf1 = f1; 369 m_currentf1 = f1;
289 370
290 BiasCurve curve; 371 BiasCurve curve;
324 405
325 float x = nx; 406 float x = nx;
326 nx = xorigin + getXForBin(bin + 1, mh, w); 407 nx = xorigin + getXForBin(bin + 1, mh, w);
327 408
328 float value = m_values[bin]; 409 float value = m_values[bin];
329
330 value *= m_gain;
331 float norm = 0.f; 410 float norm = 0.f;
332 float y = 0.f; 411 float y = getYForValue(value, v, norm);
333
334 switch (m_energyScale) {
335
336 case dBScale:
337 {
338 float db = thresh;
339 if (value > 0.f) db = 10.f * log10f(value);
340 if (db < thresh) db = thresh;
341 norm = (db - thresh) / -thresh;
342 y = yorigin - (float(h) * norm);
343 break;
344 }
345
346 case MeterScale:
347 y = AudioLevel::multiplier_to_preview(value, h);
348 norm = float(y) / float(h);
349 y = yorigin - y;
350 break;
351
352 default:
353 norm = value;
354 y = yorigin - (float(h) * value);
355 break;
356 }
357 412
358 if (m_plotStyle == PlotLines) { 413 if (m_plotStyle == PlotLines) {
359 414
360 if (bin == 0) { 415 if (bin == 0) {
361 path.moveTo(x, y); 416 path.moveTo(x, y);