Skip to content

Commit

Permalink
Added RehearsalMark to midi export as Markers
Browse files Browse the repository at this point in the history
  • Loading branch information
heavy-matill committed Jan 21, 2025
1 parent d9e3ed9 commit 2484d93
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/importexport/midi/internal/midiexport/exportmidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<int>(len));

int tick = r->segment()->tick().ticks() + tickOffset;
track.insert(CompatMidiRender::tick(context, tick), ev);
}
}
}
}
++staffIdx;
}
return !m_midiFile.write(device);
Expand Down

0 comments on commit 2484d93

Please sign in to comment.