From c514f1789aa67c878e7cab6057543b362035b53e Mon Sep 17 00:00:00 2001 From: Ben Bryan Date: Mon, 14 Sep 2015 21:44:35 -0500 Subject: [PATCH] Add per-key note selection to piano roll editor, as discussed in #529. Add missing break. Fix tabs. --- include/PianoRoll.h | 2 ++ src/gui/editors/PianoRoll.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/PianoRoll.h b/include/PianoRoll.h index e4821ab01..4348c47c2 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -130,6 +130,7 @@ protected: void removeSelection(); void selectAll(); NoteVector getSelectedNotes(); + void selectNotesOnKey(); // for entering values with dblclick in the vol/pan bars void enterValue( NoteVector* nv ); @@ -199,6 +200,7 @@ private: stmaMarkCurrentSemiTone, stmaMarkCurrentScale, stmaMarkCurrentChord, + stmaCopyAllNotesOnKey }; enum PianoRollKeyTypes diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 29d83d020..f6f4639e0 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -235,16 +235,19 @@ PianoRoll::PianoRoll() : QAction* markScaleAction = new QAction( tr("Mark current scale"), this ); QAction* markChordAction = new QAction( tr("Mark current chord"), this ); QAction* unmarkAllAction = new QAction( tr("Unmark all"), this ); + QAction* copyAllNotesAction = new QAction( tr("Select all notes on this key"), this); connect( markSemitoneAction, SIGNAL(triggered()), signalMapper, SLOT(map()) ); connect( markScaleAction, SIGNAL(triggered()), signalMapper, SLOT(map()) ); connect( markChordAction, SIGNAL(triggered()), signalMapper, SLOT(map()) ); connect( unmarkAllAction, SIGNAL(triggered()), signalMapper, SLOT(map()) ); + connect( copyAllNotesAction, SIGNAL(triggered()), signalMapper, SLOT(map()) ); signalMapper->setMapping( markSemitoneAction, static_cast( stmaMarkCurrentSemiTone ) ); signalMapper->setMapping( markScaleAction, static_cast( stmaMarkCurrentScale ) ); signalMapper->setMapping( markChordAction, static_cast( stmaMarkCurrentChord ) ); signalMapper->setMapping( unmarkAllAction, static_cast( stmaUnmarkAll ) ); + signalMapper->setMapping( copyAllNotesAction, static_cast( stmaCopyAllNotesOnKey ) ); markScaleAction->setEnabled( false ); markChordAction->setEnabled( false ); @@ -258,6 +261,7 @@ PianoRoll::PianoRoll() : m_semiToneMarkerMenu->addAction( markScaleAction ); m_semiToneMarkerMenu->addAction( markChordAction ); m_semiToneMarkerMenu->addAction( unmarkAllAction ); + m_semiToneMarkerMenu->addAction( copyAllNotesAction ); // init pixmaps if( s_whiteKeySmallPm == NULL ) @@ -567,6 +571,11 @@ void PianoRoll::markSemiTone( int i ) } break; } + case stmaCopyAllNotesOnKey: + { + selectNotesOnKey(); + break; + } default: ; } @@ -1578,6 +1587,11 @@ void PianoRoll::mousePressEvent(QMouseEvent * me ) } else if( me->y() < keyAreaBottom() ) { + // reference to last key needed for both + // right click (used for copy all keys on note) + // and for playing the key when left-clicked + m_lastKey = key_num; + // clicked on keyboard on the left if( me->buttons() == Qt::RightButton ) { @@ -1587,7 +1601,6 @@ void PianoRoll::mousePressEvent(QMouseEvent * me ) else { // left click - play the note - m_lastKey = key_num; int v = ( (float) x ) / ( (float) WHITE_KEY_WIDTH ) * MidiDefaultVelocity; m_pattern->instrumentTrack()->pianoModel()->handleKeyPress( key_num, v ); } @@ -3497,6 +3510,17 @@ NoteVector PianoRoll::getSelectedNotes() return selectedNotes; } +// selects all notess associated with m_lastKey +void PianoRoll::selectNotesOnKey() +{ + if (hasValidPattern()) { + for (Note * note : m_pattern->notes()) { + if (note->key() == m_lastKey) { + note->setSelected(true); + } + } + } +} void PianoRoll::enterValue( NoteVector* nv ) {