Skip to content

Commit

Permalink
fix #269672: Show selected notes on the piano control
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcclinch committed Feb 26, 2018
1 parent 36dca0a commit d8b245c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mscore/musescore.cpp
Expand Up @@ -1282,6 +1282,8 @@ void MuseScore::selectionChanged(SelState selectionState)
pianorollEditor->changeSelection(selectionState);
if (drumrollEditor)
drumrollEditor->changeSelection(selectionState);
if (_pianoTools && _pianoTools->isVisible())
_pianoTools->changeSelection(cs->selection());
if (_inspector)
updateInspector();
}
Expand Down
38 changes: 38 additions & 0 deletions mscore/pianotools.cpp
Expand Up @@ -20,6 +20,7 @@

#include "pianotools.h"
#include "preferences.h"
#include "libmscore/chord.h"

namespace Ms {

Expand Down Expand Up @@ -167,6 +168,25 @@ void HPiano::releasePitch(int pitch)
updateAllKeys();
}

//---------------------------------------------------------
// changeSelection
//---------------------------------------------------------

void HPiano::changeSelection(Selection selection)
{
for (PianoKeyItem* key : keys) {
key->setHighlighted(false);
key->setSelected(false);
}
for (Note* n : selection.uniqueNotes()) {
keys[n->pitch() - _firstKey]->setSelected(true);
for (Note* other : n->chord()->notes())
keys[other->pitch() - _firstKey]->setHighlighted(true);
}
for (PianoKeyItem* key : keys)
key->update();
}

//---------------------------------------------------------
// updateAllKeys
//---------------------------------------------------------
Expand All @@ -189,6 +209,8 @@ PianoKeyItem::PianoKeyItem(HPiano* _piano, int p)
piano = _piano;
_pitch = p;
_pressed = false;
_selected = false;
_highlighted = false;
type = -1;
}

Expand Down Expand Up @@ -329,6 +351,13 @@ void PianoKeyItem::paint(QPainter* p, const QStyleOptionGraphicsItem* /*o*/, QWi
c.setAlpha(180);
p->setBrush(c);
}
else if (_selected) {
QColor c(preferences.pianoHlColor);
c.setAlpha(100);
p->setBrush(c);
}
else if (_highlighted)
p->setBrush(type >= 7 ? QColor(125, 125, 125) : QColor(200, 200, 200));
else
p->setBrush(type >= 7 ? Qt::black : Qt::white);
p->drawPath(path());
Expand Down Expand Up @@ -437,5 +466,14 @@ bool HPiano::gestureEvent(QGestureEvent *event)
}
return true;
}

//---------------------------------------------------------
// changeSelection
//---------------------------------------------------------

void PianoTools::changeSelection(Selection selection)
{
_piano->changeSelection(selection);
}
}

7 changes: 7 additions & 0 deletions mscore/pianotools.h
Expand Up @@ -22,6 +22,7 @@
#define __PIANOTOOLS_H__

#include "libmscore/note.h"
#include "libmscore/select.h"

namespace Ms {

Expand All @@ -35,6 +36,8 @@ class PianoKeyItem : public QGraphicsPathItem {
int type;
int _pitch;
bool _pressed;
bool _highlighted;
bool _selected;
HPiano* piano;

virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
Expand All @@ -46,6 +49,8 @@ class PianoKeyItem : public QGraphicsPathItem {
void setType(int val);
int pitch() { return _pitch; }
void setPressed(bool p) { _pressed = p; }
void setHighlighted(bool h) { _highlighted = h; }
void setSelected(bool s) { _selected = s; }
};

//---------------------------------------------------------
Expand Down Expand Up @@ -74,6 +79,7 @@ class HPiano : public QGraphicsView {
void setPressedPitches(QSet<int> pitches);
void pressPitch(int pitch);
void releasePitch(int pitch);
void changeSelection(Selection selection);
void updateAllKeys();
virtual QSize sizeHint() const;
};
Expand All @@ -96,6 +102,7 @@ class PianoTools : public QDockWidget {
void pressPitch(int pitch) { _piano->pressPitch(pitch); }
void releasePitch(int pitch) { _piano->releasePitch(pitch); }
void heartBeat(QList<const Note*> notes);
void changeSelection(Selection selection);
};


Expand Down

0 comments on commit d8b245c

Please sign in to comment.