diff layer/FlexiNoteLayer.cpp @ 745:d50f91fe374e tonioni

Fix (to some extent) the "gross assumption about layer order" and thus #840 Note split adaptation broken
author Chris Cannam
date Tue, 25 Mar 2014 13:06:27 +0000
parents 137d3ff48f73
children 8d5df70b5ed7
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp	Thu Mar 06 15:16:25 2014 +0000
+++ b/layer/FlexiNoteLayer.cpp	Tue Mar 25 13:06:27 2014 +0000
@@ -1286,16 +1286,28 @@
     }
 }
 
+SparseTimeValueModel *
+FlexiNoteLayer::getAssociatedPitchModel(View *v) const
+{
+    // Better than we used to do, but still not very satisfactory
+
+    for (int i = 0; i < v->getLayerCount(); ++i) {
+        Layer *layer = v->getLayer(i);
+        if (layer) {
+            SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *>
+                (layer->getModel());
+            if (model && model->getScaleUnits() == "Hz") {
+                return model;
+            }
+        }
+    }
+    return 0;
+}
 
 void
 FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point &note) const
 {
-    //GF: update the note value conforming the median of pitch values in the underlying note layer
-    Layer *layer = v->getLayer(1); // GF: !!! gross assumption about correct layer order
-    SparseTimeValueModel *model = 0;
-    if (layer && layer->getModel()) 
-        model = dynamic_cast<SparseTimeValueModel *>(layer->getModel());
-        
+    SparseTimeValueModel *model = getAssociatedPitchModel(v);
     if (!model) return;
         
     std::cerr << model->getTypeName() << std::endl;