Skip to content

Commit

Permalink
Fix #23977: Export to MusicXml wavy line starts in second voices
Browse files Browse the repository at this point in the history
  • Loading branch information
pacebes committed Dec 12, 2024
1 parent 22510c3 commit 4d29922
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
28 changes: 24 additions & 4 deletions src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4577,6 +4577,26 @@ ChordRest* Score::findCR(Fraction tick, track_idx_t track) const
//---------------------------------------------------------

ChordRest* Score::findChordRestEndingBeforeTickInStaff(const Fraction& tick, staff_idx_t staffIdx) const
{
return findChordRestEndingBeforeTickInStaffAndVoice(tick, staffIdx, false, 0);
}

//-----------------------------------------------------------------
// findCRinStaff
// find last chord/rest on staff and voice that ends before tick
//-----------------------------------------------------------------
ChordRest* Score::findChordRestEndingBeforeTickInStaffAndVoice(const Fraction& tick, staff_idx_t staffIdx, voice_idx_t voice) const
{
return findChordRestEndingBeforeTickInStaffAndVoice(tick, staffIdx, true, voice);
}

//-----------------------------------------------------------------
// findCRinStaff
// find last chord/rest on staff and voice that ends before tick
// allow no specific voice
//-----------------------------------------------------------------
ChordRest* Score::findChordRestEndingBeforeTickInStaffAndVoice(const Fraction& tick, staff_idx_t staffIdx, bool forceVoice,
voice_idx_t voice) const
{
Fraction ptick = tick - Fraction::fromTicks(1);
Measure* m = tick2measureMM(ptick);
Expand All @@ -4589,9 +4609,9 @@ ChordRest* Score::findChordRestEndingBeforeTickInStaff(const Fraction& tick, sta
ptick = m->tick();
}

Segment* s = m->first(SegmentType::ChordRest);
track_idx_t strack = staffIdx * VOICES;
track_idx_t etrack = strack + VOICES;
Segment* s = m->first(SegmentType::ChordRest);
track_idx_t strack = staffIdx * VOICES;
track_idx_t etrack = strack + VOICES;
track_idx_t actualTrack = strack;

Fraction lastTick = Fraction(-1, 1);
Expand All @@ -4602,7 +4622,7 @@ ChordRest* Score::findChordRestEndingBeforeTickInStaff(const Fraction& tick, sta
// found a segment; now find longest cr on this staff that does not overlap tick
for (track_idx_t t = strack; t < etrack; ++t) {
ChordRest* cr = toChordRest(ns->element(t));
if (cr) {
if ((cr) && ((!forceVoice) || voice == cr->voice())) {
Fraction endTick = cr->tick() + cr->actualTicks();
if (endTick >= lastTick && endTick <= tick) {
s = ns;
Expand Down
3 changes: 3 additions & 0 deletions src/engraving/dom/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ class Score : public EngravingObject, public muse::Injectable

ChordRest* findCR(Fraction tick, track_idx_t track) const;
ChordRest* findChordRestEndingBeforeTickInStaff(const Fraction& tick, staff_idx_t staffIdx) const;
ChordRest* findChordRestEndingBeforeTickInStaffAndVoice(const Fraction& tick, staff_idx_t staffIdx, voice_idx_t voice) const;
ChordRest* findChordRestEndingBeforeTickInTrack(const Fraction& tick, track_idx_t trackIdx) const;
void insertTime(const Fraction& tickPos, const Fraction& tickLen);

Expand Down Expand Up @@ -1055,6 +1056,8 @@ class Score : public EngravingObject, public muse::Injectable
Note* getSelectedNote();
ChordRest* nextTrack(ChordRest* cr, bool skipMeasureRepeatRests = true);
ChordRest* prevTrack(ChordRest* cr, bool skipMeasureRepeatRests = true);
ChordRest* findChordRestEndingBeforeTickInStaffAndVoice(const Fraction& tick, staff_idx_t staffIdx, bool forceVoice,
voice_idx_t voice) const;

void addTempo();
void addMetronome();
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/trill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,6 @@ String Trill::accessibleInfo() const

void Trill::doComputeEndElement()
{
setEndElement(score()->findChordRestEndingBeforeTickInStaff(tick2(), track2staff(track2())));
setEndElement(score()->findChordRestEndingBeforeTickInStaffAndVoice(tick2(), track2staff(track2()), voice()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8513,6 +8513,8 @@ static void addWavyLine(ChordRest* cr, const Fraction& tick,
trill = Factory::createTrill(cr->score()->dummy());
trill->setTrack(trk);
trill->setTrack2(trk);
// To be sure the right voice is set as createTrill does not copy the right voice from cr->score
trill->setVoice(cr->voice());
if (wavyLineType == u"start") {
spanners[trill] = std::pair<int, int>(tick.ticks(), -1);
// LOGD("trill=%p inserted at first tick %d", trill, tick);
Expand Down

0 comments on commit 4d29922

Please sign in to comment.