# HG changeset patch # User Chris Cannam # Date 1395752787 0 # Node ID d50f91fe374e7799be924e05f0811e158cb8ef73 # Parent 56ba2b03508ecc2f5952a8db978360503845e711 Fix (to some extent) the "gross assumption about layer order" and thus #840 Note split adaptation broken diff -r 56ba2b03508e -r d50f91fe374e layer/FlexiNoteLayer.cpp --- 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 + (layer->getModel()); + if (model && model->getScaleUnits() == "Hz") { + return model; + } + } + } + return 0; +} void FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point ¬e) 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(layer->getModel()); - + SparseTimeValueModel *model = getAssociatedPitchModel(v); if (!model) return; std::cerr << model->getTypeName() << std::endl; diff -r 56ba2b03508e -r d50f91fe374e layer/FlexiNoteLayer.h --- 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 ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const; + SparseTimeValueModel *getAssociatedPitchModel(View *v) const; void updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const; FlexiNoteModel *m_model;