changeset 168:c5e4eaeb9a27

Add ability to delete selection of pitch track
author Chris Cannam
date Tue, 04 Feb 2014 13:55:26 +0000
parents 6b6906017536
children 89bcb03a4849
files src/Analyser.cpp src/Analyser.h src/MainWindow.cpp src/MainWindow.h
diffstat 4 files changed, 99 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/Analyser.cpp	Mon Feb 03 17:04:03 2014 +0000
+++ b/src/Analyser.cpp	Tue Feb 04 13:55:26 2014 +0000
@@ -333,29 +333,24 @@
 
     if (up) {
         m_currentCandidate = m_currentCandidate + 1;
-        if (m_currentCandidate >= m_reAnalysisCandidates.size()) {
+        if (m_currentCandidate >= (int)m_reAnalysisCandidates.size()) {
             m_currentCandidate = 0;
         }
     } else {
         m_currentCandidate = m_currentCandidate - 1;
         if (m_currentCandidate < 0) {
-            m_currentCandidate = m_reAnalysisCandidates.size() - 1;
+            m_currentCandidate = (int)m_reAnalysisCandidates.size() - 1;
         }
     }
 
     Layer *pitchTrack = m_layers[PitchTrack];
     if (!pitchTrack) return;
 
-    CommandHistory::getInstance()->startCompoundOperation
-        (tr("Switch Pitch Candidate"), true);
-
     Clipboard clip;
     pitchTrack->deleteSelection(sel);
     m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip);
     pitchTrack->paste(m_pane, clip, 0, false);
 
-    CommandHistory::getInstance()->endCompoundOperation();
-
     // raise the pitch track, then notes on top (if present)
     m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]);
     if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) {
@@ -364,10 +359,53 @@
 }
 
 void
+Analyser::shiftOctave(Selection sel, bool up)
+{
+    float factor = (up ? 2.f : 0.5f);
+    
+    vector<Layer *> actOn;
+
+    Layer *pitchTrack = m_layers[PitchTrack];
+    if (pitchTrack) actOn.push_back(pitchTrack);
+
+    foreach (Layer *c, m_reAnalysisCandidates) {
+        actOn.push_back(c);
+    }
+
+    foreach (Layer *layer, actOn) {
+        
+        Clipboard clip;
+        layer->copy(m_pane, sel, clip);
+        layer->deleteSelection(sel);
+
+        Clipboard shifted;
+        foreach (Clipboard::Point p, clip.getPoints()) {
+            if (p.haveValue()) {
+                Clipboard::Point sp = p.withValue(p.getValue() * factor);
+                shifted.addPoint(sp);
+            } else {
+                shifted.addPoint(p);
+            }
+        }
+        
+        layer->paste(m_pane, shifted, 0, false);
+    }
+}
+
+void
+Analyser::clearPitches(Selection sel)
+{
+    Layer *pitchTrack = m_layers[PitchTrack];
+    if (!pitchTrack) return;
+
+    pitchTrack->deleteSelection(sel);
+}
+
+void
 Analyser::clearReAnalysis()
 {
     foreach (Layer *layer, m_reAnalysisCandidates) {
-        m_pane->removeLayer(layer);
+        m_document->removeLayerFromView(m_pane, layer);
         m_document->deleteLayer(layer); // also releases its model
     }
     m_reAnalysisCandidates.clear();
--- a/src/Analyser.h	Mon Feb 03 17:04:03 2014 +0000
+++ b/src/Analyser.h	Tue Feb 04 13:55:26 2014 +0000
@@ -98,6 +98,18 @@
     void switchPitchCandidate(Selection sel, bool up);
 
     /**
+     * Remove the pitch estimates from the selected area of the main
+     * pitch track.
+     */
+    void clearPitches(Selection sel);
+
+    /**
+     * Move the main pitch track and any active analysis candidate
+     * tracks up or down an octave in the selected area.
+     */
+    void shiftOctave(Selection sel, bool up);
+
+    /**
      * Remove any re-analysis layers.
      */
     void clearReAnalysis();
--- a/src/MainWindow.cpp	Mon Feb 03 17:04:03 2014 +0000
+++ b/src/MainWindow.cpp	Tue Feb 04 13:55:26 2014 +0000
@@ -85,7 +85,6 @@
     MainWindowBase(withAudioOutput, withOSCSupport, false),
     m_overview(0),
     m_mainMenusCreated(false),
-    m_intelligentActionOn(true), //GF: !!! temporary
     m_playbackMenu(0),
     m_recentFilesMenu(0), 
     m_rightButtonMenu(0),
@@ -93,6 +92,7 @@
     m_deleteSelectedAction(0),
     m_ffwdAction(0),
     m_rwdAction(0),
+    m_intelligentActionOn(true), //GF: !!! temporary
     m_keyReference(new KeyReference())
 {
     setWindowTitle(QApplication::applicationName());
@@ -525,6 +525,13 @@
     menu->addSeparator();
     
     //!!! shortcuts, status tip, key reference etc
+    action = new QAction(tr("Clear Pitches"), this);
+    action->setShortcut(tr("Backspace"));
+    connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
+    connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
+    menu->addAction(action);
+
+    //!!! shortcuts, status tip, key reference etc
     action = new QAction(tr("Octave Shift Up"), this);
     action->setShortcut(tr("PgUp"));
     connect(action, SIGNAL(triggered()), this, SLOT(octaveShiftUp()));
@@ -540,7 +547,7 @@
     //!!! shortcuts, status tip, key reference etc
     action = new QAction(tr("Switch Pitch Candidate"), this);
     action->setShortcut(tr("Return"));
-    connect(action, SIGNAL(triggered()), this, SLOT(switchPitchUp()));
+    connect(action, SIGNAL(triggered()), this, SLOT(switchPitch()));
     connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
 }
@@ -1642,8 +1649,12 @@
 {
     cerr << "MainWindow::clearSelection()" << endl;
 
+    CommandHistory::getInstance()->startCompoundOperation(tr("Clear Selection"), true);
+
     m_analyser->clearReAnalysis();
     MainWindowBase::clearSelection();
+
+    CommandHistory::getInstance()->endCompoundOperation();
 }
 
 void
@@ -1666,6 +1677,21 @@
 }
 
 void
