changeset 184:ea15fa75ae6f

Ctrl+Return now switches the alternate pitch candidates on and off; Ctrl+Up/Down selects among them
author Chris Cannam
date Sun, 23 Feb 2014 17:59:23 +0000
parents bdee9e6f135b
children 4a98ce5b4266
files src/Analyser.cpp src/Analyser.h src/MainWindow.cpp src/MainWindow.h
diffstat 4 files changed, 91 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/Analyser.cpp	Thu Feb 20 12:00:16 2014 +0000
+++ b/src/Analyser.cpp	Sun Feb 23 17:59:23 2014 +0000
@@ -75,6 +75,7 @@
     m_reAnalysingSelection = Selection();
     m_reAnalysisCandidates.clear();
     m_currentCandidate = -1;
+    m_candidatesVisible = false;
 
     // Note that we need at least one main-model layer (time ruler,
     // waveform or what have you). It could be hidden if we don't want
@@ -296,6 +297,28 @@
     return "";
 }
 
+bool
+Analyser::arePitchCandidatesShown() const
+{
+    return m_candidatesVisible;
+}
+
+void
+Analyser::showPitchCandidates(bool shown) 
+{
+    if (m_candidatesVisible == shown) return;
+
+    foreach (Layer *layer, m_reAnalysisCandidates) {
+        if (shown) {
+            m_document->addLayerToView(m_pane, layer);
+        } else {
+            m_document->removeLayerFromView(m_pane, layer);
+        }
+    }
+
+    m_candidatesVisible = shown;
+}
+
 void
 Analyser::layersCreated(vector<Layer *> primary,
                         vector<Layer *> additional)
@@ -320,7 +343,9 @@
             }
             t->setBaseColour
                 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Orange")));
-            m_document->addLayerToView(m_pane, t);
+            if (m_candidatesVisible) {
+                m_document->addLayerToView(m_pane, t);
+            }
             m_reAnalysisCandidates.push_back(t);
         }
     }
@@ -393,7 +418,7 @@
 }
 
 void
-Analyser::clearPitches(Selection sel)
+Analyser::deletePitches(Selection sel)
 {
     Layer *pitchTrack = m_layers[PitchTrack];
     if (!pitchTrack) return;
--- a/src/Analyser.h	Thu Feb 20 12:00:16 2014 +0000
+++ b/src/Analyser.h	Sun Feb 23 17:59:23 2014 +0000
@@ -91,6 +91,24 @@
     QString reAnalyseSelection(Selection sel);
 
     /**
+     * Return true if the analysed pitch candidates are currently
+     * visible (by default they are hidden after construction until
+     * the user requests them). Note that the shown/hidden state is
+     * independent of whether any pitch candidates actually exist --
+     * it's possible they might be shown but not have been created yet
+     * because creation (through reAnalyseSelection) is asynchronous.
+     */
+    bool arePitchCandidatesShown() const;
+
+    /**
+     * Show or hide the analysed pitch candidate layers. As in
+     * arePitchCandidatesShown, this is independent of whether the
+     * candidate layers actually exist. Call reAnalyseSelection to
+     * schedule creation of those layers.
+     */
+    void showPitchCandidates(bool shown);
+
+    /**
      * If a re-analysis has been activated, switch the selected area
      * of the main pitch track to a different candidate from the
      * analysis results.
@@ -98,10 +116,10 @@
     void switchPitchCandidate(Selection sel, bool up);
 
     /**
-     * Remove the pitch estimates from the selected area of the main
+     * Delete the pitch estimates from the selected area of the main
      * pitch track.
      */
-    void clearPitches(Selection sel);
+    void deletePitches(Selection sel);
 
     /**
      * Move the main pitch track and any active analysis candidate
@@ -142,6 +160,7 @@
     Selection m_reAnalysingSelection;
     std::vector<Layer *> m_reAnalysisCandidates;
     int m_currentCandidate;
+    bool m_candidatesVisible;
 
     QString addVisualisations();
     QString addWaveform();
--- a/src/MainWindow.cpp	Thu Feb 20 12:00:16 2014 +0000
+++ b/src/MainWindow.cpp	Sun Feb 23 17:59:23 2014 +0000
@@ -554,9 +554,23 @@
     menu->addAction(action);
     
     //!!! shortcuts, status tip, key reference etc
-    action = new QAction(tr("Switch Pitch Candidate"), this);
+    action = new QAction(tr("Toggle Alternative Pitch Candidates"), this);
     action->setShortcut(tr("Ctrl+Return"));
-    connect(action, SIGNAL(triggered()), this, SLOT(switchPitch()));
+    connect(action, SIGNAL(triggered()), this, SLOT(togglePitchCandidates()));
+    connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
+    menu->addAction(action);
+    
+    //!!! shortcuts, status tip, key reference etc
+    action = new QAction(tr("Pick Higher Pitch Candidate"), this);
+    action->setShortcut(tr("Ctrl+Up"));
+    connect(action, SIGNAL(triggered()), this, SLOT(switchPitchUp()));
+    connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
+    menu->addAction(action);
+    
+    //!!! shortcuts, status tip, key reference etc
+    action = new QAction(tr("Pick Lower Pitch Candidate"), this);
+    action->setShortcut(tr("Ctrl+Down"));
+    connect(action, SIGNAL(triggered()), this, SLOT(switchPitchDown()));
     connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
 }
@@ -1752,7 +1766,7 @@
 
     for (MultiSelection::SelectionList::iterator k = selections.begin();
          k != selections.end(); ++k) {
-        m_analyser->clearPitches(*k);
+        m_analyser->deletePitches(*k);
     }
 
     CommandHistory::getInstance()->endCompoundOperation();
@@ -1787,7 +1801,13 @@
 }
 
 void
-MainWindow::switchPitch()
+MainWindow::togglePitchCandidates()
+{
+    m_analyser->showPitchCandidates(!m_analyser->arePitchCandidatesShown());
+}
+
+void
+MainWindow::switchPitchUp()
 {
     CommandHistory::getInstance()->startCompoundOperation
         (tr("Switch Pitch Candidate"), true);
@@ -1803,6 +1823,22 @@
 }
 
 void
+MainWindow::switchPitchDown()
+{
+    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, false);
+    }
+
+    CommandHistory::getInstance()->endCompoundOperation();
+}
+
+void
 MainWindow::playSpeedChanged(int position)
 {
     PlaySpeedRangeMapper mapper(0, 200);
--- a/src/MainWindow.h	Thu Feb 20 12:00:16 2014 +0000
+++ b/src/MainWindow.h	Sun Feb 23 17:59:23 2014 +0000
@@ -52,7 +52,9 @@
     virtual void clearPitches();
     virtual void octaveShiftUp();
     virtual void octaveShiftDown();
-    virtual void switchPitch();
+    virtual void togglePitchCandidates();
+    virtual void switchPitchUp();
+    virtual void switchPitchDown();
 
     virtual void showAudioToggled();
     virtual void showSpectToggled();