From 36f86da4b01f723eda7e33c9576d6e3391091061 Mon Sep 17 00:00:00 2001 From: Matthew James Briggs Date: Wed, 25 Nov 2026 16:52:16 +0100 Subject: [PATCH 1/4] feat: keep and in mx::api Add LevelData and FootnoteData, and an optional level and footnote on NoteData, LyricData, BarlineData, FigureData, FiguredBassData, PartGroupData (start element), DirectionData ( only) and ChordData (the , shared by a direction's chords: the reader copies it onto every chord, the writer takes the first chord that has one). One helper pair in mx::impl reads and writes the three core editorial groups; writers copy the group so is kept. A DirectionData whose level or footnote has no to go on reports droppedData. Remove NoteData::miscData and its ##misc-data## footnote encoding. A note's is now NoteData::footnote. Claude-Session: https://claude.ai/code/session_01A8XRpcx6L2kGcYfiUhYJ8V --- src/include/mx/api/BarlineData.h | 13 +- src/include/mx/api/ChordData.h | 13 ++ src/include/mx/api/DirectionData.h | 15 +- src/include/mx/api/FiguredBassData.h | 24 ++- src/include/mx/api/FootnoteData.h | 60 +++++++ src/include/mx/api/LevelData.h | 191 +++++++++++++++++++++ src/include/mx/api/LyricData.h | 12 +- src/include/mx/api/NoteData.h | 20 ++- src/include/mx/api/PartGroupData.h | 15 +- src/private/mx/api/ChordData.cpp | 2 +- src/private/mx/api/NoteData.cpp | 2 +- src/private/mx/impl/Converter.cpp | 16 ++ src/private/mx/impl/Converter.h | 7 + src/private/mx/impl/DirectionReader.cpp | 6 + src/private/mx/impl/DirectionWriter.cpp | 34 +++- src/private/mx/impl/EditorialFunctions.cpp | 147 ++++++++++++++++ src/private/mx/impl/EditorialFunctions.h | 73 ++++++++ src/private/mx/impl/MeasureReader.cpp | 8 + src/private/mx/impl/MeasureWriter.cpp | 4 + src/private/mx/impl/NoteFunctions.cpp | 48 +----- src/private/mx/impl/NoteFunctions.h | 1 - src/private/mx/impl/NoteReader.cpp | 3 + src/private/mx/impl/NoteWriter.cpp | 53 +----- src/private/mx/impl/NoteWriter.h | 3 +- src/private/mx/impl/ScoreReader.cpp | 4 +- src/private/mx/impl/ScoreWriter.cpp | 5 + src/private/mxtest/api/NoteDataTest.cpp | 57 ------ 27 files changed, 663 insertions(+), 173 deletions(-) create mode 100644 src/include/mx/api/FootnoteData.h create mode 100644 src/include/mx/api/LevelData.h create mode 100644 src/private/mx/impl/EditorialFunctions.cpp create mode 100644 src/private/mx/impl/EditorialFunctions.h diff --git a/src/include/mx/api/BarlineData.h b/src/include/mx/api/BarlineData.h index 5c47794c3..5b87f7ec4 100644 --- a/src/include/mx/api/BarlineData.h +++ b/src/include/mx/api/BarlineData.h @@ -5,7 +5,9 @@ #pragma once #include "mx/api/ApiCommon.h" +#include "mx/api/FootnoteData.h" #include "mx/api/Id.h" +#include "mx/api/LevelData.h" #include "mx/api/PositionData.h" #include @@ -150,13 +152,20 @@ class BarlineData RepeatWinged repeatWinged; HorizontalAlignment location; + // The editorial status of this barline (see LevelData), for example a repeat sign the editor + // added. + std::optional level; + + // Editorial commentary about this barline, printed as a footnote (see FootnoteData). + std::optional footnote; + // The element's id attribute (see Id.h). std::optional id; BarlineData() : tickTimePosition{0}, barlineType{BarlineType::normal}, ending{}, repeat{false}, repeatTimes{0}, repeatDirection{RepeatDirection::unspecified}, repeatAfterJump{Bool::unspecified}, - repeatWinged{RepeatWinged::unspecified}, location{HorizontalAlignment::unspecified}, id{} + repeatWinged{RepeatWinged::unspecified}, location{HorizontalAlignment::unspecified}, level{}, footnote{}, id{} { } }; @@ -171,6 +180,8 @@ MXAPI_EQUALS_MEMBER(repeatDirection) MXAPI_EQUALS_MEMBER(repeatAfterJump) MXAPI_EQUALS_MEMBER(repeatWinged) MXAPI_EQUALS_MEMBER(location) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_MEMBER(id) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(BarlineData); diff --git a/src/include/mx/api/ChordData.h b/src/include/mx/api/ChordData.h index 34f4bf7fb..42e1cfa3d 100644 --- a/src/include/mx/api/ChordData.h +++ b/src/include/mx/api/ChordData.h @@ -5,6 +5,8 @@ #pragma once #include "mx/api/ApiCommon.h" +#include "mx/api/FootnoteData.h" +#include "mx/api/LevelData.h" #include "mx/api/MiscData.h" #include "mx/api/PitchData.h" #include "mx/api/PositionData.h" @@ -323,6 +325,15 @@ class ChordData // value; when they differ, the first chord that is not unspecified is used. Bool printFrame; PositionData positionData; + + // The editorial status of the chord symbol (see LevelData), for example a chord the editor + // supplied. The chords of one direction share a single level, so give them all the same + // value; when they differ, the first chord that has one is used. + std::optional level; + + // Editorial commentary about the chord symbol, printed as a footnote (see FootnoteData). The + // chords of one direction share a single footnote, the same way they share level. + std::optional footnote; }; MXAPI_EQUALS_BEGIN(ChordData) @@ -356,6 +367,8 @@ MXAPI_EQUALS_MEMBER(hasFrameData) MXAPI_EQUALS_MEMBER(frameData) MXAPI_EQUALS_MEMBER(printFrame) MXAPI_EQUALS_MEMBER(positionData) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(ChordData); diff --git a/src/include/mx/api/DirectionData.h b/src/include/mx/api/DirectionData.h index 5893bac47..411c59603 100644 --- a/src/include/mx/api/DirectionData.h +++ b/src/include/mx/api/DirectionData.h @@ -8,7 +8,9 @@ #include "mx/api/ChordData.h" #include "mx/api/DirectionChoice.h" #include "mx/api/FiguredBassData.h" +#include "mx/api/FootnoteData.h" #include "mx/api/Id.h" +#include "mx/api/LevelData.h" #include "mx/api/SoundData.h" #include @@ -102,6 +104,15 @@ struct DirectionData // serialize as their own elements, not as direction-type content. std::vector figuredBasses; + // The editorial status of the direction's content (see LevelData), for example a dynamic the + // editor added, drawn in brackets. It belongs to the element, so it is written only + // when directionTypes is not empty. The chords and figured bass held here carry their own. + std::optional level; + + // Editorial commentary about the direction's content, printed as a footnote (see FootnoteData). + // Like level, it is written only when directionTypes is not empty. + std::optional footnote; + // The element's id attribute (see Id.h). std::optional id; @@ -109,7 +120,7 @@ struct DirectionData : tickTimePosition{0}, placement{Placement::unspecified}, systemRelation{SystemRelation::unspecified}, directive{Bool::unspecified}, offset{}, offsetSound{Bool::unspecified}, voice{VALUE_UNSPECIFIED}, isStaffValueSpecified{true}, isSoundDataSpecified{false}, soundData{}, directionTypes{}, chords{}, - figuredBasses{}, id{} + figuredBasses{}, level{}, footnote{}, id{} { } }; @@ -134,6 +145,8 @@ MXAPI_EQUALS_MEMBER(soundData) MXAPI_EQUALS_MEMBER(directionTypes) MXAPI_EQUALS_MEMBER(chords) MXAPI_EQUALS_MEMBER(figuredBasses) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_MEMBER(id) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(DirectionData); diff --git a/src/include/mx/api/FiguredBassData.h b/src/include/mx/api/FiguredBassData.h index ba7e554f5..84140d7e9 100644 --- a/src/include/mx/api/FiguredBassData.h +++ b/src/include/mx/api/FiguredBassData.h @@ -5,7 +5,9 @@ #pragma once #include "mx/api/ApiCommon.h" +#include "mx/api/FootnoteData.h" #include "mx/api/Id.h" +#include "mx/api/LevelData.h" #include "mx/api/PositionData.h" #include "mx/api/PrintData.h" @@ -55,7 +57,14 @@ class FigureData // The figure's continuation line. Absent when the figure does not have one. std::optional extend; - FigureData() : prefix{}, figureNumber{}, suffix{}, extend{} + // The editorial status of this one figure (see LevelData), for example a figure the editor + // added, drawn in brackets. + std::optional level; + + // Editorial commentary about this one figure, printed as a footnote (see FootnoteData). + std::optional footnote; + + FigureData() : prefix{}, figureNumber{}, suffix{}, extend{}, level{}, footnote{} { } }; @@ -65,6 +74,8 @@ MXAPI_EQUALS_MEMBER(prefix) MXAPI_EQUALS_MEMBER(figureNumber) MXAPI_EQUALS_MEMBER(suffix) MXAPI_EQUALS_MEMBER(extend) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(FigureData); @@ -97,9 +108,16 @@ class FiguredBassData // appearance. PrintData printData; + // The editorial status of the whole figured bass (see LevelData), for example figures the + // editor supplied where the source does not have any. + std::optional level; + + // Editorial commentary about the whole figured bass, printed as a footnote (see FootnoteData). + std::optional footnote; + FiguredBassData() : figures{}, parentheses{Bool::unspecified}, durationTimeTicks{VALUE_UNSPECIFIED}, id{}, positionData{}, - printData{} + printData{}, level{}, footnote{} { } }; @@ -111,6 +129,8 @@ MXAPI_EQUALS_MEMBER(durationTimeTicks) MXAPI_EQUALS_MEMBER(id) MXAPI_EQUALS_MEMBER(positionData) MXAPI_EQUALS_MEMBER(printData) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(FiguredBassData); diff --git a/src/include/mx/api/FootnoteData.h b/src/include/mx/api/FootnoteData.h new file mode 100644 index 000000000..408f59f70 --- /dev/null +++ b/src/include/mx/api/FootnoteData.h @@ -0,0 +1,60 @@ +// MusicXML Class Library +// Copyright (c) by Matthew James Briggs +// Distributed under the MIT License + +#pragma once + +#include "mx/api/ApiCommon.h" +#include "mx/api/ColorData.h" +#include "mx/api/FontData.h" +#include "mx/api/PositionData.h" + +#include +#include + +namespace mx +{ +namespace api +{ +// The MusicXML element: editorial commentary about a symbol, printed as a footnote in +// the score, such as "m. 12: slur absent in the autograph". A footnote explains in prose, while a +// level (see LevelData) classifies the symbol and says how to draw it. One symbol may carry both. +struct FootnoteData +{ + // The words of the footnote. + std::string text; + + // Where the footnote text is drawn, in tenths of a staff space, and how it aligns against that + // point. placement is not used. Leave this alone to let the application place it. + PositionData positionData; + + // The font of the footnote text. + FontData fontData; + + // The color of the footnote text. Leave it empty to draw it in the score's usual color. + std::optional color; + + // How the lines of the footnote line up with each other when it spans more than one line. + // Leave it unspecified to let the application decide. + HorizontalAlignment justify = HorizontalAlignment::unspecified; + + // A shape drawn around the footnote text. Enclosure::unspecified does not draw an enclosure; + // Enclosure::none states explicitly that there is no enclosure. + Enclosure enclosure = Enclosure::unspecified; + + // Whether the spaces at the start and end of text are part of it (see XmlSpace). + XmlSpace xmlSpace = XmlSpace::unspecified; +}; + +MXAPI_EQUALS_BEGIN(FootnoteData) +MXAPI_EQUALS_MEMBER(text) +MXAPI_EQUALS_MEMBER(positionData) +MXAPI_EQUALS_MEMBER(fontData) +MXAPI_EQUALS_MEMBER(color) +MXAPI_EQUALS_MEMBER(justify) +MXAPI_EQUALS_MEMBER(enclosure) +MXAPI_EQUALS_MEMBER(xmlSpace) +MXAPI_EQUALS_END; +MXAPI_NOT_EQUALS_AND_VECTORS(FootnoteData); +} // namespace api +} // namespace mx diff --git a/src/include/mx/api/LevelData.h b/src/include/mx/api/LevelData.h new file mode 100644 index 000000000..a90e4f368 --- /dev/null +++ b/src/include/mx/api/LevelData.h @@ -0,0 +1,191 @@ +// MusicXML Class Library +// Copyright (c) by Matthew James Briggs +// Distributed under the MIT License + +#pragma once + +#include "mx/api/ApiCommon.h" + +#include + +namespace mx +{ +namespace api +{ +// Whether a level covers one symbol or a run of symbols, MusicXML's type attribute of . +enum class LevelType +{ + // The attribute is absent. MusicXML reads that as single. + unspecified, + + // The first symbol of a run that the level covers. + start, + + // The last symbol of a run that the level covers. + stop, + + // The level covers this symbol alone. + single +}; + +// The MusicXML element. +// +// What is, and why it has that name +// +// `` is a provenance tag: metadata attached to a symbol that labels its editorial status. +// Like a `git blame` annotation, it records where a mark came from rather than changing the music. +// +// The name comes from MuseData, a 1980s-90s encoding format for critical editions. When asked about +// the confusing name, Michael Good, the creator of MusicXML, answered (w3c-cg/musicxml#146): +// +// > "This was a generalization of the integer level field in MuseData. In MusicXML it is used to +// > identify and describe different types of editorial information." +// +// In MuseData, each record could carry an integer "level". The editor defined what each number +// meant, for example 1 = from the autograph, 2 = editor's addition, 3 = from the first print. So +// "level" means an editorial layer, like a layer in a graphics program. MusicXML widened the integer +// to free text. That's why the content is just a string with no defined vocabulary. +// +// The XSD wording: +// +// > "The level type is used to specify editorial information for different MusicXML elements. The +// > content contains identifying and/or descriptive text about the editorial status of the parent +// > element." +// +// The second sentence was added in 4.0 to clarify the meaning (w3c-cg/musicxml#146). +// +// Good's example comes from his paper "Using MusicXML 2.0 for Editorial Applications" (Listing +// 19). Two slurs in a Brahms edition come from different sources: +// +// ... 1 +// ... 2 (pencil) +// +// Read it as: slur 1 belongs to editorial layer "1". Slur 2 belongs to layer "2 (pencil)", someone's +// pencil marking in a source, and it's shown for reference only. That's the original use case: +// scholarly editions that record where each mark came from. +// +// Why this design: MusicXML had to round-trip MuseData-style scholarly encodings without dictating +// anyone's source classification scheme. An open string tag fits that, since each edition defines +// its own layers. The cost is that the content means nothing to a program. Only the attributes carry +// machine-readable meaning. +// +// The attributes: where becomes machine-readable +// +// Intuition: the text content is the human label. The attributes are three independent things a +// program can act on: a playback flag, a span marker, and display hints. +// +// free text label +// +// `reference` (added in MusicXML 1.1). The XSD says: +// +// > "editorial information that is for display only and should not affect playback. For instance, +// > a modern edition of older music may set reference="yes" on the attributes containing the +// > music's original clef, key, and time signature." +// +// This is the "incipit" case. A modern Renaissance edition prints a small prefatory staff showing +// the original C clef and mensuration sign, then continues in treble clef. Both `` +// elements exist in the file, but a player must ignore the original one. +// +// Display hints (`level-display`, also 1.1). The XSD: +// +// > "three common ways to indicate editorial indications: putting parentheses or square brackets +// > around a symbol, or making the symbol a different size." +// +// These are engraving conventions. An editor's added slur is often drawn dashed, an added dynamic in +// brackets, an added accidental small or in parentheses. The same attribute group sits on +// ``, which is why AccidentalMarkData also has parentheses, bracket and size. Editorial +// accidentals were the first application. +// +// A rest is the common modern case. In w3c-cg/musicxml PR 736, Good wrote: +// +// > "Not really, since rests don't have noteheads. Parenthesizing a rest is best done with a +// > `` child element." +// +// +// +// 4 +// +// 1 +// quarter +// +// +// The element has drifted from "provenance tag" to "editorial display hint", often with empty +// content. MusicXML doesn't offer another clean way to parenthesize a rest. Some files use +// `` on a rest; Good calls that wrong because a rest doesn't have a +// notehead. To draw a rest in parentheses, give its NoteData a level with parentheses set to yes and +// the text left empty. +// +// `type` (added in 4.0, issue 288). Start/stop/single lets one `` cover a run of symbols +// instead of tagging each one. In that same PR 736 thread, a Finale user asked how to parenthesize a +// whole chord (a Finale "entry"). A contributor proposed `type="start"` on the first chord note and +// `type="stop"` on the last. Good called it "a good clarification of the way this is indeed intended +// to work," but it isn't in the spec as an example. Good placed `type` on `` itself, not in +// `level-display`, because it's semantic and `` shares that group. +// +// `type` on a `` creates an implicit start/stop pair across notes. Each note carries its own +// LevelData, and mx does not check that a start has a matching stop. That's like a spanner without +// an id: you must keep starts and stops consistent yourself. +// +// and +// +// `` and `` are two complementary editorial channels (see FootnoteData). +// +// +// XSD says: "editorial information that appears in footnotes in the printed score" +// Content: formatted text: text plus font, color, position, justify, enclosure +// Purpose: explains in prose, printed at the page foot +// Example: "m. 12: slur absent in the autograph" +// +// +// XSD says: "editorial status of the parent element" +// Content: plain string +// Purpose: classifies and tells a renderer how to draw it +// Example: editor +// +// Think of it as a commit message vs a label. In a critical edition one symbol might carry both: +// `2` draws the slur bracketed as layer 2, and `` holds the +// commentary text printed below. Each is optional and appears at most once per host. +struct LevelData +{ + // The editorial label, such as "editor", "1" or "2 (pencil)". Each edition decides what its + // labels mean. It is often empty, as in , and the level is still + // there: an empty text does not remove it. + std::string text; + + // yes: the symbol is editorial material for display only, and a player should not perform it. + // Leave it unspecified for MusicXML's default, which is no. + Bool reference = Bool::unspecified; + + // Whether this level covers this symbol alone, or starts or stops a run of symbols. Leave it + // unspecified for MusicXML's default, which is single. + LevelType type = LevelType::unspecified; + + // yes: the symbol is drawn in parentheses to show that it is editorial. Leave it unspecified to + // let the application decide. + Bool parentheses = Bool::unspecified; + + // yes: the symbol is drawn in square brackets to show that it is editorial. Leave it + // unspecified to let the application decide. + Bool bracket = Bool::unspecified; + + // How large the symbol is drawn. A smaller size is another way to show that it is editorial. + // Leave it unspecified to let the application decide. + SymbolSize size = SymbolSize::unspecified; +}; + +MXAPI_EQUALS_BEGIN(LevelData) +MXAPI_EQUALS_MEMBER(text) +MXAPI_EQUALS_MEMBER(reference) +MXAPI_EQUALS_MEMBER(type) +MXAPI_EQUALS_MEMBER(parentheses) +MXAPI_EQUALS_MEMBER(bracket) +MXAPI_EQUALS_MEMBER(size) +MXAPI_EQUALS_END; +MXAPI_NOT_EQUALS_AND_VECTORS(LevelData); +} // namespace api +} // namespace mx diff --git a/src/include/mx/api/LyricData.h b/src/include/mx/api/LyricData.h index 1c4a0934d..8e6c33aa0 100644 --- a/src/include/mx/api/LyricData.h +++ b/src/include/mx/api/LyricData.h @@ -5,7 +5,9 @@ #pragma once #include "mx/api/ApiCommon.h" +#include "mx/api/FootnoteData.h" #include "mx/api/Id.h" +#include "mx/api/LevelData.h" #include "mx/api/PositionData.h" #include "mx/api/PrintData.h" @@ -66,7 +68,7 @@ class LyricData public: LyricData() : text{}, verseNumber{}, verseName{}, syllabic{LyricSyllabic::unspecified}, hasExtend{false}, - extendType{LyricExtendType::unspecified}, positionData{}, printData{}, id{} + extendType{LyricExtendType::unspecified}, positionData{}, printData{}, level{}, footnote{}, id{} { } @@ -84,6 +86,12 @@ class LyricData PositionData positionData; PrintData printData; + // The editorial status of this lyric (see LevelData), for example a syllable the editor added. + std::optional level; + + // Editorial commentary about this lyric, printed as a footnote (see FootnoteData). + std::optional footnote; + // The element's id attribute (see Id.h). std::optional id; }; @@ -106,6 +114,8 @@ MXAPI_EQUALS_MEMBER(hasExtend) MXAPI_EQUALS_MEMBER(extendType) MXAPI_EQUALS_MEMBER(positionData) MXAPI_EQUALS_MEMBER(printData) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_MEMBER(id) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(LyricData); diff --git a/src/include/mx/api/NoteData.h b/src/include/mx/api/NoteData.h index 4c2cd0402..c6e73b9fe 100644 --- a/src/include/mx/api/NoteData.h +++ b/src/include/mx/api/NoteData.h @@ -7,7 +7,9 @@ #include "mx/api/ColorData.h" #include "mx/api/CurveData.h" #include "mx/api/DurationData.h" +#include "mx/api/FootnoteData.h" #include "mx/api/Id.h" +#include "mx/api/LevelData.h" #include "mx/api/LyricData.h" #include "mx/api/NoteAttachmentData.h" #include "mx/api/PitchData.h" @@ -266,17 +268,16 @@ class NoteData NoteAttachmentData noteAttachmentData; std::vector lyrics; - // these strings will be stuffed into the editorial element - // preceded by the string ##misc-data##. for example if you have the - // strings Bob, Cat, Hello then we will get: - // ##misc-data##Bob,Cat,Hello - // similarly when parsing if we see ##misc-data## in this element, it - // will be parsed into these strings. do not use commas in your misc - // data strings as these are the delimiter + // The editorial status of this note or rest (see LevelData), for example a rest the editor + // added, drawn in parentheses. Parentheses around a rest go here, because a rest does not have + // a notehead. Leave it absent for a note that is not marked as editorial. + std::optional level; + + // Editorial commentary about this note or rest, printed as a footnote (see FootnoteData). + std::optional footnote; // The element's id attribute (see Id.h). std::optional id; - std::vector miscData; }; MXAPI_EQUALS_BEGIN(NoteData) @@ -317,7 +318,8 @@ MXAPI_EQUALS_MEMBER(printData) MXAPI_EQUALS_MEMBER(printLeger) MXAPI_EQUALS_MEMBER(noteAttachmentData) MXAPI_EQUALS_MEMBER(lyrics) -MXAPI_EQUALS_MEMBER(miscData) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_MEMBER(id) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(NoteData); diff --git a/src/include/mx/api/PartGroupData.h b/src/include/mx/api/PartGroupData.h index 5a9d88aed..c057679a1 100644 --- a/src/include/mx/api/PartGroupData.h +++ b/src/include/mx/api/PartGroupData.h @@ -6,6 +6,8 @@ #include "mx/api/ApiCommon.h" #include "mx/api/ColorData.h" +#include "mx/api/FootnoteData.h" +#include "mx/api/LevelData.h" #include "mx/api/PositionData.h" #include @@ -75,7 +77,14 @@ class PartGroupData std::optional bracketColor; GroupBarline groupBarline; // TODO - group time - // TODO - group editorial + + // The editorial status of this group (see LevelData). It belongs to the group as a whole and + // is written on the element that starts it. + std::optional level; + + // Editorial commentary about this group, printed as a footnote (see FootnoteData). Like level, + // it is written on the element that starts the group. + std::optional footnote; // The number attribute is used to distinguish overlapping // and nested part-groups, not the sequence of groups. @@ -85,7 +94,7 @@ class PartGroupData PartGroupData() : firstPartIndex{INDEX_UNSPECIFIED}, lastPartIndex{INDEX_UNSPECIFIED}, name{}, bracketType{BracketType::unspecified}, bracketPositionData{}, bracketColor{}, - groupBarline{GroupBarline::unspecified}, number{NUMBER_LEVEL_UNSPECIFIED} + groupBarline{GroupBarline::unspecified}, level{}, footnote{}, number{NUMBER_LEVEL_UNSPECIFIED} { } }; @@ -101,6 +110,8 @@ MXAPI_EQUALS_MEMBER(bracketType) MXAPI_EQUALS_MEMBER(bracketPositionData) MXAPI_EQUALS_MEMBER(bracketColor) MXAPI_EQUALS_MEMBER(groupBarline) +MXAPI_EQUALS_MEMBER(level) +MXAPI_EQUALS_MEMBER(footnote) MXAPI_EQUALS_MEMBER(number) MXAPI_EQUALS_END; MXAPI_NOT_EQUALS_AND_VECTORS(PartGroupData); diff --git a/src/private/mx/api/ChordData.cpp b/src/private/mx/api/ChordData.cpp index 47368224a..9e4da5f67 100644 --- a/src/private/mx/api/ChordData.cpp +++ b/src/private/mx/api/ChordData.cpp @@ -37,7 +37,7 @@ ChordData::ChordData() useSymbols{Bool::unspecified}, stackDegrees{Bool::unspecified}, parenthesesDegrees{Bool::unspecified}, bass{Step::unspecified}, bassAlter{0}, bassText{}, bassSeparator{}, bassArrangement{BassArrangement::unspecified}, inversion{0}, hasInversion{false}, extensions{}, miscData{}, hasFrameData{false}, frameData{}, - printFrame{Bool::unspecified}, positionData{} + printFrame{Bool::unspecified}, positionData{}, level{}, footnote{} { } diff --git a/src/private/mx/api/NoteData.cpp b/src/private/mx/api/NoteData.cpp index e28a17c1a..426b13982 100644 --- a/src/private/mx/api/NoteData.cpp +++ b/src/private/mx/api/NoteData.cpp @@ -16,7 +16,7 @@ NoteData::NoteData() noteheadParentheses{Bool::unspecified}, noteheadColor{}, pitchData{}, accidentalSmufl{}, velocityStart{}, velocityStop{}, instruments{}, userRequestedVoiceNumber{VALUE_UNSPECIFIED}, writeStaffNumber{Bool::unspecified}, stem{Stem::unspecified}, tickTimePosition{0}, durationData{}, beams{}, positionData{}, printData{}, - printLeger{Bool::unspecified}, noteAttachmentData{}, lyrics{} + printLeger{Bool::unspecified}, noteAttachmentData{}, lyrics{}, level{}, footnote{}, id{} { } } // namespace api diff --git a/src/private/mx/impl/Converter.cpp b/src/private/mx/impl/Converter.cpp index 315705ed7..5b4d76f31 100644 --- a/src/private/mx/impl/Converter.cpp +++ b/src/private/mx/impl/Converter.cpp @@ -221,6 +221,12 @@ const Converter::EnumMap Converte {core::StartStopSingle::single(), api::OtherNotationType::single}, }; +const Converter::EnumMap Converter::levelTypeMap = { + {core::StartStopSingle::start(), api::LevelType::start}, + {core::StartStopSingle::stop(), api::LevelType::stop}, + {core::StartStopSingle::single(), api::LevelType::single}, +}; + const Converter::EnumMap Converter::ornamentsMap = { {core::OrnamentsGroupChoice::Kind::trillMark, api::MarkType::trillMark}, {core::OrnamentsGroupChoice::Kind::turn, api::MarkType::turn}, @@ -1808,6 +1814,16 @@ api::OtherNotationType Converter::convert(core::StartStopSingle value) const return findApiItem(otherNotationTypeMap, api::OtherNotationType::single, value); } +core::StartStopSingle Converter::convertLevelType(api::LevelType value) const +{ + return findCoreItem(levelTypeMap, core::StartStopSingle::single(), value); +} + +api::LevelType Converter::convertLevelType(core::StartStopSingle value) const +{ + return findApiItem(levelTypeMap, api::LevelType::unspecified, value); +} + core::OrnamentsGroupChoice::Kind Converter::convertOrnament(api::MarkType value) const { // All tremolo variants map to Kind::tremolo; the specific slash count is encoded diff --git a/src/private/mx/impl/Converter.h b/src/private/mx/impl/Converter.h index 38078a7d5..fda2e4c4c 100644 --- a/src/private/mx/impl/Converter.h +++ b/src/private/mx/impl/Converter.h @@ -7,6 +7,7 @@ #include "mx/api/BarlineData.h" #include "mx/api/ClefData.h" #include "mx/api/KeyData.h" +#include "mx/api/LevelData.h" #include "mx/api/MarkData.h" #include "mx/api/NoteData.h" #include "mx/api/PercussionData.h" @@ -141,6 +142,11 @@ class Converter core::StartStopSingle convert(api::OtherNotationType value) const; api::OtherNotationType convert(core::StartStopSingle value) const; + // The type attribute of . api::LevelType::unspecified has no wire spelling; callers skip + // the attribute for it. + core::StartStopSingle convertLevelType(api::LevelType value) const; + api::LevelType convertLevelType(core::StartStopSingle value) const; + core::OrnamentsGroupChoice::Kind convertOrnament(api::MarkType value) const; api::MarkType convertOrnament(core::OrnamentsGroupChoice::Kind value) const; @@ -297,6 +303,7 @@ class Converter const static EnumMap articulationsMap; const static EnumMap standardDynamicsMap; const static EnumMap otherNotationTypeMap; + const static EnumMap levelTypeMap; const static EnumMap ornamentsMap; const static EnumMap accidentalMarkMap; const static EnumMap technicalMarkMap; diff --git a/src/private/mx/impl/DirectionReader.cpp b/src/private/mx/impl/DirectionReader.cpp index b5a47762d..e1a341131 100644 --- a/src/private/mx/impl/DirectionReader.cpp +++ b/src/private/mx/impl/DirectionReader.cpp @@ -84,6 +84,7 @@ #include "mx/core/generated/WedgeType.h" #include "mx/core/generated/YesNo.h" #include "mx/impl/DynamicsReader.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/IdFunctions.h" #include "mx/impl/MarkDataFunctions.h" #include "mx/impl/MetronomeReader.h" @@ -255,6 +256,9 @@ void DirectionReader::parseValues() } } + myOutDirectionData.level = getLevel(myDirection->editorialVoiceDirection()); + myOutDirectionData.footnote = getFootnote(myDirection->editorialVoiceDirection()); + // The 's editorial-voice assigns the direction to a voice. A value of // VALUE_UNSPECIFIED on DirectionData::voice means none was present. if (myDirection->editorialVoiceDirection().voice().has_value()) @@ -1562,6 +1566,8 @@ void DirectionReader::parseHarmony(const core::Harmony &inHarmony, const core::H } chord.positionData = getPositionData(inHarmony); + chord.level = getLevel(inHarmony.editorial()); + chord.footnote = getFootnote(inHarmony.editorial()); myOutDirectionData.chords.push_back(chord); } diff --git a/src/private/mx/impl/DirectionWriter.cpp b/src/private/mx/impl/DirectionWriter.cpp index 9f52c6de9..8055452f2 100644 --- a/src/private/mx/impl/DirectionWriter.cpp +++ b/src/private/mx/impl/DirectionWriter.cpp @@ -110,6 +110,7 @@ #include "mx/core/generated/WedgeType.h" #include "mx/core/generated/YesNo.h" #include "mx/impl/DynamicsWriter.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/FontFunctions.h" #include "mx/impl/IdFunctions.h" #include "mx/impl/LineFunctions.h" @@ -220,16 +221,17 @@ std::vector DirectionWriter::getDirectionLikeThings() direction.setOffset(coreOffset); } - // Assign the direction to a voice via the editorial-voice . Only emitted when this - // direction also writes direction-type content (guarded by myIsDirectionTypeAdded below), + // The editorial-voice group: the direction's , and . Only emitted when + // this direction also writes direction-type content (guarded by myIsDirectionTypeAdded below), // so a voice carried in from a figured-bass or harmony element never produces an empty // . + auto editorialVoice = direction.editorialVoiceDirection(); if (myDirectionData.voice >= 0) { - core::EditorialVoiceDirectionGroup editorialVoice{}; editorialVoice.setVoice(std::to_string(myDirectionData.voice)); - direction.setEditorialVoiceDirection(std::move(editorialVoice)); } + setEditorial(myDirectionData.level, myDirectionData.footnote, editorialVoice); + direction.setEditorialVoiceDirection(std::move(editorialVoice)); emitDirectionTypes(direction); @@ -264,6 +266,13 @@ std::vector DirectionWriter::getDirectionLikeThings() output.push_back(core::MusicDataChoice::sound(std::move(sound))); } + if (!myIsDirectionTypeAdded && (myDirectionData.level.has_value() || myDirectionData.footnote.has_value())) + { + myDiagnostics.report(api::Severity::error, api::DiagnosticCode::droppedData, cursorLocation(myCursor), + "a direction level or footnote is not written; the direction does not have any " + "direction types"); + } + auto harmonyMdcs = createHarmonyElements(offset, offsetSound); addMusicDataChoices(harmonyMdcs, output); @@ -1467,6 +1476,17 @@ std::vector DirectionWriter::createHarmonyElements(int in harmony.setPrintFrame(myConverter.convert(printFrameChord->printFrame)); } + // The level and footnote also belong to the whole ; each comes from the first chord + // that has one. + const auto levelChord = + std::find_if(chords.cbegin(), chords.cend(), [](const api::ChordData &c) { return c.level.has_value(); }); + const auto footnoteChord = + std::find_if(chords.cbegin(), chords.cend(), [](const api::ChordData &c) { return c.footnote.has_value(); }); + auto harmonyEditorial = harmony.editorial(); + setEditorial(levelChord != chords.cend() ? levelChord->level : std::nullopt, + footnoteChord != chords.cend() ? footnoteChord->footnote : std::nullopt, harmonyEditorial); + harmony.setEditorial(std::move(harmonyEditorial)); + auto chordIter = chords.cbegin(); const auto chordEnd = chords.cend(); @@ -1870,10 +1890,16 @@ std::vector DirectionWriter::createFiguredBassElements() figure.setExtend(std::move(extend)); } + auto figureEditorial = figure.editorial(); + setEditorial(figureData.level, figureData.footnote, figureEditorial); + figure.setEditorial(std::move(figureEditorial)); figuredBass.addFigure(figure); } setId(figuredBassData.id, figuredBass, myDiagnostics, cursorLocation(myCursor)); + auto figuredBassEditorial = figuredBass.editorial(); + setEditorial(figuredBassData.level, figuredBassData.footnote, figuredBassEditorial); + figuredBass.setEditorial(std::move(figuredBassEditorial)); setAttributesFromPositionData(figuredBassData.positionData, figuredBass); setAttributesFromPrintData(figuredBassData.printData, figuredBass); diff --git a/src/private/mx/impl/EditorialFunctions.cpp b/src/private/mx/impl/EditorialFunctions.cpp new file mode 100644 index 000000000..f658da269 --- /dev/null +++ b/src/private/mx/impl/EditorialFunctions.cpp @@ -0,0 +1,147 @@ +// MusicXML Class Library +// Copyright (c) by Matthew James Briggs +// Distributed under the MIT License + +#include "mx/impl/EditorialFunctions.h" +#include "mx/impl/Converter.h" +#include "mx/impl/FontFunctions.h" +#include "mx/impl/PositionFunctions.h" +#include "mx/impl/PrintFunctions.h" + +namespace mx +{ +namespace impl +{ +api::LevelData makeLevelData(const core::Level &inLevel) +{ + Converter converter; + api::LevelData outLevel; + outLevel.text = inLevel.value(); + + if (inLevel.reference().has_value()) + { + outLevel.reference = converter.convert(*inLevel.reference()); + } + + if (inLevel.type().has_value()) + { + outLevel.type = converter.convertLevelType(*inLevel.type()); + } + + if (inLevel.parentheses().has_value()) + { + outLevel.parentheses = converter.convert(*inLevel.parentheses()); + } + + if (inLevel.bracket().has_value()) + { + outLevel.bracket = converter.convert(*inLevel.bracket()); + } + + if (inLevel.size().has_value()) + { + outLevel.size = converter.convert(*inLevel.size()); + } + + return outLevel; +} + +core::Level makeCoreLevel(const api::LevelData &inLevelData) +{ + Converter converter; + core::Level outLevel; + outLevel.setValue(inLevelData.text); + + if (inLevelData.reference != api::Bool::unspecified) + { + outLevel.setReference(converter.convert(inLevelData.reference)); + } + + if (inLevelData.type != api::LevelType::unspecified) + { + outLevel.setType(converter.convertLevelType(inLevelData.type)); + } + + if (inLevelData.parentheses != api::Bool::unspecified) + { + outLevel.setParentheses(converter.convert(inLevelData.parentheses)); + } + + if (inLevelData.bracket != api::Bool::unspecified) + { + outLevel.setBracket(converter.convert(inLevelData.bracket)); + } + + if (inLevelData.size != api::SymbolSize::unspecified) + { + outLevel.setSize(converter.convert(inLevelData.size)); + } + + return outLevel; +} + +api::FootnoteData makeFootnoteData(const core::FormattedText &inFootnote) +{ + Converter converter; + api::FootnoteData outFootnote; + outFootnote.text = inFootnote.value(); + outFootnote.positionData = getPositionData(inFootnote); + outFootnote.fontData = getFontData(inFootnote); + + if (inFootnote.color().has_value()) + { + outFootnote.color = getColor(inFootnote); + } + + if (inFootnote.justify().has_value()) + { + outFootnote.justify = converter.convert(*inFootnote.justify()); + } + + if (inFootnote.enclosure().has_value()) + { + outFootnote.enclosure = converter.convert(*inFootnote.enclosure()); + } + + if (inFootnote.xmlSpace().has_value()) + { + outFootnote.xmlSpace = converter.convert(*inFootnote.xmlSpace()); + } + + return outFootnote; +} + +core::FormattedText makeCoreFootnote(const api::FootnoteData &inFootnoteData) +{ + Converter converter; + core::FormattedText outFootnote; + outFootnote.setValue(inFootnoteData.text); + + // does not have a placement attribute, so setAttributesFromPositionData skips it. + setAttributesFromPositionData(inFootnoteData.positionData, outFootnote); + setAttributesFromFontData(inFootnoteData.fontData, outFootnote); + + if (inFootnoteData.color.has_value()) + { + setAttributesFromColorData(*inFootnoteData.color, outFootnote); + } + + if (inFootnoteData.justify != api::HorizontalAlignment::unspecified) + { + outFootnote.setJustify(converter.convert(inFootnoteData.justify)); + } + + if (inFootnoteData.enclosure != api::Enclosure::unspecified) + { + outFootnote.setEnclosure(converter.convert(inFootnoteData.enclosure)); + } + + if (inFootnoteData.xmlSpace != api::XmlSpace::unspecified) + { + outFootnote.setXMLSpace(converter.convert(inFootnoteData.xmlSpace)); + } + + return outFootnote; +} +} // namespace impl +} // namespace mx diff --git a/src/private/mx/impl/EditorialFunctions.h b/src/private/mx/impl/EditorialFunctions.h new file mode 100644 index 000000000..82ca04cdc --- /dev/null +++ b/src/private/mx/impl/EditorialFunctions.h @@ -0,0 +1,73 @@ +// MusicXML Class Library +// Copyright (c) by Matthew James Briggs +// Distributed under the MIT License + +#pragma once + +#include "mx/api/FootnoteData.h" +#include "mx/api/LevelData.h" +#include "mx/core/generated/FormattedText.h" +#include "mx/core/generated/Level.h" + +#include + +namespace mx +{ +namespace impl +{ +// Conversions between the api level and footnote and their core elements. +api::LevelData makeLevelData(const core::Level &inLevel); +core::Level makeCoreLevel(const api::LevelData &inLevelData); +api::FootnoteData makeFootnoteData(const core::FormattedText &inFootnote); +core::FormattedText makeCoreFootnote(const api::FootnoteData &inFootnoteData); + +// Read the of any of the three core editorial groups (EditorialGroup, EditorialVoiceGroup, +// EditorialVoiceDirectionGroup). Absent stays absent. +template std::optional getLevel(const GROUP &inGroup) +{ + if (!inGroup.level().has_value()) + { + return std::nullopt; + } + + return makeLevelData(*inGroup.level()); +} + +// Read the of any of the three core editorial groups. Absent stays absent. +template std::optional getFootnote(const GROUP &inGroup) +{ + if (!inGroup.footnote().has_value()) + { + return std::nullopt; + } + + return makeFootnoteData(*inGroup.footnote()); +} + +// Replace the and of any of the three core editorial groups; an absent one is +// removed. The group's is left as it is. A host returns its group by const reference, so +// copy the group out of the host, call this on the copy, and set the copy back. +template +void setEditorial(const std::optional &inLevel, const std::optional &inFootnote, + GROUP &ioGroup) +{ + if (inLevel.has_value()) + { + ioGroup.setLevel(makeCoreLevel(*inLevel)); + } + else + { + ioGroup.setLevel(std::nullopt); + } + + if (inFootnote.has_value()) + { + ioGroup.setFootnote(makeCoreFootnote(*inFootnote)); + } + else + { + ioGroup.setFootnote(std::nullopt); + } +} +} // namespace impl +} // namespace mx diff --git a/src/private/mx/impl/MeasureReader.cpp b/src/private/mx/impl/MeasureReader.cpp index a131cc42d..d68bbecaf 100644 --- a/src/private/mx/impl/MeasureReader.cpp +++ b/src/private/mx/impl/MeasureReader.cpp @@ -59,6 +59,7 @@ #include "mx/core/generated/YesNo.h" #include "mx/impl/Converter.h" #include "mx/impl/DirectionReader.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/IdFunctions.h" #include "mx/impl/NameDisplayFunctions.h" #include "mx/impl/NoteFunctions.h" @@ -142,6 +143,9 @@ api::FigureData MeasureReader::parseFigure(const core::Figure &figure) figureData.extend = extend; } + figureData.level = getLevel(figure.editorial()); + figureData.footnote = getFootnote(figure.editorial()); + return figureData; } @@ -1159,6 +1163,8 @@ void MeasureReader::parseFiguredBass(const core::FiguredBass &inMxFiguredBass, c figuredBass.id = getId(inMxFiguredBass); figuredBass.positionData = impl::getPositionData(inMxFiguredBass); figuredBass.printData = impl::getPrintData(inMxFiguredBass); + figuredBass.level = impl::getLevel(inMxFiguredBass.editorial()); + figuredBass.footnote = impl::getFootnote(inMxFiguredBass.editorial()); auto direction = api::DirectionData{}; direction.tickTimePosition = myCurrentCursor.tickTimePosition; @@ -1342,6 +1348,8 @@ void MeasureReader::parseBarline(const core::Barline &inMxBarline) const barline.repeatAfterJump = repeatAfterJump; barline.repeatWinged = repeatWinged; barline.id = getId(inMxBarline); + barline.level = getLevel(inMxBarline.editorial()); + barline.footnote = getFootnote(inMxBarline.editorial()); myOutMeasureData.barlines.emplace_back(std::move(barline)); } diff --git a/src/private/mx/impl/MeasureWriter.cpp b/src/private/mx/impl/MeasureWriter.cpp index 53c3f8022..be2f3a575 100644 --- a/src/private/mx/impl/MeasureWriter.cpp +++ b/src/private/mx/impl/MeasureWriter.cpp @@ -36,6 +36,7 @@ #include "mx/core/generated/YesNo.h" #include "mx/impl/Converter.h" #include "mx/impl/DirectionWriter.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/IdFunctions.h" #include "mx/impl/LayoutFunctions.h" #include "mx/impl/NameDisplayFunctions.h" @@ -1205,6 +1206,9 @@ void MeasureWriter::writeBarline(const api::BarlineData &barline) } impl::setId(barline.id, barlineElement, myScoreWriter.getDiagnostics(), cursorLocation(myHistory.getCursor())); + auto barlineEditorial = barlineElement.editorial(); + impl::setEditorial(barline.level, barline.footnote, barlineEditorial); + barlineElement.setEditorial(std::move(barlineEditorial)); myOutMeasure.addMusicData(core::MusicDataChoice::barline(barlineElement)); myHistory.log("writeBarline"); } diff --git a/src/private/mx/impl/NoteFunctions.cpp b/src/private/mx/impl/NoteFunctions.cpp index 29d911cfd..0692a5787 100644 --- a/src/private/mx/impl/NoteFunctions.cpp +++ b/src/private/mx/impl/NoteFunctions.cpp @@ -10,6 +10,7 @@ #include "mx/impl/ArticulationsFunctions.h" #include "mx/impl/CurveFunctions.h" #include "mx/impl/DynamicsReader.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/FermataFunctions.h" #include "mx/impl/GlissandoFunctions.h" #include "mx/impl/IdFunctions.h" @@ -184,7 +185,8 @@ api::NoteData NoteFunctions::parseNote() const myOutNoteData.isTieStop = reader.getIsTieStop(); myOutNoteData.lyrics = reader.getLyrics(); - parseMiscData(); + myOutNoteData.level = impl::getLevel(myNote.editorialVoice()); + myOutNoteData.footnote = impl::getFootnote(myNote.editorialVoice()); myOutNoteData.positionData = impl::getPositionData(myNote); myOutNoteData.id = impl::getId(myNote); @@ -351,49 +353,5 @@ void NoteFunctions::parseNotations() const } } } - -void NoteFunctions::parseMiscData() const -{ - if (!myNote.editorialVoice().footnote().has_value()) - { - return; - } - - const auto &footnote = myNote.editorialVoice().footnote().value(); - - if (!footnote.value().empty()) - { - // we expect this element to be unused if it is - // stuffed with ##misc-data## in the font-family - return; - } - - if (!footnote.fontFamily().has_value()) - { - return; - } - - const auto &miscData = footnote.fontFamily().value(); - const auto items = miscData.items(); - - if (items.empty()) - { - return; - } - - const auto &firstString = items[0]; - - if (firstString.substr(0, 13) != "##misc-data##") - { - return; - } - - myOutNoteData.miscData.push_back(firstString.substr(13)); - - for (size_t i = 1; i < items.size(); ++i) - { - myOutNoteData.miscData.push_back(items[i]); - } -} } // namespace impl } // namespace mx diff --git a/src/private/mx/impl/NoteFunctions.h b/src/private/mx/impl/NoteFunctions.h index cd87d0787..fc376dfd2 100644 --- a/src/private/mx/impl/NoteFunctions.h +++ b/src/private/mx/impl/NoteFunctions.h @@ -35,7 +35,6 @@ class NoteFunctions private: api::DurationName deriveNoteTypeFromDurationValue(const NoteReader &reader) const; void parseNotations() const; - void parseMiscData() const; }; } // namespace impl } // namespace mx diff --git a/src/private/mx/impl/NoteReader.cpp b/src/private/mx/impl/NoteReader.cpp index 71201417d..cc220ab54 100644 --- a/src/private/mx/impl/NoteReader.cpp +++ b/src/private/mx/impl/NoteReader.cpp @@ -15,6 +15,7 @@ #include "mx/core/generated/Syllabic.h" #include "mx/core/generated/TextElementData.h" #include "mx/core/generated/Tied.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/FontFunctions.h" #include "mx/impl/IdFunctions.h" #include "mx/impl/PositionFunctions.h" @@ -561,6 +562,8 @@ void NoteReader::setLyric() api::LyricData lyricData; lyricData.positionData = getLyricPositionData(lyric); lyricData.id = getId(lyric); + lyricData.level = getLevel(lyric.editorial()); + lyricData.footnote = getFootnote(lyric.editorial()); if (lyric.number().has_value()) { diff --git a/src/private/mx/impl/NoteWriter.cpp b/src/private/mx/impl/NoteWriter.cpp index 5d8c19530..0c2da0a71 100644 --- a/src/private/mx/impl/NoteWriter.cpp +++ b/src/private/mx/impl/NoteWriter.cpp @@ -13,7 +13,6 @@ #include "mx/core/generated/Elision.h" #include "mx/core/generated/ElisionSyllabicGroup.h" #include "mx/core/generated/Extend.h" -#include "mx/core/generated/FormattedText.h" #include "mx/core/generated/FullNoteGroupChoice.h" #include "mx/core/generated/GraceCueNoteGroup.h" #include "mx/core/generated/GraceNormalNoteGroup.h" @@ -39,6 +38,7 @@ #include "mx/core/generated/TimeModification.h" #include "mx/core/generated/TimeModificationGroup.h" #include "mx/core/generated/Unpitched.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/IdFunctions.h" #include "mx/impl/NotationsWriter.h" #include "mx/impl/PositionFunctions.h" @@ -112,7 +112,7 @@ core::Note NoteWriter::getNote(bool isStartOfChord) const setDurationNameAndDots(); setNotehead(); setStemDirection(); - setMiscData(); + setEditorial(); setInstruments(); impl::setId(myNoteData.id, myOutNote, myScoreWriter.getDiagnostics(), cursorLocation(myCursor)); NotationsWriter notationsWriter{myNoteData, myCursor, myScoreWriter}; @@ -633,6 +633,9 @@ void NoteWriter::setLyrics() const impl::setAttributesFromPositionData(lyricData.positionData, lyric); impl::setId(lyricData.id, lyric, myScoreWriter.getDiagnostics(), cursorLocation(myCursor)); + auto lyricEditorial = lyric.editorial(); + impl::setEditorial(lyricData.level, lyricData.footnote, lyricEditorial); + lyric.setEditorial(std::move(lyricEditorial)); if (lyricData.positionData.horizontalAlignment != api::HorizontalAlignment::unspecified) { lyric.setJustify(myConverter.convert(lyricData.positionData.horizontalAlignment)); @@ -754,52 +757,10 @@ void NoteWriter::setInstruments() const } } -void NoteWriter::setMiscData() const +void NoteWriter::setEditorial() const { - if (myNoteData.miscData.size() == 0) - { - return; - } - - const std::string comma = ","; - const std::string underscore = "_"; - - std::vector miscItems; - bool isFirst = true; - for (auto s : myNoteData.miscData) - { - // Comma is the item separator in the miscellaneous-field wire encoding, so commas - // inside user misc-data are irreversibly replaced with underscores. - if (s.find(comma) != std::string::npos) - { - const auto original = s; - std::string::size_type position = 0; - while ((position = s.find(comma, position)) != std::string::npos) - { - s.replace(position, comma.size(), underscore); - position++; - } - myScoreWriter.getDiagnostics().report( - api::Severity::warning, api::DiagnosticCode::valueAdjusted, cursorLocation(myCursor), - "note misc data \"" + original + "\" contains a comma; using \"" + s + "\""); - } - - if (isFirst) - { - isFirst = false; - miscItems.push_back(std::string{"##misc-data##"} + s); - } - else - { - miscItems.push_back(s); - } - } - - core::FormattedText footnote; - footnote.setFontFamily(core::FontFamily{std::move(miscItems)}); - auto editorialVoice = myOutNote.editorialVoice(); - editorialVoice.setFootnote(std::move(footnote)); + impl::setEditorial(myNoteData.level, myNoteData.footnote, editorialVoice); myOutNote.setEditorialVoice(std::move(editorialVoice)); } } // namespace impl diff --git a/src/private/mx/impl/NoteWriter.h b/src/private/mx/impl/NoteWriter.h index 94e9b8bbd..e5955ab16 100644 --- a/src/private/mx/impl/NoteWriter.h +++ b/src/private/mx/impl/NoteWriter.h @@ -69,7 +69,8 @@ class NoteWriter // Writes an for each of the note's instruments that is one of the part's, and // reports each one that is not. void setInstruments() const; - void setMiscData() const; + // Writes the note's level and footnote, keeping the that setStaffAndVoice wrote. + void setEditorial() const; }; } // namespace impl } // namespace mx diff --git a/src/private/mx/impl/ScoreReader.cpp b/src/private/mx/impl/ScoreReader.cpp index ae1e683f3..012af8ff7 100644 --- a/src/private/mx/impl/ScoreReader.cpp +++ b/src/private/mx/impl/ScoreReader.cpp @@ -30,6 +30,7 @@ #include "mx/core/generated/Work.h" #include "mx/core/generated/YesNo.h" #include "mx/impl/Converter.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/EncodingFunctions.h" #include "mx/impl/LayoutFunctions.h" #include "mx/impl/NameDisplayFunctions.h" @@ -397,7 +398,8 @@ void ScoreReader::startPartGroup(int partIndex, const core::PartGroup &inPartGro grpData.firstPartIndex = partIndex; // TODO - group time - // TODO - editorial (footnote/level) + grpData.level = impl::getLevel(inPartGroup.editorial()); + grpData.footnote = impl::getFootnote(inPartGroup.editorial()); myPartGroupStack.push_front(grpData); } diff --git a/src/private/mx/impl/ScoreWriter.cpp b/src/private/mx/impl/ScoreWriter.cpp index 960988d0c..83df36c31 100644 --- a/src/private/mx/impl/ScoreWriter.cpp +++ b/src/private/mx/impl/ScoreWriter.cpp @@ -26,6 +26,7 @@ #include "mx/core/generated/TypedText.h" #include "mx/core/generated/Work.h" #include "mx/impl/Converter.h" +#include "mx/impl/EditorialFunctions.h" #include "mx/impl/EncodingFunctions.h" #include "mx/impl/LayoutFunctions.h" #include "mx/impl/NameDisplayFunctions.h" @@ -481,6 +482,10 @@ core::PartGroup ScoreWriter::makePartGroupStart(const api::PartGroupData &apiGrp mxGrp.setGroupBarline(groupBarline); } + auto groupEditorial = mxGrp.editorial(); + impl::setEditorial(apiGrp.level, apiGrp.footnote, groupEditorial); + mxGrp.setEditorial(std::move(groupEditorial)); + return mxGrp; } diff --git a/src/private/mxtest/api/NoteDataTest.cpp b/src/private/mxtest/api/NoteDataTest.cpp index 2d6e46550..9a8a0dec2 100644 --- a/src/private/mxtest/api/NoteDataTest.cpp +++ b/src/private/mxtest/api/NoteDataTest.cpp @@ -724,63 +724,6 @@ TEST(unmeasuredTremoloFromSyntheticFile, NoteData) T_END; -TEST(miscFields, NoteData) -{ - ScoreData score; - score.parts.emplace_back(); - auto &part = score.parts.back(); - part.measures.emplace_back(); - auto &measure = part.measures.back(); - measure.staves.emplace_back(); - auto &staff = measure.staves.back(); - auto &voice = staff.voices[0]; - voice.notes.emplace_back(); - auto ¬e = voice.notes.back(); - note.miscData.push_back("Hello,There"); - note.miscData.push_back("Bones"); - note.miscData.push_back("Bishop"); - - // round trip it through xml - auto r1 = fromScore(score); - REQUIRE(r1.ok()); - std::stringstream ss; - std::move(r1).value().writeToStream(ss); - const std::string xml = ss.str(); - std::istringstream iss{xml}; - auto r2 = MusicXml::fromStream(iss); - REQUIRE(r2.ok()); - const auto rd = getScore(std::move(r2).value()); - REQUIRE(rd.ok()); - auto oscore = rd.value(); - - // get the data after the round trip - auto &opart = oscore.parts.back(); - auto &omeasure = opart.measures.back(); - auto &ostaff = omeasure.staves.back(); - auto &ovoice = ostaff.voices[0]; - auto &onote = ovoice.notes.back(); - auto &omisc = onote.miscData; - auto iter = omisc.cbegin(); - const auto end = omisc.cend(); - - // assert - CHECK(iter != end); - CHECK_EQUAL("Hello_There", *iter); - ++iter; - - CHECK(iter != end); - CHECK_EQUAL("Bones", *iter); - ++iter; - - CHECK(iter != end); - CHECK_EQUAL("Bishop", *iter); - ++iter; - - CHECK(iter == end); -} - -T_END; - // SlurTieNumberLevel tests: build a score with a note that has a tie/slur using // mx::api directly, round-trip it, then check that the number is unspecified (absent). From 1d87dd271c52a53506b78c1fac86bb044b2235d8 Mon Sep 17 00:00:00 2001 From: Matthew James Briggs Date: Wed, 25 Nov 2026 16:52:16 +0100 Subject: [PATCH 2/4] test: cover level and footnote on every mx::api host Round-trip fixtures for each host, a parenthesized rest, a note with level, footnote and voice together, the harmony first-chord rule, and the dropped-direction diagnostic. Pin synthetic/level.3.0.xml and level.4.0.xml in the api round-trip baseline. Claude-Session: https://claude.ai/code/session_01A8XRpcx6L2kGcYfiUhYJ8V --- src/private/mxtest/api/EditorialApiTest.cpp | 575 ++++++++++++++++++ src/private/mxtest/api/roundtrip-baseline.txt | 6 + 2 files changed, 581 insertions(+) create mode 100644 src/private/mxtest/api/EditorialApiTest.cpp diff --git a/src/private/mxtest/api/EditorialApiTest.cpp b/src/private/mxtest/api/EditorialApiTest.cpp new file mode 100644 index 000000000..f325d98e5 --- /dev/null +++ b/src/private/mxtest/api/EditorialApiTest.cpp @@ -0,0 +1,575 @@ +// MusicXML Class Library +// Copyright (c) by Matthew James Briggs +// Distributed under the MIT License + +#include "mxtest/control/CompileControl.h" +#ifdef MX_COMPILE_API_TESTS + +#include "cpul/cpulTestHarness.h" +#include "mx/api/Diagnostics.h" +#include "mx/api/MusicXml.h" +#include "mx/api/ScoreData.h" +#include "mxtest/api/RoundTrip.h" +#include "mxtest/api/TestHelpers.h" + +#include +#include + +using namespace std; +using namespace mx::api; +using namespace mxtest; + +// A one-part score with one measure. partListExtra goes into before the +// and partListTail after it; measureBody follows the measure's . +static std::string editorialScoreXml(const std::string &measureBody, const std::string &partListExtra = "", + const std::string &partListTail = "") +{ + return std::string{R"( + + +)"} + partListExtra + + R"( + Music + +)" + partListTail + + R"( + + + + 1 + + + G + 2 + + +)" + measureBody + + R"( + + +)"; +} + +// A that sets every attribute FootnoteData models, each to a value no other one shares. +static const std::string kEditorialFootnoteXml = + R"()" + R"(m. 12: slur absent in the autograph)"; + +// The FootnoteData that kEditorialFootnoteXml reads as. +static FootnoteData editorialExpectedFootnote() +{ + FootnoteData footnote; + footnote.text = "m. 12: slur absent in the autograph"; + footnote.positionData.isDefaultXSpecified = true; + footnote.positionData.defaultX = 11.0; + footnote.positionData.isDefaultYSpecified = true; + footnote.positionData.defaultY = -22.0; + footnote.positionData.isRelativeXSpecified = true; + footnote.positionData.relativeX = 33.0; + footnote.positionData.isRelativeYSpecified = true; + footnote.positionData.relativeY = -44.0; + footnote.positionData.horizontalAlignment = HorizontalAlignment::right; + footnote.positionData.verticalAlignment = VerticalAlignment::top; + footnote.fontData.fontFamily = {"Times"}; + footnote.fontData.style = FontStyle::italic; + footnote.fontData.sizeType = FontSizeType::point; + footnote.fontData.sizePoint = 9.0; + footnote.fontData.weight = FontWeight::bold; + footnote.fontData.underline = 1; + footnote.fontData.overline = 2; + footnote.fontData.lineThrough = 3; + ColorData color; + color.red = 0x10; + color.green = 0x20; + color.blue = 0x30; + footnote.color = color; + footnote.justify = HorizontalAlignment::center; + footnote.enclosure = Enclosure::oval; + footnote.xmlSpace = XmlSpace::preserve; + return footnote; +} + +static LevelData editorialLevel(const std::string &text, Bool reference, LevelType type, Bool parentheses, Bool bracket, + SymbolSize size) +{ + LevelData level; + level.text = text; + level.reference = reference; + level.type = type; + level.parentheses = parentheses; + level.bracket = bracket; + level.size = size; + return level; +} + +static const MeasureData &editorialMeasure(const ScoreData &score) +{ + return score.parts.at(0).measures.at(0); +} + +// Writes the score and reads it back, returning the XML written along the way. +static ScoreData editorialRoundTrip(const ScoreData &score, std::string &outXml) +{ + outXml = toXml(score); + return fromXml(outXml); +} + +// A rest with : the way MusicXML parenthesizes a rest, which does not +// have a notehead. +TEST(parenthesizedRest, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( + + 1 + + 1 + quarter + +)"); + const auto score = fromXml(xml); + const auto ¬e = editorialMeasure(score).staves.at(0).voices.at(0).notes.at(0); + CHECK(note.isRest); + REQUIRE(note.level.has_value()); + CHECK(*note.level == editorialLevel("", Bool::unspecified, LevelType::unspecified, Bool::yes, Bool::unspecified, + SymbolSize::unspecified)); + CHECK(!note.footnote.has_value()); + + std::string written; + const auto out = editorialRoundTrip(score, written); + CHECK(written.find(" + + C + 5 + + 1 + )" + kEditorialFootnoteXml + R"( + 2 (pencil) + 1 + quarter + +)"); + const auto score = fromXml(xml); + const auto ¬e = editorialMeasure(score).staves.at(0).voices.at(0).notes.at(0); + REQUIRE(note.level.has_value()); + CHECK(*note.level == + editorialLevel("2 (pencil)", Bool::yes, LevelType::start, Bool::no, Bool::unspecified, SymbolSize::cue)); + REQUIRE(note.footnote.has_value()); + CHECK(*note.footnote == editorialExpectedFootnote()); + CHECK_EQUAL(1, note.userRequestedVoiceNumber); + + std::string written; + const auto out = editorialRoundTrip(score, written); + const auto footnotePos = written.find("1"); + REQUIRE(footnotePos != std::string::npos); + REQUIRE(levelPos != std::string::npos); + REQUIRE(voicePos != std::string::npos); + CHECK(footnotePos < levelPos); + CHECK(levelPos < voicePos); + CHECK(out.parts.at(0).measures.at(0).staves.at(0).voices.at(0).notes.at(0) == note); +} + +T_END; + +// The same three on a note authored through the api, in the second voice, so the writer has to +// state the voice. +TEST(authoredNoteLevelFootnoteAndVoice, EditorialApi) +{ + ScoreData score; + score.ticksPerQuarter = 1; + score.parts.emplace_back(); + auto &part = score.parts.back(); + part.uniqueId = "P1"; + part.name = "Music"; + part.measures.emplace_back(); + auto &staff = part.measures.back().staves.emplace_back(); + for (int voiceIndex = 0; voiceIndex < 2; ++voiceIndex) + { + NoteData note; + note.pitchData.step = voiceIndex == 0 ? Step::e : Step::c; + note.pitchData.octave = 4; + note.durationData.durationName = DurationName::quarter; + note.durationData.durationTimeTicks = 1; + staff.voices[voiceIndex].notes.push_back(note); + } + auto ¬e = staff.voices[1].notes.back(); + note.level = + editorialLevel("editor", Bool::no, LevelType::stop, Bool::unspecified, Bool::yes, SymbolSize::graceCue); + note.footnote = editorialExpectedFootnote(); + + std::string written; + const auto out = editorialRoundTrip(score, written); + CHECK(written.find("2") != std::string::npos); + const auto &onote = editorialMeasure(out).staves.at(0).voices.at(1).notes.at(0); + REQUIRE(onote.level.has_value()); + CHECK(*onote.level == *note.level); + REQUIRE(onote.footnote.has_value()); + CHECK(*onote.footnote == *note.footnote); + CHECK(!editorialMeasure(out).staves.at(0).voices.at(0).notes.at(0).level.has_value()); +} + +T_END; + +TEST(lyric, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( + + D + 4 + + 1 + quarter + + single + la + )" + kEditorialFootnoteXml + R"( + lyric layer + + +)"); + const auto score = fromXml(xml); + const auto ¬e = editorialMeasure(score).staves.at(0).voices.at(0).notes.at(0); + REQUIRE(note.lyrics.size() == 1); + const auto &lyric = note.lyrics.front(); + REQUIRE(lyric.level.has_value()); + CHECK(*lyric.level == + editorialLevel("lyric layer", Bool::no, LevelType::single, Bool::unspecified, Bool::yes, SymbolSize::large)); + REQUIRE(lyric.footnote.has_value()); + CHECK(*lyric.footnote == editorialExpectedFootnote()); + CHECK(!note.level.has_value()); + + std::string written; + const auto out = editorialRoundTrip(score, written); + CHECK(editorialMeasure(out).staves.at(0).voices.at(0).notes.at(0).lyrics == note.lyrics); +} + +T_END; + +TEST(barline, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( + + E + 4 + + 1 + quarter + + + light-heavy + )" + kEditorialFootnoteXml + R"( + barline layer + + +)"); + const auto score = fromXml(xml); + const auto &measure = editorialMeasure(score); + REQUIRE(measure.barlines.size() == 1); + const auto &barline = measure.barlines.front(); + REQUIRE(barline.level.has_value()); + CHECK(*barline.level == + editorialLevel("barline layer", Bool::unspecified, LevelType::stop, Bool::yes, Bool::no, SymbolSize::full)); + REQUIRE(barline.footnote.has_value()); + CHECK(*barline.footnote == editorialExpectedFootnote()); + + std::string written; + const auto out = editorialRoundTrip(score, written); + CHECK(editorialMeasure(out).barlines == measure.barlines); +} + +T_END; + +// A level and footnote on the whole , and different ones on one of its
s. +TEST(figuredBassAndFigure, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( +
+ 6 + figure layer +
+
+ 4 +
+ )" + kEditorialFootnoteXml + R"( + bass layer +
+ + + F + 3 + + 1 + quarter + +)"); + const auto score = fromXml(xml); + const auto &directions = editorialMeasure(score).staves.at(0).directions; + REQUIRE(directions.size() == 1); + const auto &direction = directions.front(); + CHECK(!direction.level.has_value()); + CHECK(!direction.footnote.has_value()); + REQUIRE(direction.figuredBasses.size() == 1); + const auto &figuredBass = direction.figuredBasses.front(); + REQUIRE(figuredBass.level.has_value()); + CHECK(*figuredBass.level == + editorialLevel("bass layer", Bool::unspecified, LevelType::start, Bool::no, Bool::yes, SymbolSize::cue)); + REQUIRE(figuredBass.footnote.has_value()); + CHECK(*figuredBass.footnote == editorialExpectedFootnote()); + REQUIRE(figuredBass.figures.size() == 2); + const auto &figure = figuredBass.figures.at(0); + REQUIRE(figure.level.has_value()); + CHECK(*figure.level == editorialLevel("figure layer", Bool::yes, LevelType::single, Bool::unspecified, Bool::no, + SymbolSize::unspecified)); + CHECK(!figure.footnote.has_value()); + CHECK(!figuredBass.figures.at(1).level.has_value()); + + std::string written; + const auto out = editorialRoundTrip(score, written); + const auto &odirections = editorialMeasure(out).staves.at(0).directions; + REQUIRE(odirections.size() == 1); + CHECK(odirections.front().figuredBasses == direction.figuredBasses); +} + +T_END; + +// A carrying a footnote, a level and a voice. +TEST(directionLevelFootnoteAndVoice, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( + + + + + + )" + kEditorialFootnoteXml + R"( + direction layer + 1 + 1 + + + + G + 4 + + 1 + 1 + quarter + +)"); + const auto score = fromXml(xml); + const auto &directions = editorialMeasure(score).staves.at(0).directions; + REQUIRE(directions.size() == 1); + const auto &direction = directions.front(); + REQUIRE(direction.level.has_value()); + CHECK(*direction.level == editorialLevel("direction layer", Bool::no, LevelType::stop, Bool::yes, Bool::unspecified, + SymbolSize::large)); + REQUIRE(direction.footnote.has_value()); + CHECK(*direction.footnote == editorialExpectedFootnote()); + CHECK_EQUAL(1, direction.voice); + + std::string written; + const auto out = editorialRoundTrip(score, written); + const auto footnotePos = written.find("1", levelPos); + REQUIRE(footnotePos != std::string::npos); + REQUIRE(levelPos != std::string::npos); + REQUIRE(voicePos != std::string::npos); + CHECK(footnotePos < levelPos); + CHECK(voicePos < written.find("1", levelPos)); + const auto &odirections = editorialMeasure(out).staves.at(0).directions; + REQUIRE(odirections.size() == 1); + CHECK(odirections.front() == direction); +} + +T_END; + +TEST(harmony, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( + + C + + major + )" + kEditorialFootnoteXml + R"( + chord layer + + + + A + 4 + + 1 + quarter + +)"); + const auto score = fromXml(xml); + const auto &directions = editorialMeasure(score).staves.at(0).directions; + REQUIRE(directions.size() == 1); + const auto &direction = directions.front(); + CHECK(!direction.level.has_value()); + REQUIRE(direction.chords.size() == 1); + const auto &chord = direction.chords.front(); + REQUIRE(chord.level.has_value()); + CHECK(*chord.level == + editorialLevel("chord layer", Bool::yes, LevelType::stop, Bool::unspecified, Bool::no, SymbolSize::graceCue)); + REQUIRE(chord.footnote.has_value()); + CHECK(*chord.footnote == editorialExpectedFootnote()); + + std::string written; + const auto out = editorialRoundTrip(score, written); + const auto &odirections = editorialMeasure(out).staves.at(0).directions; + REQUIRE(odirections.size() == 1); + CHECK(odirections.front().chords == direction.chords); +} + +T_END; + +// The chords of one direction become one , which has room for one level and one footnote. +// Each comes from the first chord that has one, and reads back onto every chord. +TEST(harmonyFirstChordRule, EditorialApi) +{ + ScoreData score; + score.ticksPerQuarter = 1; + score.parts.emplace_back(); + auto &part = score.parts.back(); + part.uniqueId = "P1"; + part.name = "Music"; + part.measures.emplace_back(); + auto &staff = part.measures.back().staves.emplace_back(); + NoteData note; + note.durationData.durationName = DurationName::quarter; + note.durationData.durationTimeTicks = 1; + staff.voices[0].notes.push_back(note); + + DirectionData direction; + direction.chords.resize(3); + direction.chords.at(0).root = Step::c; + direction.chords.at(0).chordKind = ChordKind::major; + direction.chords.at(0).footnote = editorialExpectedFootnote(); + direction.chords.at(1).root = Step::f; + direction.chords.at(1).chordKind = ChordKind::major; + direction.chords.at(1).level = + editorialLevel("second", Bool::yes, LevelType::start, Bool::no, Bool::unspecified, SymbolSize::cue); + direction.chords.at(2).root = Step::g; + direction.chords.at(2).chordKind = ChordKind::dominant; + direction.chords.at(2).level = + editorialLevel("third", Bool::no, LevelType::stop, Bool::yes, Bool::yes, SymbolSize::large); + FootnoteData thirdFootnote; + thirdFootnote.text = "third"; + direction.chords.at(2).footnote = thirdFootnote; + staff.directions.push_back(direction); + + std::string written; + const auto out = editorialRoundTrip(score, written); + CHECK(written.find("second") != std::string::npos); + CHECK(written.find(">third<") == std::string::npos); + const auto &odirections = editorialMeasure(out).staves.at(0).directions; + REQUIRE(odirections.size() == 1); + REQUIRE(odirections.front().chords.size() == 3); + for (const auto &chord : odirections.front().chords) + { + REQUIRE(chord.level.has_value()); + CHECK(*chord.level == *direction.chords.at(1).level); + REQUIRE(chord.footnote.has_value()); + CHECK(*chord.footnote == editorialExpectedFootnote()); + } +} + +T_END; + +// The level and footnote of a part group are on its start element. +TEST(partGroup, EditorialApi) +{ + const auto xml = editorialScoreXml(R"( + + B + 4 + + 1 + quarter + +)", + R"( + Winds + bracket + )" + kEditorialFootnoteXml + R"( + group layer + +)", + R"( +)"); + const auto score = fromXml(xml); + REQUIRE(score.partGroups.size() == 1); + const auto &group = score.partGroups.front(); + REQUIRE(group.level.has_value()); + CHECK(*group.level == editorialLevel("group layer", Bool::unspecified, LevelType::start, Bool::yes, Bool::no, + SymbolSize::unspecified)); + REQUIRE(group.footnote.has_value()); + CHECK(*group.footnote == editorialExpectedFootnote()); + + std::string written; + const auto out = editorialRoundTrip(score, written); + REQUIRE(out.partGroups.size() == 1); + CHECK(out.partGroups.front() == group); + const auto stopPos = written.find(" element to hold it. +TEST(directionWithoutDirectionTypesDropsLevel, EditorialApi) +{ + ScoreData score; + score.ticksPerQuarter = 1; + score.parts.emplace_back(); + auto &part = score.parts.back(); + part.uniqueId = "P1"; + part.name = "Music"; + part.measures.emplace_back(); + auto &staff = part.measures.back().staves.emplace_back(); + NoteData note; + note.durationData.durationName = DurationName::quarter; + note.durationData.durationTimeTicks = 1; + staff.voices[0].notes.push_back(note); + DirectionData direction; + direction.level = editorialLevel("lost", Bool::yes, LevelType::single, Bool::no, Bool::yes, SymbolSize::full); + staff.directions.push_back(direction); + + Diagnostics diagnostics; + const auto result = fromScore(score, diagnostics); + REQUIRE(result.ok()); + REQUIRE(diagnostics.all().size() == 1); + const auto &diagnostic = diagnostics.all().front(); + CHECK(DiagnosticCode::droppedData == diagnostic.code); + CHECK(Severity::error == diagnostic.severity); + CHECK_EQUAL("a direction level or footnote is not written; the direction does not have any direction types", + diagnostic.message); + + std::ostringstream xml; + REQUIRE(result.value().writeToStream(xml).ok()); + CHECK(xml.str().find(" and a . musuite/testVoiceMapper1.xml + +# Unblocked by LevelData and FootnoteData. The of a was dropped; a part group +# now keeps its level and footnote, as do notes, lyrics, barlines, directions, harmonies and +# figured bass. +synthetic/level.3.0.xml +synthetic/level.4.0.xml From 0ba09990aaf17fee2344e341995e1247c6c15286 Mon Sep 17 00:00:00 2001 From: Matthew James Briggs Date: Wed, 25 Nov 2026 16:52:16 +0100 Subject: [PATCH 3/4] docs: drop the padded possessives deslag reports in the level explainer Claude-Session: https://claude.ai/code/session_01A8XRpcx6L2kGcYfiUhYJ8V --- docs/level-element-explained.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/level-element-explained.md b/docs/level-element-explained.md index f4563396f..885ee3e1b 100644 --- a/docs/level-element-explained.md +++ b/docs/level-element-explained.md @@ -24,7 +24,7 @@ The XSD wording (`docs/musicxml-4.0-ed15c23.xsd:2645`): The second sentence was added in 4.0 to clarify the meaning (w3c-cg/musicxml#146). -Good's own example comes from his paper *Using MusicXML 2.0 for Editorial Applications* (Listing +Good's example comes from his paper *Using MusicXML 2.0 for Editorial Applications* (Listing 19). Two slurs in a Brahms edition come from different sources: ```xml @@ -280,7 +280,7 @@ std::optional level; parentheses around a rest the editor added") and say that a rest's parentheses go here, not on the notehead. -Scope recommendation, unchanged: note only. The XSD's own `reference` example is on `` +Scope recommendation, unchanged: note only. The XSD's `reference` example is on `` (original clef/key/time). That's the strongest case for another element, but `mx::api` doesn't model `` as an object, so it stays out unless someone designs one. From 945b58e2eb0f7180c01975737cbf94dc1c1e97cf Mon Sep 17 00:00:00 2001 From: Matthew James Briggs Date: Wed, 25 Nov 2026 17:31:09 +0100 Subject: [PATCH 4/4] feat: report harmony chords that disagree on level or footnote The chords of one direction share one , so the writer uses the first chord's level and footnote; a later chord with a different one now reports valueAdjusted, naming the chord used. Reword the DirectionData and FootnoteData comments for a musician. Test a text-only footnote, a figure footnote, a footnote-only dropped direction, and that a direction with level, footnote and voice writes without diagnostics. Claude-Session: https://claude.ai/code/session_01A8XRpcx6L2kGcYfiUhYJ8V --- src/include/mx/api/DirectionData.h | 7 +- src/include/mx/api/FootnoteData.h | 2 +- src/private/mx/impl/DirectionWriter.cpp | 20 ++- src/private/mxtest/api/EditorialApiTest.cpp | 146 +++++++++++++++----- 4 files changed, 137 insertions(+), 38 deletions(-) diff --git a/src/include/mx/api/DirectionData.h b/src/include/mx/api/DirectionData.h index 411c59603..3261387d2 100644 --- a/src/include/mx/api/DirectionData.h +++ b/src/include/mx/api/DirectionData.h @@ -105,12 +105,13 @@ struct DirectionData std::vector figuredBasses; // The editorial status of the direction's content (see LevelData), for example a dynamic the - // editor added, drawn in brackets. It belongs to the element, so it is written only - // when directionTypes is not empty. The chords and figured bass held here carry their own. + // editor added, drawn in brackets. MusicXML keeps it on the element, which needs at + // least one direction type, so give the direction something in directionTypes. The chords and + // figured bass held here carry their own. std::optional level; // Editorial commentary about the direction's content, printed as a footnote (see FootnoteData). - // Like level, it is written only when directionTypes is not empty. + // Like level, it is kept on the element, which needs at least one direction type. std::optional footnote; // The element's id attribute (see Id.h). diff --git a/src/include/mx/api/FootnoteData.h b/src/include/mx/api/FootnoteData.h index 408f59f70..1c1421ac6 100644 --- a/src/include/mx/api/FootnoteData.h +++ b/src/include/mx/api/FootnoteData.h @@ -25,7 +25,7 @@ struct FootnoteData std::string text; // Where the footnote text is drawn, in tenths of a staff space, and how it aligns against that - // point. placement is not used. Leave this alone to let the application place it. + // point. placement is ignored. Leave this alone to let the application place it. PositionData positionData; // The font of the footnote text. diff --git a/src/private/mx/impl/DirectionWriter.cpp b/src/private/mx/impl/DirectionWriter.cpp index 8055452f2..d8a3211e6 100644 --- a/src/private/mx/impl/DirectionWriter.cpp +++ b/src/private/mx/impl/DirectionWriter.cpp @@ -123,6 +123,7 @@ #include "mx/impl/TuningFunctions.h" #include +#include namespace mx { @@ -1477,11 +1478,28 @@ std::vector DirectionWriter::createHarmonyElements(int in } // The level and footnote also belong to the whole ; each comes from the first chord - // that has one. + // that has one. A later chord with a different one is reported. const auto levelChord = std::find_if(chords.cbegin(), chords.cend(), [](const api::ChordData &c) { return c.level.has_value(); }); const auto footnoteChord = std::find_if(chords.cbegin(), chords.cend(), [](const api::ChordData &c) { return c.footnote.has_value(); }); + if (levelChord != chords.cend() && std::any_of(levelChord, chords.cend(), [&levelChord](const api::ChordData &c) { + return c.level.has_value() && *c.level != *levelChord->level; + })) + { + myDiagnostics.report(api::Severity::warning, api::DiagnosticCode::valueAdjusted, cursorLocation(myCursor), + "the chords of a harmony have different levels; using the level of chord " + + std::to_string(std::distance(chords.cbegin(), levelChord) + 1)); + } + if (footnoteChord != chords.cend() && + std::any_of(footnoteChord, chords.cend(), [&footnoteChord](const api::ChordData &c) { + return c.footnote.has_value() && *c.footnote != *footnoteChord->footnote; + })) + { + myDiagnostics.report(api::Severity::warning, api::DiagnosticCode::valueAdjusted, cursorLocation(myCursor), + "the chords of a harmony have different footnotes; using the footnote of chord " + + std::to_string(std::distance(chords.cbegin(), footnoteChord) + 1)); + } auto harmonyEditorial = harmony.editorial(); setEditorial(levelChord != chords.cend() ? levelChord->level : std::nullopt, footnoteChord != chords.cend() ? footnoteChord->footnote : std::nullopt, harmonyEditorial); diff --git a/src/private/mxtest/api/EditorialApiTest.cpp b/src/private/mxtest/api/EditorialApiTest.cpp index f325d98e5..0098dc801 100644 --- a/src/private/mxtest/api/EditorialApiTest.cpp +++ b/src/private/mxtest/api/EditorialApiTest.cpp @@ -112,6 +112,38 @@ static const MeasureData &editorialMeasure(const ScoreData &score) return score.parts.at(0).measures.at(0); } +// A one-part score authored through the api, with one quarter note in its only measure. +static ScoreData editorialOneNoteScore() +{ + ScoreData score; + score.ticksPerQuarter = 1; + score.parts.emplace_back(); + auto &part = score.parts.back(); + part.uniqueId = "P1"; + part.name = "Music"; + part.measures.emplace_back(); + auto &staff = part.measures.back().staves.emplace_back(); + NoteData note; + note.durationData.durationName = DurationName::quarter; + note.durationData.durationTimeTicks = 1; + staff.voices[0].notes.push_back(note); + return score; +} + +static StaffData &editorialStaff(ScoreData &score) +{ + return score.parts.at(0).measures.at(0).staves.at(0); +} + +// The diagnostics that writing the score reports. +static Diagnostics editorialWriteDiagnostics(const ScoreData &score) +{ + Diagnostics diagnostics; + const auto result = fromScore(score, diagnostics); + REQUIRE(result.ok()); + return diagnostics; +} + // Writes the score and reads it back, returning the XML written along the way. static ScoreData editorialRoundTrip(const ScoreData &score, std::string &outXml) { @@ -226,6 +258,25 @@ TEST(authoredNoteLevelFootnoteAndVoice, EditorialApi) T_END; +// A footnote with only its words set is written without any attributes. +TEST(footnoteTextOnly, EditorialApi) +{ + auto score = editorialOneNoteScore(); + FootnoteData footnote; + footnote.text = "text"; + editorialStaff(score).voices[0].notes.back().footnote = footnote; + + std::string written; + const auto out = editorialRoundTrip(score, written); + CHECK(written.find("text") != std::string::npos); + const auto &onote = editorialMeasure(out).staves.at(0).voices.at(0).notes.at(0); + REQUIRE(onote.footnote.has_value()); + CHECK(*onote.footnote == footnote); + CHECK(!onote.level.has_value()); +} + +T_END; + TEST(lyric, EditorialApi) { const auto xml = editorialScoreXml(R"( @@ -301,6 +352,7 @@ TEST(figuredBassAndFigure, EditorialApi) const auto xml = editorialScoreXml(R"(
6 + figure note figure layer
@@ -336,14 +388,20 @@ TEST(figuredBassAndFigure, EditorialApi) REQUIRE(figure.level.has_value()); CHECK(*figure.level == editorialLevel("figure layer", Bool::yes, LevelType::single, Bool::unspecified, Bool::no, SymbolSize::unspecified)); - CHECK(!figure.footnote.has_value()); + REQUIRE(figure.footnote.has_value()); + FootnoteData figureFootnote; + figureFootnote.text = "figure note"; + figureFootnote.fontData.style = FontStyle::normal; + CHECK(*figure.footnote == figureFootnote); CHECK(!figuredBass.figures.at(1).level.has_value()); + CHECK(!figuredBass.figures.at(1).footnote.has_value()); std::string written; const auto out = editorialRoundTrip(score, written); const auto &odirections = editorialMeasure(out).staves.at(0).directions; REQUIRE(odirections.size() == 1); CHECK(odirections.front().figuredBasses == direction.figuredBasses); + CHECK(written.find("figure note") != std::string::npos); } T_END; @@ -396,6 +454,7 @@ TEST(directionLevelFootnoteAndVoice, EditorialApi) const auto &odirections = editorialMeasure(out).staves.at(0).directions; REQUIRE(odirections.size() == 1); CHECK(odirections.front() == direction); + CHECK(editorialWriteDiagnostics(score).all().empty()); } T_END; @@ -443,21 +502,9 @@ T_END; // The chords of one direction become one , which has room for one level and one footnote. // Each comes from the first chord that has one, and reads back onto every chord. -TEST(harmonyFirstChordRule, EditorialApi) +static ScoreData editorialMixedHarmonyScore() { - ScoreData score; - score.ticksPerQuarter = 1; - score.parts.emplace_back(); - auto &part = score.parts.back(); - part.uniqueId = "P1"; - part.name = "Music"; - part.measures.emplace_back(); - auto &staff = part.measures.back().staves.emplace_back(); - NoteData note; - note.durationData.durationName = DurationName::quarter; - note.durationData.durationTimeTicks = 1; - staff.voices[0].notes.push_back(note); - + auto score = editorialOneNoteScore(); DirectionData direction; direction.chords.resize(3); direction.chords.at(0).root = Step::c; @@ -474,7 +521,14 @@ TEST(harmonyFirstChordRule, EditorialApi) FootnoteData thirdFootnote; thirdFootnote.text = "third"; direction.chords.at(2).footnote = thirdFootnote; - staff.directions.push_back(direction); + editorialStaff(score).directions.push_back(direction); + return score; +} + +TEST(harmonyFirstChordRule, EditorialApi) +{ + const auto score = editorialMixedHarmonyScore(); + const auto &direction = editorialMeasure(score).staves.at(0).directions.at(0); std::string written; const auto out = editorialRoundTrip(score, written); @@ -490,6 +544,27 @@ TEST(harmonyFirstChordRule, EditorialApi) REQUIRE(chord.footnote.has_value()); CHECK(*chord.footnote == editorialExpectedFootnote()); } + + // Read back, every chord holds the same level and footnote, so writing again is silent. + CHECK(editorialWriteDiagnostics(out).all().empty()); +} + +T_END; + +// Chords of one harmony that disagree are reported, naming the chord whose value is used. +TEST(harmonyDifferentEditorialIsReported, EditorialApi) +{ + const auto diagnostics = editorialWriteDiagnostics(editorialMixedHarmonyScore()); + REQUIRE(diagnostics.all().size() == 2); + const auto &levelDiagnostic = diagnostics.all()[0]; + CHECK(DiagnosticCode::valueAdjusted == levelDiagnostic.code); + CHECK(Severity::warning == levelDiagnostic.severity); + CHECK_EQUAL("the chords of a harmony have different levels; using the level of chord 2", levelDiagnostic.message); + const auto &footnoteDiagnostic = diagnostics.all()[1]; + CHECK(DiagnosticCode::valueAdjusted == footnoteDiagnostic.code); + CHECK(Severity::warning == footnoteDiagnostic.severity); + CHECK_EQUAL("the chords of a harmony have different footnotes; using the footnote of chord 1", + footnoteDiagnostic.message); } T_END; @@ -536,24 +611,10 @@ TEST(partGroup, EditorialApi) T_END; -// A direction whose only content is a level has no element to hold it. -TEST(directionWithoutDirectionTypesDropsLevel, EditorialApi) +static void editorialCheckDroppedDirection(const DirectionData &direction) { - ScoreData score; - score.ticksPerQuarter = 1; - score.parts.emplace_back(); - auto &part = score.parts.back(); - part.uniqueId = "P1"; - part.name = "Music"; - part.measures.emplace_back(); - auto &staff = part.measures.back().staves.emplace_back(); - NoteData note; - note.durationData.durationName = DurationName::quarter; - note.durationData.durationTimeTicks = 1; - staff.voices[0].notes.push_back(note); - DirectionData direction; - direction.level = editorialLevel("lost", Bool::yes, LevelType::single, Bool::no, Bool::yes, SymbolSize::full); - staff.directions.push_back(direction); + auto score = editorialOneNoteScore(); + editorialStaff(score).directions.push_back(direction); Diagnostics diagnostics; const auto result = fromScore(score, diagnostics); @@ -568,6 +629,25 @@ TEST(directionWithoutDirectionTypesDropsLevel, EditorialApi) std::ostringstream xml; REQUIRE(result.value().writeToStream(xml).ok()); CHECK(xml.str().find(" element to hold it. +TEST(directionWithoutDirectionTypesDropsLevel, EditorialApi) +{ + DirectionData direction; + direction.level = editorialLevel("lost", Bool::yes, LevelType::single, Bool::no, Bool::yes, SymbolSize::full); + editorialCheckDroppedDirection(direction); +} + +T_END; + +// The same for a direction whose only content is a footnote. +TEST(directionWithoutDirectionTypesDropsFootnote, EditorialApi) +{ + DirectionData direction; + direction.footnote = editorialExpectedFootnote(); + editorialCheckDroppedDirection(direction); } T_END;