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); + } } } }