Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new feature slurs #13

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
New feature for adding <xml:id> to slurs
riedde committed Sep 29, 2016
commit 8616fd05f16c3d643a67dbfd45f3133294ca4317
86 changes: 86 additions & 0 deletions mei2verovioSlurID/slurTstampToID.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mei="http://www.music-encoding.org/ns/mei"
exclude-result-prefixes="xs"
version="2.0">

<xsl:output encoding="UTF-16"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="mei:slur">
<xsl:variable name="staffN" select="@staff"/>
<xsl:variable name="layerN" select="@layer"/>
<xsl:variable name="events" select="../mei:staff[@n = $staffN]/mei:layer[@n = $layerN]//*[@dur]"/>

<xsl:variable name="startid">
<xsl:choose>
<xsl:when test="@tstamp = 1"><xsl:value-of select ="$events[1]/@xml:id"/></xsl:when>
<xsl:when test="@tstamp &gt; 1">
<xsl:call-template name="sumDur">
<xsl:with-param name="events" select="$events"/>
<xsl:with-param name="tstamp" select="@tstamp"/>
</xsl:call-template></xsl:when>
<xsl:when test="@tstamp = 4"><xsl:value-of select ="$events[1]/@xml:id"/></xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="endid">
<xsl:choose>
<xsl:when test="@tstamp2 = 1"><xsl:value-of select ="$events[1]/@xml:id"/></xsl:when>
<xsl:when test="@tstamp2 &gt; 1">
<xsl:call-template name="sumDur">
<xsl:with-param name="events" select="$events"/>
<xsl:with-param name="tstamp" select="@tstamp2"/>
</xsl:call-template></xsl:when>
<xsl:when test="@tstamp2 = 4"><xsl:value-of select ="$events[1]/@xml:id"/></xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:copy>
<xsl:if test="not(@startid)">
<xsl:attribute name="startid" select="concat('#', $startid)">
</xsl:attribute>
</xsl:if>
<xsl:if test="not(@endid)">
<xsl:attribute name="endid" select="concat('#', $endid)">
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template name="sumDur">
<xsl:param name="events"/>
<xsl:param name="tstamp" as="xs:double"/>
<xsl:param name="position" select ="1"/>
<xsl:param name="sum" select="1" as="xs:double"/>

<xsl:variable name="newsum" select="$sum + 4 div number($events[position()=$position]/@dur)"/>
<!-- wenn Summe(@meter.unit / events/@dur) ≥ tstamp -->
<xsl:choose>
<xsl:when test="$newsum gt $tstamp">
<xsl:value-of select ="$events[position()=$position]/@xml:id"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="sumDur">
<xsl:with-param name="events" select="$events"/>
<xsl:with-param name="tstamp" select="$tstamp"/>
<xsl:with-param name="position" select="$position + 1"/>
<xsl:with-param name="sum" select="$newsum"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>