# HG changeset patch # User matthiasm # Date 1371675945 -3600 # Node ID 902c7c9d77eaef3363711b7871b140aaec632097 # Parent c572a070522359e2c001973d0258ebad782cb190 vertical scale adapts to note range diff -r c572a0705223 -r 902c7c9d77ea layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Wed Jun 19 08:26:24 2013 +0100 +++ b/layer/FlexiNoteLayer.cpp Wed Jun 19 22:05:45 2013 +0100 @@ -1052,7 +1052,7 @@ { // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; - + if (!m_model || !m_editing) return; if (m_editingCommand) { @@ -1532,24 +1532,30 @@ float min = attributes.value("scaleMinimum").toFloat(&ok); float max = attributes.value("scaleMaximum").toFloat(&alsoOk); - if (ok && alsoOk) setDisplayExtents(min, max); + // if (ok && alsoOk) setDisplayExtents(min, max); } void -FlexiNoteLayer::setVerticalRangeToNoteRange() +FlexiNoteLayer::setVerticalRangeToNoteRange(View *v) { - float minf = std::numeric_limits::max();; + float minf = std::numeric_limits::max(); float maxf = 0; + bool hasNotes = 0; for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); i != m_model->getPoints().end(); ++i) { + hasNotes = 1; FlexiNote note = *i; if (note.value < minf) minf = note.value; - else if (note.value > maxf) maxf = note.value; - std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; + if (note.value > maxf) maxf = note.value; } - if (this) { - setDisplayExtents(minf,maxf); + std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; + + if (hasNotes) { + v->getLayer(1)->setDisplayExtents(minf*0.8,maxf*1.2); + // MM: this is a hack because we rely on + // * this layer being automatically aligned to layer 1 + // * layer one is a log frequency layer. } } diff -r c572a0705223 -r 902c7c9d77ea layer/FlexiNoteLayer.h --- a/layer/FlexiNoteLayer.h Wed Jun 19 08:26:24 2013 +0100 +++ b/layer/FlexiNoteLayer.h Wed Jun 19 22:05:45 2013 +0100 @@ -142,7 +142,7 @@ void setProperties(const QXmlAttributes &attributes); - void setVerticalRangeToNoteRange(); + void setVerticalRangeToNoteRange(View *v); protected: void getScaleExtents(View *, float &min, float &max, bool &log) const;