# HG changeset patch # User Chris Cannam # Date 1416575757 0 # Node ID b23db4cef02fe49264ee030a3be61fede426db6e # Parent a67245dce0d4014d16e14b02b8aba2169f999895 Emit a signal when alignment completes diff -r a67245dce0d4 -r b23db4cef02f framework/Align.cpp --- a/framework/Align.cpp Fri Nov 21 11:48:39 2014 +0000 +++ b/framework/Align.cpp Fri Nov 21 13:15:57 2014 +0000 @@ -46,6 +46,26 @@ } } +QString +Align::getAlignmentTransformName() +{ + QSettings settings; + settings.beginGroup("Alignment"); + TransformId id = + settings.value("transform-id", + "vamp:match-vamp-plugin:match:path").toString(); + settings.endGroup(); + return id; +} + +bool +Align::canAlign() +{ + TransformId id = getAlignmentTransformName(); + TransformFactory *factory = TransformFactory::getInstance(); + return factory->haveTransform(id); +} + bool Align::alignModelViaTransform(Model *ref, Model *other) { @@ -87,7 +107,7 @@ Model *aggregateModel = new AggregateWaveModel(components); ModelTransformer::Input aggregate(aggregateModel); - TransformId id = "vamp:match-vamp-plugin:match:path"; //!!! configure + TransformId id = getAlignmentTransformName(); TransformFactory *tf = TransformFactory::getInstance(); @@ -126,11 +146,26 @@ AlignmentModel *alignmentModel = new AlignmentModel (reference, other, aggregateModel, path); + connect(alignmentModel, SIGNAL(completionChanged()), + this, SLOT(alignmentCompletionChanged())); + rm->setAlignment(alignmentModel); return true; } +void +Align::alignmentCompletionChanged() +{ + AlignmentModel *am = qobject_cast(sender()); + if (!am) return; + if (am->isReady()) { + disconnect(am, SIGNAL(completionChanged()), + this, SLOT(alignmentCompletionChanged())); + emit alignmentComplete(am); + } +} + bool Align::alignModelViaProgram(Model *ref, Model *other, QString program) { @@ -244,6 +279,8 @@ alignmentModel->setPathFrom(path); + emit alignmentComplete(alignmentModel); + } else { cerr << "ERROR: Align::alignmentProgramFinished: Aligner program " << "failed: exit code " << exitCode << ", status " << status diff -r a67245dce0d4 -r b23db4cef02f framework/Align.h --- a/framework/Align.h Fri Nov 21 11:48:39 2014 +0000 +++ b/framework/Align.h Fri Nov 21 13:15:57 2014 +0000 @@ -43,22 +43,38 @@ * starting a new one. * * The Align object must survive after this call, for at least as - * long as the alignment takes. There is currently no way in this - * API to discover when an alignment is complete -- the - * expectation is that the Align object will simply share the - * process or document lifespan. + * long as the alignment takes. The usual expectation is that the + * Align object will simply share the process or document + * lifespan. */ bool alignModel(Model *reference, Model *other); // via user preference bool alignModelViaTransform(Model *reference, Model *other); bool alignModelViaProgram(Model *reference, Model *other, QString program); + /** + * Return true if the alignment facility is available (relevant + * plugin installed, etc). + */ + static bool canAlign(); + QString getError() const { return m_error; } - + +signals: + /** + * Emitted when an alignment is successfully completed. The + * reference and other models can be queried from the alignment + * model. + */ + void alignmentComplete(AlignmentModel *alignment); + private slots: + void alignmentCompletionChanged(); void alignmentProgramFinished(int, QProcess::ExitStatus); private: + static QString getAlignmentTransformName(); + QString m_error; std::map m_processModels; }; diff -r a67245dce0d4 -r b23db4cef02f framework/Document.cpp --- a/framework/Document.cpp Fri Nov 21 11:48:39 2014 +0000 +++ b/framework/Document.cpp Fri Nov 21 13:15:57 2014 +0000 @@ -55,6 +55,9 @@ connect(this, SIGNAL(modelAboutToBeDeleted(Model *)), ModelTransformerFactory::getInstance(), SLOT(modelAboutToBeDeleted(Model *))); + + connect(m_align, SIGNAL(alignmentComplete(AlignmentModel *)), + this, SIGNAL(alignmentComplete(AlignmentModel *))); } Document::~Document() @@ -1033,24 +1036,10 @@ return (m_models.find(const_cast(model)) != m_models.end()); } -TransformId -Document::getAlignmentTransformName() +bool +Document::canAlign() { - QSettings settings; - settings.beginGroup("Alignment"); - TransformId id = - settings.value("transform-id", - "vamp:match-vamp-plugin:match:path").toString(); - settings.endGroup(); - return id; -} - -bool -Document::canAlign() -{ - TransformId id = getAlignmentTransformName(); - TransformFactory *factory = TransformFactory::getInstance(); - return factory->haveTransform(id); + return Align::canAlign(); } void diff -r a67245dce0d4 -r b23db4cef02f framework/Document.h --- a/framework/Document.h Fri Nov 21 11:48:39 2014 +0000 +++ b/framework/Document.h Fri Nov 21 13:15:57 2014 +0000 @@ -303,6 +303,8 @@ QString message); void modelRegenerationWarning(QString layerName, QString transformName, QString message); + + void alignmentComplete(AlignmentModel *); void alignmentFailed(QString message); void activity(QString); @@ -409,8 +411,6 @@ void writeBackwardCompatibleDerivation(QTextStream &, QString, Model *, const ModelRecord &) const; - static TransformId getAlignmentTransformName(); - void toXml(QTextStream &, QString, QString, bool asTemplate) const; void writePlaceholderMainModel(QTextStream &, QString) const;