diff transform/TransformFactory.cpp @ 118:b4110b17bca8

* Fix #1672407 confused by plugin-named files in cwd (or home?) * Fix #1491848 crash when loading new file while transform plugin runs * Fix #1502287 Background remains black after spectrogram layer deleted * Fix #1604477 Replacing the main audio file silences secondary audio file * Fix failure to initialise property box layout to last preference on startup * Fix resample/wrong-rate display in Pane, ensure that right rate is chosen if all current models have an acceptable rate even if previous main model had a different one * Fix "global zoom" broken in previous commit * Some fixes to spectrogram cache area updating (makes spectrogram appear more quickly, previously it had a tendency to refresh with empty space) * Fixes to colour 3d plot normalization
author Chris Cannam
date Thu, 08 Mar 2007 16:53:08 +0000
parents 58f21cf235c7
children 006c90387f40
line wrap: on
line diff
--- a/transform/TransformFactory.cpp	Wed Mar 07 18:00:49 2007 +0000
+++ b/transform/TransformFactory.cpp	Thu Mar 08 16:53:08 2007 +0000
@@ -717,7 +717,7 @@
 Transform *
 TransformFactory::createTransform(TransformId identifier, Model *inputModel,
                                   const PluginTransform::ExecutionContext &context,
-                                  QString configurationXml, bool start)
+                                  QString configurationXml)
 {
     Transform *transform = 0;
 
@@ -744,8 +744,7 @@
         return transform;
     }
 
-    if (start && transform) transform->start();
-    transform->setObjectName(identifier);
+    if (transform) transform->setObjectName(identifier);
     return transform;
 }
 
@@ -755,12 +754,14 @@
                             QString configurationXml)
 {
     Transform *t = createTransform(identifier, inputModel, context,
-                                   configurationXml, false);
+                                   configurationXml);
 
     if (!t) return 0;
 
     connect(t, SIGNAL(finished()), this, SLOT(transformFinished()));
 
+    m_runningTransforms.insert(t);
+
     t->start();
     Model *model = t->detachOutputModel();
 
@@ -787,12 +788,51 @@
     QObject *s = sender();
     Transform *transform = dynamic_cast<Transform *>(s);
     
+    std::cerr << "TransformFactory::transformFinished(" << transform << ")" << std::endl;
+
     if (!transform) {
 	std::cerr << "WARNING: TransformFactory::transformFinished: sender is not a transform" << std::endl;
 	return;
     }
 
+    if (m_runningTransforms.find(transform) == m_runningTransforms.end()) {
+        std::cerr << "WARNING: TransformFactory::transformFinished(" 
+                  << transform
+                  << "): I have no record of this transform running!"
+                  << std::endl;
+    }
+
+    m_runningTransforms.erase(transform);
+
     transform->wait(); // unnecessary but reassuring
     delete transform;
 }
 
+void
+TransformFactory::modelAboutToBeDeleted(Model *m)
+{
+    TransformSet affected;
+
+    for (TransformSet::iterator i = m_runningTransforms.begin();
+         i != m_runningTransforms.end(); ++i) {
+
+        Transform *t = *i;
+
+        if (t->getInputModel() == m || t->getOutputModel() == m) {
+            affected.insert(t);
+        }
+    }
+
+    for (TransformSet::iterator i = affected.begin();
+         i != affected.end(); ++i) {
+
+        Transform *t = *i;
+
+        t->abandon();
+
+        t->wait(); // this should eventually call back on
+                   // transformFinished, which will remove from
+                   // m_runningTransforms and delete.
+    }
+}
+