changeset 187:dedd09297a3e

Fix #884 (erroneously allows you to change candidate even when candidates not visible) and remaining part of #874 (show pitch candidates only on request). Also reorder menu items a little
author Chris Cannam
date Tue, 04 Mar 2014 14:10:37 +0000
parents 01139b1cb98d
children b970b39e1fab
files src/Analyser.cpp src/MainWindow.cpp src/MainWindow.h
diffstat 3 files changed, 56 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/Analyser.cpp	Mon Feb 24 17:53:24 2014 -0500
+++ b/src/Analyser.cpp	Tue Mar 04 14:10:37 2014 +0000
@@ -349,6 +349,8 @@
             m_reAnalysisCandidates.push_back(t);
         }
     }
+
+    emit layersChanged();
 }
 
 void
--- a/src/MainWindow.cpp	Mon Feb 24 17:53:24 2014 -0500
+++ b/src/MainWindow.cpp	Tue Mar 04 14:10:37 2014 +0000
@@ -335,6 +335,8 @@
     m_analyser = new Analyser();
     connect(m_analyser, SIGNAL(layersChanged()),
             this, SLOT(updateLayerStatuses()));
+    connect(m_analyser, SIGNAL(layersChanged()),
+            this, SLOT(updateMenuStates()));
 
     setupMenus();
     setupToolbars();
@@ -534,12 +536,28 @@
     menu->addSeparator();
     
     //!!! shortcuts, status tip, key reference etc
-    action = new QAction(tr("Clear Pitches"), this);
-    action->setShortcut(tr("Ctrl+Backspace"));
-    connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
-    connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
+    m_showCandidatesAction = new QAction(tr("Show Pitch Candidates"), this);
+    m_showCandidatesAction->setShortcut(tr("Ctrl+Return"));
+    connect(m_showCandidatesAction, SIGNAL(triggered()), this, SLOT(togglePitchCandidates()));
+    connect(this, SIGNAL(canClearSelection(bool)), m_showCandidatesAction, SLOT(setEnabled(bool)));
+    menu->addAction(m_showCandidatesAction);
+    
+    //!!! 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(canChangePitchCandidate(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(canChangePitchCandidate(bool)), action, SLOT(setEnabled(bool)));
+    menu->addAction(action);
+    
+    menu->addSeparator();
+    
     //!!! shortcuts, status tip, key reference etc
     action = new QAction(tr("Octave Shift Up"), this);
     action->setShortcut(tr("PgUp"));
@@ -552,25 +570,13 @@
     connect(action, SIGNAL(triggered()), this, SLOT(octaveShiftDown()));
     connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
+
+    menu->addSeparator();
     
     //!!! shortcuts, status tip, key reference etc
-    action = new QAction(tr("Toggle Alternative Pitch Candidates"), this);
-    action->setShortcut(tr("Ctrl+Return"));
-    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()));
+    action = new QAction(tr("Remove Pitches"), this);
+    action->setShortcut(tr("Ctrl+Backspace"));
+    connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
     connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
 }
@@ -1015,23 +1021,35 @@
         (haveCurrentPane &&
          (currentLayer != 0));
     bool haveSelection = 
-    (m_viewManager &&
-     !m_viewManager->getSelections().empty());
+        (m_viewManager &&
+         !m_viewManager->getSelections().empty());
     bool haveCurrentEditableLayer =
-    (haveCurrentLayer &&
-     currentLayer->isLayerEditable());
+        (haveCurrentLayer &&
+         currentLayer->isLayerEditable());
     bool haveCurrentTimeInstantsLayer = 
-    (haveCurrentLayer &&
-     qobject_cast<TimeInstantLayer *>(currentLayer));
+        (haveCurrentLayer &&
+         qobject_cast<TimeInstantLayer *>(currentLayer));
     bool haveCurrentTimeValueLayer = 
-    (haveCurrentLayer &&
-     qobject_cast<TimeValueLayer *>(currentLayer));
+        (haveCurrentLayer &&
+         qobject_cast<TimeValueLayer *>(currentLayer));
+    bool pitchCandidatesVisible = 
+        m_analyser->arePitchCandidatesShown();
 
     emit canChangePlaybackSpeed(true);
     int v = m_playSpeed->value();
     emit canSpeedUpPlayback(v < m_playSpeed->maximum());
     emit canSlowDownPlayback(v > m_playSpeed->minimum());
 
+    emit canChangePitchCandidate(pitchCandidatesVisible && haveSelection);
+
+    if (pitchCandidatesVisible) {
+        m_showCandidatesAction->setText(tr("Hide Pitch Candidates"));
+        m_showCandidatesAction->setStatusTip(tr("Remove the display of alternate pitch candidates for the selected region"));
+    } else {
+        m_showCandidatesAction->setText(tr("Show Pitch Candidates"));
+        m_showCandidatesAction->setStatusTip(tr("Show alternate pitch candidates for the selected region"));
+    }
+
     if (m_ffwdAction && m_rwdAction) {
         if (haveCurrentTimeInstantsLayer) {
             m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
@@ -1760,6 +1778,7 @@
     if (!selections.empty()) {
         Selection sel = *selections.begin();
         cerr << "MainWindow::selectionChanged: have selection" << endl;
+        m_analyser->showPitchCandidates(false);
         QString error = m_analyser->reAnalyseSelection(sel);
         if (error != "") {
             QMessageBox::critical
@@ -1816,6 +1835,7 @@
 MainWindow::togglePitchCandidates()
 {
     m_analyser->showPitchCandidates(!m_analyser->arePitchCandidatesShown());
+    updateMenuStates();
 }
 
 void
--- a/src/MainWindow.h	Mon Feb 24 17:53:24 2014 -0500
+++ b/src/MainWindow.h	Tue Mar 04 14:10:37 2014 +0000
@@ -30,6 +30,9 @@
                bool withOSCSupport = true);
     virtual ~MainWindow();
 
+signals:
+    virtual void canChangePitchCandidate(bool);
+
 public slots:
     virtual bool commitData(bool mayAskUser); // on session shutdown
 
@@ -175,6 +178,7 @@
     QAction       *m_ffwdAction;
     QAction       *m_rwdAction;
     QAction       *m_editSelectAction;
+    QAction       *m_showCandidatesAction;
     QAction       *m_toggleIntelligenceAction;
     bool           m_intelligentActionOn; // GF: !!! temporary