From 0a75bba3997f1e38ef74ac26224f07206c41c2d2 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Thu, 27 Feb 2025 15:38:37 +0000 Subject: [PATCH 1/3] Fix drum note input when switching voices --- src/engraving/dom/cmd.cpp | 15 --------------- 1 file changed, 15 deletions(-) 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); From 52946d620ab99b26ddd937908117bf7ca414d547 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Fri, 28 Feb 2025 09:31:38 +0000 Subject: [PATCH 2/3] Fix percussion note entry to middle of tuplet --- src/engraving/dom/input.cpp | 18 +++++++++++++++++- src/notation/internal/notationnoteinput.cpp | 15 +-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/engraving/dom/input.cpp b/src/engraving/dom/input.cpp index 1105dc618312b..c2f0ffe0f3d9d 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 || 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..cfd4369f52fe4 100644 --- a/src/notation/internal/notationnoteinput.cpp +++ b/src/notation/internal/notationnoteinput.cpp @@ -663,21 +663,8 @@ void NotationNoteInput::setCurrentVoice(voice_idx_t voiceIndex) } 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); - } - } - } - inputState.setVoice(voiceIndex); + notifyAboutStateChanged(); } From 346675104ae5820f2fb73357803a417d9285113b Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Fri, 28 Feb 2025 10:06:27 +0000 Subject: [PATCH 3/3] Optimizations to InputState::setVoice and NotationNoteInput::setCurrentVoice --- src/engraving/dom/input.cpp | 2 +- src/notation/internal/notationnoteinput.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/engraving/dom/input.cpp b/src/engraving/dom/input.cpp index c2f0ffe0f3d9d..6c208e01bb4c6 100644 --- a/src/engraving/dom/input.cpp +++ b/src/engraving/dom/input.cpp @@ -141,7 +141,7 @@ void InputState::setVoice(voice_idx_t v) { const Score* score = m_segment ? m_segment->score() : nullptr; - if (!score || v >= VOICES || m_track == muse::nidx) { + if (!score || v >= VOICES || v == voice() || m_track == muse::nidx) { return; } diff --git a/src/notation/internal/notationnoteinput.cpp b/src/notation/internal/notationnoteinput.cpp index cfd4369f52fe4..dd2595d27cbdb 100644 --- a/src/notation/internal/notationnoteinput.cpp +++ b/src/notation/internal/notationnoteinput.cpp @@ -658,13 +658,12 @@ void NotationNoteInput::setCurrentVoice(voice_idx_t voiceIndex) { TRACEFUNC; - if (!isVoiceIndexValid(voiceIndex)) { + mu::engraving::InputState& inputState = score()->inputState(); + if (!isVoiceIndexValid(voiceIndex) || voiceIndex == inputState.voice()) { return; } - mu::engraving::InputState& inputState = score()->inputState(); inputState.setVoice(voiceIndex); - notifyAboutStateChanged(); }