diff src/MainWindow.cpp @ 238:fce61899aeea

Add Merge Notes
author Chris Cannam
date Thu, 27 Mar 2014 16:30:26 +0000
parents 63092d9871f9
children d40c6cdb30a4
line wrap: on
line diff
--- a/src/MainWindow.cpp	Thu Mar 27 15:59:46 2014 +0000
+++ b/src/MainWindow.cpp	Thu Mar 27 16:30:26 2014 +0000
@@ -591,15 +591,6 @@
     menu->addSeparator();
     m_rightButtonMenu->addSeparator();
     
-    action = new QAction(tr("Snap Notes to Pitch Track"), this);
-    action->setShortcut(tr("Ctrl+="));
-    action->setStatusTip(tr("Set all notes within the selected region to have the median frequency of their underlying pitches"));
-    m_keyReference->registerShortcut(action);
-    connect(action, SIGNAL(triggered()), this, SLOT(snapNotesToPitches()));
-    connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
-    menu->addAction(action);
-    m_rightButtonMenu->addAction(action);
-    
     action = new QAction(tr("Split Notes at Selection Boundaries"), this);
     action->setShortcut(tr("Ctrl+/"));
     action->setStatusTip(tr("If any notes overlap the start or end of the selected region, split them at those points"));
@@ -608,6 +599,25 @@
     connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
     m_rightButtonMenu->addAction(action);
+
+    action = new QAction(tr("Merge Notes"), this);
+    action->setShortcut(tr("Ctrl+."));
+    action->setStatusTip(tr("Merge all notes within the selected region into a single note"));
+    m_keyReference->registerShortcut(action);
+    connect(action, SIGNAL(triggered()), this, SLOT(mergeNotes()));
+    connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
+    menu->addAction(action);
+    m_rightButtonMenu->addAction(action);
+    
+    action = new QAction(tr("Snap Notes to Pitch Track"), this);
+    action->setShortcut(tr("Ctrl+="));
+    action->setStatusTip(tr("Set notes within the selected region to the median frequency of their underlying pitches, or remove them if there are no underlying pitches"));
+    m_keyReference->registerShortcut(action);
+    connect(action, SIGNAL(triggered()), this, SLOT(snapNotesToPitches()));
+    connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
+    menu->addAction(action);
+    m_rightButtonMenu->addAction(action);
+    
 }
 
 void
@@ -2094,6 +2104,29 @@
 }
 
 void
+MainWindow::mergeNotes()
+{
+    FlexiNoteLayer *layer =
+        qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
+    if (!layer) return;
+
+    MultiSelection::SelectionList selections = m_viewManager->getSelections();
+
+    if (!selections.empty()) {
+
+        CommandHistory::getInstance()->startCompoundOperation
+            (tr("Merge Notes"), true);
+                
+        for (MultiSelection::SelectionList::iterator k = selections.begin();
+             k != selections.end(); ++k) {
+            layer->mergeNotes(m_analyser->getPane(), *k);
+        }
+        
+        CommandHistory::getInstance()->endCompoundOperation();
+    }
+}
+
+void
 MainWindow::playSpeedChanged(int position)
 {
     PlaySpeedRangeMapper mapper(0, 200);