# HG changeset patch # User Chris Cannam # Date 1193322743 0 # Node ID 984c1975f1ff373de578abdb351f2ee2e859c080 # Parent 2a50c1ecc990444c9ebaac09f30ff4265dfe5286 * Some tidying up to handling of alignment; add alignment status label to pane; ensure alignment when dragging with mouse as well as when playing diff -r 2a50c1ecc990 -r 984c1975f1ff layer/Colour3DPlotLayer.cpp --- 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)), diff -r 2a50c1ecc990 -r 984c1975f1ff layer/ImageLayer.cpp --- 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(); } diff -r 2a50c1ecc990 -r 984c1975f1ff layer/Layer.cpp --- 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 { diff -r 2a50c1ecc990 -r 984c1975f1ff layer/Layer.h --- 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; diff -r 2a50c1ecc990 -r 984c1975f1ff layer/NoteLayer.cpp --- 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; diff -r 2a50c1ecc990 -r 984c1975f1ff layer/SliceLayer.cpp --- 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(); } diff -r 2a50c1ecc990 -r 984c1975f1ff layer/SpectrogramLayer.cpp --- 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)), diff -r 2a50c1ecc990 -r 984c1975f1ff layer/TextLayer.cpp --- 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; diff -r 2a50c1ecc990 -r 984c1975f1ff layer/TimeInstantLayer.cpp --- 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; diff -r 2a50c1ecc990 -r 984c1975f1ff layer/TimeValueLayer.cpp --- 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; diff -r 2a50c1ecc990 -r 984c1975f1ff layer/WaveformLayer.cpp --- 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(); diff -r 2a50c1ecc990 -r 984c1975f1ff view/Pane.cpp --- 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(); diff -r 2a50c1ecc990 -r 984c1975f1ff view/Pane.h --- 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); diff -r 2a50c1ecc990 -r 984c1975f1ff view/PaneStack.cpp --- 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 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); +} + + diff -r 2a50c1ecc990 -r 984c1975f1ff view/PaneStack.h --- 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); diff -r 2a50c1ecc990 -r 984c1975f1ff view/View.cpp --- 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(*i)) continue; + for (LayerList::const_iterator i = m_layers.begin(); + i != m_layers.end(); ++i) { + + Layer *layer = *i; + + if (!layer) continue; + if (dynamic_cast(layer)) continue; Model *model = (*i)->getModel(); if (!model) continue; - waveformModel = dynamic_cast(model); - if (!waveformModel) { - waveformModel = dynamic_cast - (model->getSourceModel()); + if (model->getAlignmentReference()) { + anyModel = model; + if (layer->isLayerOpaque() || + dynamic_cast(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 - (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; diff -r 2a50c1ecc990 -r 984c1975f1ff view/View.h --- 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();