changeset 281:2a18f846dd6c

implemented move by one note (replacing big jumps left/right)
author matthiasm
date Thu, 22 May 2014 17:49:58 +0100
parents 3fe77ed06eba
children 118775decf28
files .hgsubstate src/MainWindow.cpp src/MainWindow.h
diffstat 3 files changed, 75 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Thu May 22 11:21:36 2014 +0100
+++ b/.hgsubstate	Thu May 22 17:49:58 2014 +0100
@@ -3,5 +3,5 @@
 d1f89559321a4a194bf98c43bb1df88c82ce1078 pyin
 27d4e7152c954bf3c4387319db088fb3cd02436b sv-dependency-builds
 36efd75d7b7b1bb88dbe6c15992b1ffe3e40d452 svapp
-2175c2ebd5c6ff89360cd0904ecd46b11914df45 svcore
-a6b87176b2599136d833e648316f804387f2990b svgui
+515c654770ca624a92b1f2f54860ea0aed2ac108 svcore
+c2291e22bf0c29aef6c33420b3654db7deeedfe7 svgui
--- a/src/MainWindow.cpp	Thu May 22 11:21:36 2014 +0100
+++ b/src/MainWindow.cpp	Thu May 22 17:49:58 2014 +0100
@@ -656,8 +656,10 @@
     menu->addAction(m_showCandidatesAction);
     m_rightButtonMenu->addAction(m_showCandidatesAction);
     
-    action = new QAction(tr("Remove Pitches"), this);
-    action->setShortcut(tr("Ctrl+Backspace"));
+
+    // action = new QAction(tr("Remove Pitches"), this);
+    action = toolbar->addAction(il.load("navigate"), tr("Navigate"));
+    action->setShortcut(tr("Backspace"));
     action->setStatusTip(tr("Remove all pitch estimates within the selected region, making it unvoiced"));
     m_keyReference->registerShortcut(action);
     connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
@@ -733,18 +735,18 @@
     m_keyReference->registerShortcut(action);
     menu->addAction(action);
     
-    action = new QAction(tr("&Jump Left"), this);
+    action = new QAction(tr("&One Note Left"), this);
     action->setShortcut(tr("Ctrl+Left"));
-    action->setStatusTip(tr("Scroll the current pane a big step to the left"));
-    connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
+    action->setStatusTip(tr("Move cursor to the preceding note (or silence) onset."));
+    connect(action, SIGNAL(triggered()), this, SLOT(moveOneNoteLeft()));
     connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
     m_keyReference->registerShortcut(action);
     menu->addAction(action);
     
-    action = new QAction(tr("J&ump Right"), this);
+    action = new QAction(tr("O&ne Note Right"), this);
     action->setShortcut(tr("Ctrl+Right"));
-    action->setStatusTip(tr("Scroll the current pane a big step to the right"));
-    connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
+    action->setStatusTip(tr("Move cursor to the succeeding note (or silence)."));
+    connect(action, SIGNAL(triggered()), this, SLOT(moveOneNoteRight()));
     connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
     m_keyReference->registerShortcut(action);
     menu->addAction(action);
@@ -1121,6 +1123,64 @@
     Pane::registerShortcuts(*m_keyReference);
 }
 
+
+void
+MainWindow::moveOneNoteRight()
+{
+    // cerr << "MainWindow::moveOneNoteRight" << endl;
+    moveByOneNote(true);
+}
+
+void
+MainWindow::moveOneNoteLeft()
+{
+    // cerr << "MainWindow::moveOneNoteLeft" << endl;
+    moveByOneNote(false);
+}
+
+void
+MainWindow::moveByOneNote(bool right)
+{
+    // cerr << "MainWindow::moveByOneNote" << endl;
+    int frame = m_viewManager->getPlaybackFrame();
+    
+    Pane *p = m_analyser->getPane();
+
+    Layer *layer = m_analyser->getLayer(Analyser::Notes);
+    if (!layer) return;
+
+    FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel());
+    if (!model) return;
+
+    FlexiNoteModel::PointList points = model->getPoints();
+    if (points.empty()) return;
+
+    FlexiNoteModel::PointList::iterator i = points.begin();
+    std::set<int> snapFrames;
+    snapFrames.insert(0);
+    while (i != points.end()) {
+        snapFrames.insert(i->frame);
+        snapFrames.insert(i->frame + i->duration + 1);
+        ++i;
+    }
+    std::set<int>::iterator i2;
+    if (snapFrames.find(frame) == snapFrames.end())
+    {
+        // we're not on an existing snap point, so go to previous
+        snapFrames.insert(frame);
+    }
+    i2 = snapFrames.find(frame);
+    if (right)
+    {
+        i2++;
+        if (i2 == snapFrames.end()) i2--;
+    } else {
+        if (i2 != snapFrames.begin()) i2--;
+    }
+    frame = *i2;
+    m_viewManager->setPlaybackFrame(frame);
+}
+
 void
 MainWindow::toolNavigateSelected()
 {
--- a/src/MainWindow.h	Thu May 22 11:21:36 2014 +0100
+++ b/src/MainWindow.h	Thu May 22 17:49:58 2014 +0100
@@ -172,6 +172,9 @@
 
     virtual void analyseNewMainModel();
 
+    void moveOneNoteRight();
+    void moveOneNoteLeft();
+
 protected:
     Analyser      *m_analyser;
 
@@ -239,6 +242,8 @@
 
     virtual void updateVisibleRangeDisplay(Pane *p) const;
     virtual void updatePositionStatusDisplays() const;
+
+    void moveByOneNote(bool right);
 };