Mercurial > hg > svgui
changeset 326:4f4f38a11cd2
* Factor out uses of "Sonic Visualiser" in "common" code to applicationName()
* Add ability to show work title + artist in top-left of pane (thinking of Vect
but may be useful in SV in future)
* A few other generalisations useful for Vect
author | Chris Cannam |
---|---|
date | Fri, 09 Nov 2007 17:46:58 +0000 |
parents | 1f67b110c1a3 |
children | 29fcf125f98b |
files | layer/Layer.cpp layer/LayerFactory.cpp layer/LayerFactory.h layer/SpectrogramLayer.cpp layer/TimeValueLayer.cpp view/Pane.cpp view/Pane.h view/View.cpp view/ViewManager.cpp view/ViewManager.h |
diffstat | 10 files changed, 165 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Layer.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/layer/Layer.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -24,6 +24,11 @@ #include <QMouseEvent> #include <QTextStream> +#include <QDomDocument> +#include <QDomElement> +#include <QDomNamedNodeMap> +#include <QDomAttr> + #include "LayerFactory.h" #include "base/PlayParameterRepository.h"
--- a/layer/LayerFactory.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/layer/LayerFactory.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -39,6 +39,13 @@ #include "data/model/WaveFileModel.h" #include "data/model/WritableWaveFileModel.h" +#include <QDomDocument> +#include <QDomElement> +#include <QDomNamedNodeMap> +#include <QDomAttr> + +#include <QSettings> + LayerFactory * LayerFactory::m_instance = new LayerFactory; @@ -212,6 +219,8 @@ case Colour3DPlot: return "colour3d"; case Spectrum: return "spectrum"; case Slice: return "spectrum"; + case MelodicRangeSpectrogram: return "spectrogram"; + case PeakFrequencySpectrogram: return "spectrogram"; default: return "unknown"; } } @@ -231,6 +240,8 @@ case Colour3DPlot: return "colour3dplot"; case Spectrum: return "spectrum"; case Slice: return "slice"; + case MelodicRangeSpectrogram: return "melodicrange"; + case PeakFrequencySpectrogram: return "peakfrequency"; default: return "unknown"; } } @@ -410,8 +421,50 @@ // std::cerr << "LayerFactory::createLayer: Setting object name " // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl; layer->setObjectName(getLayerPresentationName(type)); + setLayerDefaultProperties(type, layer); } return layer; } +void +LayerFactory::setLayerDefaultProperties(LayerType type, Layer *layer) +{ + QSettings settings; + settings.beginGroup("LayerDefaults"); + QString defaults = settings.value(getLayerTypeName(type), "").toString(); + if (defaults == "") return; + + QString xml = layer->toXmlString(); + QDomDocument docOld, docNew; + + if (docOld.setContent(xml, false) && + docNew.setContent(defaults, false)) { + + QXmlAttributes attrs; + + QDomElement layerElt = docNew.firstChildElement("layer"); + QDomNamedNodeMap attrNodes = layerElt.attributes(); + + for (unsigned int i = 0; i < attrNodes.length(); ++i) { + QDomAttr attr = attrNodes.item(i).toAttr(); + if (attr.isNull()) continue; + attrs.append(attr.name(), "", "", attr.value()); + } + + layerElt = docOld.firstChildElement("layer"); + attrNodes = layerElt.attributes(); + for (unsigned int i = 0; i < attrNodes.length(); ++i) { + QDomAttr attr = attrNodes.item(i).toAttr(); + if (attr.isNull()) continue; + if (attrs.value(attr.name()) == "") { + attrs.append(attr.name(), "", "", attr.value()); + } + } + + layer->setProperties(attrs); + } + + settings.endGroup(); +} +
--- a/layer/LayerFactory.h Wed Nov 07 16:52:52 2007 +0000 +++ b/layer/LayerFactory.h Fri Nov 09 17:46:58 2007 +0000 @@ -60,6 +60,8 @@ Layer *createLayer(LayerType type); + void setLayerDefaultProperties(LayerType type, Layer *layer); + QString getLayerPresentationName(LayerType type); bool isLayerSliceable(const Layer *);
--- a/layer/SpectrogramLayer.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -1539,7 +1539,8 @@ m_windowSize, getWindowIncrement(), fftSize, - true, +//!!! true, + false, m_candidateFillStartFrame); if (!model->isOK()) {
--- a/layer/TimeValueLayer.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/layer/TimeValueLayer.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -663,7 +663,10 @@ if (m_plotStyle != PlotLines && m_plotStyle != PlotCurve && m_plotStyle != PlotSegmentation) { - paint.drawRect(x, y - 1, w, 2); + if (m_plotStyle != PlotStems || + w > 1) { + paint.drawRect(x, y - 1, w, 2); + } } if (m_plotStyle == PlotConnectedPoints ||
--- a/view/Pane.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/view/Pane.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -24,6 +24,9 @@ #include "base/TextAbbrev.h" #include "layer/WaveformLayer.h" +//!!! ugh +#include "data/model/WaveFileModel.h" + #include <QPaintEvent> #include <QPainter> #include <QBitmap> @@ -313,6 +316,10 @@ return false; } + if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) { + return false; + } + if (layer == getSelectedLayer() && !shouldIlluminateLocalSelection(discard, b0, b1)) { @@ -410,6 +417,8 @@ bool haveSomeTimeXAxis = false; const Model *waveformModel = 0; // just for reporting purposes + const Model *workModel = 0; + for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { --vi; if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { @@ -417,8 +426,17 @@ } if (dynamic_cast<WaveformLayer *>(*vi)) { waveformModel = (*vi)->getModel(); + workModel = waveformModel; + } else { + Model *m = (*vi)->getModel(); + if (dynamic_cast<WaveFileModel *>(m)) { + workModel = m; + } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) { + workModel = m->getSourceModel(); + } } - if (waveformModel && haveSomeTimeXAxis) break; + + if (waveformModel && workModel && haveSomeTimeXAxis) break; } m_scaleWidth = 0; @@ -427,7 +445,9 @@ drawVerticalScale(r, topLayer, paint); } - if (m_identifyFeatures && topLayer) { + if (m_identifyFeatures && + m_manager && m_manager->shouldIlluminateLocalFeatures() && + topLayer) { drawFeatureDescription(topLayer, paint); } @@ -448,10 +468,19 @@ drawDurationAndRate(r, waveformModel, sampleRate, paint); } - if (waveformModel && + bool haveWorkTitle = false; + + if (workModel && + m_manager && + m_manager->shouldShowWorkTitle()) { + drawWorkTitle(r, paint, workModel); + haveWorkTitle = true; + } + + if (workModel && m_manager && m_manager->getAlignMode()) { - drawAlignmentStatus(r, paint, waveformModel); + drawAlignmentStatus(r, paint, workModel, haveWorkTitle); } if (m_manager && @@ -717,7 +746,8 @@ } void -Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model) +Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model, + bool down) { const Model *reference = model->getAlignmentReference(); /* @@ -747,17 +777,23 @@ } } - int w = paint.fontMetrics().width(text), h = paint.fontMetrics().height(); - if (r.top() > h + 5 || r.left() > w + m_scaleWidth + 5) return; - paint.save(); QFont font(paint.font()); font.setBold(true); paint.setFont(font); - if (completion < 100) paint.setPen(Qt::red); + if (completion < 100) paint.setBrush(Qt::red); + + int y = 5; + if (down) y += paint.fontMetrics().height(); + int w = paint.fontMetrics().width(text); + int h = paint.fontMetrics().height(); + if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) { + paint.restore(); + return; + } drawVisibleText(paint, m_scaleWidth + 5, - paint.fontMetrics().ascent() + 5, text, OutlinedText); + paint.fontMetrics().ascent() + y, text, OutlinedText); paint.restore(); } @@ -770,6 +806,37 @@ } void +Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model) +{ + QString title = model->getTitle(); + QString maker = model->getMaker(); + if (title == "") return; + + QString text = title; + if (maker != "") { + text = tr("%1 - %2").arg(title).arg(maker); + } + + paint.save(); + QFont font(paint.font()); + font.setItalic(true); + paint.setFont(font); + + int y = 5; + int w = paint.fontMetrics().width(text); + int h = paint.fontMetrics().height(); + if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) { + paint.restore(); + return; + } + + drawVisibleText(paint, m_scaleWidth + 5, + paint.fontMetrics().ascent() + y, text, OutlinedText); + + paint.restore(); +} + +void Pane::drawLayerNames(QRect r, QPainter &paint) { int fontHeight = paint.fontMetrics().height(); @@ -1363,7 +1430,8 @@ bool updating = false; - if (getSelectedLayer()) { + if (getSelectedLayer() && + m_manager->shouldIlluminateLocalFeatures()) { bool previouslyIdentifying = m_identifyFeatures; m_identifyFeatures = true;
--- a/view/Pane.h Wed Nov 07 16:52:52 2007 +0000 +++ b/view/Pane.h Fri Nov 09 17:46:58 2007 +0000 @@ -103,9 +103,10 @@ void drawFeatureDescription(Layer *, QPainter &); void drawCentreLine(int, QPainter &, bool omitLine); void drawDurationAndRate(QRect, const Model *, int, QPainter &); + void drawWorkTitle(QRect, QPainter &, const Model *); void drawLayerNames(QRect, QPainter &); void drawEditingSelection(QPainter &); - void drawAlignmentStatus(QRect, QPainter &, const Model *); + void drawAlignmentStatus(QRect, QPainter &, const Model *, bool down); virtual bool render(QPainter &paint, int x0, size_t f0, size_t f1);
--- a/view/View.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/view/View.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -802,7 +802,7 @@ void View::modelCompletionChanged() { - std::cerr << "View(" << this << ")::modelCompletionChanged()" << std::endl; +// std::cerr << "View(" << this << ")::modelCompletionChanged()" << std::endl; QObject *obj = sender(); checkProgress(obj); @@ -811,7 +811,7 @@ void View::modelAlignmentCompletionChanged() { - std::cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << std::endl; +// std::cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << std::endl; QObject *obj = sender(); checkProgress(obj); @@ -1354,7 +1354,9 @@ Model *model = i->first->getModel(); RangeSummarisableTimeValueModel *wfm = dynamic_cast<RangeSummarisableTimeValueModel *>(model); - if (wfm) { + if (wfm || + dynamic_cast<RangeSummarisableTimeValueModel *> + (model->getSourceModel())) { completion = wfm->getAlignmentCompletion(); if (completion < 100) { text = tr("Alignment");
--- a/view/ViewManager.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/view/ViewManager.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -43,6 +43,8 @@ m_alignMode(false), m_overlayMode(StandardOverlays), m_zoomWheelsEnabled(true), + m_illuminateLocalFeatures(true), + m_showWorkTitle(false), m_lightPalette(QApplication::palette()), m_darkPalette(QApplication::palette()) {
--- a/view/ViewManager.h Wed Nov 07 16:52:52 2007 +0000 +++ b/view/ViewManager.h Fri Nov 09 17:46:58 2007 +0000 @@ -115,6 +115,9 @@ bool getAlignMode() const { return m_alignMode; } void setAlignMode(bool on); + void setIlluminateLocalFeatures(bool i) { m_illuminateLocalFeatures = i; } + void setShowWorkTitle(bool show) { m_showWorkTitle = show; } + /** * The sample rate that is used for playback. This is usually the * rate of the main model, but not always. Models whose rates @@ -169,6 +172,12 @@ bool shouldShowScaleGuides() const { return m_overlayMode != NoOverlays; } + bool shouldShowWorkTitle() const { + return m_showWorkTitle; + } + bool shouldIlluminateLocalFeatures() const { + return m_illuminateLocalFeatures; + } void setZoomWheelsEnabled(bool enable); bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; } @@ -277,6 +286,8 @@ OverlayMode m_overlayMode; bool m_zoomWheelsEnabled; + bool m_illuminateLocalFeatures; + bool m_showWorkTitle; QPalette m_lightPalette; QPalette m_darkPalette;