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 15, 2024
1 parent 22510c3 commit d1b6c98
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
30 changes: 25 additions & 5 deletions src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4572,11 +4572,31 @@ ChordRest* Score::findCR(Fraction tick, track_idx_t track) const
}

//---------------------------------------------------------
// findCRinStaff
// findChordRestEndingBeforeTickInStaff
// find last chord/rest on staff that ends before tick
//---------------------------------------------------------

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

//-----------------------------------------------------------------
// findChordRestEndingBeforeTickInStaffAndVoice
// 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);
}

//-----------------------------------------------------------------
// findChordRestEndingBeforeTickInStaffAndVoice
// 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 @@ -8504,15 +8504,18 @@ static void addWavyLine(ChordRest* cr, const Fraction& tick,
if (!wavyLineType.empty()) {
const Fraction ticks = cr->ticks();
const track_idx_t track = cr->track();
const track_idx_t trk = (track / VOICES) * VOICES; // first track of staff
Trill*& trill = trills[wavyLineNo];
if (wavyLineType == u"start" || wavyLineType == u"startstop") {
if (trill) {
logger->logError(String(u"overlapping wavy-line number %1").arg(wavyLineNo + 1), xmlreader);
} else {
trill = Factory::createTrill(cr->score()->dummy());
trill->setTrack(trk);
trill->setTrack2(trk);
trill->setTrack(track);
trill->setTrack2(track);

Ornament trillOrnament(cr);
trill->setOrnament(trillOrnament.clone());

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
3 changes: 3 additions & 0 deletions src/inspector/models/abstractinspectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ mu::engraving::Sid AbstractInspectorModel::styleIdByPropertyId(const mu::engravi
mu::engraving::Sid result = mu::engraving::Sid::NOSTYLE;

for (const mu::engraving::EngravingItem* element : m_elementList) {
IF_ASSERT_FAILED(element) {
continue;
}
result = element->getPropertyStyle(pid);

if (result != mu::engraving::Sid::NOSTYLE) {
Expand Down

0 comments on commit d1b6c98

Please sign in to comment.