+MainWindow::clearPitches()
+{
+    MultiSelection::SelectionList selections = m_viewManager->getSelections();
+
+    CommandHistory::getInstance()->startCompoundOperation(tr("Clear Pitches"), true);
+
+    for (MultiSelection::SelectionList::iterator k = selections.begin();
+         k != selections.end(); ++k) {
+        m_analyser->clearPitches(*k);
+    }
+
+    CommandHistory::getInstance()->endCompoundOperation();
+}
+
+void
 MainWindow::octaveShiftUp()
 {
     octaveShift(true);
@@ -1680,70 +1706,33 @@
 void
 MainWindow::octaveShift(bool up)
 {
-    // Should this be in the Analyser?
-
-    float factor = (up ? 2.f : 0.5f);
-
     MultiSelection::SelectionList selections = m_viewManager->getSelections();
 
     CommandHistory::getInstance()->startCompoundOperation(tr("Octave Shift"), true);
 
-    for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
+    for (MultiSelection::SelectionList::iterator k = selections.begin();
+         k != selections.end(); ++k) {
 
-        Pane *pane = m_paneStack->getPane(i);
-        if (!pane) continue;
-
-        for (int j = 0; j < pane->getLayerCount(); ++j) {
-
-            Layer *layer = pane->getLayer(j);
-            if (!layer) continue;
-
-            for (MultiSelection::SelectionList::iterator k = selections.begin();
-                 k != selections.end(); ++k) {
-
-                Clipboard clip;
-                layer->copy(pane, *k, clip);
-                layer->deleteSelection(*k);
-
-                Clipboard shifted;
-                foreach (Clipboard::Point p, clip.getPoints()) {
-                    if (p.haveValue()) {
-                        Clipboard::Point sp = 
-                            p.withValue(p.getValue() * factor);
-                        shifted.addPoint(sp);
-                    } else {
-                        shifted.addPoint(p);
-                    }
-                }
-
-                layer->paste(pane, shifted, 0, false);
-            }
-        }
+        m_analyser->shiftOctave(*k, up);
     }
 
     CommandHistory::getInstance()->endCompoundOperation();
 }
 
 void
-MainWindow::switchPitchUp()
+MainWindow::switchPitch()
 {
+    CommandHistory::getInstance()->startCompoundOperation
+        (tr("Switch Pitch Candidate"), true);
+
     MultiSelection::SelectionList selections = m_viewManager->getSelections();
 
     for (MultiSelection::SelectionList::iterator k = selections.begin();
          k != selections.end(); ++k) {
         m_analyser->switchPitchCandidate(*k, true);
     }
-}
 
-void
-MainWindow::switchPitchDown()
-{
-    MultiSelection::SelectionList selections = m_viewManager->getSelections();
-
-    for (MultiSelection::SelectionList::iterator k = selections.begin();
-         k != selections.end(); ++k) {
-        m_analyser->switchPitchCandidate(*k, false);
-    }
+    CommandHistory::getInstance()->endCompoundOperation();
 }
 
 void
@@ -2188,8 +2177,11 @@
     MainWindowBase::mainModelChanged(model);
 
     if (m_playTarget) {
+
         connect(m_fader, SIGNAL(valueChanged(float)),
                 m_playTarget, SLOT(setOutputGain(float)));
+
+        m_playSource->setSelectionMargin(RealTime(2, 0));
     }
 
     if (model) {
--- a/src/MainWindow.h	Mon Feb 03 17:04:03 2014 +0000
+++ b/src/MainWindow.h	Tue Feb 04 13:55:26 2014 +0000
@@ -50,10 +50,10 @@
     virtual void toolEditSelected();
     virtual void toolFreeEditSelected();
 
+    virtual void clearPitches();
     virtual void octaveShiftUp();
     virtual void octaveShiftDown();
-    virtual void switchPitchUp();
-    virtual void switchPitchDown();
+    virtual void switchPitch();
 
     virtual void showAudioToggled();
     virtual void showSpectToggled();