Mercurial > hg > svgui
changeset 320:984c1975f1ff
* Some tidying up to handling of alignment; add alignment status label to
pane; ensure alignment when dragging with mouse as well as when playing
author | Chris Cannam |
---|---|
date | Thu, 25 Oct 2007 14:32:23 +0000 |
parents | 2a50c1ecc990 |
children | 973a0272b712 |
files | layer/Colour3DPlotLayer.cpp layer/ImageLayer.cpp layer/Layer.cpp layer/Layer.h layer/NoteLayer.cpp layer/SliceLayer.cpp layer/SpectrogramLayer.cpp layer/TextLayer.cpp layer/TimeInstantLayer.cpp layer/TimeValueLayer.cpp layer/WaveformLayer.cpp view/Pane.cpp view/Pane.h view/PaneStack.cpp view/PaneStack.h view/View.cpp view/View.h |
diffstat | 17 files changed, 200 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/Colour3DPlotLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -56,12 +56,7 @@ m_model = model; if (!m_model || !m_model->isOK()) return; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid())); connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
--- a/layer/ImageLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/ImageLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -64,20 +64,7 @@ if (m_model == model) return; m_model = model; - connect(m_model, SIGNAL(modelChanged()), - this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); - -// connect(m_model, SIGNAL(modelChanged()), -// this, SLOT(checkAddRemotes())); - -// std::cerr << "ImageLayer::setModel(" << model << ")" << std::endl; - -// checkAddRemotes(); + connectSignals(m_model); emit modelReplaced(); }
--- a/layer/Layer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/Layer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -40,6 +40,22 @@ // std::cerr << "Layer::~Layer(" << this << ")" << std::endl; } +void +Layer::connectSignals(const Model *model) +{ + connect(model, SIGNAL(modelChanged()), + this, SIGNAL(modelChanged())); + + connect(model, SIGNAL(modelChanged(size_t, size_t)), + this, SIGNAL(modelChanged(size_t, size_t))); + + connect(model, SIGNAL(completionChanged()), + this, SIGNAL(modelCompletionChanged())); + + connect(model, SIGNAL(alignmentCompletionChanged()), + this, SIGNAL(modelAlignmentCompletionChanged())); +} + QString Layer::getPropertyContainerIconName() const {
--- a/layer/Layer.h Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/Layer.h Thu Oct 25 14:32:23 2007 +0000 @@ -447,6 +447,7 @@ signals: void modelChanged(); void modelCompletionChanged(); + void modelAlignmentCompletionChanged(); void modelChanged(size_t startFrame, size_t endFrame); void modelReplaced(); @@ -458,6 +459,8 @@ void verticalZoomChanged(); protected: + void connectSignals(const Model *); + struct MeasureRect { mutable QRect pixrect;
--- a/layer/NoteLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/NoteLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -55,12 +55,7 @@ if (m_model == model) return; m_model = model; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); // std::cerr << "NoteLayer::setModel(" << model << ")" << std::endl;
--- a/layer/SliceLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/SliceLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -66,14 +66,7 @@ m_sliceableModel = sliceable; - connect(m_sliceableModel, SIGNAL(modelChanged()), - this, SIGNAL(modelChanged())); - - connect(m_sliceableModel, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_sliceableModel, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_sliceableModel); emit modelReplaced(); }
--- a/layer/SpectrogramLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -127,12 +127,7 @@ if (!m_model || !m_model->isOK()) return; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid())); connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
--- a/layer/TextLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/TextLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -48,12 +48,7 @@ if (m_model == model) return; m_model = model; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); // std::cerr << "TextLayer::setModel(" << model << ")" << std::endl;
--- a/layer/TimeInstantLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -53,12 +53,7 @@ if (m_model == model) return; m_model = model; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); std::cerr << "TimeInstantLayer::setModel(" << model << ")" << std::endl;
--- a/layer/TimeValueLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/TimeValueLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -59,12 +59,7 @@ if (m_model == model) return; m_model = model; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); // std::cerr << "TimeValueLayer::setModel(" << model << ")" << std::endl;
--- a/layer/WaveformLayer.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/layer/WaveformLayer.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -76,15 +76,7 @@ m_cacheValid = false; if (!m_model || !m_model->isOK()) return; - connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(m_model, SIGNAL(modelChanged(size_t, size_t)), - this, SIGNAL(modelChanged(size_t, size_t))); - - connect(m_model, SIGNAL(completionChanged()), - this, SIGNAL(modelCompletionChanged())); - - connect(model, SIGNAL(alignmentCompletionChanged()), - this, SIGNAL(modelCompletionChanged())); + connectSignals(m_model); emit modelReplaced();
--- a/view/Pane.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/view/Pane.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -448,6 +448,12 @@ drawDurationAndRate(r, waveformModel, sampleRate, paint); } + if (waveformModel && + m_manager && + m_manager->getAlignMode()) { + drawAlignmentStatus(r, paint, waveformModel); + } + if (m_manager && m_manager->shouldShowLayerNames()) { drawLayerNames(r, paint); @@ -711,6 +717,59 @@ } void +Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model) +{ + const Model *reference = model->getAlignmentReference(); +/* + if (!reference) { + std::cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << std::endl; + } else if (reference == model) { + std::cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << std::endl; + } else { + std::cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << std::endl; + } +*/ + QString text; + int completion = 100; + + if (reference == model) { + text = tr("Reference"); + } else if (!reference) { + text = tr("Unaligned"); + } else { + completion = model->getAlignmentCompletion(); + if (completion == 0) { + text = tr("Unaligned"); + } else if (completion < 100) { + text = tr("Aligning: %1%").arg(completion); + } else { + text = tr("Aligned"); + } + } + + 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); + + drawVisibleText(paint, m_scaleWidth + 5, + paint.fontMetrics().ascent() + 5, text, OutlinedText); + + paint.restore(); +} + +void +Pane::modelAlignmentCompletionChanged() +{ + View::modelAlignmentCompletionChanged(); + update(QRect(0, 0, 300, 100)); +} + +void Pane::drawLayerNames(QRect r, QPainter &paint) { int fontHeight = paint.fontMetrics().height();
--- a/view/Pane.h Mon Oct 22 14:24:31 2007 +0000 +++ b/view/Pane.h Thu Oct 25 14:32:23 2007 +0000 @@ -73,6 +73,7 @@ virtual void toolModeChanged(); virtual void zoomWheelsEnabledChanged(); virtual void viewZoomLevelChanged(View *v, unsigned long z, bool locked); + virtual void modelAlignmentCompletionChanged(); virtual void horizontalThumbwheelMoved(int value); virtual void verticalThumbwheelMoved(int value); @@ -104,6 +105,7 @@ void drawDurationAndRate(QRect, const Model *, int, QPainter &); void drawLayerNames(QRect, QPainter &); void drawEditingSelection(QPainter &); + void drawAlignmentStatus(QRect, QPainter &, const Model *); virtual bool render(QPainter &paint, int x0, size_t f0, size_t f1);
--- a/view/PaneStack.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/view/PaneStack.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -503,3 +503,44 @@ emit dropAccepted(pane, text); } +void +PaneStack::sizePanesEqually() +{ + QList<int> sizes = m_splitter->sizes(); + if (sizes.empty()) return; + + int count = sizes.size(); + + int total = 0; + for (int i = 0; i < count; ++i) { + total += sizes[i]; + } + + if (total == 0) return; + + sizes.clear(); + + int each = total / count; + int remaining = total; + + for (int i = 0; i < count; ++i) { + if (i == count - 1) { + sizes.push_back(remaining); + } else { + sizes.push_back(each); + remaining -= each; + } + } + +/* + std::cerr << "sizes: "; + for (int i = 0; i < sizes.size(); ++i) { + std::cerr << sizes[i] << " "; + } + std::cerr << std::endl; +*/ + + m_splitter->setSizes(sizes); +} + +
--- a/view/PaneStack.h Mon Oct 22 14:24:31 2007 +0000 +++ b/view/PaneStack.h Thu Oct 25 14:32:23 2007 +0000 @@ -66,6 +66,8 @@ void setPropertyStackMinWidth(int mw); + void sizePanesEqually(); + signals: void currentPaneChanged(Pane *pane); void currentLayerChanged(Pane *pane, Layer *layer);
--- a/view/View.cpp Mon Oct 22 14:24:31 2007 +0000 +++ b/view/View.cpp Thu Oct 25 14:32:23 2007 +0000 @@ -326,7 +326,8 @@ changeVisible = true; } - if (e) emit centreFrameChanged(f, m_followPan, m_followPlay); + if (e) emit centreFrameChanged(alignFromReference(f), + m_followPan, m_followPlay); } return changeVisible; @@ -531,6 +532,8 @@ this, SLOT(modelChanged())); connect(layer, SIGNAL(modelCompletionChanged()), this, SLOT(modelCompletionChanged())); + connect(layer, SIGNAL(modelAlignmentCompletionChanged()), + this, SLOT(modelAlignmentCompletionChanged())); connect(layer, SIGNAL(modelChanged(size_t, size_t)), this, SLOT(modelChanged(size_t, size_t))); connect(layer, SIGNAL(modelReplaced()), @@ -572,6 +575,8 @@ this, SLOT(modelChanged())); disconnect(layer, SIGNAL(modelCompletionChanged()), this, SLOT(modelCompletionChanged())); + disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()), + this, SLOT(modelAlignmentCompletionChanged())); disconnect(layer, SIGNAL(modelChanged(size_t, size_t)), this, SLOT(modelChanged(size_t, size_t))); disconnect(layer, SIGNAL(modelReplaced()), @@ -804,6 +809,15 @@ } void +View::modelAlignmentCompletionChanged() +{ + std::cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << std::endl; + + QObject *obj = sender(); + checkProgress(obj); +} + +void View::modelReplaced() { #ifdef DEBUG_VIEW_WIDGET_PAINT @@ -858,7 +872,7 @@ View::globalCentreFrameChanged(unsigned long f) { if (m_followPan) { - setCentreFrame(f, false); + setCentreFrame(alignToReference(f), false); } } @@ -1074,40 +1088,68 @@ return models; } -int -View::getAlignedPlaybackFrame() const +Model * +View::getAligningModel() const { - if (!m_manager) return 0; - if (!m_manager->getAlignMode() || + if (!m_manager || + !m_manager->getAlignMode() || !m_manager->getPlaybackModel()) { - return m_manager->getPlaybackFrame(); + return 0; } - RangeSummarisableTimeValueModel *waveformModel = 0; - for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { + Model *anyModel = 0; + Model *goodModel = 0; - if (!*i) continue; - if (dynamic_cast<TimeRulerLayer *>(*i)) continue; + for (LayerList::const_iterator i = m_layers.begin(); + i != m_layers.end(); ++i) { + + Layer *layer = *i; + + if (!layer) continue; + if (dynamic_cast<TimeRulerLayer *>(layer)) continue; Model *model = (*i)->getModel(); if (!model) continue; - waveformModel = dynamic_cast<RangeSummarisableTimeValueModel *>(model); - if (!waveformModel) { - waveformModel = dynamic_cast<RangeSummarisableTimeValueModel *> - (model->getSourceModel()); + if (model->getAlignmentReference()) { + anyModel = model; + if (layer->isLayerOpaque() || + dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { + goodModel = model; + } } + } - if (waveformModel) break; - } + if (goodModel) return goodModel; + else return anyModel; +} + +size_t +View::alignFromReference(size_t f) const +{ + Model *aligningModel = getAligningModel(); + if (!aligningModel) return f; + return aligningModel->alignFromReference(f); +} + +size_t +View::alignToReference(size_t f) const +{ + Model *aligningModel = getAligningModel(); + if (!aligningModel) return f; + return aligningModel->alignToReference(f); +} + +int +View::getAlignedPlaybackFrame() const +{ + Model *aligningModel = getAligningModel(); int pf = m_manager->getPlaybackFrame(); - if (!waveformModel) return pf; + if (!aligningModel) return pf; - RangeSummarisableTimeValueModel *pm = - dynamic_cast<RangeSummarisableTimeValueModel *> - (m_manager->getPlaybackModel()); + Model *pm = m_manager->getPlaybackModel(); // std::cerr << "View[" << this << "]::getAlignedPlaybackFrame: pf = " << pf; @@ -1116,7 +1158,7 @@ // std::cerr << " -> " << pf; } - int af = waveformModel->alignToReference(pf); + int af = aligningModel->alignToReference(pf); // std::cerr << ", aligned = " << af << std::endl; return af;
--- a/view/View.h Mon Oct 22 14:24:31 2007 +0000 +++ b/view/View.h Thu Oct 25 14:32:23 2007 +0000 @@ -257,6 +257,9 @@ ModelSet getModels(); //!!! + Model *getAligningModel() const; + size_t alignFromReference(size_t) const; + size_t alignToReference(size_t) const; int getAlignedPlaybackFrame() const; signals: @@ -280,6 +283,7 @@ virtual void modelChanged(); virtual void modelChanged(size_t startFrame, size_t endFrame); virtual void modelCompletionChanged(); + virtual void modelAlignmentCompletionChanged(); virtual void modelReplaced(); virtual void layerParametersChanged(); virtual void layerParameterRangesChanged();