Skip to content

Commit

Permalink
fix #278977 Allow stripes to be highlighted in piano roll editor
Browse files Browse the repository at this point in the history
Can now control-click on keyboard area to toggle highlights on background bars.
Fixing spelling error.

Moving properties into correct module.

Moving properties into correct module.

Fixing vairable name.
  • Loading branch information
blackears committed Apr 17, 2020
1 parent 63bc7fc commit 5a8bd27
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions global/settings/types/preferencekeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
#define PREF_UI_PIANOROLL_DARK_NOTE_UNSEL_COLOR "ui/pianoroll/dark/note/unselected/color"
#define PREF_UI_PIANOROLL_DARK_NOTE_SEL_COLOR "ui/pianoroll/dark/note/selected/color"
#define PREF_UI_PIANOROLL_DARK_BG_BASE_COLOR "ui/pianoroll/dark/background/base/color"
#define PREF_UI_PIANOROLL_DARK_BG_KEY_HIGHLIGHT_COLOR "ui/pianoroll/dark/background/keys/hilight/color"
#define PREF_UI_PIANOROLL_DARK_BG_KEY_WHITE_COLOR "ui/pianoroll/dark/background/keys/white/color"
#define PREF_UI_PIANOROLL_DARK_BG_KEY_BLACK_COLOR "ui/pianoroll/dark/background/keys/black/color"
#define PREF_UI_PIANOROLL_DARK_BG_GRIDLINE_COLOR "ui/pianoroll/dark/background/gridLine/color"
Expand All @@ -157,6 +158,7 @@
#define PREF_UI_PIANOROLL_LIGHT_NOTE_UNSEL_COLOR "ui/pianoroll/light/note/unselected/color"
#define PREF_UI_PIANOROLL_LIGHT_NOTE_SEL_COLOR "ui/pianoroll/light/note/selected/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_BASE_COLOR "ui/pianoroll/light/background/base/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_KEY_HIGHLIGHT_COLOR "ui/pianoroll/light/background/keys/highlight/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_KEY_WHITE_COLOR "ui/pianoroll/light/background/keys/white/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_KEY_BLACK_COLOR "ui/pianoroll/light/background/keys/black/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_GRIDLINE_COLOR "ui/pianoroll/light/background/gridLine/color"
Expand Down
22 changes: 16 additions & 6 deletions mscore/pianoroll/pianokeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "libmscore/part.h"
#include "libmscore/drumset.h"


namespace Ms {

const QColor colKeySelect = QColor(224, 170, 20);
Expand Down Expand Up @@ -250,11 +251,18 @@ void PianoKeyboard::mousePressEvent(QMouseEvent* event)
? event->pos().x()
: 128 * noteHeight - (event->y() + _ypos);

curKeyPressed = offset / noteHeight;
if (curKeyPressed < 0 || curKeyPressed > 127)
curKeyPressed = -1;
int pitch = curKeyPressed = offset / noteHeight;
if (pitch < 0 || pitch > 127)
pitch = -1;

emit keyPressed(curKeyPressed);
uint modifiers = QGuiApplication::keyboardModifiers();
bool bnCtrl = modifiers & Qt::ControlModifier;
if (bnCtrl)
pitchHighlightToggled(curKeyPressed);
else {
curKeyPressed = pitch;
emit keyPressed(curKeyPressed);
}
}

//---------------------------------------------------------
Expand All @@ -263,8 +271,10 @@ void PianoKeyboard::mousePressEvent(QMouseEvent* event)

void PianoKeyboard::mouseReleaseEvent(QMouseEvent*)
{
emit keyReleased(curKeyPressed);
curKeyPressed = -1;
if (curKeyPressed != -1) {
emit keyReleased(curKeyPressed);
curKeyPressed = -1;
}
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mscore/pianoroll/pianokeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PianoKeyboard : public QWidget {
void pitchChanged(int);
void keyPressed(int pitch);
void keyReleased(int pitch);
void pitchHighlightToggled(int pitch);

public slots:
void setYpos(int val);
Expand Down
1 change: 1 addition & 0 deletions mscore/pianoroll/pianoroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ PianorollEditor::PianorollEditor(QWidget* parent)
connect(subdiv, SIGNAL(valueChanged(int)), pianoView, SLOT(setSubdiv(int)));
connect(subdiv, SIGNAL(valueChanged(int)), pianoLevels, SLOT(setSubdiv(int)));
connect(pianoLevelsChooser, SIGNAL(levelsIndexChanged(int)), pianoLevels, SLOT(setLevelsIndex(int)));
connect(pianoKbd, SIGNAL(pitchHighlightToggled(int)), pianoView, SLOT(togglePitchHighlight(int)));

connect(hsb, SIGNAL(valueChanged(int)), SLOT(setXpos(int)));
connect(pianoView->horizontalScrollBar(), SIGNAL(valueChanged(int)), SLOT(setXpos(int)));
Expand Down
22 changes: 19 additions & 3 deletions mscore/pianoroll/pianoview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ PianoView::PianoView()
_mouseDown = false;
_dragStyle = DragStyle::NONE;
_inProgressUndoEvent = false;

memset(_pitchHighlight, 0, 128);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -319,13 +321,15 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r)
QColor colWhiteKeyBg;
QColor colGutter;
QColor colBlackKeyBg;
QColor colHilightKeyBg;

QColor colGridLine;

switch (preferences.globalStyle()) {
case MuseScoreStyleType::DARK_FUSION:
colSelectionBox = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_SELECTION_BOX_COLOR));

colHilightKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_KEY_HIGHLIGHT_COLOR));
colWhiteKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_KEY_WHITE_COLOR));
colGutter = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_BASE_COLOR));
colBlackKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_KEY_BLACK_COLOR));
Expand All @@ -335,6 +339,7 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r)
default:
colSelectionBox = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_SELECTION_BOX_COLOR));

colHilightKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_KEY_HIGHLIGHT_COLOR));
colWhiteKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_KEY_WHITE_COLOR));
colGutter = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_BASE_COLOR));
colBlackKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_KEY_BLACK_COLOR));
Expand Down Expand Up @@ -382,14 +387,15 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r)

int degree = (pitch - transp.chromatic + 60) % 12;
const BarPattern& pat = barPatterns[_barPattern];
// if (degree == 1 || degree == 3 || degree == 6 || degree == 8 || degree == 10) {
if (!pat.isWhiteKey[degree]) {

if (!pat.isWhiteKey[degree] || _pitchHighlight[pitch]) {
qreal px0 = qMax(r.x(), (qreal)tickToPixelX(0));
qreal px1 = qMin(r.x() + r.width(), (qreal)tickToPixelX(_ticks));
QRectF hbar;

hbar.setCoords(px0, y, px1, y + _noteHeight);
p->fillRect(hbar, colBlackKeyBg);
p->fillRect(hbar,
_pitchHighlight[pitch] ? colHilightKeyBg : colBlackKeyBg);
}

//Lines between rows
Expand Down Expand Up @@ -1219,6 +1225,16 @@ void PianoView::setBarPattern(int value)
}
}

//---------------------------------------------------------
// setBarPattern
//---------------------------------------------------------

void PianoView::togglePitchHighlight(int pitch)
{
_pitchHighlight[pitch] = _pitchHighlight[pitch] ? 0 : 1;
scene()->update();
}

//---------------------------------------------------------
// setSubBeats
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions mscore/pianoroll/pianoview.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class PianoView : public QGraphicsView {
bool _inProgressUndoEvent;

QList<PianoItem*> _noteList;
quint8 _pitchHighlight[128];

virtual void drawBackground(QPainter* painter, const QRectF& rect);

Expand Down Expand Up @@ -140,6 +141,7 @@ class PianoView : public QGraphicsView {
void setTuplet(int);
void setSubdiv(int);
void setBarPattern(int);
void togglePitchHighlight(int pitch);

public:
PianoView();
Expand Down
2 changes: 2 additions & 0 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_UI_PIANOROLL_DARK_NOTE_UNSEL_COLOR, new ColorPreference(QColor("#1dcca0"))},
{PREF_UI_PIANOROLL_DARK_NOTE_SEL_COLOR, new ColorPreference(QColor("#ffff00"))},
{PREF_UI_PIANOROLL_DARK_BG_BASE_COLOR, new ColorPreference(QColor("#3a3a3a"))},
{PREF_UI_PIANOROLL_DARK_BG_KEY_HIGHLIGHT_COLOR, new ColorPreference(QColor("#555577"))},
{PREF_UI_PIANOROLL_DARK_BG_KEY_WHITE_COLOR, new ColorPreference(QColor("#3a3a3a"))},
{PREF_UI_PIANOROLL_DARK_BG_KEY_BLACK_COLOR, new ColorPreference(QColor("#262626"))},
{PREF_UI_PIANOROLL_DARK_BG_GRIDLINE_COLOR, new ColorPreference(QColor("#111111"))},
Expand All @@ -202,6 +203,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_UI_PIANOROLL_LIGHT_NOTE_UNSEL_COLOR, new ColorPreference(QColor("#1dcca0"))},
{PREF_UI_PIANOROLL_LIGHT_NOTE_SEL_COLOR, new ColorPreference(QColor("#ffff00"))},
{PREF_UI_PIANOROLL_LIGHT_BG_BASE_COLOR, new ColorPreference(QColor("#e0e0e7"))},
{PREF_UI_PIANOROLL_LIGHT_BG_KEY_HIGHLIGHT_COLOR, new ColorPreference(QColor("#aaaaff"))},
{PREF_UI_PIANOROLL_LIGHT_BG_KEY_WHITE_COLOR, new ColorPreference(QColor("#ffffff"))},
{PREF_UI_PIANOROLL_LIGHT_BG_KEY_BLACK_COLOR, new ColorPreference(QColor("#e6e6e6"))},
{PREF_UI_PIANOROLL_LIGHT_BG_GRIDLINE_COLOR, new ColorPreference(QColor("#a2a2a6"))},
Expand Down

0 comments on commit 5a8bd27

Please sign in to comment.