comparison src/MainWindow.cpp @ 237:63092d9871f9

Add command to snap notes back to pitch track median on request; add split at selection boundaries
author Chris Cannam
date Thu, 27 Mar 2014 15:59:46 +0000
parents 135e0f1fd1ee
children fce61899aeea
comparison
equal deleted inserted replaced
236:389ed196d23b 237:63092d9871f9
585 m_keyReference->registerShortcut(action); 585 m_keyReference->registerShortcut(action);
586 connect(action, SIGNAL(triggered()), this, SLOT(clearPitches())); 586 connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
587 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool))); 587 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
588 menu->addAction(action); 588 menu->addAction(action);
589 m_rightButtonMenu->addAction(action); 589 m_rightButtonMenu->addAction(action);
590
591 menu->addSeparator();
592 m_rightButtonMenu->addSeparator();
593
594 action = new QAction(tr("Snap Notes to Pitch Track"), this);
595 action->setShortcut(tr("Ctrl+="));
596 action->setStatusTip(tr("Set all notes within the selected region to have the median frequency of their underlying pitches"));
597 m_keyReference->registerShortcut(action);
598 connect(action, SIGNAL(triggered()), this, SLOT(snapNotesToPitches()));
599 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
600 menu->addAction(action);
601 m_rightButtonMenu->addAction(action);
602
603 action = new QAction(tr("Split Notes at Selection Boundaries"), this);
604 action->setShortcut(tr("Ctrl+/"));
605 action->setStatusTip(tr("If any notes overlap the start or end of the selected region, split them at those points"));
606 m_keyReference->registerShortcut(action);
607 connect(action, SIGNAL(triggered()), this, SLOT(splitNotesAtSelection()));
608 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
609 menu->addAction(action);
610 m_rightButtonMenu->addAction(action);
590 } 611 }
591 612
592 void 613 void
593 MainWindow::setupViewMenu() 614 MainWindow::setupViewMenu()
594 { 615 {
1066 emit canChangePlaybackSpeed(true); 1087 emit canChangePlaybackSpeed(true);
1067 int v = m_playSpeed->value(); 1088 int v = m_playSpeed->value();
1068 emit canSpeedUpPlayback(v < m_playSpeed->maximum()); 1089 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
1069 emit canSlowDownPlayback(v > m_playSpeed->minimum()); 1090 emit canSlowDownPlayback(v > m_playSpeed->minimum());
1070 1091
1071 emit canExportPitchTrack(m_analyser->isVisible(Analyser::PitchTrack) && 1092 bool havePitchTrack =
1072 m_analyser->getLayer(Analyser::PitchTrack)); 1093 m_analyser->isVisible(Analyser::PitchTrack) &&
1073 emit canExportNotes(m_analyser->isVisible(Analyser::Notes) && 1094 m_analyser->getLayer(Analyser::PitchTrack);
1074 m_analyser->getLayer(Analyser::Notes)); 1095
1096 bool haveNotes =
1097 m_analyser->isVisible(Analyser::Notes) &&
1098 m_analyser->getLayer(Analyser::Notes);
1099
1100 emit canExportPitchTrack(havePitchTrack);
1101 emit canExportNotes(haveNotes);
1102 emit canSnapNotes(haveSelection && haveNotes);
1075 1103
1076 if (pitchCandidatesVisible) { 1104 if (pitchCandidatesVisible) {
1077 m_showCandidatesAction->setText(tr("Hide Pitch Candidates")); 1105 m_showCandidatesAction->setText(tr("Hide Pitch Candidates"));
1078 m_showCandidatesAction->setStatusTip(tr("Remove the display of alternate pitch candidates for the selected region")); 1106 m_showCandidatesAction->setStatusTip(tr("Remove the display of alternate pitch candidates for the selected region"));
1079 } else { 1107 } else {
2017 octaveShift(false); 2045 octaveShift(false);
2018 } 2046 }
2019 } 2047 }
2020 2048
2021 void 2049 void
2050 MainWindow::snapNotesToPitches()
2051 {
2052 FlexiNoteLayer *layer =
2053 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
2054 if (!layer) return;
2055
2056 MultiSelection::SelectionList selections = m_viewManager->getSelections();
2057
2058 if (!selections.empty()) {
2059
2060 CommandHistory::getInstance()->startCompoundOperation
2061 (tr("Snap Notes to Pitches"), true);
2062
2063 for (MultiSelection::SelectionList::iterator k = selections.begin();
2064 k != selections.end(); ++k) {
2065 layer->snapSelectedNotesToPitchTrack(m_analyser->getPane(), *k);
2066 }
2067
2068 CommandHistory::getInstance()->endCompoundOperation();
2069 }
2070 }
2071
2072 void
2073 MainWindow::splitNotesAtSelection()
2074 {
2075 FlexiNoteLayer *layer =
2076 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
2077 if (!layer) return;
2078
2079 MultiSelection::SelectionList selections = m_viewManager->getSelections();
2080
2081 if (!selections.empty()) {
2082
2083 CommandHistory::getInstance()->startCompoundOperation
2084 (tr("Split Notes at Selection Boundaries"), true);
2085
2086 for (MultiSelection::SelectionList::iterator k = selections.begin();
2087 k != selections.end(); ++k) {
2088 layer->splitNotesAt(m_analyser->getPane(), k->getStartFrame());
2089 layer->splitNotesAt(m_analyser->getPane(), k->getEndFrame());
2090 }
2091
2092 CommandHistory::getInstance()->endCompoundOperation();
2093 }
2094 }
2095
2096 void
2022 MainWindow::playSpeedChanged(int position) 2097 MainWindow::playSpeedChanged(int position)
2023 { 2098 {
2024 PlaySpeedRangeMapper mapper(0, 200); 2099 PlaySpeedRangeMapper mapper(0, 200);
2025 2100
2026 float percent = m_playSpeed->mappedValue(); 2101 float percent = m_playSpeed->mappedValue();