Mercurial > hg > svgui
comparison layer/SpectrumLayer.cpp @ 918:4fe7a09be0fe osx-retina
Many fixes for the previous stuff
author | Chris Cannam |
---|---|
date | Tue, 17 Mar 2015 16:56:03 +0000 |
parents | 94e4952a6774 |
children | 64c2b3a4435a |
comparison
equal
deleted
inserted
replaced
917:77a1d42353ce | 918:4fe7a09be0fe |
---|---|
384 | 384 |
385 return x; | 385 return x; |
386 } | 386 } |
387 | 387 |
388 bool | 388 bool |
389 SpectrumLayer::getXScaleValue(const View *v, int x, | 389 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x, |
390 double &value, QString &unit) const | 390 double &value, QString &unit) const |
391 { | 391 { |
392 if (m_xorigins.find(v) == m_xorigins.end()) return false; | 392 if (m_xorigins.find(v) == m_xorigins.end()) return false; |
393 int xorigin = m_xorigins.find(v)->second; | 393 int xorigin = m_xorigins.find(v)->second; |
394 value = getFrequencyForX(x - xorigin, v->width() - xorigin - 1); | 394 value = getFrequencyForX(x - xorigin, v->getPaintWidth() - xorigin - 1); |
395 unit = "Hz"; | 395 unit = "Hz"; |
396 return true; | 396 return true; |
397 } | 397 } |
398 | 398 |
399 bool | 399 bool |
400 SpectrumLayer::getYScaleValue(const View *v, int y, | 400 SpectrumLayer::getYScaleValue(const LayerGeometryProvider *v, int y, |
401 double &value, QString &unit) const | 401 double &value, QString &unit) const |
402 { | 402 { |
403 value = getValueForY(y, v); | 403 value = getValueForY(y, v); |
404 | 404 |
405 if (m_energyScale == dBScale || m_energyScale == MeterScale) { | 405 if (m_energyScale == dBScale || m_energyScale == MeterScale) { |
417 | 417 |
418 return true; | 418 return true; |
419 } | 419 } |
420 | 420 |
421 bool | 421 bool |
422 SpectrumLayer::getYScaleDifference(const View *v, int y0, int y1, | 422 SpectrumLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, |
423 double &diff, QString &unit) const | 423 double &diff, QString &unit) const |
424 { | 424 { |
425 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit); | 425 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit); |
426 if (rv && (unit == "dBV")) unit = "dB"; | 426 if (rv && (unit == "dBV")) unit = "dB"; |
427 return rv; | 427 return rv; |
428 } | 428 } |
429 | 429 |
430 | 430 |
431 bool | 431 bool |
432 SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint, | 432 SpectrumLayer::getCrosshairExtents(LayerGeometryProvider *v, QPainter &paint, |
433 QPoint cursorPos, | 433 QPoint cursorPos, |
434 std::vector<QRect> &extents) const | 434 std::vector<QRect> &extents) const |
435 { | 435 { |
436 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y()); | 436 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->getPaintHeight() - cursorPos.y()); |
437 extents.push_back(vertical); | 437 extents.push_back(vertical); |
438 | 438 |
439 QRect horizontal(0, cursorPos.y(), v->width(), 12); | 439 QRect horizontal(0, cursorPos.y(), v->getPaintWidth(), 12); |
440 extents.push_back(horizontal); | 440 extents.push_back(horizontal); |
441 | 441 |
442 int hoffset = 2; | 442 int hoffset = 2; |
443 if (m_binScale == LogBins) hoffset = 13; | 443 if (m_binScale == LogBins) hoffset = 13; |
444 | 444 |
453 paint.fontMetrics().width("-80.000 dBV") + 2, | 453 paint.fontMetrics().width("-80.000 dBV") + 2, |
454 paint.fontMetrics().height()); | 454 paint.fontMetrics().height()); |
455 extents.push_back(log); | 455 extents.push_back(log); |
456 | 456 |
457 QRect freq(cursorPos.x(), | 457 QRect freq(cursorPos.x(), |
458 v->height() - paint.fontMetrics().height() - hoffset, | 458 v->getPaintHeight() - paint.fontMetrics().height() - hoffset, |
459 paint.fontMetrics().width("123456 Hz") + 2, | 459 paint.fontMetrics().width("123456 Hz") + 2, |
460 paint.fontMetrics().height()); | 460 paint.fontMetrics().height()); |
461 extents.push_back(freq); | 461 extents.push_back(freq); |
462 | 462 |
463 int w(paint.fontMetrics().width("C#10+50c") + 2); | 463 int w(paint.fontMetrics().width("C#10+50c") + 2); |
464 QRect pitch(cursorPos.x() - w, | 464 QRect pitch(cursorPos.x() - w, |
465 v->height() - paint.fontMetrics().height() - hoffset, | 465 v->getPaintHeight() - paint.fontMetrics().height() - hoffset, |
466 w, | 466 w, |
467 paint.fontMetrics().height()); | 467 paint.fontMetrics().height()); |
468 extents.push_back(pitch); | 468 extents.push_back(pitch); |
469 | 469 |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 void | 473 void |
474 SpectrumLayer::paintCrosshairs(View *v, QPainter &paint, | 474 SpectrumLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint, |
475 QPoint cursorPos) const | 475 QPoint cursorPos) const |
476 { | 476 { |
477 if (!m_sliceableModel) return; | 477 if (!m_sliceableModel) return; |
478 | 478 |
479 paint.save(); | 479 paint.save(); |
485 | 485 |
486 ColourMapper mapper(m_colourMap, 0, 1); | 486 ColourMapper mapper(m_colourMap, 0, 1); |
487 paint.setPen(mapper.getContrastingColour()); | 487 paint.setPen(mapper.getContrastingColour()); |
488 | 488 |
489 int xorigin = m_xorigins[v]; | 489 int xorigin = m_xorigins[v]; |
490 int w = v->width() - xorigin - 1; | 490 int w = v->getPaintWidth() - xorigin - 1; |
491 | 491 |
492 paint.drawLine(xorigin, cursorPos.y(), v->width(), cursorPos.y()); | 492 paint.drawLine(xorigin, cursorPos.y(), v->getPaintWidth(), cursorPos.y()); |
493 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->height()); | 493 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->getPaintHeight()); |
494 | 494 |
495 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); | 495 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); |
496 | 496 |
497 int hoffset = 2; | 497 int hoffset = 2; |
498 if (m_binScale == LogBins) hoffset = 13; | 498 if (m_binScale == LogBins) hoffset = 13; |
499 | 499 |
500 v->drawVisibleText(paint, | 500 v->drawVisibleText(paint, |
501 cursorPos.x() + 2, | 501 cursorPos.x() + 2, |
502 v->height() - 2 - hoffset, | 502 v->getPaintHeight() - 2 - hoffset, |
503 QString("%1 Hz").arg(fundamental), | 503 QString("%1 Hz").arg(fundamental), |
504 View::OutlinedText); | 504 View::OutlinedText); |
505 | 505 |
506 if (Pitch::isFrequencyInMidiRange(fundamental)) { | 506 if (Pitch::isFrequencyInMidiRange(fundamental)) { |
507 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); | 507 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); |
508 v->drawVisibleText(paint, | 508 v->drawVisibleText(paint, |
509 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, | 509 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, |
510 v->height() - 2 - hoffset, | 510 v->getPaintHeight() - 2 - hoffset, |
511 pitchLabel, | 511 pitchLabel, |
512 View::OutlinedText); | 512 View::OutlinedText); |
513 } | 513 } |
514 | 514 |
515 double value = getValueForY(cursorPos.y(), v); | 515 double value = getValueForY(cursorPos.y(), v); |
535 while (harmonic < 100) { | 535 while (harmonic < 100) { |
536 | 536 |
537 int hx = int(lrint(getXForFrequency(fundamental * harmonic, w))); | 537 int hx = int(lrint(getXForFrequency(fundamental * harmonic, w))); |
538 hx += xorigin; | 538 hx += xorigin; |
539 | 539 |
540 if (hx < xorigin || hx > v->width()) break; | 540 if (hx < xorigin || hx > v->getPaintWidth()) break; |
541 | 541 |
542 int len = 7; | 542 int len = 7; |
543 | 543 |
544 if (harmonic % 2 == 0) { | 544 if (harmonic % 2 == 0) { |
545 if (harmonic % 4 == 0) { | 545 if (harmonic % 4 == 0) { |
559 | 559 |
560 paint.restore(); | 560 paint.restore(); |
561 } | 561 } |
562 | 562 |
563 QString | 563 QString |
564 SpectrumLayer::getFeatureDescription(View *v, QPoint &p) const | 564 SpectrumLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const |
565 { | 565 { |
566 if (!m_sliceableModel) return ""; | 566 if (!m_sliceableModel) return ""; |
567 | 567 |
568 int minbin = 0, maxbin = 0, range = 0; | 568 int minbin = 0, maxbin = 0, range = 0; |
569 QString genericDesc = SliceLayer::getFeatureDescriptionAux | 569 QString genericDesc = SliceLayer::getFeatureDescriptionAux |
667 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | 667 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); |
668 | 668 |
669 double thresh = (pow(10, -6) / m_gain) * (m_windowSize / 2.0); // -60dB adj | 669 double thresh = (pow(10, -6) / m_gain) * (m_windowSize / 2.0); // -60dB adj |
670 | 670 |
671 int xorigin = getVerticalScaleWidth(v, false, paint) + 1; | 671 int xorigin = getVerticalScaleWidth(v, false, paint) + 1; |
672 int w = v->width() - xorigin - 1; | 672 int w = v->getPaintWidth() - xorigin - 1; |
673 | 673 |
674 int pkh = 0; | 674 int pkh = 0; |
675 //!!! if (m_binScale == LogBins) { | 675 //!!! if (m_binScale == LogBins) { |
676 pkh = 10; | 676 pkh = 10; |
677 //!!! } | 677 //!!! } |
727 | 727 |
728 double norm = 0.f; | 728 double norm = 0.f; |
729 (void)getYForValue(values[bin], v, norm); // don't need return value, need norm | 729 (void)getYForValue(values[bin], v, norm); // don't need return value, need norm |
730 | 730 |
731 paint.setPen(mapper.map(norm)); | 731 paint.setPen(mapper.map(norm)); |
732 paint.drawLine(xorigin + x, 0, xorigin + x, v->height() - pkh - 1); | 732 paint.drawLine(xorigin + x, 0, xorigin + x, v->getPaintHeight() - pkh - 1); |
733 } | 733 } |
734 | 734 |
735 paint.restore(); | 735 paint.restore(); |
736 } | 736 } |
737 | 737 |
747 //proposition. | 747 //proposition. |
748 | 748 |
749 // if (m_binScale == LogBins) { | 749 // if (m_binScale == LogBins) { |
750 | 750 |
751 // int pkh = 10; | 751 // int pkh = 10; |
752 int h = v->height(); | 752 int h = v->getPaintHeight(); |
753 | 753 |
754 // piano keyboard | 754 // piano keyboard |
755 //!!! should be in a new paintHorizontalScale()? | 755 //!!! should be in a new paintHorizontalScale()? |
756 // nice to have a piano keyboard class, of course | 756 // nice to have a piano keyboard class, of course |
757 | 757 |