diff --git a/src/engraving/dom/cmd.cpp b/src/engraving/dom/cmd.cpp index 1d81fa25245bf..4c2e563c87500 100644 --- a/src/engraving/dom/cmd.cpp +++ b/src/engraving/dom/cmd.cpp @@ -5023,21 +5023,6 @@ void Score::cmdAddPitch(const EditData& ed, const NoteInputParams& params, bool if (ds) { is.setDrumNote(params.drumPitch); is.setVoice(ds->voice(params.drumPitch)); - - if (is.segment()) { - Segment* seg = is.segment(); - while (seg) { - if (seg->element(is.track())) { - break; - } - seg = seg->prev(SegmentType::ChordRest); - } - if (seg) { - is.setSegment(seg); - } else { - is.setSegment(is.segment()->measure()->first(SegmentType::ChordRest)); - } - } } cmdAddPitch(params.step, addFlag, insert); diff --git a/src/engraving/dom/input.cpp b/src/engraving/dom/input.cpp index 1105dc618312b..6c208e01bb4c6 100644 --- a/src/engraving/dom/input.cpp +++ b/src/engraving/dom/input.cpp @@ -35,6 +35,7 @@ #include "select.h" #include "staff.h" #include "stem.h" +#include "tuplet.h" using namespace mu; @@ -138,10 +139,25 @@ void InputState::setDots(int n) void InputState::setVoice(voice_idx_t v) { - if (v >= VOICES || m_track == muse::nidx) { + const Score* score = m_segment ? m_segment->score() : nullptr; + + if (!score || v >= VOICES || v == voice() || m_track == muse::nidx) { return; } + // TODO: Inserting notes to a new voice in the middle of a tuplet is not yet supported. In this case + // we'll move the input to the start of the tuplet... + if (const Segment* prevSeg = segment()) { + const ChordRest* prevCr = prevSeg->cr(track()); + //! NOTE: if there's an existing ChordRest at the new voiceIndex, we don't need to move the cursor + if (prevCr && prevCr->topTuplet() && !prevSeg->cr(v)) { + Segment* newSeg = score->tick2segment(prevCr->topTuplet()->tick()); + if (newSeg) { + setSegment(newSeg); + } + } + } + setTrack((m_track / VOICES) * VOICES + v); } diff --git a/src/notation/internal/notationnoteinput.cpp b/src/notation/internal/notationnoteinput.cpp index 4605047ba0c99..dd2595d27cbdb 100644 --- a/src/notation/internal/notationnoteinput.cpp +++ b/src/notation/internal/notationnoteinput.cpp @@ -658,23 +658,9 @@ void NotationNoteInput::setCurrentVoice(voice_idx_t voiceIndex) { TRACEFUNC; - if (!isVoiceIndexValid(voiceIndex)) { - return; - } - mu::engraving::InputState& inputState = score()->inputState(); - - // TODO: Inserting notes to a new voice in the middle of a tuplet is not yet supported. In this case - // we'll move the input to the start of the tuplet... - if (const Segment* prevSeg = inputState.segment()) { - const ChordRest* prevCr = prevSeg->cr(inputState.track()); - //! NOTE: if there's an existing ChordRest at the new voiceIndex, we don't need to move the cursor - if (prevCr && prevCr->topTuplet() && !prevSeg->cr(voiceIndex)) { - Segment* newSeg = score()->tick2segment(prevCr->topTuplet()->tick()); - if (newSeg) { - inputState.setSegment(newSeg); - } - } + if (!isVoiceIndexValid(voiceIndex) || voiceIndex == inputState.voice()) { + return; } inputState.setVoice(voiceIndex);