rism-digital / verovio

🎵 Music notation engraving library for MEI with MusicXML and Humdrum support and various toolkits (JavaScript, Python)
https://www.verovio.org
GNU Lesser General Public License v3.0
679 stars 185 forks source link

Grace note spacing #1459

Closed wergo closed 4 years ago

wergo commented 4 years ago

Related to #648.

I came across a small spacing issue regarding grace notes with upwards stem direction where the grace notes are too far away from the target notes and too close to their previous notes. If stems go down, everything is alright:

grafik

The original edition looks like this: grafik

MEI code:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://music-encoding.org/schema/4.0.0/mei-all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://music-encoding.org/schema/4.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="4.0.0">
    <meiHead>
        <fileDesc>
            <titleStmt>
                <title>grace note spacing</title>
                <respStmt>
                    <persName role="composer">Ludwig van Beethoven</persName>
                    <persName role="encoder" enddate="2019-07-31T17:18:10">Werner Goebl</persName>
                </respStmt>
            </titleStmt>
            <pubStmt>
                <respStmt>
                    <persName role="encoder" auth.uri="http://d-nb.info/gnd" auth="GND" codedval="1138881465">Werner Goebl</persName>
                </respStmt>
            </pubStmt>
        </fileDesc>
        <encodingDesc xml:id="encodingdesc-0000001205577039">
            <appInfo xml:id="appinfo-0000001492290593">
                <application xml:id="application-0000001245369466" isodate="2018-11-23T11:17:35" version="2.0.0-dev-e42e3a6">
                    <name xml:id="name-0000000401085565">Verovio</name>
                    <p xml:id="p-0000001059740050">Transcoded from MusicXML</p>
                </application>
            </appInfo>
        </encodingDesc>
    </meiHead>
    <music>
        <body>
            <mdiv xml:id="mdiv-0000000720917863">
                <score xml:id="score-0000000926025859">
                    <scoreDef xml:id="scoredef-0000000962089473" key.mode="major" key.sig="3f" meter.count="3" meter.unit="4">
                        <staffGrp xml:id="staffgrp-0000001520233015" label="." symbol="brace" bar.thru="true">
                            <staffDef xml:id="staffdef-0000000421725253" n="1" lines="5" clef.shape="G" clef.line="2">
                                <instrDef xml:id="instrdef-0000000255494442" midi.channel="0" midi.instrnum="0" midi.volume="79.00%"/>
                            </staffDef>
                            <staffDef xml:id="staffdef-0000001701180460" n="2" lines="5" clef.shape="G" clef.line="2">
                                <instrDef xml:id="instrdef-0000000070220525" midi.channel="1" midi.instrnum="0" midi.volume="74.00%"/>
                            </staffDef>
                        </staffGrp>
                    </scoreDef>
                    <section xml:id="section-WoO80">
                        <measure xml:id="measure-0000000708609674" n="201">
                            <staff xml:id="staff-0000000841250496" n="1">
                                <layer xml:id="layer-0000000303439294" n="1">
                                    <beam xml:id="beam-0000000016779588">
                                        <note xml:id="note-0000001783566621" dur="16" oct="5" pname="e" stem.dir="up" accid.ges="f"/>
                                        <note xml:id="note-0000000990884447" dur="16" oct="4" pname="g" stem.dir="up"/>
                                        <note xml:id="note-0000000121289911" dur="8" oct="4" pname="b" grace="unacc" stem.dir="up" accid.ges="f"/>
                                        <note xml:id="note-0000000655216343" dur="16" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                        <note xml:id="note-0000000596419962" dur="16" oct="4" pname="g" stem.dir="up"/>
                                    </beam>
                                    <note xml:id="note-0000000121289965" dur="8" oct="5" pname="f" grace="unacc" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000098727143" dur="16" oct="5" pname="e" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000214614184" dur="16" oct="4" pname="g" stem.dir="up"/>
                                    <note xml:id="note-0000000847567293" dur="8" oct="4" pname="b" grace="unacc" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000001646254174" dur="16" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000367826101" dur="16" oct="4" pname="g" stem.dir="up"/>
                                    <note xml:id="note-0000000125489965" dur="8" oct="4" pname="b" grace="acc" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000655216543" dur="4" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000127689965" dur="8" oct="4" pname="b" grace="acc" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000655287543" dur="4" oct="4" pname="a" stem.dir="up" accid.ges="f"/>

                                </layer>
                            </staff>
                            <staff xml:id="staff-0000001758386617" n="2">
                                <layer xml:id="layer-0000000062224407" n="1">
                                    <beam xml:id="beam-0000001194462086">
                                        <note xml:id="note-0000001829892534" dur="16" oct="5" pname="e" stem.dir="up" accid.ges="f"/>
                                        <note xml:id="note-0000001857218412" dur="16" oct="4" pname="g" stem.dir="up"/>
                                        <note xml:id="note-0000001595006499" dur="8" oct="4" pname="b" grace="unacc" stem.dir="down" accid.ges="f"/>
                                        <note xml:id="note-0000000086135382" dur="16" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                        <note xml:id="note-0000000258707541" dur="16" oct="4" pname="g" stem.dir="up"/>
                                    </beam>
                                    <note xml:id="note-0000000121289435" dur="8" oct="5" pname="f" grace="unacc" stem.dir="down" accid.ges="f"/>
                                    <note xml:id="note-0000000098729843" dur="16" oct="5" pname="e" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000214610984" dur="16" oct="4" pname="g" stem.dir="up"/>
                                    <note xml:id="note-0000000847569893" dur="8" oct="4" pname="b" grace="unacc" stem.dir="down" accid.ges="f"/>
                                    <note xml:id="note-0000001646258774" dur="16" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000367827601" dur="16" oct="4" pname="g" stem.dir="up"/>
                                    <note xml:id="note-0000000121289325" dur="8" oct="4" pname="b" grace="acc" stem.dir="down" accid.ges="f"/>
                                    <note xml:id="note-0000000655216543" dur="4" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                    <note xml:id="note-0000000121289125" dur="8" oct="4" pname="b" grace="acc" stem.dir="down" accid.ges="f"/>
                                    <note xml:id="note-0000000655216653" dur="4" oct="4" pname="a" stem.dir="up" accid.ges="f"/>
                                </layer>
                            </staff>
                        </measure>
                    </section>
                </score>
            </mdiv>
        </body>
    </music>
</mei>
lpugin commented 4 years ago

Yes, this does not look good. A proper fix would require a significant refactoring of the grace note layout algorithm. The problem is the bounding boxes of the slash and of the flag that push to the left the grace notes with stem up. (I adjusted the slashes - and corrected the angle that was wrong with stem down.)

image