From 6fbd133e1a2a30e3de1411596c75c21d6cf6fa96 Mon Sep 17 00:00:00 2001 From: bakajikara <102702868+bakajikara@users.noreply.github.com> Date: Fri, 23 Aug 2024 21:57:14 +0900 Subject: [PATCH] Fix #24168: Correctly export repeat lyrics --- .../midi/internal/midiexport/exportmidi.cpp | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/importexport/midi/internal/midiexport/exportmidi.cpp b/src/importexport/midi/internal/midiexport/exportmidi.cpp index 4db8e406e3988..529ca037b286d 100644 --- a/src/importexport/midi/internal/midiexport/exportmidi.cpp +++ b/src/importexport/midi/internal/midiexport/exportmidi.cpp @@ -373,25 +373,32 @@ bool ExportMidi::write(QIODevice* device, bool midiExpandRepeats, bool exportRPN } // Export lyrics - SegmentType st = SegmentType::ChordRest; - for (Segment* seg = m_score->firstMeasure()->first(st); seg; seg = seg->next1(st)) { - for (track_idx_t i = part->startTrack(); i < part->endTrack(); ++i) { - ChordRest* cr = toChordRest(seg->element(i)); - if (cr) { - for (const auto& lyric : cr->lyrics()) { - muse::ByteArray lyricText = lyric->plainText().toUtf8(); - size_t len = lyricText.size() + 1; - unsigned char* data = new unsigned char[len]; - - memcpy(data, lyricText.constData(), len); - - MidiEvent ev; - ev.setType(ME_META); - ev.setMetaType(META_LYRIC); - ev.setEData(data); - ev.setLen(static_cast(len)); - - track.insert(cr->tick().ticks(), ev); + for (const RepeatSegment* rs : m_score->repeatList()) { + int startTick = rs->tick; + int endTick = startTick + rs->len(); + int tickOffset = rs->utick - rs->tick; + + SegmentType st = SegmentType::ChordRest; + for (Segment* seg = rs->firstMeasure()->first(st); seg && seg->tick().ticks() < endTick; seg = seg->next1(st)) { + for (track_idx_t i = part->startTrack(); i < part->endTrack(); ++i) { + ChordRest* cr = toChordRest(seg->element(i)); + if (cr) { + for (const auto& lyric : cr->lyrics()) { + muse::ByteArray lyricText = lyric->plainText().toUtf8(); + size_t len = lyricText.size() + 1; + unsigned char* data = new unsigned char[len]; + + memcpy(data, lyricText.constData(), len); + + MidiEvent ev; + ev.setType(ME_META); + ev.setMetaType(META_LYRIC); + ev.setEData(data); + ev.setLen(static_cast(len)); + + int tick = cr->tick().ticks() + tickOffset; + track.insert(CompatMidiRender::tick(context, tick), ev); + } } } }