Skip to content

Commit

Permalink
Merge pull request #23487 from miiizen/23002-lyric-rash
Browse files Browse the repository at this point in the history
Fix crash on lyric navigation and dash between voices
  • Loading branch information
mike-spa authored Jul 8, 2024
2 parents f6b44b4 + 92c931c commit a340eab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/engraving/dom/lyrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ bool Lyrics::setProperty(Pid propertyId, const PropertyValue& v)
if (Lyrics* l = prevLyrics(this)) {
l->setNeedRemoveInvalidSegments();
}
if (Lyrics* l = nextLyrics(this)) {
setNeedRemoveInvalidSegments();
}
setPlacement(newVal);
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/engraving/dom/navigate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,4 +1039,25 @@ Lyrics* prevLyrics(const Lyrics* lyrics)
}
return nullptr;
}

Lyrics* nextLyrics(const Lyrics* lyrics)
{
Segment* seg = lyrics->explicitParent() ? lyrics->segment() : nullptr;
if (!seg) {
return nullptr;
}
Segment* nextSegment = seg;
while ((nextSegment = nextSegment->next1(mu::engraving::SegmentType::ChordRest))) {
const track_idx_t strack = lyrics->staffIdx() * VOICES;
const track_idx_t etrack = strack + VOICES;
for (track_idx_t track = strack; track < etrack; ++track) {
EngravingItem* el = nextSegment->element(track);
Lyrics* nextLyrics = el && el->isChord() ? toChordRest(el)->lyrics(lyrics->no(), lyrics->placement()) : nullptr;
if (nextLyrics) {
return nextLyrics;
}
}
}
return nullptr;
}
}
1 change: 1 addition & 0 deletions src/engraving/dom/navigate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ extern int pitch2y(int pitch, int enh, int clefOffset, int key, int& prefix, con
extern ChordRest* nextChordRest(const ChordRest* cr, bool skipGrace = false, bool skipMeasureRepeatRests = true);
extern ChordRest* prevChordRest(const ChordRest* cr, bool skipGrace = false, bool skipMeasureRepeatRests = true);
extern Lyrics* prevLyrics(const Lyrics* lyrics);
extern Lyrics* nextLyrics(const Lyrics* lyrics);
} // namespace mu::engraving
#endif
1 change: 1 addition & 0 deletions src/engraving/rendering/dev/lyricslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void LyricsLayout::layout(LyricsLine* item, LayoutContext& ctx)
item->lyrics()->no(),
item->lyrics()->placement()
));
item->setTrack2(item->nextLyrics() ? item->nextLyrics()->track() : item->track());

item->setTick2(item->nextLyrics() ? item->nextLyrics()->segment()->tick() : item->tick());
}
Expand Down
6 changes: 4 additions & 2 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5049,6 +5049,7 @@ void NotationInteraction::navigateToNextSyllable()
}
mu::engraving::Lyrics* lyrics = toLyrics(m_editData.element);
track_idx_t track = lyrics->track();
track_idx_t toLyricTrack = track;
mu::engraving::Segment* segment = lyrics->segment();
int verse = lyrics->no();
mu::engraving::PlacementV placement = lyrics->placement();
Expand All @@ -5065,7 +5066,8 @@ void NotationInteraction::navigateToNextSyllable()
const track_idx_t etrack = strack + VOICES;
for (track_idx_t t = strack; t < etrack; ++t) {
el = nextSegment->element(t);
if (el && el->isChord()) {
if (el && el->isChord() && toChord(el)->lyrics(verse, placement)) {
toLyricTrack = t;
break;
}
}
Expand Down Expand Up @@ -5098,7 +5100,7 @@ void NotationInteraction::navigateToNextSyllable()
}

score()->startCmd();
ChordRest* cr = toChordRest(nextSegment->element(track));
ChordRest* cr = toChordRest(nextSegment->element(toLyricTrack));
mu::engraving::Lyrics* toLyrics = cr->lyrics(verse, placement);

// If no lyrics in current track, check others
Expand Down

0 comments on commit a340eab

Please sign in to comment.