diff framework/Align.cpp @ 428:b23db4cef02f alignment_view

Emit a signal when alignment completes
author Chris Cannam
date Fri, 21 Nov 2014 13:15:57 +0000
parents 5882462fa747
children adfb2948fabf
line wrap: on
line diff
--- 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<AlignmentModel *>(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