Mercurial > hg > svapp
diff framework/Document.cpp @ 582:b2d49e7c4149
Merge from branch 3.0-integration
author | Chris Cannam |
---|---|
date | Fri, 13 Jan 2017 10:29:55 +0000 |
parents | 36aa947ec962 |
children | d122d3595a32 |
line wrap: on
line diff
--- a/framework/Document.cpp Sat Jan 30 12:05:14 2016 +0000 +++ b/framework/Document.cpp Fri Jan 13 10:29:55 2017 +0000 @@ -15,6 +15,8 @@ #include "Document.h" +#include "Align.h" + #include "data/model/WaveFileModel.h" #include "data/model/WritableWaveFileModel.h" #include "data/model/DenseThreeDimensionalModel.h" @@ -36,10 +38,8 @@ #include <iostream> #include <typeinfo> -// For alignment: -#include "data/model/AggregateWaveModel.h" -#include "data/model/SparseTimeValueModel.h" #include "data/model/AlignmentModel.h" +#include "Align.h" using std::vector; @@ -49,7 +49,8 @@ Document::Document() : m_mainModel(0), - m_autoAlignment(false) + m_autoAlignment(false), + m_align(new Align()) { connect(this, SIGNAL(modelAboutToBeDeleted(Model *)), @@ -60,6 +61,9 @@ SIGNAL(transformFailed(QString, QString)), this, SIGNAL(modelGenerationFailed(QString, QString))); + + connect(m_align, SIGNAL(alignmentComplete(AlignmentModel *)), + this, SIGNAL(alignmentComplete(AlignmentModel *))); } Document::~Document() @@ -736,6 +740,10 @@ // remember is correct for what was actually applied, with the // current plugin version. + //!!! would be nice to short-circuit this -- the version is + //!!! static data, shouldn't have to construct a plugin for it + //!!! (which may be expensive in Piper-world) + Transform applied = transforms[j]; applied.setPluginVersion (TransformFactory::getInstance()-> @@ -1038,24 +1046,10 @@ return (m_models.find(const_cast<Model *>(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 @@ -1090,75 +1084,10 @@ return; } - // This involves creating three new models: - - // 1. an AggregateWaveModel to provide the mixdowns of the main - // model and the new model in its two channels, as input to the - // MATCH plugin - - // 2. a SparseTimeValueModel, which is the model automatically - // created by FeatureExtractionPluginTransformer when running the - // MATCH plugin (thus containing the alignment path) - - // 3. an AlignmentModel, which stores the path model and carries - // out alignment lookups on it. - - // The first two of these are provided as arguments to the - // constructor for the third, which takes responsibility for - // deleting them. The AlignmentModel, meanwhile, is passed to the - // new model we are aligning, which also takes responsibility for - // it. We should not have to delete any of these new models here. - - AggregateWaveModel::ChannelSpecList components; - - components.push_back(AggregateWaveModel::ModelChannelSpec - (m_mainModel, -1)); - - components.push_back(AggregateWaveModel::ModelChannelSpec - (rm, -1)); - - Model *aggregateModel = new AggregateWaveModel(components); - ModelTransformer::Input aggregate(aggregateModel); - - TransformId id = "vamp:match-vamp-plugin:match:path"; //!!! configure - - TransformFactory *tf = TransformFactory::getInstance(); - - Transform transform = tf->getDefaultTransformFor - (id, aggregateModel->getSampleRate()); - - transform.setStepSize(transform.getBlockSize()/2); - transform.setParameter("serialise", 1); - - SVDEBUG << "Document::alignModel: Alignment transform step size " << transform.getStepSize() << ", block size " << transform.getBlockSize() << endl; - - ModelTransformerFactory *mtf = ModelTransformerFactory::getInstance(); - - QString message; - Model *transformOutput = mtf->transform(transform, aggregate, message); - - if (!transformOutput) { - transform.setStepSize(0); - transformOutput = mtf->transform(transform, aggregate, message); + if (!m_align->alignModel(m_mainModel, rm)) { + cerr << "Alignment failed: " << m_align->getError() << endl; + emit alignmentFailed(m_align->getError()); } - - SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *> - (transformOutput); - - if (!path) { - cerr << "Document::alignModel: ERROR: Failed to create alignment path (no MATCH plugin?)" << endl; - emit alignmentFailed(id, message); - delete transformOutput; - delete aggregateModel; - return; - } - - path->setCompletion(0); - - AlignmentModel *alignmentModel = new AlignmentModel - (m_mainModel, model, aggregateModel, path); - - rm->setAlignment(alignmentModel); } void