changeset 660:8663a831838f tonioni

instrument is now "click" -- some other minor changes I don't remember
author matthiasm
date Thu, 20 Jun 2013 13:47:36 +0100
parents 65b966394650 (diff) 050404ae7799 (current diff)
children 1a0fdad4af4d
files layer/FlexiNoteLayer.cpp layer/FlexiNoteLayer.h layer/Layer.h view/Pane.cpp
diffstat 4 files changed, 54 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp	Thu Jun 20 10:58:40 2013 +0100
+++ b/layer/FlexiNoteLayer.cpp	Thu Jun 20 13:47:36 2013 +0100
@@ -1158,6 +1158,44 @@
 }
 
 void
+FlexiNoteLayer::addNote(View *v, QMouseEvent *e)
+{
+    std::cerr << "addNote" << std::endl;
+    if (!m_model) return;
+
+    long duration = 10000;
+    
+    long frame = v->getFrameForX(e->x());
+    float value = getValueForY(v, e->y());
+    
+    if (m_intelligentActions) {
+        long smallestRightNeighbourFrame = 0;
+        for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
+             i != m_model->getPoints().end(); ++i) {
+            FlexiNote currentNote = *i;
+            if (currentNote.frame > frame) {
+                smallestRightNeighbourFrame = currentNote.frame;
+                break;
+            }
+        }
+        
+        duration = std::min(smallestRightNeighbourFrame - frame + 1, duration);
+        duration = (duration > 0) ? duration : 0;
+    }
+
+    if (!m_intelligentActions || 
+        m_model->getPoints(frame).empty() && duration > 0)
+    {
+        FlexiNote newNote(frame, value, duration, 100, "new note");
+        FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
+          (m_model, tr("Add Point"));
+        command->addPoint(newNote);
+        finish(command);
+    }
+}
+
+
+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
@@ -1561,7 +1599,7 @@
     std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl;
     
     if (hasNotes) {
-        v->getLayer(1)->setDisplayExtents(minf*0.8,maxf*1.2); 
+        v->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5); 
         // 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	Thu Jun 20 10:58:40 2013 +0100
+++ b/layer/FlexiNoteLayer.h	Thu Jun 20 13:47:36 2013 +0100
@@ -56,6 +56,8 @@
 
     virtual void splitStart(View *v, QMouseEvent *);
     virtual void splitEnd(View *v, QMouseEvent *);
+    
+    virtual void addNote(View *v, QMouseEvent *e);
 
     virtual void mouseMoveEvent(View *v, QMouseEvent *);
 
--- a/layer/Layer.h	Thu Jun 20 10:58:40 2013 +0100
+++ b/layer/Layer.h	Thu Jun 20 13:47:36 2013 +0100
@@ -231,6 +231,7 @@
 
     virtual void splitStart(View *, QMouseEvent *) { }
     virtual void splitEnd(View *, QMouseEvent *) { }
+    virtual void addNote(View *v, QMouseEvent *e) { };
 
     // Measurement rectangle (or equivalent).  Unlike draw and edit,
     // the base Layer class can provide working implementations of
--- a/view/Pane.cpp	Thu Jun 20 10:58:40 2013 +0100
+++ b/view/Pane.cpp	Thu Jun 20 13:47:36 2013 +0100
@@ -2107,10 +2107,10 @@
     if (mode == ViewManager::NavigateMode ||
         mode == ViewManager::EditMode) {
 
-    Layer *layer = getSelectedLayer();
-    if (layer && layer->isLayerEditable()) {
-        if (layer->editOpen(this, e)) relocate = false;
-    }
+        Layer *layer = getSelectedLayer();
+        if (layer && layer->isLayerEditable()) {
+            if (layer->editOpen(this, e)) relocate = false;
+        }
 
     } else if (mode == ViewManager::MeasureMode) {
 
@@ -2134,6 +2134,14 @@
             m_dragStartMinValue = dmin;
         }
     }
+    
+    if (mode == ViewManager::NoteEditMode) {
+        std::cerr << "double click in note edit mode" << std::endl;
+        Layer *layer = getSelectedLayer();
+        if (layer && layer->isLayerEditable()) {
+            layer->addNote(this, e); 
+        }
+    }
 
     m_clickedInRange = false; // in case mouseReleaseEvent is not properly called
 }