# HG changeset patch # User Chris Cannam # Date 1194630418 0 # Node ID 4f4f38a11cd2b6011c6e94e332f2f894b01eef6e # Parent 1f67b110c1a35947a15f808b7e15f8d766c2505c * 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 diff -r 1f67b110c1a3 -r 4f4f38a11cd2 layer/Layer.cpp --- 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 #include +#include +#include +#include +#include + #include "LayerFactory.h" #include "base/PlayParameterRepository.h" diff -r 1f67b110c1a3 -r 4f4f38a11cd2 layer/LayerFactory.cpp --- 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 +#include +#include +#include + +#include + 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(); +} + diff -r 1f67b110c1a3 -r 4f4f38a11cd2 layer/LayerFactory.h --- 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 *); diff -r 1f67b110c1a3 -r 4f4f38a11cd2 layer/SpectrogramLayer.cpp --- 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()) { diff -r 1f67b110c1a3 -r 4f4f38a11cd2 layer/TimeValueLayer.cpp --- 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 || diff -r 1f67b110c1a3 -r 4f4f38a11cd2 view/Pane.cpp --- 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 #include #include @@ -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(*vi)) { waveformModel = (*vi)->getModel(); + workModel = waveformModel; + } else { + Model *m = (*vi)->getModel(); + if (dynamic_cast(m)) { + workModel = m; + } else if (m && dynamic_cast(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; diff -r 1f67b110c1a3 -r 4f4f38a11cd2 view/Pane.h --- 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); diff -r 1f67b110c1a3 -r 4f4f38a11cd2 view/View.cpp --- 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(model); - if (wfm) { + if (wfm || + dynamic_cast + (model->getSourceModel())) { completion = wfm->getAlignmentCompletion(); if (completion < 100) { text = tr("Alignment"); diff -r 1f67b110c1a3 -r 4f4f38a11cd2 view/ViewManager.cpp --- 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()) { diff -r 1f67b110c1a3 -r 4f4f38a11cd2 view/ViewManager.h --- 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;