From aaa412c2bb641bea0dc0ba4349e33297945e7fa4 Mon Sep 17 00:00:00 2001 From: Ben Bryan Date: Wed, 23 Sep 2015 00:38:08 -0500 Subject: [PATCH] Add functionality to allow feature mentioned in #2193. Fix declaration of return value. Add mapping and new menu option for octave-marking of semitones. Finish switch case for add/remove multiple octave semitones. Fix segfault due to illogical access using iterators from one collection on another. --- include/PianoRoll.h | 2 ++ src/gui/editors/PianoRoll.cpp | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/PianoRoll.h b/include/PianoRoll.h index 4348c47c2b8..d0815e54996 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -125,6 +125,7 @@ class PianoRoll : public QWidget virtual void focusOutEvent( QFocusEvent * ); int getKey( int y ) const; + QList getAllOctavesForKey( int keyToMirror ) const; static void drawNoteRect( QPainter & p, int x, int y, int width, const Note * n, const QColor & noteCol ); void removeSelection(); @@ -198,6 +199,7 @@ protected slots: { stmaUnmarkAll, stmaMarkCurrentSemiTone, + stmaMarkAllOctaveSemiTones, stmaMarkCurrentScale, stmaMarkCurrentChord, stmaCopyAllNotesOnKey diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index f6f4639e04a..6d69674dc3c 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -232,18 +232,21 @@ PianoRoll::PianoRoll() : m_semiToneMarkerMenu = new QMenu( this ); QAction* markSemitoneAction = new QAction( tr("Mark/unmark current semitone"), this ); + QAction* markAllOctaveSemitonesAction = new QAction( tr("Mark/unmark all corresponding octave semitones"), this ); 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( markAllOctaveSemitonesAction, 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( markAllOctaveSemitonesAction, static_cast( stmaMarkAllOctaveSemiTones ) ); signalMapper->setMapping( markScaleAction, static_cast( stmaMarkCurrentScale ) ); signalMapper->setMapping( markChordAction, static_cast( stmaMarkCurrentChord ) ); signalMapper->setMapping( unmarkAllAction, static_cast( stmaUnmarkAll ) ); @@ -258,6 +261,7 @@ PianoRoll::PianoRoll() : connect( signalMapper, SIGNAL(mapped(int)), this, SLOT(markSemiTone(int)) ); m_semiToneMarkerMenu->addAction( markSemitoneAction ); + m_semiToneMarkerMenu->addAction( markAllOctaveSemitonesAction ); m_semiToneMarkerMenu->addAction( markScaleAction ); m_semiToneMarkerMenu->addAction( markChordAction ); m_semiToneMarkerMenu->addAction( unmarkAllAction ); @@ -538,6 +542,28 @@ void PianoRoll::markSemiTone( int i ) } break; } + case stmaMarkAllOctaveSemiTones: + { + QList aok = getAllOctavesForKey(key); + + if ( m_markedSemiTones.contains(key) ) + { + // lets erase all of the ones that match this by octave + QList::iterator i; + for (int ix = 0; ix < aok.size(); ++ix) + { + i = qFind(m_markedSemiTones.begin(), m_markedSemiTones.end(), aok.at(ix)); + m_markedSemiTones.erase(i); + } + } + else + { + // we should add all of the ones that match this by octave + m_markedSemiTones.append(aok); + } + + break; + } case stmaMarkCurrentScale: chord = & InstrumentFunctionNoteStacking::ChordTable::getInstance() .getScaleByName( m_scaleModel.currentText() ); @@ -3261,8 +3287,22 @@ int PianoRoll::getKey(int y ) const return key_num; } +QList PianoRoll::getAllOctavesForKey( int keyToMirror ) const +{ + QList keys; + for (int i = 0; i < NumKeys; ++i) + { + if ((i < keyToMirror && (keyToMirror - i) % KeysPerOctave == 0) || (i > keyToMirror && (i - keyToMirror) % KeysPerOctave == 0)) + { + keys.append(i); + } + } + keys.append(keyToMirror); + + return keys; +} Song::PlayModes PianoRoll::desiredPlayModeForAccompany() const {