Skip to content
Merged
Show file tree
Hide file tree
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
52 changes: 43 additions & 9 deletions src/importexport/musicxml/internal/export/exportmusicxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class ExportMusicXml : public muse::Contextable
void rest(Rest* chord, staff_idx_t staff, const std::vector<Lyrics*>& ll);
void clef(staff_idx_t staff, const ClefType ct, const String& extraAttributes = u"");
void timesig(const TimeSig* tsig, staff_idx_t staff);
void keysig(const KeySig* ks, ClefType ct, staff_idx_t staff = 0, bool visible = true);
void keysig(const KeySig* ks, ClefType ct, staff_idx_t staff = 0);
void barlineLeft(const Measure* const m, const track_idx_t track);
void barlineMiddle(const BarLine* bl);
void barlineRight(const Measure* const m, const track_idx_t strack, const track_idx_t etrack);
Expand Down Expand Up @@ -2205,7 +2205,8 @@ void ExportMusicXml::timesig(const TimeSig* tsig, staff_idx_t staff)
attrs.push_back({ "number", staff });
}

if (!tsig->visible() || !tsig->showOnThisStaff()) {
if (!tsig->visible() || !tsig->showOnThisStaff()
|| (tsig->staff() && !tsig->staff()->staffType(tsig->tick())->genTimesig())) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
attrs.emplace_back(std::make_pair("print-object", "no"));
}

Expand Down Expand Up @@ -2433,7 +2434,7 @@ static double accSymId2alter(SymId id)
// keysig
//---------------------------------------------------------

void ExportMusicXml::keysig(const KeySig* ks, ClefType ct, staff_idx_t staff, bool visible)
void ExportMusicXml::keysig(const KeySig* ks, ClefType ct, staff_idx_t staff)
{
static char16_t table2[] = u"CDEFGAB";
int po = ClefInfo::pitchOffset(ct); // actually 7 * oct + step for topmost staff line
Expand All @@ -2444,7 +2445,7 @@ void ExportMusicXml::keysig(const KeySig* ks, ClefType ct, staff_idx_t staff, bo
if (staff) {
attrs.emplace_back(std::make_pair("number", staff));
}
if (!visible) {
if (!ks->visible() || (ks->staff() && ks->staff()->isTabStaff(Fraction(0, 1)))) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
attrs.emplace_back(std::make_pair("print-object", "no"));
}
addColorAttr(ks, attrs);
Expand Down Expand Up @@ -4558,7 +4559,9 @@ void ExportMusicXml::rest(Rest* rest, staff_idx_t staff, const std::vector<Lyric
String noteTag = u"note";
noteTag += color2xml(rest);
noteTag += elementPosition(this, rest);
if (!rest->visible()) {
if (!rest->visible()
|| (rest->staff() && rest->staff()->staffType(rest->tick())->isTabStaff()
&& !rest->staff()->staffType(rest->tick())->showRests())) {
noteTag += u" print-object=\"no\"";
}
m_xml.startElementRaw(noteTag);
Expand Down Expand Up @@ -7014,16 +7017,27 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p)
}
}
}
if (singleKey) {
auto keyPrintObject = [](const KeySig* ks) {
return !ks->visible() || (ks->staff() && ks->staff()->isTabStaff(ks->tick()));
};
for (staff_idx_t i = 1; i < nstaves; i++) {
if (keyPrintObject(keysigs.at(i)) != keyPrintObject(keysigs.at(0))) {
singleKey = false;
break;
}
}
}

// write the keysigs
//LOGD(" singleKey %d", singleKey);
if (singleKey) {
// keysig applies to all staves
keysig(keysigs.at(0), p->staff(0)->clef(m->tick()), 0, keysigs.at(0)->visible());
keysig(keysigs.at(0), p->staff(0)->clef(m->tick()), 0);
} else {
// staff-specific keysigs
for (const auto& [st, ks] : keysigs) {
keysig(ks, p->staff(st)->clef(m->tick()), st + 1, ks->visible());
keysig(ks, p->staff(st)->clef(m->tick()), st + 1);
}
}
} else {
Expand All @@ -7032,6 +7046,9 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p)
//KeySigEvent kse;
//kse.setKey(Key::C);
KeySig* ks = Factory::createKeySig(m_score->dummy()->segment());
if (p->staff(0)->isTabStaff(Fraction(0, 1))) {
ks->setVisible(false);
}
ks->setKey(Key::C);
keysig(ks, p->staff(0)->clef(m->tick()));
delete ks;
Expand Down Expand Up @@ -7059,6 +7076,18 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p)
}
}
}
if (singleTime) {
auto timePrintObject = [](const TimeSig* ts) {
return !ts->visible() || !ts->showOnThisStaff()
|| (ts->staff() && !ts->staff()->staffType(ts->tick())->genTimesig());
};
for (staff_idx_t i = 1; i < nstaves; i++) {
if (timePrintObject(timesigs.at(i)) != timePrintObject(timesigs.at(0))) {
singleTime = false;
break;
}
}
}

