# HG changeset patch # User Chris Cannam # Date 1144689779 0 # Node ID fd348f36c0d35559f2c45ddbe9c74e94a5eddd61 # Parent 45ba0b381c5d2a854b36fc13df6904b35650e15f * 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. diff -r 45ba0b381c5d -r fd348f36c0d3 layer/SpectrogramLayer.cpp --- 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 &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 { diff -r 45ba0b381c5d -r fd348f36c0d3 layer/SpectrogramLayer.h --- 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 &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; diff -r 45ba0b381c5d -r fd348f36c0d3 widgets/Pane.cpp --- 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(*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(*vi)) { - waveformModel = (*vi)->getModel(); + std::vector 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();