Skip to content

Commit

Permalink
Adjust template for all examples with optional elements
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Nov 12, 2023
1 parent 794d477 commit 7c4fc56
Show file tree
Hide file tree
Showing 281 changed files with 20,513 additions and 9,964 deletions.
44 changes: 36 additions & 8 deletions src/js/musicxml-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,25 @@ function scaffoldMusicXml(xml) {
"-//Recordare//DTD MusicXML ${MUSICXML_VERSION} Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="${MUSICXML_VERSION}">
<defaults>
<system-layout optional-example="yes"/>
<staff-layout optional-example="yes"/>
<appearance optional-example="yes"/>
</defaults>
<credit optional-example="yes"/>
<part-list>
<part-group optional-example="yes"/>
<score-part id="P1">
<part-name>placeholder</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<direction>
<direction-type>
<other-direction>placeholder</other-direction>
<direction optional-example="yes">
<direction-type optional-example="yes">
<dynamics optional-example="yes"/>
<metronome optional-example="yes"/>
<scordatura optional-example="yes"/>
<accordion-registration optional-example="yes"/>
</direction-type>
</direction>
Expand All @@ -141,36 +149,55 @@ function scaffoldMusicXml(xml) {
<time>
<beats>4</beats>
<beat-type>4</beat-type>
<interchangeable optional-example="yes">
<time-relation optional-example="yes"/>
</interchangeable>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
<staff-details optional-example="yes"/>
<measure-style optional-example="yes"/>
</attributes>
<harmony optional-example="yes">
<harmony>
<root>
<root-step>C</root-step>
</root>
<kind use-symbols="yes">major-seventh</kind>
<inversion optional-example="yes"/>
<degree optional-example="yes"/>
<frame optional-example="yes"/>
</harmony>
<figured-bass optional-example="yes"/>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<type>whole</type>
<notations optional-example="yes"/>
<notehead-text optional-example="yes"/>
<notations>
<technical optional-example="yes"/>
</notations>
<lyric optional-example="yes"/>
</note>
<barline optional-example="yes"/>
<print>
<part-name-display optional-example="yes"/>
<part-abbreviation-display optional-example="yes"/>
</print>
</measure>
</part>
</score-partwise>
`.trim()

// Insert the example fragment into the fully-formed template.
// 1. Find the example's root element in the template
// 2. Replace it with the full example fragment
// 3. Remove all tags that include attribute optional-example="yes"
// - Find the example's root element in the template
// - Replace it with the full example fragment
// - Remove optional-example attribute from parents of the example fragment
// - Remove all elements that still include attribute optional-example="yes"
const src = cheerio.load(xml, { xml: true })
const core = src.root().children().first().prop('nodeName')
const dst = cheerio.load(template, { xml: { xmlMode: true, lowerCaseTags: true, lowerCaseAttributeNames : true }})
Expand All @@ -179,6 +206,7 @@ function scaffoldMusicXml(xml) {
return `<?xml version="1.0" encoding="utf-8"?>\n${xml}`
}
dst(core).replaceWith(src.root())
dst(src.root()).parents().removeAttr('optional-example')
dst('[optional-example="yes"]').remove()
return xmlFormat(dst.html(), { collapseContent: true })
}
70 changes: 54 additions & 16 deletions test/data/examples/accent-element.musicxml
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<note default-x="36">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
<stem default-y="10">up</stem>
<notations>
<articulations>
<accent default-x="-1" default-y="-55" placement="below"/>
</articulations>
</notations>
</note>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 4.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<defaults>
</defaults>
<part-list>
<score-part id="P1">
<part-name>placeholder</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<harmony>
<root>
<root-step>C</root-step>
</root>
<kind use-symbols="yes">major-seventh</kind>
</harmony>
<note default-x="36">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
<stem default-y="10">up</stem>
<notations>
<articulations>
<accent default-x="-1" default-y="-55" placement="below"/>
</articulations>
</notations>
</note>
<print>
</print>
</measure>
</part>
</score-partwise>
64 changes: 51 additions & 13 deletions test/data/examples/accidental-element.musicxml
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<note default-x="83">
<pitch>
<step>A</step>
<alter>1</alter>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<accidental>sharp</accidental>
<stem default-y="10">up</stem>
</note>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 4.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<defaults>
</defaults>
<part-list>
<score-part id="P1">
<part-name>placeholder</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<harmony>
<root>
<root-step>C</root-step>
</root>
<kind use-symbols="yes">major-seventh</kind>
</harmony>
<note default-x="83">
<pitch>
<step>A</step>
<alter>1</alter>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<accidental>sharp</accidental>
<stem default-y="10">up</stem>
</note>
<print>
</print>
</measure>
</part>
</score-partwise>
66 changes: 52 additions & 14 deletions test/data/examples/accidental-mark-element-notation.musicxml
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<note default-x="84">
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<stem default-y="-45">down</stem>
<notations>
<accidental-mark default-y="22">sharp</accidental-mark>
</notations>
</note>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 4.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<defaults>
</defaults>
<part-list>
<score-part id="P1">
<part-name>placeholder</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<harmony>
<root>
<root-step>C</root-step>
</root>
<kind use-symbols="yes">major-seventh</kind>
</harmony>
<note default-x="84">
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<stem default-y="-45">down</stem>
<notations>
<accidental-mark default-y="22">sharp</accidental-mark>
</notations>
</note>
<print>
</print>
</measure>
</part>
</score-partwise>
72 changes: 55 additions & 17 deletions test/data/examples/accidental-mark-element-ornament.musicxml
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<note default-x="229">
<pitch>
<step>E</step>
<octave>5</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<stem default-y="-40">down</stem>
<notations>
<ornaments>
<trill-mark/>
<accidental-mark placement="above">natural</accidental-mark>
</ornaments>
</notations>
</note>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 4.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<defaults>
</defaults>
<part-list>
<score-part id="P1">
<part-name>placeholder</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<harmony>
<root>
<root-step>C</root-step>
</root>
<kind use-symbols="yes">major-seventh</kind>
</harmony>
<note default-x="229">
<pitch>
<step>E</step>
<octave>5</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<stem default-y="-40">down</stem>
<notations>
<ornaments>
<trill-mark/>
<accidental-mark placement="above">natural</accidental-mark>
</ornaments>
</notations>
</note>
<print>
</print>
</measure>
</part>
</score-partwise>
Loading

0 comments on commit 7c4fc56

Please sign in to comment.