changeset 656:902c7c9d77ea tonioni

vertical scale adapts to note range
author matthiasm
date Wed, 19 Jun 2013 22:05:45 +0100
parents c572a0705223
children ac26de7b727a
files layer/FlexiNoteLayer.cpp layer/FlexiNoteLayer.h
diffstat 2 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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<float>::max();;
+    float minf = std::numeric_limits<float>::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.
     }
 }
 
--- 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;