Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RehearsalMark to midi export as Markers #26196

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/importexport/midi/internal/midiexport/exportmidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "engraving/dom/masterscore.h"
#include "engraving/dom/note.h"
#include "engraving/dom/part.h"
#include "engraving/dom/rehearsalmark.h"
#include "engraving/dom/repeatlist.h"
#include "engraving/dom/sig.h"
#include "engraving/dom/staff.h"
Expand Down Expand Up @@ -372,12 +373,13 @@ bool ExportMidi::write(QIODevice* device, bool midiExpandRepeats, bool exportRPN
}
}

// Export lyrics
// Export lyrics and RehearsalMarks as Meta events
for (const RepeatSegment* rs : m_score->repeatList()) {
int startTick = rs->tick;
int endTick = startTick + rs->len();
int tickOffset = rs->utick - rs->tick;

// export Lyrics
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) {
Expand All @@ -402,6 +404,33 @@ bool ExportMidi::write(QIODevice* device, bool midiExpandRepeats, bool exportRPN
}
}
}

// export RehearsalMarks only for first track
if (staffIdx == 0) {
for (Segment* seg = rs->firstMeasure()->first(Segment::CHORD_REST_OR_TIME_TICK_TYPE);
seg && seg->tick().ticks() < endTick;
seg = seg->next1(Segment::CHORD_REST_OR_TIME_TICK_TYPE)) {
for (EngravingItem* e : seg->annotations()) {
if (e->isRehearsalMark()) {
RehearsalMark* r = toRehearsalMark(e);
muse::ByteArray rText = r->plainText().toUtf8();
size_t len = rText.size() + 1;
unsigned char* data = new unsigned char[len];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Just for the record: beware that there's a data leak here. But you don't need to fix it in this PR, because it's exactly the same for lyrics and port changes.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the problem is tracked elsewhere i'd like to make a note there rather than a code comment now

Copy link
Contributor

@cbjeukendrup cbjeukendrup Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a tech debt issue about it, so you don't need to do anything with it now. (Update: created #26415)


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;
}
Expand Down
Loading