Skip to content

Commit

Permalink
Merge pull request #4158 from blackears/278339-crash-adding-note-befo…
Browse files Browse the repository at this point in the history
…re-inputState-initialized

fix #278339 Fix crash when note entered in piano roll
  • Loading branch information
anatoly-os committed Nov 21, 2018
2 parents 53a6a97 + 613ae88 commit 9a76140
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
70 changes: 41 additions & 29 deletions mscore/pianoview.cpp
Expand Up @@ -321,7 +321,7 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r)

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

colWhiteKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_KEY_WHITE_COLOR));
colGutter = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_BASE_COLOR));
Expand All @@ -330,7 +330,7 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r)
colGridLine = QColor(preferences.getColor(PREF_UI_PIANOROLL_DARK_BG_GRIDLINE_COLOR));
break;
default:
colSelectionBox = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_KEY_WHITE_COLOR));
colSelectionBox = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_SELECTION_BOX_COLOR));

colWhiteKeyBg = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_KEY_WHITE_COLOR));
colGutter = QColor(preferences.getColor(PREF_UI_PIANOROLL_LIGHT_BG_BASE_COLOR));
Expand Down Expand Up @@ -511,47 +511,47 @@ void PianoView::wheelEvent(QWheelEvent* event)
{
int step = event->delta() / 120;

if (event->modifiers() == Qt::ControlModifier) {
//Horizontal zoom

QRectF viewRect = mapToScene(viewport()->geometry()).boundingRect();

int mouseXTick = pixelXToTick(event->x() + (int)viewRect.x());

_xZoom *= pow(X_ZOOM_RATIO, step);
emit xZoomChanged(_xZoom);

updateBoundingSize();
updateNotes();

int mousePixX = tickToPixelX(mouseXTick);
horizontalScrollBar()->setValue(mousePixX - event->x());

scene()->update();
if (event->modifiers() == 0) {
//Vertical scroll
QGraphicsView::wheelEvent(event);
}
else if (event->modifiers() == Qt::ShiftModifier) {
//Horizontal scroll
QWheelEvent we(event->pos(), event->delta(), event->buttons(), 0, Qt::Horizontal);
QGraphicsView::wheelEvent(&we);
}
else if (event->modifiers() == 0) {
//Vertical scroll
QGraphicsView::wheelEvent(event);
}
else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) {
else if (event->modifiers() == Qt::ControlModifier) {
//Vertical zoom
QRectF viewRect = mapToScene(viewport()->geometry()).boundingRect();
qreal mouseYNote = (event->y() + (int)viewRect.y()) / (qreal)_noteHeight;

_noteHeight = qMax(qMin(_noteHeight + step, MAX_KEY_HEIGHT), MIN_KEY_HEIGHT);
emit noteHeightChanged(_noteHeight);

updateBoundingSize();
updateNotes();

int mousePixY = (int)(mouseYNote * _noteHeight);
verticalScrollBar()->setValue(mousePixY - event->y());

scene()->update();
}
else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) {
//Horizontal zoom

QRectF viewRect = mapToScene(viewport()->geometry()).boundingRect();

int mouseXTick = pixelXToTick(event->x() + (int)viewRect.x());

_xZoom *= pow(X_ZOOM_RATIO, step);
emit xZoomChanged(_xZoom);

updateBoundingSize();
updateNotes();

int mousePixX = tickToPixelX(mouseXTick);
horizontalScrollBar()->setValue(mousePixX - event->x());

scene()->update();
}
}
Expand Down Expand Up @@ -675,15 +675,22 @@ void PianoView::mouseReleaseEvent(QMouseEvent* event)
NoteVal nv(pickPitch);


Segment* seg = score->tick2segment(roundedTick);
score->expandVoice(seg, track);

ChordRest* e = score->findCR(roundedTick, track);
if (e && !e->tuplet() && _tuplet == 1) {
//Ignore tuplets
score->startCmd();
score->expandVoice(e->segment(), track);

ChordRest* cr0;
ChordRest* cr1;
Fraction frac = is.duration().fraction();

//Default to quarter note if faction is invalid
if (!frac.isValid() || frac.isZero())
frac.set(1, 4);

if (cutChordRest(e, track, roundedTick, cr0, cr1)) {
score->setNoteRest(cr1->segment(), track, nv, frac);
}
Expand All @@ -708,6 +715,9 @@ void PianoView::mouseReleaseEvent(QMouseEvent* event)
//Find best chord to add to
int track = _staff->idx() * VOICES + voice;

Segment* seg = score->tick2segment(pickTick);
score->expandVoice(seg, track);

ChordRest* e = score->findCR(pickTick, track);

if (e && e->isChord()) {
Expand Down Expand Up @@ -741,10 +751,12 @@ void PianoView::mouseReleaseEvent(QMouseEvent* event)
int subbeatTicks = MScore::division / subbeats;
int roundedTick = (pickTick / subbeatTicks) * subbeatTicks;

Segment* seg = score->tick2segment(roundedTick);
score->expandVoice(seg, track);

ChordRest* e = score->findCR(roundedTick, track);
if (e && !e->tuplet() && _tuplet == 1) {
score->startCmd();
score->expandVoice(e->segment(), track);
int startTick = e->tick();

if (roundedTick != startTick) {
Expand Down
2 changes: 1 addition & 1 deletion mscore/preferences.cpp
Expand Up @@ -184,7 +184,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_UI_PIANOROLL_DARK_BG_KEY_BLACK_COLOR, new ColorPreference(QColor("#262626"))},
{PREF_UI_PIANOROLL_DARK_BG_GRIDLINE_COLOR, new ColorPreference(QColor("#111111"))},
{PREF_UI_PIANOROLL_DARK_BG_TEXT_COLOR, new ColorPreference(QColor("#999999"))},
{PREF_UI_PIANOROLL_DARK_SELECTION_BOX_COLOR, new ColorPreference(QColor("#0cebff"))},
{PREF_UI_PIANOROLL_LIGHT_SELECTION_BOX_COLOR, new ColorPreference(QColor("#2085c3"))},
{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"))},
Expand Down

0 comments on commit 9a76140

Please sign in to comment.