Skip to content

Commit b85a902

Browse files
rettinghausJojo-Schmitz
authored andcommitted
[MusicXML] invisible notations
Backport of musescore#27422
1 parent 919eccc commit b85a902

File tree

5 files changed

+367
-103
lines changed

5 files changed

+367
-103
lines changed

importexport/musicxml/exportxml.cpp

+54-59
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Notations {
192192

193193
public:
194194
Notations() { notationsPrinted = false; }
195-
void tag(XmlWriter& xml);
195+
void tag(XmlWriter& xml, const Element* e);
196196
void etag(XmlWriter& xml);
197197
};
198198

@@ -525,11 +525,20 @@ static QString positioningAttributes(Element const* const el, bool isSpanStart =
525525
// tag
526526
//---------------------------------------------------------
527527

528-
void Notations::tag(XmlWriter& xml)
528+
void Notations::tag(XmlWriter& xml, const Element* e)
529529
{
530-
if (!notationsPrinted)
531-
xml.stag("notations");
530+
//if (notationsPrinted && _prevElementVisible != e->visible())
531+
// etag(xml);
532+
533+
if (!notationsPrinted) {
534+
if (e->visible())
535+
xml.stag("notations");
536+
else
537+
xml.stag("notations print-object=\"no\"");
538+
}
539+
532540
notationsPrinted = true;
541+
//_prevElementVisible = e->visible();
533542
}
534543

535544
//---------------------------------------------------------
@@ -784,7 +793,7 @@ void SlurHandler::doSlurs(const ChordRest* chordRest, Notations& notations, XmlW
784793
// search for slur(s) starting or stopping at this chord
785794
for (const auto& it : chordRest->score()->spanner()) {
786795
auto sp = it.second;
787-
if (sp->generated() || sp->type() != ElementType::SLUR || !ExportMusicXml::canWrite(sp))
796+
if (sp->generated() || sp->type() != ElementType::SLUR)
788797
continue;
789798
if (chordRest == sp->startElement() || chordRest == sp->endElement()) {
790799
const Slur* s = static_cast<const Slur*>(sp);
@@ -824,7 +833,7 @@ void SlurHandler::doSlurStart(const Slur* s, Notations& notations, XmlWriter& xm
824833
// remove from list and print start
825834
slur[i] = 0;
826835
started[i] = false;
827-
notations.tag(xml);
836+
notations.tag(xml, s);
828837
tagName += QString(" number=\"%1\"").arg(i + 1);
829838
xml.tagE(tagName);
830839
}
@@ -834,7 +843,7 @@ void SlurHandler::doSlurStart(const Slur* s, Notations& notations, XmlWriter& xm
834843
if (i >= 0) {
835844
slur[i] = s;
836845
started[i] = true;
837-
notations.tag(xml);
846+
notations.tag(xml, s);
838847
tagName += QString(" number=\"%1\"").arg(i + 1);
839848
xml.tagE(tagName);
840849
}
@@ -863,7 +872,7 @@ void SlurHandler::doSlurStop(const Slur* s, Notations& notations, XmlWriter& xml
863872
if (i >= 0) {
864873
slur[i] = s;
865874
started[i] = false;
866-
notations.tag(xml);
875+
notations.tag(xml, s);
867876
QString tagName = QString("slur type=\"stop\" number=\"%1\"").arg(i + 1);
868877
tagName += positioningAttributes(s, false);
869878
xml.tagE(tagName);
@@ -875,7 +884,7 @@ void SlurHandler::doSlurStop(const Slur* s, Notations& notations, XmlWriter& xml
875884
// found (already started), stop it and remove from list
876885
slur[i] = 0;
877886
started[i] = false;
878-
notations.tag(xml);
887+
notations.tag(xml, s);
879888
QString tagName = QString("slur type=\"stop\" number=\"%1\"").arg(i + 1);
880889
tagName += positioningAttributes(s, false);
881890
xml.tagE(tagName);
@@ -922,7 +931,7 @@ static void glissando(const Glissando* gli, int number, bool start, Notations& n
922931
tagName += color2xml(gli);
923932
tagName += positioningAttributes(gli, start);
924933
}
925-
notations.tag(xml);
934+
notations.tag(xml, gli);
926935
if (start && gli->showText() && !gli->text().isEmpty())
927936
xml.tag(tagName, gli->text());
928937
else
@@ -1051,7 +1060,7 @@ static void findTrills(const Measure* const measure, int strack, int etrack, Tri
10511060
for (auto it = measure->score()->spanner().lower_bound(stick.ticks()); it != measure->score()->spanner().upper_bound(etick.ticks()); ++it) {
10521061
Element* e = it->second;
10531062
//qDebug("1 trill %p type %d track %d tick %s", e, e->type(), e->track(), qPrintable(e->tick().print()));
1054-
if (e->isTrill() && ExportMusicXml::canWrite(e) && strack <= e->track() && e->track() < etrack
1063+
if (e->isTrill() && strack <= e->track() && e->track() < etrack
10551064
&& e->tick() >= measure->tick() && e->tick() < (measure->tick() + measure->ticks()))
10561065
{
10571066
//qDebug("2 trill %p", e);
@@ -2550,7 +2559,7 @@ static void tupletActualAndNormal(const Tuplet* const t, XmlWriter& xml)
25502559

25512560
static void tupletStart(const Tuplet* const t, const int number, const bool needActualAndNormal, Notations& notations, XmlWriter& xml)
25522561
{
2553-
notations.tag(xml);
2562+
notations.tag(xml, t);
25542563
QString tupletTag = "tuplet type=\"start\"";
25552564
if (!isSimpleTuplet(t))
25562565
tupletTag += QString(" number=\"%1\"").arg(number);
@@ -2581,7 +2590,7 @@ static void tupletStart(const Tuplet* const t, const int number, const bool need
25812590

25822591
static void tupletStop(const Tuplet* const t, const int number, Notations& notations, XmlWriter& xml)
25832592
{
2584-
notations.tag(xml);
2593+
notations.tag(xml, t);
25852594
QString tupletTag = "tuplet type=\"stop\"";
25862595
if (!isSimpleTuplet(t))
25872596
tupletTag += QString(" number=\"%1\"").arg(number);
@@ -2695,7 +2704,7 @@ static void writeDisplayName(XmlWriter& xml, const QString& partName)
26952704

26962705
static void wavyLineStart(const Trill* tr, const int number, Notations& notations, Ornaments& ornaments, XmlWriter& xml)
26972706
{
2698-
notations.tag(xml);
2707+
notations.tag(xml, tr);
26992708
ornaments.tag(xml);
27002709
switch (tr->trillType()) {
27012710
case Trill::Type::TRILL_LINE:
@@ -2725,7 +2734,7 @@ static void wavyLineStart(const Trill* tr, const int number, Notations& notation
27252734

27262735
static void wavyLineStop(const Trill* tr, const int number, Notations& notations, Ornaments& ornaments, XmlWriter& xml)
27272736
{
2728-
notations.tag(xml);
2737+
notations.tag(xml, tr);
27292738
ornaments.tag(xml);
27302739
QString trillXml = QString("wavy-line type=\"stop\" number=\"%1\"").arg(number + 1);
27312740
trillXml += positioningAttributes(tr, false);
@@ -2798,7 +2807,7 @@ void ExportMusicXml::wavyLineStartStop(const ChordRest* const cr, Notations& not
27982807
static void tremoloSingleStartStop(Chord* chord, Notations& notations, Ornaments& ornaments, XmlWriter& xml)
27992808
{
28002809
Tremolo* tr = chord->tremolo();
2801-
if (tr && ExportMusicXml::canWrite(tr)) {
2810+
if (tr) {
28022811
int count = 0;
28032812
TremoloType st = tr->tremoloType();
28042813
QString type;
@@ -2843,7 +2852,7 @@ static void tremoloSingleStartStop(Chord* chord, Notations& notations, Ornaments
28432852

28442853

28452854
if (!type.isEmpty() && ((count > 0 && type != "unmeasured") || (count == 0 && type == "unmeasured"))) {
2846-
notations.tag(xml);
2855+
notations.tag(xml, tr);
28472856
ornaments.tag(xml);
28482857
QString tagName = "tremolo";
28492858
tagName += QString(" type=\"%1\"").arg(type);
@@ -2861,9 +2870,9 @@ static void tremoloSingleStartStop(Chord* chord, Notations& notations, Ornaments
28612870
static void fermatas(const QVector<Element*>& cra, XmlWriter& xml, Notations& notations)
28622871
{
28632872
for (const Element* e : cra) {
2864-
if (!e->isFermata() || !ExportMusicXml::canWrite(e))
2873+
if (!e->isFermata())
28652874
continue;
2866-
notations.tag(xml);
2875+
notations.tag(xml, e);
28672876
fermata(toFermata(e), xml);
28682877
}
28692878
}
@@ -3115,9 +3124,9 @@ static void writeChordLines(const Chord* const chord, XmlWriter& xml, Notations&
31153124
default:
31163125
qDebug("unknown ChordLine subtype %d", int(cl->chordLineType()));
31173126
}
3118-
subtype += color2xml(cl);
31193127
if (!subtype.isEmpty()) {
3120-
notations.tag(xml);
3128+
subtype += color2xml(cl);
3129+
notations.tag(xml, cl);
31213130
articulations.tag(xml);
31223131
xml.tagE(subtype);
31233132
}
@@ -3131,11 +3140,11 @@ static void writeChordLines(const Chord* const chord, XmlWriter& xml, Notations&
31313140

31323141
static void writeBreathMark(const Breath* const breath, XmlWriter& xml, Notations& notations, Articulations& articulations)
31333142
{
3134-
if (breath && ExportMusicXml::canWrite(breath)) {
3143+
if (breath) {
31353144
QString tagName;
31363145
QString type;
31373146

3138-
notations.tag(xml);
3147+
notations.tag(xml, breath);
31393148
articulations.tag(xml);
31403149
if (breath->isCaesura()) {
31413150
tagName = "caesura";
@@ -3214,9 +3223,6 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
32143223
// first the attributes whose elements are children of <articulations>
32153224
Articulations articulations;
32163225
for (const Articulation* a : na) {
3217-
if (!ExportMusicXml::canWrite(a))
3218-
continue;
3219-
32203226
SymId sid = a->symId();
32213227
std::vector<QString> mxmlArtics = symIdToArtics(sid);
32223228

@@ -3237,7 +3243,7 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
32373243
mxmlArtic += color2xml(a);
32383244
mxmlArtic += positioningAttributes(a);
32393245

3240-
notations.tag(_xml);
3246+
notations.tag(_xml, a);
32413247
articulations.tag(_xml);
32423248
_xml.tagE(mxmlArtic);
32433249
}
@@ -3251,8 +3257,6 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
32513257
// then the attributes whose elements are children of <ornaments>
32523258
Ornaments ornaments;
32533259
for (const Articulation* a : na) {
3254-
if (!ExportMusicXml::canWrite(a))
3255-
continue;
32563260
if (!a->isOrnament())
32573261
continue;
32583262

@@ -3266,7 +3270,7 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
32663270
mxmlOrnam += QString(" placement=\"%1\"").arg(placement);
32673271
mxmlOrnam += color2xml(a);
32683272

3269-
notations.tag(_xml);
3273+
notations.tag(_xml, a);
32703274
ornaments.tag(_xml);
32713275
_xml.tagE(mxmlOrnam);
32723276
// accidental-mark is missing
@@ -3279,9 +3283,6 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
32793283

32803284
// and finally the attributes whose elements are children of <technical>
32813285
for (const Articulation* a : na) {
3282-
if (!ExportMusicXml::canWrite(a))
3283-
continue;
3284-
32853286
SymId sid = a->symId();
32863287
QString placement;
32873288
QString direction;
@@ -3303,7 +3304,7 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
33033304

33043305
QString mxmlTechn = symIdToTechn(sid);
33053306
if (!mxmlTechn.isEmpty()) {
3306-
notations.tag(_xml);
3307+
notations.tag(_xml, a);
33073308
technical.tag(_xml);
33083309
mxmlTechn += color2xml(a);
33093310
mxmlTechn += positioningAttributes(a);
@@ -3369,9 +3370,6 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
33693370

33703371
// check if all articulations were handled
33713372
for (const Articulation* a : na) {
3372-
if (!ExportMusicXml::canWrite(a))
3373-
continue;
3374-
33753373
SymId sid = a->symId();
33763374
if (symIdToArtics(sid).empty()
33773375
&& symIdToTechn(sid).isEmpty()
@@ -3411,32 +3409,29 @@ static Arpeggio* findArpeggio(Note* note)
34113409

34123410
static void arpeggiate(Arpeggio* arp, bool front, bool back, XmlWriter& xml, Notations& notations)
34133411
{
3414-
if (!ExportMusicXml::canWrite(arp))
3415-
return;
3416-
34173412
QString tagName;
34183413
switch (arp->arpeggioType()) {
34193414
case ArpeggioType::NORMAL:
3420-
notations.tag(xml);
3415+
notations.tag(xml, arp);
34213416
tagName = "arpeggiate";
34223417
break;
34233418
case ArpeggioType::UP: // fall through
34243419
case ArpeggioType::UP_STRAIGHT: // not supported by MusicXML, export as normal arpeggio
3425-
notations.tag(xml);
3420+
notations.tag(xml, arp);
34263421
tagName = "arpeggiate direction=\"up\"";
34273422
break;
34283423
case ArpeggioType::DOWN: // fall through
34293424
case ArpeggioType::DOWN_STRAIGHT: // not supported by MusicXML, export as normal arpeggio
3430-
notations.tag(xml);
3425+
notations.tag(xml, arp);
34313426
tagName = "arpeggiate direction=\"down\"";
34323427
break;
34333428
case ArpeggioType::BRACKET:
34343429
if (front) {
3435-
notations.tag(xml);
3430+
notations.tag(xml, arp);
34363431
tagName = "non-arpeggiate type=\"bottom\"";
34373432
}
34383433
if (back) {
3439-
notations.tag(xml);
3434+
notations.tag(xml, arp);
34403435
tagName = "non-arpeggiate type=\"top\"";
34413436
}
34423437
break;
@@ -3666,12 +3661,9 @@ static void writeNotehead(XmlWriter& xml, const Note* const note)
36663661
static void writeFingering(XmlWriter& xml, Notations& notations, Technical& technical, const Note* const note)
36673662
{
36683663
for (const Element* e : note->el()) {
3669-
if (!ExportMusicXml::canWrite(e))
3670-
continue;
3671-
36723664
if (e->type() == ElementType::FINGERING) {
36733665
const TextBase* f = toTextBase(e);
3674-
notations.tag(xml);
3666+
notations.tag(xml, e);
36753667
technical.tag(xml);
36763668
QString t = MScoreTextToMXML::toPlainText(f->xmlText());
36773669
QString attr;
@@ -4021,18 +4013,18 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector<Lyrics*>*
40214013
Technical technical;
40224014

40234015
const Tie* tieBack = note->tieBack();
4024-
if (tieBack && ExportMusicXml::canWrite(tieBack)) {
4025-
notations.tag(_xml);
4016+
if (tieBack) {
4017+
notations.tag(_xml, tieBack);
40264018
_xml.tagE("tied type=\"stop\"");
40274019
}
40284020
const Tie* tieFor = note->tieFor();
4029-
if (tieFor && ExportMusicXml::canWrite(tieFor)) {
4030-
notations.tag(_xml);
4021+
if (tieFor) {
4022+
notations.tag(_xml, tieFor);
40314023
QString rest = slurTieLineStyle(tieFor);
40324024
_xml.tagE(QString("tied type=\"start\"%1").arg(rest));
40334025
}
4034-
if (hasLaissezVibrer(chord)/* && ExportMusicXml::canWrite(laissezVibrer)*/) {
4035-
notations.tag(_xml);
4026+
if (hasLaissezVibrer(chord)) {
4027+
notations.tag(_xml, tieFor);
40364028
_xml.tagE("tied type=\"let-ring\"");
40374029
}
40384030

@@ -4050,7 +4042,7 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector<Lyrics*>*
40504042
// write tablature string / fret
40514043
if (chord->staff() && chord->staff()->isTabStaff(Fraction(0,1)))
40524044
if (note->fret() >= 0 && note->string() >= 0) {
4053-
notations.tag(_xml);
4045+
notations.tag(_xml, note);
40544046
technical.tag(_xml);
40554047
_xml.tag("string", note->string() + 1);
40564048
_xml.tag("fret", note->fret());
@@ -4061,11 +4053,11 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector<Lyrics*>*
40614053
arpeggiate(arp, note == nl.front(), note == nl.back(), _xml, notations);
40624054
}
40634055
for (Spanner* spanner : note->spannerFor())
4064-
if (spanner->type() == ElementType::GLISSANDO && ExportMusicXml::canWrite(spanner)) {
4056+
if (spanner->type() == ElementType::GLISSANDO) {
40654057
gh.doGlissandoStart(static_cast<Glissando*>(spanner), notations, _xml);
40664058
}
40674059
for (Spanner* spanner : note->spannerBack())
4068-
if (spanner->type() == ElementType::GLISSANDO && ExportMusicXml::canWrite(spanner)) {
4060+
if (spanner->type() == ElementType::GLISSANDO) {
40694061
gh.doGlissandoStop(static_cast<Glissando*>(spanner), notations, _xml);
40704062
}
40714063
// write glissando (only for last note)
@@ -5813,6 +5805,9 @@ static void measureStyle(XmlWriter& xml, Attributes& attr, const Measure* const
58135805

58145806
static bool commonAnnotations(ExportMusicXml* exp, const Element* e, int sstaff)
58155807
{
5808+
if (!exp->canWrite(e))
5809+
return false;
5810+
58165811
bool instrChangeHandled = false;
58175812

58185813
// note: the instrument change details are handled in ExportMusicXml::writeMeasureTracks,
@@ -7595,7 +7590,7 @@ void ExportMusicXml::writeMeasure(const Measure* const m,
75957590
writeInstrumentDetails(part->instrument(), _score->styleB(Sid::concertPitch));
75967591
}
75977592
else {
7598-
for (size_t staffIdx : _hiddenStaves) {
7593+
for (int& staffIdx : _hiddenStaves) {
75997594
_attr.doAttr(_xml, true);
76007595
QString attributes;
76017596
if (staves > 1)

0 commit comments

Comments
 (0)