From 2484d932ef0cbbb8c4ccf1cf5dacd0f89897de6e Mon Sep 17 00:00:00 2001 From: heavy-matill Date: Tue, 21 Jan 2025 20:44:55 +0100 Subject: [PATCH] Added RehearsalMark to midi export as Markers --- .../midi/internal/midiexport/exportmidi.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/importexport/midi/internal/midiexport/exportmidi.cpp b/src/importexport/midi/internal/midiexport/exportmidi.cpp index 37f794b18e3d0..cfefddf9c809c 100644 --- a/src/importexport/midi/internal/midiexport/exportmidi.cpp +++ b/src/importexport/midi/internal/midiexport/exportmidi.cpp @@ -24,6 +24,7 @@ #include "engraving/dom/key.h" #include "engraving/dom/lyrics.h" +#include "engraving/dom/rehearsalmark.h" #include "engraving/dom/masterscore.h" #include "engraving/dom/note.h" #include "engraving/dom/part.h" @@ -403,6 +404,35 @@ bool ExportMidi::write(QIODevice* device, bool midiExpandRepeats, bool exportRPN } } } + + // Export RehearsalMarks as Markers + for (const RepeatSegment *rs : m_score->repeatList()) { + int startTick = rs->tick; + int endTick = startTick + rs->len(); + int tickOffset = rs->utick - rs->tick; + + for (Segment* seg = rs->firstMeasure()->first(); seg && seg->tick().ticks() < endTick; seg = seg->next1()) { + for (EngravingItem* e : seg->annotations()) { + if (e->type() == ElementType::REHEARSAL_MARK) { + RehearsalMark* r = toRehearsalMark(e); + muse::ByteArray rText = r->plainText().toUtf8(); + size_t len = rText.size() + 1; + unsigned char *data = new unsigned char[len]; + + memcpy(data, rText.constData(), len); + + MidiEvent ev; + ev.setType(ME_META); + ev.setMetaType(META_MARKER); + ev.setEData(data); + ev.setLen(static_cast(len)); + + int tick = r->segment()->tick().ticks() + tickOffset; + track.insert(CompatMidiRender::tick(context, tick), ev); + } + } + } + } ++staffIdx; } return !m_midiFile.write(device);