changeset 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 56ba2b03508e
children 8d5df70b5ed7
files layer/FlexiNoteLayer.cpp layer/FlexiNoteLayer.h
diffstat 2 files changed, 20 insertions(+), 7 deletions(-) [+]
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;
--- a/layer/FlexiNoteLayer.h	Thu Mar 06 15:16:25 2014 +0000
+++ b/layer/FlexiNoteLayer.h	Tue Mar 25 13:06:27 2014 +0000
@@ -28,7 +28,7 @@
 
 class View;
 class QPainter;
-
+class SparseTimeValueModel;
 
 class FlexiNoteLayer : public SingleColourLayer,
                        public VerticalScaleLayer
@@ -169,6 +169,7 @@
     bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const;
     bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const;
     void getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const;
+    SparseTimeValueModel *getAssociatedPitchModel(View *v) const;
     void updateNoteValue(View *v, FlexiNoteModel::Point &note) const;
 
     FlexiNoteModel *m_model;