From 3e11d32aae8aafbed4f90cf5f50734db507442bf Mon Sep 17 00:00:00 2001 From: muelleki Date: Thu, 10 Jan 2013 00:34:35 +0100 Subject: [PATCH 1/2] safeguard GUI against addPitch() returning 0 --- libmscore/cmd.cpp | 4 +++- mscore/scoreview.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libmscore/cmd.cpp b/libmscore/cmd.cpp index 2bfb3aa2708dc..99ea3bbe5ecf0 100644 --- a/libmscore/cmd.cpp +++ b/libmscore/cmd.cpp @@ -1573,7 +1573,9 @@ bool Score::processMidiInput() startCmd(); cmdActive = true; } - n = addPitch(ev.pitch, ev.chord); + Note* n2 = addPitch(ev.pitch, ev.chord); + if (n2) + n = n2; } } if (cmdActive) { diff --git a/mscore/scoreview.cpp b/mscore/scoreview.cpp index ff5410ccebefa..69a92969104b2 100644 --- a/mscore/scoreview.cpp +++ b/mscore/scoreview.cpp @@ -3501,7 +3501,9 @@ void ScoreView::adjustCanvasPosition(const Element* el, bool playBack) } const Measure* m; - if (el->type() == Element::NOTE) + if (!el) + return; + else if (el->type() == Element::NOTE) m = static_cast(el)->chord()->measure(); else if (el->type() == Element::REST) m = static_cast(el)->measure(); From e8159e18e8b3b88a31058ecbcc8e5c22803e168b Mon Sep 17 00:00:00 2001 From: muelleki Date: Thu, 10 Jan 2013 00:34:11 +0100 Subject: [PATCH 2/2] #17906 (Using MIDI input to input chords causes crash): Reworked moveToNextInput() logic in addPitch(). moveToNextInput() is called before actually inserting a new node, except if adding to a chord or if it is the first note inserted. A new flag InputState::moveBeforeAdding has been added just for this purpuse. --- libmscore/cmd.cpp | 6 ++++-- libmscore/input.cpp | 1 + libmscore/input.h | 4 ++++ libmscore/score.cpp | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libmscore/cmd.cpp b/libmscore/cmd.cpp index 99ea3bbe5ecf0..d207276aa9c19 100644 --- a/libmscore/cmd.cpp +++ b/libmscore/cmd.cpp @@ -384,9 +384,12 @@ qDebug("add pitch %d %d", pitch, addFlag); Note* n = addNote(chord, pitch); setLayoutAll(false); setLayout(chord->measure()); - moveToNextInputPos(); return n; } + if (_is.moveBeforeAdding()) + moveToNextInputPos(); + else + _is.setMoveBeforeAdding(true); expandVoice(); // insert note @@ -444,7 +447,6 @@ qDebug("add pitch %d %d", pitch, addFlag); qDebug("addPitch: cannot find slur note"); setLayoutAll(true); } - moveToNextInputPos(); return note; } diff --git a/libmscore/input.cpp b/libmscore/input.cpp index dc2ea04946e15..856fea999d663 100644 --- a/libmscore/input.cpp +++ b/libmscore/input.cpp @@ -32,6 +32,7 @@ InputState::InputState() : _segment(0), _string(VISUAL_STRING_NONE), _repitchMode(false), + _moveBeforeAdding(false), rest(false), pitch(72), noteType(NOTE_NORMAL), diff --git a/libmscore/input.h b/libmscore/input.h index 6649e0eee6589..d8c93411e3944 100644 --- a/libmscore/input.h +++ b/libmscore/input.h @@ -34,6 +34,7 @@ class InputState { Segment* _segment; // current segment int _string; // visual string selected for input (TAB staves only) bool _repitchMode; + bool _moveBeforeAdding; public: bool rest; // rest mode @@ -70,6 +71,9 @@ class InputState { bool repitchMode() const { return _repitchMode; } void setRepitchMode(bool val) { _repitchMode = val; } + bool moveBeforeAdding() const { return _moveBeforeAdding; } + void setMoveBeforeAdding(bool val) { _moveBeforeAdding = val; } + StaffGroup staffGroup() const; }; diff --git a/libmscore/score.cpp b/libmscore/score.cpp index 7aa284e4436c4..a56e90aa24610 100644 --- a/libmscore/score.cpp +++ b/libmscore/score.cpp @@ -2714,6 +2714,7 @@ void Score::setInputState(Element* e) e = static_cast(e)->upNote(); _is.setDrumNote(-1); + _is.setMoveBeforeAdding(false); // _is.setDrumset(0); if (e->type() == Element::NOTE) { Note* note = static_cast(e);