changeset 875:0e674f1bbf08 tonioni

(Very slowly) perform local reanalysis when dragging a note up or down
author Chris Cannam
date Tue, 11 Nov 2014 14:11:07 +0000
parents 7a80fa6a6dfc
children b62c2785ed83
files layer/FlexiNoteLayer.cpp layer/FlexiNoteLayer.h view/Pane.cpp
diffstat 3 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp	Tue Nov 11 12:55:30 2014 +0000
+++ b/layer/FlexiNoteLayer.cpp	Tue Nov 11 14:11:07 2014 +0000
@@ -1166,19 +1166,30 @@
         }
         m_editingPoint.frame = dragFrame;
         m_editingPoint.value = value;
+
+        // Re-analyse region within +/- 1 semitone of the dragged value
+        float cents = 0;
+        int midiPitch = Pitch::getPitchForFrequency(m_editingPoint.value, &cents);
+        float lower = Pitch::getFrequencyForPitch(midiPitch - 1, cents);
+        float higher = Pitch::getFrequencyForPitch(midiPitch + 1, cents);
+        
+        emit reAnalyseRegion(m_editingPoint.frame,
+                             m_editingPoint.frame + m_editingPoint.duration,
+                             lower, higher);
         break;
     }
     case SplitNote: // nothing
         break;
     }
-    updateNoteValue(v, m_editingPoint);
+
+//    updateNoteValueFromPitchCurve(v, m_editingPoint);
     m_editingCommand->addPoint(m_editingPoint);
+
     std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl;
-    
 }
 
 void
-FlexiNoteLayer::editEnd(View *, QMouseEvent *e)
+FlexiNoteLayer::editEnd(View *v, QMouseEvent *e)
 {
 //    SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
     std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
@@ -1189,6 +1200,10 @@
 
         QString newName = m_editingCommand->getName();
 
+        m_editingCommand->deletePoint(m_editingPoint);
+        updateNoteValueFromPitchCurve(v, m_editingPoint);
+        m_editingCommand->addPoint(m_editingPoint);
+
         if (m_editingPoint.frame != m_originalPoint.frame) {
             if (m_editingPoint.value != m_originalPoint.value) {
                 newName = tr("Edit Point");
@@ -1280,10 +1295,10 @@
                            note.level, note.label);
                        
         if (m_intelligentActions) {
-            if (updateNoteValue(v, newNote1)) {
+            if (updateNoteValueFromPitchCurve(v, newNote1)) {
                 command->addPoint(newNote1);
             }
-            if (updateNoteValue(v, newNote2)) {
+            if (updateNoteValueFromPitchCurve(v, newNote2)) {
                 command->addPoint(newNote2);
             }
         } else {
@@ -1389,7 +1404,7 @@
 
         command->deletePoint(note);
 
-        if (updateNoteValue(v, newNote)) {
+        if (updateNoteValueFromPitchCurve(v, newNote)) {
             command->addPoint(newNote);
         }
     }
@@ -1435,13 +1450,14 @@
         ++i;
     }
 
-    updateNoteValue(v, newNote);
+    updateNoteValueFromPitchCurve(v, newNote);
     command->addPoint(newNote);
     finish(command);
 }
 
 bool
-FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point &note) const
+FlexiNoteLayer::updateNoteValueFromPitchCurve(View *v,
+                                              FlexiNoteModel::Point &note) const
 {
     SparseTimeValueModel *model = getAssociatedPitchModel(v);
     if (!model) return false;
@@ -1476,6 +1492,8 @@
     } else {
         median = pitchValues[size/2];
     }
+
+    std::cerr << "updateNoteValueFromPitchCurve: corrected from " << note.value << " to median " << median << std::endl;
     
     note.value = median;
 
--- a/layer/FlexiNoteLayer.h	Tue Nov 11 12:55:30 2014 +0000
+++ b/layer/FlexiNoteLayer.h	Tue Nov 11 14:11:07 2014 +0000
@@ -163,6 +163,9 @@
     virtual float getValueForY(View *v, int y) const;
     virtual QString getScaleUnits() const;
 
+signals:
+    void reAnalyseRegion(int, int, float, float);
+    
 protected:
     void getScaleExtents(View *, float &min, float &max, bool &log) const;
     bool shouldConvertMIDIToHz() const;
@@ -173,9 +176,13 @@
 
     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;
+    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;
-    bool updateNoteValue(View *v, FlexiNoteModel::Point &note) const;
+    bool updateNoteValueFromPitchCurve(View *v,
+                                       FlexiNoteModel::Point &note) const;
     void splitNotesAt(View *v, int frame, QMouseEvent *e);
 
     FlexiNoteModel *m_model;
--- a/view/Pane.cpp	Tue Nov 11 12:55:30 2014 +0000
+++ b/view/Pane.cpp	Tue Nov 11 14:11:07 2014 +0000
@@ -1740,9 +1740,9 @@
 
             if (!editSelectionDrag(e)) {
 
-                Layer *layer = getInteractionLayer();
-
-                if (layer && layer->isLayerEditable()) {
+                Layer *layer = getTopFlexiNoteLayer();
+
+                if (layer) {
 
                     int x = e->x();
                     int y = e->y();