Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percussion panel - fix drum note input when switching voices #26804

Merged
merged 3 commits into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/engraving/dom/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion src/engraving/dom/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "select.h"
#include "staff.h"
#include "stem.h"
#include "tuplet.h"

using namespace mu;

Expand Down Expand Up @@ -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);
}

Expand Down
18 changes: 2 additions & 16 deletions src/notation/internal/notationnoteinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading