Skip to content

Commit

Permalink
Set style from defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Dec 8, 2024
1 parent 5c0fb5d commit 14c8a2d
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 15 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ MusicXML to MuseScore converter and back.
- `npm run --silent convert:mscx /path/to/score.musicxml instrumentsFile=/path/to/MuseScore/share/instruments/instruments.xml styleFile=/path/to/MuseScore/stylesheet.mss`

# Examples
Screenshot of an [official MusicXML example](https://w3c.github.io/musicxml/musicxml-reference/examples/tutorial-percussion/) converted to MuseScore format. There are subtle differences from what MuseScore itself would import from MusicXML.
Screenshot of an [official MusicXML example](https://w3c.github.io/musicxml/musicxml-reference/examples/tutorial-apres-un-reve/) converted to MuseScore format. There are subtle differences from what MuseScore itself would import from MusicXML.

![Screenshot of an official MusicXML example converted to MuseScore format.](https://github.com/infojunkie/musicxml-mscx/blob/main/doc/screenshots/tutorial-percussion.png?raw=true)
![Screenshot of an official MusicXML example converted to MuseScore format.](https://github.com/infojunkie/musicxml-mscx/blob/main/doc/screenshots/tutorial-apres-un-reve.png?raw=true)

Screenshot of another [official MusicXML example](https://w3c.github.io/musicxml/musicxml-reference/examples/tutorial-percussion/) converted to MuseScore format. There are subtle differences from what MuseScore itself would import from MusicXML.

![Screenshot of another official MusicXML example converted to MuseScore format.](https://github.com/infojunkie/musicxml-mscx/blob/main/doc/screenshots/tutorial-percussion.png?raw=true)

Screenshot of a [Lilypond test snippet with microtonal accidentals](https://lilypond.org/doc/v2.24/input/regression/musicxml/collated-files.html#t_g01-_002e_002e_002e-pitches). Not shown are the note tunings that are converted correctly and that MuseScore would miss when it imports the MusicXML.

Expand Down
2 changes: 1 addition & 1 deletion build/libmusicxml.sef.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/mscx.sef.json

Large diffs are not rendered by default.

Binary file added doc/screenshots/tutorial-apres-un-reve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "musicxml-mscx",
"version": "0.4.0",
"version": "0.4.1",
"description": "MuseScore to MusicXML converter and back.",
"author": "Karim Ratib <[email protected]> (https://github.com/infojunkie)",
"license": "GPL-3.0-only",
Expand Down
120 changes: 112 additions & 8 deletions src/mscx.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@
<xsl:choose>
<xsl:when test="score-instrument/instrument-sound">
<instrumentId><xsl:value-of select="score-instrument[1]/instrument-sound"/></instrumentId>
<xsl:apply-templates select="$instruments//Instrument[musicXMLid = current()/score-instrument[1]/instrument-sound]" mode="pitchRange"/>
</xsl:when>
<xsl:when test="$instruments//Instrument[@id = mscx:toHyphenated(part-name)]">
<instrumentId><xsl:value-of select="$instruments//Instrument[@id = mscx:toHyphenated(part-name)]/musicXMLid"/></instrumentId>
<xsl:when test="$instruments//Instrument[@id = mscx:toHyphenated(current()/part-name)]">
<instrumentId><xsl:value-of select="$instruments//Instrument[@id = mscx:toHyphenated(current()/part-name)]/musicXMLid"/></instrumentId>
<xsl:apply-templates select="$instruments//Instrument[@id = mscx:toHyphenated(current()/part-name)]" mode="pitchRange"/>
</xsl:when>
</xsl:choose>
<xsl:if test="midi-instrument/midi-unpitched">
Expand All @@ -208,6 +210,20 @@
</Part>
</xsl:template>

<!--
Template: Instrument > Pitch Range
-->
<xsl:template match="Instrument" mode="pitchRange">
<xsl:if test="pPitchRange">
<minPitchP><xsl:value-of select="tokenize(pPitchRange, '-')[1]"/></minPitchP>
<maxPitchP><xsl:value-of select="tokenize(pPitchRange, '-')[2]"/></maxPitchP>
</xsl:if>
<xsl:if test="aPitchRange">
<minPitchA><xsl:value-of select="tokenize(aPitchRange, '-')[1]"/></minPitchA>
<maxPitchA><xsl:value-of select="tokenize(aPitchRange, '-')[2]"/></maxPitchA>
</xsl:if>
</xsl:template>

<!--
Template: Part > Drum.
-->
Expand Down Expand Up @@ -389,13 +405,16 @@
<xsl:template match="clef">
<xsl:variable name="clefType">
<xsl:choose>
<xsl:when test="sign = 'jianpu'"><xsl:message>[clef] Unhandled sign 'jianpu'.</xsl:message></xsl:when>
<xsl:when test="sign = 'none'">G<xsl:message>[clef] Deprecated sign 'none'.</xsl:message></xsl:when>
<xsl:when test="sign = 'percussion'">PERC</xsl:when>
<xsl:when test="sign = 'none'">G</xsl:when>
<xsl:when test="sign = 'C'"><xsl:value-of select="sign"/><xsl:value-of select="if (line) then line else 3"/></xsl:when>
<xsl:when test="clef-octave-change = 1"><xsl:value-of select="sign"/>8va</xsl:when>
<xsl:when test="clef-octave-change = -1"><xsl:value-of select="sign"/>8vb</xsl:when>
<xsl:otherwise><xsl:value-of select="sign"/></xsl:otherwise>
<xsl:when test="clef-octave-change = 2"><xsl:value-of select="sign"/>15ma</xsl:when>
<xsl:when test="clef-octave-change = -2"><xsl:value-of select="sign"/>15mb</xsl:when>
<xsl:when test="sign = 'C'"><xsl:value-of select="sign"/><xsl:value-of select="if (line = (1,2,3,4,5)) then line else ''"/></xsl:when>
<xsl:when test="sign = 'G'"><xsl:value-of select="sign"/><xsl:value-of select="if (line = (1)) then line else ''"/></xsl:when>
<xsl:when test="sign = 'F'"><xsl:value-of select="sign"/><xsl:value-of select="if (line = (3,5)) then line else ''"/></xsl:when>
<xsl:otherwise><xsl:message>[clef] Unhandled sign '<xsl:value-of select="sign"/>'.</xsl:message></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<Clef>
Expand Down Expand Up @@ -646,8 +665,7 @@
<Chord>
<xsl:apply-templates select="notations/slur"/>
<xsl:apply-templates select="stem"/>
<xsl:apply-templates select="beam"/>
<xsl:apply-templates select="preceding-sibling::note[not(chord) and current()/chord]/beam"/>
<xsl:apply-templates select="(beam, preceding-sibling::note[current()/chord and not(chord)][1]/beam)[1]"/>
<xsl:apply-templates select="current()" mode="inner">
<xsl:with-param name="overrideChord" select="true()"/>
</xsl:apply-templates>
Expand Down Expand Up @@ -1178,6 +1196,92 @@
<xsl:if test="//defaults/page-layout/page-height">
<pageHeight><xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-height)), '0.00')"/></pageHeight>
</xsl:if>
<xsl:if test="//defaults/page-layout/page-margins[@type = ('even', 'both')]">
<pageEvenLeftMargin>
<xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-margins[@type = ('even', 'both')]/left-margin)), '0.00')"/>
</pageEvenLeftMargin>
<pageEvenTopMargin>
<xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-margins[@type = ('even', 'both')]/top-margin)), '0.00')"/>
</pageEvenTopMargin>
<pageEvenBottomMargin>
<xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-margins[@type = ('even', 'both')]/bottom-margin)), '0.00')"/>
</pageEvenBottomMargin>
</xsl:if>
<xsl:if test="//defaults/page-layout/page-margins[@type = ('odd', 'both')]">
<pageOddLeftMargin>
<xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-margins[@type = ('odd', 'both')]/left-margin)), '0.00')"/>
</pageOddLeftMargin>
<pageOddTopMargin>
<xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-margins[@type = ('odd', 'both')]/top-margin)), '0.00')"/>
</pageOddTopMargin>
<pageOddBottomMargin>
<xsl:value-of select="format-number(mscx:tenthsToInches(number(//defaults/page-layout/page-margins[@type = ('odd', 'both')]/bottom-margin)), '0.00')"/>
</pageOddBottomMargin>
</xsl:if>
<xsl:if test="//defaults/page-layout/page-width and //defaults/page-layout/page-margins">
<pagePrintableWidth>
<xsl:value-of select="format-number(mscx:tenthsToInches(min((
number(//defaults/page-layout/page-width) - number(//defaults/page-layout/page-margins[@type = ('odd', 'both')]/left-margin) - number(//defaults/page-layout/page-margins[@type = ('odd', 'both')]/right-margin),
number(//defaults/page-layout/page-width) - number(//defaults/page-layout/page-margins[@type = ('even', 'both')]/left-margin) - number(//defaults/page-layout/page-margins[@type = ('even', 'both')]/right-margin)
))), '0.00')"/>
</pagePrintableWidth>
</xsl:if>
<pageTwosided>0</pageTwosided>
<xsl:if test="//defaults/staff-layout/staff-distance">
<staffDistance>
<xsl:value-of select="format-number(number(//defaults/staff-layout/staff-distance) div 10, '0.00')"/>
</staffDistance>
</xsl:if>
<xsl:if test="//defaults/system-layout/system-distance">
<minSystemDistance>
<xsl:value-of select="format-number(number(//defaults/system-layout/system-distance) div 10, '0.00')"/>
</minSystemDistance>
</xsl:if>
<xsl:if test="//defaults/word-font[@font-size]">
<xsl:variable name="size" select="//defaults/word-font/@font-size"/>
<chordSymbolAFontSize><xsl:value-of select="$size"/></chordSymbolAFontSize>
<chordSymbolBFontSize><xsl:value-of select="$size"/></chordSymbolBFontSize>
<nashvilleNumberFontSize><xsl:value-of select="$size"/></nashvilleNumberFontSize>
<tupletFontSize><xsl:value-of select="$size"/></tupletFontSize>
<fingeringFontSize><xsl:value-of select="$size"/></fingeringFontSize>
<lhGuitarFingeringFontSize><xsl:value-of select="$size"/></lhGuitarFingeringFontSize>
<rhGuitarFingeringFontSize><xsl:value-of select="$size"/></rhGuitarFingeringFontSize>
<stringNumberFontSize><xsl:value-of select="$size"/></stringNumberFontSize>
<longInstrumentFontSize><xsl:value-of select="$size"/></longInstrumentFontSize>
<shortInstrumentFontSize><xsl:value-of select="$size"/></shortInstrumentFontSize>
<partInstrumentFontSize><xsl:value-of select="$size"/></partInstrumentFontSize>
<dynamicsFontSize><xsl:value-of select="$size"/></dynamicsFontSize>
<expressionFontSize><xsl:value-of select="$size"/></expressionFontSize>
<tempoFontSize><xsl:value-of select="$size"/></tempoFontSize>
<metronomeFontSize><xsl:value-of select="$size"/></metronomeFontSize>
<measureNumberFontSize><xsl:value-of select="$size"/></measureNumberFontSize>
<mmRestRangeFontSize><xsl:value-of select="$size"/></mmRestRangeFontSize>
<translatorFontSize><xsl:value-of select="$size"/></translatorFontSize>
<systemFontSize><xsl:value-of select="$size"/></systemFontSize>
<staffFontSize><xsl:value-of select="$size"/></staffFontSize>
<rehearsalMarkFontSize><xsl:value-of select="$size"/></rehearsalMarkFontSize>
<repeatLeftFontSize><xsl:value-of select="$size"/></repeatLeftFontSize>
<repeatRightFontSize><xsl:value-of select="$size"/></repeatRightFontSize>
<frameFontSize><xsl:value-of select="$size"/></frameFontSize>
<glissandoFontSize><xsl:value-of select="$size"/></glissandoFontSize>
<bendFontSize><xsl:value-of select="$size"/></bendFontSize>
<headerFontSize><xsl:value-of select="$size"/></headerFontSize>
<footerFontSize><xsl:value-of select="$size"/></footerFontSize>
<instrumentChangeFontSize><xsl:value-of select="$size"/></instrumentChangeFontSize>
<stickingFontSize><xsl:value-of select="$size"/></stickingFontSize>
<user1FontSize><xsl:value-of select="$size"/></user1FontSize>
<user2FontSize><xsl:value-of select="$size"/></user2FontSize>
<user3FontSize><xsl:value-of select="$size"/></user3FontSize>
<user4FontSize><xsl:value-of select="$size"/></user4FontSize>
<user5FontSize><xsl:value-of select="$size"/></user5FontSize>
<user6FontSize><xsl:value-of select="$size"/></user6FontSize>
<user7FontSize><xsl:value-of select="$size"/></user7FontSize>
<user8FontSize><xsl:value-of select="$size"/></user8FontSize>
<user9FontSize><xsl:value-of select="$size"/></user9FontSize>
<user10FontSize><xsl:value-of select="$size"/></user10FontSize>
<user11FontSize><xsl:value-of select="$size"/></user11FontSize>
<user12FontSize><xsl:value-of select="$size"/></user12FontSize>
</xsl:if>
<Spatium><xsl:value-of select="$defaultSpatium"/></Spatium>
</Style>
</xsl:otherwise>
Expand Down

0 comments on commit 14c8a2d

Please sign in to comment.