Mercurial > hg > svgui
changeset 77:fd348f36c0d3
* Implement harmonic cursor in spectrogram
* Implement layer export. This doesn't quite do the right thing for the SV
XML layer export yet -- it doesn't include layer display information, so
when imported, it only creates an invisible model. Could also do with
fixing CSV file import so as to work correctly for note and text layers.
author | Chris Cannam |
---|---|
date | Mon, 10 Apr 2006 17:22:59 +0000 |
parents | 45ba0b381c5d |
children | 967193b6c7aa |
files | layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h widgets/Pane.cpp |
diffstat | 3 files changed, 148 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Fri Apr 07 17:50:33 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Mon Apr 10 17:22:59 2006 +0000 @@ -948,19 +948,24 @@ case DefaultColours: hue = 256 - pixel; colour = QColor::fromHsv(hue, pixel/2 + 128, pixel); + m_crosshairColour = QColor(255, 150, 50); +// m_crosshairColour = QColor::fromHsv(240, 160, 255); break; case WhiteOnBlack: colour = QColor(pixel, pixel, pixel); + m_crosshairColour = Qt::red; break; case BlackOnWhite: colour = QColor(256-pixel, 256-pixel, 256-pixel); + m_crosshairColour = Qt::darkGreen; break; case RedOnBlue: colour = QColor(pixel > 128 ? (pixel - 128) * 2 : 0, 0, pixel < 128 ? pixel : (256 - pixel)); + m_crosshairColour = Qt::green; break; case YellowOnBlack: @@ -971,18 +976,21 @@ 256 - px, pixel, pixel / 4); + m_crosshairColour = QColor::fromHsv(240, 255, 255); break; case BlueOnBlack: colour = QColor::fromHsv (240, pixel > 226 ? 256 - (pixel - 226) * 8 : 255, (pixel * pixel) / 255); + m_crosshairColour = Qt::red; break; case Rainbow: hue = 250 - pixel; if (hue < 0) hue += 256; colour = QColor::fromHsv(pixel, 255, 255); + m_crosshairColour = Qt::white; break; } @@ -2105,6 +2113,60 @@ return true; } +bool +SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint, + QPoint cursorPos, + std::vector<QRect> &extents) const +{ + QRect vertical(cursorPos.x() - 12, 0, 12, v->height()); + extents.push_back(vertical); + + QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1); + extents.push_back(horizontal); + + return true; +} + +void +SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint, + QPoint cursorPos) const +{ + paint.save(); + paint.setPen(m_crosshairColour); + + paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y()); + paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->height()); + + float fundamental = getFrequencyForY(v, cursorPos.y()); + + int harmonic = 2; + + while (harmonic < 100) { + + float hy = lrintf(getYForFrequency(v, fundamental * harmonic)); + if (hy < 0 || hy > v->height()) break; + + int len = 7; + + if (harmonic % 2 == 0) { + if (harmonic % 4 == 0) { + len = 12; + } else { + len = 10; + } + } + + paint.drawLine(cursorPos.x() - len, + hy, + cursorPos.x(), + hy); + + ++harmonic; + } + + paint.restore(); +} + QString SpectrogramLayer::getFeatureDescription(View *v, QPoint &pos) const {
--- a/layer/SpectrogramLayer.h Fri Apr 07 17:50:33 2006 +0000 +++ b/layer/SpectrogramLayer.h Mon Apr 10 17:22:59 2006 +0000 @@ -59,6 +59,10 @@ virtual int getVerticalScaleWidth(View *v, QPainter &) const; virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const; + virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, + std::vector<QRect> &extents) const; + virtual void paintCrosshairs(View *, QPainter &, QPoint) const; + virtual QString getFeatureDescription(View *v, QPoint &) const; virtual bool snapToFeatureFrame(View *v, int &frame, @@ -207,6 +211,7 @@ size_t m_maxFrequency; ColourScale m_colourScale; ColourScheme m_colourScheme; + QColor m_crosshairColour; FrequencyScale m_frequencyScale; BinDisplay m_binDisplay; bool m_normalizeColumns;
--- a/widgets/Pane.cpp Fri Apr 07 17:50:33 2006 +0000 +++ b/widgets/Pane.cpp Mon Apr 10 17:22:59 2006 +0000 @@ -144,90 +144,103 @@ int fontHeight = paint.fontMetrics().height(); int fontAscent = paint.fontMetrics().ascent(); - if (m_manager && - m_manager->getOverlayMode() != ViewManager::NoOverlays) { + for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { + --vi; + + if (dynamic_cast<WaveformLayer *>(*vi)) { + waveformModel = (*vi)->getModel(); + } - for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { - --vi; + if (m_manager && + !m_manager->isPlaying() && + m_manager->getToolMode() == ViewManager::SelectMode) { - if (dynamic_cast<WaveformLayer *>(*vi)) { - waveformModel = (*vi)->getModel(); + std::vector<QRect> crosshairExtents; + + if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint, + crosshairExtents)) { + (*vi)->paintCrosshairs(this, paint, m_identifyPoint); } + } - verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint); + if (!m_manager || + m_manager->getOverlayMode() == ViewManager::NoOverlays) { + break; + } - if (verticalScaleWidth > 0 && r.left() < verticalScaleWidth) { + verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint); + + if (verticalScaleWidth > 0 && r.left() < verticalScaleWidth) { // Profiler profiler("Pane::paintEvent - painting vertical scale", true); // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl; + paint.save(); + + paint.setPen(Qt::black); + paint.setBrush(Qt::white); + paint.drawRect(0, -1, verticalScaleWidth, height()+1); + + paint.setBrush(Qt::NoBrush); + (*vi)->paintVerticalScale + (this, paint, QRect(0, 0, verticalScaleWidth, height())); + + paint.restore(); + } + + if (m_identifyFeatures) { + + QPoint pos = m_identifyPoint; + QString desc = (*vi)->getFeatureDescription(this, pos); + + if (desc != "") { + paint.save(); + + int tabStop = + paint.fontMetrics().width(tr("Some lengthy prefix:")); + + QRect boundingRect = + paint.fontMetrics().boundingRect + (rect(), + Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs, + desc, tabStop); - paint.setPen(Qt::black); - paint.setBrush(Qt::white); - paint.drawRect(0, -1, verticalScaleWidth, height()+1); + if (hasLightBackground()) { + paint.setPen(Qt::NoPen); + paint.setBrush(QColor(250, 250, 250, 200)); + } else { + paint.setPen(Qt::NoPen); + paint.setBrush(QColor(50, 50, 50, 200)); + } - paint.setBrush(Qt::NoBrush); - (*vi)->paintVerticalScale - (this, paint, QRect(0, 0, verticalScaleWidth, height())); + int extra = paint.fontMetrics().descent(); + paint.drawRect(width() - boundingRect.width() - 10 - extra, + 10 - extra, + boundingRect.width() + 2 * extra, + boundingRect.height() + extra); + + if (hasLightBackground()) { + paint.setPen(QColor(150, 20, 0)); + } else { + paint.setPen(QColor(255, 150, 100)); + } + + QTextOption option; + option.setWrapMode(QTextOption::NoWrap); + option.setAlignment(Qt::AlignRight | Qt::AlignTop); + option.setTabStop(tabStop); + paint.drawText(QRectF(width() - boundingRect.width() - 10, 10, + boundingRect.width(), + boundingRect.height()), + desc, + option); paint.restore(); } - - if (m_identifyFeatures) { + } - QPoint pos = m_identifyPoint; - QString desc = (*vi)->getFeatureDescription(this, pos); - - if (desc != "") { - - paint.save(); - - int tabStop = - paint.fontMetrics().width(tr("Some lengthy prefix:")); - - QRect boundingRect = - paint.fontMetrics().boundingRect - (rect(), - Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs, - desc, tabStop); - - if (hasLightBackground()) { - paint.setPen(Qt::NoPen); - paint.setBrush(QColor(250, 250, 250, 200)); - } else { - paint.setPen(Qt::NoPen); - paint.setBrush(QColor(50, 50, 50, 200)); - } - - int extra = paint.fontMetrics().descent(); - paint.drawRect(width() - boundingRect.width() - 10 - extra, - 10 - extra, - boundingRect.width() + 2 * extra, - boundingRect.height() + extra); - - if (hasLightBackground()) { - paint.setPen(QColor(150, 20, 0)); - } else { - paint.setPen(QColor(255, 150, 100)); - } - - QTextOption option; - option.setWrapMode(QTextOption::NoWrap); - option.setAlignment(Qt::AlignRight | Qt::AlignTop); - option.setTabStop(tabStop); - paint.drawText(QRectF(width() - boundingRect.width() - 10, 10, - boundingRect.width(), - boundingRect.height()), - desc, - option); - - paint.restore(); - } - } - - break; - } + break; } int sampleRate = getModelsSampleRate();