Skip to content

Commit 5302561

Browse files
--score-elements: export ties as flag rather than separate elements
1 parent a6d7347 commit 5302561

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

src/converter/internal/compat/backendapi.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,25 @@ muse::Ret BackendApi::doExportScoreElements(const notation::INotationPtr notatio
677677
}
678678
};
679679

680+
auto writeFlags = [](const ElementInfo::Flags& flags, QJsonObject& obj) {
681+
if (flags.testFlag(ElementInfo::FlagType::Tied)) {
682+
obj["tied"] = true;
683+
}
684+
};
685+
686+
auto writeNotes = [&writeFlags](const ElementInfo::NoteList& notes, QJsonObject& obj) {
687+
QJsonArray noteArray;
688+
689+
for (const ElementInfo::Note& note : notes) {
690+
QJsonObject noteObj;
691+
noteObj["name"] = note.name.toQString();
692+
writeFlags(note.flags, noteObj);
693+
noteArray << noteObj;
694+
}
695+
696+
obj["notes"] = noteArray;
697+
};
698+
680699
for (const auto& instrumentPair : elements) {
681700
QJsonArray elementArray;
682701

@@ -690,7 +709,9 @@ muse::Ret BackendApi::doExportScoreElements(const notation::INotationPtr notatio
690709
}
691710

692711
if (!element.notes.empty()) {
693-
obj["notes"] = element.notes.toQString();
712+
writeNotes(element.notes, obj);
713+
} else {
714+
writeFlags(element.flags, obj);
694715
}
695716

696717
if (!element.duration.empty()) {

src/converter/internal/compat/backendtypes.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#pragma once
2323

2424
#include "global/types/string.h"
25+
#include "global/types/flags.h"
2526
#include "global/realfn.h"
2627

2728
#include "engraving/types/types.h"
@@ -31,10 +32,25 @@ struct ElementInfo
3132
{
3233
mu::engraving::ElementType type = mu::engraving::ElementType::INVALID;
3334
muse::String name;
34-
muse::String notes;
3535
muse::String duration;
3636
muse::String text;
3737

38+
enum class FlagType {
39+
NoFlags = 0,
40+
Tied,
41+
};
42+
43+
using Flags = muse::Flags<FlagType>;
44+
Flags flags;
45+
46+
struct Note {
47+
muse::String name;
48+
muse::Flags<FlagType> flags;
49+
};
50+
51+
using NoteList = std::vector<Note>;
52+
NoteList notes;
53+
3854
struct Location {
3955
mu::engraving::staff_idx_t staffIdx = muse::nidx;
4056
mu::engraving::voice_idx_t voiceIdx = muse::nidx;

src/converter/internal/compat/scoreelementsscanner.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static bool itemAccepted(const EngravingItem* item)
5454
ElementType::HOOK,
5555
ElementType::BEAM,
5656
ElementType::NOTEDOT,
57+
ElementType::TIE,
58+
ElementType::TIE_SEGMENT,
5759
};
5860

5961
if (muse::contains(NOTE_PARTS, item->type())) {
@@ -88,16 +90,23 @@ static muse::String noteName(const Note* note)
8890
return tpc2name(note->tpc(), NoteSpellingType::STANDARD, NoteCaseType::AUTO) + String::number(note->octave());
8991
}
9092

91-
static muse::String chordToNotes(const Chord* chord)
93+
static ElementInfo::NoteList chordToNotes(const Chord* chord)
9294
{
93-
muse::StringList notes;
95+
ElementInfo::NoteList notes;
9496
notes.reserve(chord->notes().size());
9597

9698
for (const Note* note : chord->notes()) {
97-
notes.push_back(noteName(note));
99+
ElementInfo::Note info;
100+
info.name = noteName(note);
101+
102+
if (note->tieFor()) {
103+
info.flags.setFlag(ElementInfo::FlagType::Tied);
104+
}
105+
106+
notes.emplace_back(std::move(info));
98107
}
99108

100-
return notes.join(u" ");
109+
return notes;
101110
}
102111

103112
static void addElementInfoIfNeed(ScannerData* scannerData, EngravingItem* item)
@@ -123,6 +132,10 @@ static void addElementInfoIfNeed(ScannerData* scannerData, EngravingItem* item)
123132
info.notes = chordToNotes(chord);
124133
} else {
125134
info.name = noteName(note);
135+
136+
if (note->tieFor()) {
137+
info.flags.setFlag(ElementInfo::FlagType::Tied);
138+
}
126139
}
127140
info.duration = chord->durationUserName();
128141
} else if (isChordArticulation(item)) {

0 commit comments

Comments
 (0)