@@ -326,7 +326,7 @@ void PlaybackContext::update(const ID partId, const Score* score, bool expandRep
326326 for (const Segment* segment = measure->first (); segment; segment = segment->next ()) {
327327 int segmentStartTick = segment->tick ().ticks () + tickPositionOffset;
328328
329- handleSegmentElements (segment, segmentStartTick, measureRepeats);
329+ handleSegmentElements (repeatSegment, segment, segmentStartTick, measureRepeats);
330330 handleSegmentAnnotations (partId, segment, segmentStartTick);
331331 }
332332 }
@@ -354,6 +354,7 @@ void PlaybackContext::clear()
354354 m_textArticulationsByTrack.clear ();
355355 m_syllablesByTrack.clear ();
356356 m_currentVerseNumByChordRest.clear ();
357+ m_multiVerseLyricsPositionMap.clear ();
357358}
358359
359360bool PlaybackContext::hasSoundFlags () const
@@ -680,7 +681,8 @@ void PlaybackContext::handleSegmentAnnotations(const ID partId, const Segment* s
680681 }
681682}
682683
683- void PlaybackContext::handleSegmentElements (const Segment* segment, const int segmentPositionTick,
684+ void PlaybackContext::handleSegmentElements (const RepeatSegment* repeat, const Segment* segment,
685+ const int segmentPositionTick,
684686 std::vector<const MeasureRepeat*>& foundMeasureRepeats)
685687{
686688 for (track_idx_t track = m_partStartTrack; track < m_partEndTrack; ++track) {
@@ -698,22 +700,26 @@ void PlaybackContext::handleSegmentElements(const Segment* segment, const int se
698700 m_usedVoices.insert (item->voice ());
699701
700702 const ChordRest* chordRest = toChordRest (item);
701- const std::vector<Lyrics*>& lyricsList = chordRest->lyrics ();
702- if (lyricsList.empty ()) {
703+ if (chordRest->lyrics ().empty ()) {
703704 continue ;
704705 }
705706
706- int verseNum = 0 ;
707+ const Lyrics* lyrics = nullptr ;
707708
708709 auto verseNumIt = m_currentVerseNumByChordRest.find (chordRest);
709710 if (verseNumIt == m_currentVerseNumByChordRest.end ()) {
710711 m_currentVerseNumByChordRest[chordRest] = 0 ;
712+ lyrics = chordRest->lyrics (0 );
713+ if (chordRest->lyrics ().size () > 1 ) {
714+ m_multiVerseLyricsPositionMap[track].insert (chordRest->tick ().ticks ());
715+ }
716+ } else if (hasOnlyOneLyricsVerse (repeat, track)) {
717+ lyrics = chordRest->lyrics (0 );
711718 } else {
712719 verseNumIt->second ++;
713- verseNum = verseNumIt->second ;
720+ lyrics = chordRest-> lyrics ( verseNumIt->second ) ;
714721 }
715722
716- const Lyrics* lyrics = chordRest->lyrics (verseNum);
717723 if (lyrics) {
718724 updateSyllableMap (lyrics, segmentPositionTick);
719725 }
@@ -827,3 +833,22 @@ bool PlaybackContext::shouldSkipTrack(const track_idx_t trackIdx) const
827833{
828834 return !muse::contains (m_usedVoices, track2voice (trackIdx));
829835}
836+
837+ bool PlaybackContext::hasOnlyOneLyricsVerse (const RepeatSegment* repeat, const track_idx_t track) const
838+ {
839+ if (m_multiVerseLyricsPositionMap.empty ()) {
840+ return true ;
841+ }
842+
843+ const auto trackIt = m_multiVerseLyricsPositionMap.find (track);
844+ if (trackIt == m_multiVerseLyricsPositionMap.cend ()) {
845+ return true ;
846+ }
847+
848+ const int startTick = repeat->tick ;
849+ const int endTick = repeat->endTick ();
850+ const auto start = trackIt->second .lower_bound (startTick);
851+ const auto end = trackIt->second .lower_bound (endTick);
852+
853+ return start == end;
854+ }
0 commit comments