// write the timesigs
LOGN(" singleTime %d", singleTime);
Expand Down Expand Up @@ -7568,7 +7597,8 @@ void ExportMusicXml::findAndExportClef(const Measure* const m, const int staves,
&& ((seg->measure() != m) || ((seg->segmentType() == SegmentType::HeaderClef) && !cle->otherClef()))) {
clefDebug("exportxml: clef exported");
String clefAttr = color2xml(cle);
if (!cle->visible()) {
if (!cle->visible()
|| (cle->staff() && !cle->staff()->staffType(cle->tick())->genClef())) {
clefAttr += u" print-object=\"no\"";
}
clef(sstaff, cle->clefType(), clefAttr);
Expand Down Expand Up @@ -7831,7 +7861,8 @@ void ExportMusicXml::writeElement(EngravingItem* el, const Measure* m, staff_idx
// these will be output at the start of the next measure
const Clef* cle = toClef(el);
const Fraction ti = cle->segment()->tick();
const String visible = (!cle->visible()) ? u" print-object=\"no\"" : String();
const String visible
= (!cle->visible() || (cle->staff() && !cle->staff()->staffType(cle->tick())->genClef())) ? u" print-object=\"no\"" : String();
clefDebug("exportxml: clef in measure ti=%d ct=%d gen=%d", ti, int(cle->clefType()), el->generated());
if (el->generated()) {
clefDebug("exportxml: generated clef not exported");
Expand Down Expand Up @@ -7922,6 +7953,9 @@ static void writeStaffDetails(XmlWriter& xml, const Part* part, const std::vecto
if (staves > 1) {
attributes.emplace_back(std::make_pair("number", i + 1));
}
if (st->isTabStaff(Fraction(0, 1)) && !st->staffType(Fraction(0, 1))->useNumbers()) {
attributes.emplace_back(std::make_pair("show-frets", "letters"));
}
if (hidden) {
attributes.emplace_back(std::make_pair("print-object", "no"));
if (st->cutaway()) {
Expand Down
6 changes: 3 additions & 3 deletions src/importexport/musicxml/tests/data/testGuitarBends_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
<time print-object="no">
<beats>4</beats>
<beat-type>4</beat-type>
</time>
Expand Down Expand Up @@ -356,7 +356,7 @@
</technical>
</notations>
</note>
<note>
<note print-object="no">
<rest/>
<duration>1</duration>
<voice>1</voice>
Expand Down
18 changes: 11 additions & 7 deletions src/importexport/musicxml/tests/data/testHarmony7_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
<key>
<fifths>0</fifths>
</key>
<time>
<time number="1">
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<time number="2" print-object="no">
<beats>4</beats>
<beat-type>4</beat-type>
</time>
Expand Down Expand Up @@ -482,7 +486,7 @@
<backup>
<duration>4</duration>
</backup>
<note>
<note print-object="no">
<rest/>
<duration>4</duration>
<voice>5</voice>
Expand Down Expand Up @@ -693,14 +697,14 @@
</technical>
</notations>
</note>
<note>
<note print-object="no">
<rest/>
<duration>1</duration>
<voice>5</voice>
<type>quarter</type>
<staff>2</staff>
</note>
<note>
<note print-object="no">
<rest/>
<duration>1</duration>
<voice>5</voice>
Expand Down Expand Up @@ -744,14 +748,14 @@
</technical>
</notations>
</note>
<note>
<note print-object="no">
<rest/>
<duration>1</duration>
<voice>6</voice>
<type>quarter</type>
<staff>2</staff>
</note>
<note>
<note print-object="no">
<rest/>
<duration>1</duration>
<voice>6</voice>
Expand All @@ -769,7 +773,7 @@
<backup>
<duration>4</duration>
</backup>
<note>
<note print-object="no">
<rest measure="yes"/>
<duration>4</duration>
<voice>5</voice>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/musicxml/tests/data/testStringData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/musicxml/tests/data/testTablature1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/musicxml/tests/data/testTablature2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/musicxml/tests/data/testTablature3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/musicxml/tests/data/testTablature4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/musicxml/tests/data/testTablature5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<key print-object="no">
<fifths>0</fifths>
</key>
<time>
Expand Down
Loading
Loading