Skip to content

Commit

Permalink
some features added, improved handling of stem.dir
Browse files Browse the repository at this point in the history
  • Loading branch information
rettinghaus committed Oct 28, 2016
1 parent 764b3ba commit ab07ff4
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Ignore test file outputs
*.log
*.ly
*.midi
*.pdf
43 changes: 28 additions & 15 deletions mei2ly.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- -->
<!-- MEILER -->
<!-- mei2ly -->
<!-- v0.8.9 -->
<!--v 0.8.10-->
<!-- -->
<!-- programmed by -->
<!-- Klaus Rettinghaus -->
Expand Down Expand Up @@ -130,6 +130,7 @@
<xsl:variable name="staffNumber" select="@n" />
<xsl:value-of select="concat('mdiv',local:number2alpha($mdivNumber),'_staff',local:number2alpha($staffNumber),' = {&#10;')" />
<xsl:for-each select="ancestor::mei:mdiv[1]//mei:staff[@n=$staffNumber]">
<xsl:variable name="currentMeasure" select="generate-id(ancestor::mei:measure)" />
<xsl:text>&#32;&#32;</xsl:text>
<!-- print rehearsal mark -->
<xsl:apply-templates select="ancestor::mei:measure/mei:reh"/>
Expand All @@ -151,7 +152,7 @@
<xsl:call-template name="setBarNumber" />
</xsl:if>
<!-- add clef change -->
<xsl:if test="ancestor::mei:measure/preceding-sibling::mei:staffDef[@n = $staffNumber][@clef.shape]/following-sibling::mei:measure[1]/@n = ancestor::mei:measure/@n">
<xsl:if test="generate-id(preceding::mei:staffDef[@n = $staffNumber][@clef.shape][1]/following::mei:measure[1]) = $currentMeasure">
<xsl:call-template name="setClef">
<xsl:with-param name="clefColor" select="preceding::mei:staffDef[@n = $staffNumber][@clef.shape][1]/@clef.color" />
<xsl:with-param name="clefDis" select="preceding::mei:staffDef[@n = $staffNumber][@clef.shape][1]/@clef.dis" />
Expand All @@ -162,7 +163,7 @@
<xsl:text>&#10;&#32;&#32;</xsl:text>
</xsl:if>
<!-- add key signature change -->
<xsl:if test="ancestor::mei:measure/preceding-sibling::*[contains(local-name(),'Def')][@*[starts-with(name(),'key')]][1]/following-sibling::mei:measure[1]/@n = ancestor::mei:measure/@n">
<xsl:if test="generate-id(ancestor::mei:measure/preceding-sibling::*[contains(local-name(),'Def')][@*[starts-with(name(),'key')]][1]/following-sibling::mei:measure[1]) = $currentMeasure">
<xsl:call-template name="setKey">
<xsl:with-param name="keyTonic" select="ancestor::mei:measure/preceding-sibling::*/@key.pname[1]" />
<xsl:with-param name="keyAccid" select="ancestor::mei:measure/preceding-sibling::*/@key.accid[1]" />
Expand All @@ -173,7 +174,7 @@
<xsl:text>&#32;&#32;</xsl:text>
</xsl:if>
<!-- add time signature change -->
<xsl:if test="ancestor::mei:measure/preceding-sibling::*[contains(local-name(),'Def')][@*[starts-with(name(),'meter')]][1]/following-sibling::mei:measure[1]/@n = ancestor::mei:measure/@n">
<xsl:if test="generate-id(ancestor::mei:measure/preceding-sibling::*[contains(local-name(),'Def')][@*[starts-with(name(),'meter')]][1]/following-sibling::mei:measure[1]) = $currentMeasure">
<xsl:call-template name="meterSig">
<xsl:with-param name="meterSymbol" select="ancestor::mei:measure/preceding-sibling::*[@meter.sym][1]/@meter.sym" />
<xsl:with-param name="meterCount" select="ancestor::mei:measure/preceding-sibling::*[@meter.count][1]/@meter.count" />
Expand All @@ -182,7 +183,7 @@
</xsl:call-template>
<xsl:text>&#10;&#32;&#32;</xsl:text>
</xsl:if>
<xsl:if test="ancestor::mei:measure/preceding::mei:meterSig[1]/preceding::mei:measure[1]/@n = ancestor::mei:measure/preceding-sibling::mei:measure[1]/@n">
<xsl:if test="generate-id(preceding::mei:meterSig[1]/following::mei:measure[1]) = $currentMeasure">
<xsl:choose>
<xsl:when test="ancestor::mei:measure/preceding::mei:meterSig[1]/parent::mei:meterSigGrp">
<xsl:apply-templates select="ancestor::mei:measure/preceding::mei:meterSigGrp[1]" />
Expand Down Expand Up @@ -421,6 +422,7 @@
<xsl:value-of select="'\autoBeamOff '" />
</xsl:otherwise>
</xsl:choose>
<!-- set MEILER default styles -->
<xsl:text>\set tieWaitForNote = ##t&#10; </xsl:text>
<xsl:if test="ancestor-or-self::*/@*[starts-with(name(),'clef.')]">
<xsl:call-template name="setClef">
Expand Down Expand Up @@ -603,6 +605,9 @@
<xsl:with-param name="color" select="$clefColor" />
</xsl:call-template>
</xsl:if>
<xsl:if test="@cautionary">
<xsl:value-of select="concat('\set Staff.forceClef = ##',substring(@cautionary,1,1),' ')"/>
</xsl:if>
<xsl:value-of select="concat('\set Staff.clefGlyph = #','&quot;clefs.',$clefShape,'&quot; ')" />
<xsl:value-of select="concat('\set Staff.clefPosition = #',$clefPos,' ')" />
<xsl:value-of select="concat('\set Staff.clefTransposition = #',$clefTrans,' ')" />
Expand Down Expand Up @@ -684,6 +689,9 @@
<xsl:if test="descendant-or-self::*/@accid or child::mei:accid/@func='caution'">
<xml:text>!</xml:text>
</xsl:if>
<xsl:if test="child::mei:accid/@func='edit' or child::mei:accid/@enclose='paren'">
<xml:text>?</xml:text>
</xsl:if>
<xsl:if test="not(parent::mei:chord) and not(parent::mei:fTrem[@measperf])">
<xsl:call-template name="setDuration" />
</xsl:if>
Expand Down Expand Up @@ -734,6 +742,9 @@
</xsl:call-template>
<xml:text>\(</xml:text>
</xsl:if>
<xsl:if test="@lv = 'true'">
<xml:text>\laissezVibrer</xml:text>
</xsl:if>
<xsl:if test="ancestor::mei:mdiv[1]//mei:hairpin/@endid = $noteKey or ancestor::mei:mdiv[1]//mei:dynam/@endid = $noteKey">
<xml:text>\!</xml:text>
</xsl:if>
Expand Down Expand Up @@ -831,6 +842,9 @@
</xsl:call-template>
<xml:text>\(</xml:text>
</xsl:if>
<xsl:if test="@lv = 'true'">
<xml:text>\laissezVibrer</xml:text>
</xsl:if>
<xsl:if test="ancestor::mei:measure/mei:arpeg[@startid = $chordKey or tokenize(@plist,' ') = $subChordKeys]">
<xml:text>\arpeggio</xml:text>
</xsl:if>
Expand Down Expand Up @@ -1602,7 +1616,9 @@
<xsl:text>-\tweak Fingering.extra-offset #&apos;</xsl:text>
<xsl:call-template name="setOffset" />
</xsl:if>
<xsl:call-template name="setMarkupDirection" />
<xsl:call-template name="setMarkupDirection">
<xsl:with-param name="direction" select="ancestor-or-self::*/@place[1]"/>
</xsl:call-template>
<xsl:apply-templates/>
</xsl:template>
<!-- MEI figured bass -->
Expand Down Expand Up @@ -2123,10 +2139,8 @@
</xsl:template>
<!-- set stem direction -->
<xsl:template name="setStemDir">
<xsl:variable name="staffPos" select="ancestor::mei:staff/@n" />
<xsl:variable name="measurePos" select="ancestor::mei:measure/@n" />
<xsl:variable name="layerPos" select="ancestor::mei:layer/@n" />
<xsl:if test="not(preceding::*[@stem.dir][1][ancestor::mei:music][ancestor::mei:layer/@n = $layerPos][ancestor::mei:staff/@n = $staffPos][ancestor::mei:measure/@n = $measurePos]) or (@stem.dir != preceding::*[@stem.dir][ancestor::mei:music][ancestor::mei:layer/@n = $layerPos][ancestor::mei:staff/@n = $staffPos][ancestor::mei:measure/@n = $measurePos][1]/@stem.dir)">
<xsl:variable name="currentLayer" select="generate-id(ancestor::mei:layer)" />
<xsl:if test="not(preceding::*[@stem.dir][generate-id(ancestor::mei:layer) = $currentLayer]) or (@stem.dir != preceding::*[@stem.dir][generate-id(ancestor::mei:layer) = $currentLayer]/@stem.dir)">
<xsl:choose>
<xsl:when test="@stem.dir='up'">
<xsl:text>\stemUp </xsl:text>
Expand Down Expand Up @@ -2628,10 +2642,10 @@
<xsl:variable name="colorComponents" as="xs:double+">
<xsl:choose>
<xsl:when test="starts-with($color, 'rgb')">
<xsl:sequence select="for $component in tokenize(substring-after($color, '('), '[^\d.\s]') return number($component) div 255" />
<xsl:sequence select="for $component in tokenize(substring-after($color, '('), '[^\d.\s]') return number($component) div 255" />
</xsl:when>
<xsl:when test="starts-with($color, '#')">
<xsl:sequence select="for $i in 1 to 3 return local:hex2number(substring($color, 2 * $i, 2)) div 255" />
<xsl:sequence select="for $i in 1 to 3 return local:hex2number(substring($color, 2 * $i, 2)) div 255" />
</xsl:when>
<xsl:when test="starts-with($color, 'hsl')">
<!-- hsl to rgb calculation as defined by http://www.w3.org/TR/css3-color/#hsl-color -->
Expand All @@ -2643,13 +2657,12 @@
<xsl:variable name="h" select="$hslComponents[1] div 360" as="xs:double" />
<xsl:variable name="s" select="$hslComponents[2] div 100" as="xs:double" />
<xsl:variable name="l" select="$hslComponents[3] div 100" as="xs:double" />
<xsl:variable name="m2" select="if ($l le .5) then $l * ($s + 1) else $l + $s - $l * $s" as="xs:double" />
<xsl:variable name="m2" select="if ($l le .5) then $l * ($s + 1) else $l + $s - $l * $s" as="xs:double" />
<xsl:variable name="m1" select="$l * 2 - $m2" as="xs:double" />
<xsl:for-each select="($h + 1 div 3, $h, $h - 1 div 3)">
<!-- Make sure h_ is between 0 and 1 -->
<xsl:variable name="h_" select="(. mod 1 + 1) mod 1" />
<xsl:copy-of select="if ($h_ * 6 lt 1) then $m1 + ($m2 - $m1) * $h_ * 6 else if ($h_ * 2 lt 1) then $m2 else if ($h_ *3 lt 2) then $m1 + ($m2 - $m1) * (2 div 3 - $h_) * 6 else $m1"
/>
<xsl:copy-of select="if ($h_ * 6 lt 1) then $m1 + ($m2 - $m1) * $h_ * 6 else if ($h_ * 2 lt 1) then $m2 else if ($h_ *3 lt 2) then $m1 + ($m2 - $m1) * (2 div 3 - $h_) * 6 else $m1"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
Expand Down
4 changes: 4 additions & 0 deletions supported.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ List of supported MEI elements and attributes

* `<accid>`
* `@color`
* `@edit` (for value 'paren')
* `@func`
* `@ho`
* `@place` (for value 'above')
* `@vo`
Expand Down Expand Up @@ -47,6 +49,7 @@ List of supported MEI elements and attributes
* `@dur`
* `@fermata`
* `@grace`
* `@lv`
* `@oct`
* `@ornam`
* `@slur`
Expand Down Expand Up @@ -204,6 +207,7 @@ List of supported MEI elements and attributes
* `@grace`
* `@head.color`
* `@head.shape`
* `@lv`
* `@oct`
* `@ornam`
* `@pname`
Expand Down
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This is an autogenerated overview of the testfiles.
![articulation.mei](articulation.preview.png)
### [multirest-and-reh.mei](multirest-and-reh.mei)
![multirest-and-reh.mei](multirest-and-reh.preview.png)
### [unmetered-and-glyphs.mei](unmetered-and-glyphs.mei)
![unmetered-and-glyphs.mei](unmetered-and-glyphs.preview.png)
### [namespace-prefixes.mei](namespace-prefixes.mei)
![namespace-prefixes.mei](namespace-prefixes.preview.png)
### [color.mei](color.mei)
Expand Down
4 changes: 3 additions & 1 deletion tests/general-functions.mei
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
</chord>
</bTrem>
<fTrem measperf="16">
<note xml:id="testnote5" dur="8" oct="5" pname="d" stem.dir="down" stem.mod="3slash"/>
<note xml:id="testnote5" dur="8" oct="5" pname="d" stem.dir="down" stem.mod="3slash">
<accid accid="n" func="edit" enclose="paren"/>
</note>
<note xml:id="testnote6" dur="8" oct="5" pname="f" stem.dir="down" stem.mod="3slash"/>
</fTrem>
<fTrem measperf="16">
Expand Down
Binary file modified tests/general-functions.preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions tests/unmetered-and-glyphs.mei
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.music-encoding.org/schema/3.0.0/mei-all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.music-encoding.org/schema/3.0.0/mei-all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="3.0.0">
<meiHead>
<fileDesc>
<titleStmt>
<title/>
</titleStmt>
<pubStmt/>
</fileDesc>
</meiHead>
<music>
<body>
<mdiv>
<score>
<scoreDef>
<staffGrp>
<staffDef n="1" clef.line="1" clef.shape="C" lines="5"/>
</staffGrp>
</scoreDef>
<section n="34" label="Fig. XXXIV.">
<measure right="single">
<staff n="1">
<layer n="1">
<note xml:id="f34n1" dur="4" oct="4" pname="g"/>
</layer>
</staff>
<trill glyphname="ornamentPrecompSlideTrillDAnglebert" place="above" startid="#f34n1"/>
</measure>
<measure right="dbl">
<staff n="1">
<layer n="1">
<beam>
<note dur="32" oct="4" pname="f"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
</beam>
</layer>
</staff>
</measure>
<measure right="single">
<staff n="1">
<layer n="1">
<note grace="unknown" dur="8" oct="4" pname="f"/>
<note xml:id="f34n2" dur="4" oct="4" pname="g"/>
</layer>
</staff>
<trill place="above" startid="#f34n2"/>
<reh place="above">(✴)</reh>
</measure>
<measure right="dbl">
<staff n="1">
<layer n="1">
<beam>
<note grace="unknown" dur="16" oct="4" pname="f"/>
<note grace="unknown" dur="16" oct="4" pname="g"/>
</beam>
<note xml:id="f34n3" dur="4" oct="4" pname="g"/>
</layer>
</staff>
<trill place="above" startid="#f34n3"/>
<reh place="above">(✴)</reh>
</measure>
</section>
<section n="41" label="Fig. XLI.">
<scoreDef>
<staffGrp>
<staffDef n="1" clef.line="1" clef.shape="C" lines="5"/>
</staffGrp>
</scoreDef>
<measure right="single">
<staff n="1">
<layer n="1">
<note xml:id="f41n1" dur="4" oct="4" pname="g"/>
</layer>
</staff>
<trill glyphname="ornamentPrecompMordentUpperPrefix" place="above" startid="#f41n1"/>
</measure>
<measure right="dbl">
<staff n="1">
<layer n="1">
<beam>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="f"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
<note dur="32" oct="4" pname="a"/>
<note dur="32" oct="4" pname="g"/>
</beam>
</layer>
</staff>
</measure>
<measure right="single">
<staff n="1">
<layer n="1">
<note xml:id="f41n2" dur="4" oct="5" pname="c"/>
</layer>
<layer n="2">
<note xml:id="f41n2a" dur="4" oct="4" pname="c"/>
</layer>
</staff>
<reh place="above">(✴)</reh>
</measure>
<measure right="dbl">
<staff n="1">
<layer n="1">
<note xml:id="f41n3" dur="2" oct="5" pname="c"/>
<beam>
<note grace="unknown" dur="16" oct="4" pname="b"/>
<note grace="unknown" dur="16" oct="4" pname="a"/>
<note grace="unknown" dur="16" oct="4" pname="g"/>
</beam>
<note xml:id="f41n4" dur="4" oct="4" pname="a"/>
</layer>
<layer n="2">
<note dur="4" oct="4" pname="d"/>
<note dur="4" oct="4" pname="d"/>
<note dur="4" oct="4" pname="d"/>
<note dur="4" oct="4" pname="d"/>
</layer>
</staff>
<trill place="above" startid="#f41n4"/>
</measure>
</section>
<section n="77" label="Fig. LXXVII.">
<scoreDef>
<staffGrp>
<staffDef n="1" clef.line="1" clef.shape="C" lines="5"/>
</staffGrp>
</scoreDef>
<measure right="single">
<staff n="1">
<layer n="1">
<note xml:id="f77n1" dur="4" oct="4" pname="e" accid="f"/>
</layer>
</staff>
<dir startid="#f77n1"><rend fontstyle="italic">ad:</rend></dir>
</measure>
<measure right="dbl">
<staff n="1">
<layer n="1">
<note xml:id="f77n2" dur="4" oct="4" pname="e">
</note>
<note xml:id="f77n3" dur="2" oct="4" pname="d" lv="true"/>
</layer>
</staff>
<trill glyphname="ornamentPrecompSlideTrillDAnglebert" place="above" startid="#f77n2"/>
</measure>
<measure right="dbl">
<staff n="1">
<layer n="1">
<note xml:id="f77n4" dur="4" oct="4" pname="e">
</note>
<note xml:id="f77n5" dur="4" oct="4" pname="d"/>
<note xml:id="f77n6" dur="2" oct="4" pname="d" lv="true"/>
</layer>
</staff>
<trill glyphname="ornamentPrecompSlideTrillDAnglebert" place="above" startid="#f77n4"/>
<trill glyphname="ornamentPrecompTrillWithMordent" place="above" startid="#f77n6"/>
</measure>
</section>
</score>
</mdiv>
</body>
</music>
</mei>
Binary file added tests/unmetered-and-glyphs.preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab07ff4

Please sign in to comment.