> From: Stefano Troncaro <stefanotronc...@gmail.com>
> To: Paolo Prete <paolopr...@gmail.com>
> Cc: Aaron Hill <lilyp...@hillvisions.com>, lilypond-user <
> lilypond-user@gnu.org>
> Date: Sat, 14 Dec 2019 19:13:43 -0300
> Subject: Re: A Javascript test code for modifying ties and slurs with mouse
> Hi Paolo,
>
> Since Aaron's svg-script function creates an empty \markup, you can use
> the properties oddFooterMarkup and evenFooterMarkup of the \paper block to
> have your script embedded at the end of every page. Look:
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \version "2.19.83"
>
> svg-script = #(define-scheme-function (body) (string?)
>    (markup #:stencil (ly:make-stencil (list 'embedded-svg
>      (string-join (list "<script type=\"text/javascript\"><![CDATA["
>        body "]]></script>") "\n")) '(0 . 0) '(0 . 0))))
>
> script-for-every-page = \svg-script
> #"var flat = document.getElementById('flat');
>    flat.style.color = 'red';
>    function spin(what, amount) {
>      let angle = 0.0;
>      return function () {
>        const bbox = what.getBBox();
>        const xform = ['rotate(',
>          (angle = (angle + amount) % 360.0),
>          bbox.x + 0.5 * bbox.width,
>          bbox.y + 0.75 * bbox.height, ')'];
>        what.setAttribute('transform', xform.join(' '));
>      }
>    }
>    setInterval(spin(flat, 5), 100);"
>
> \paper {
>   oddFooterMarkup = \script-for-every-page
>   evenFooterMarkup = \script-for-every-page
> }
>
> { g'4 a' \tweak Accidental.output-attributes #'((id . "flat")) bes'2
> \pageBreak
>   g'4 a' \tweak Accidental.output-attributes #'((id . "flat")) bes'2 }
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> Love what your script is doing so far!
>
> Hope that helps,
> Stefano
>
> El sáb., 14 dic. 2019 a las 18:39, Paolo Prete (<paolopr...@gmail.com>)
> escribió:
>
>> Thanks Aaron, it did the trick.
>>
>> However, how can I make it work for multiple pages output?
>>
>
Here is an approach to this issue: create an HTML document that includes
each SVG.
In which case, you don't need to embed the script in the SVG, you can link
it once in the HTML file:

Here is the MWE

% lily-easy-slurs.ly
\version "2.19.45"
\include "lily-easy-slurs.ily"
figure = \relative c' { g4_\( a' b2 ~ | \noBreak 2 ( e8 d ) c,4 \) | }
{ \figure \pageBreak \figure }


Here is the script to run lilypond on the MWE, then create an HTML file
that includes all the SVGs, and open it:

#!/usr/local/bin/bash
# Usage: buildLilyEasySlurs.sh file-base-name

FILE_BASE_NAME="lily-easy-slurs"
if [ "$1" != "" ]; then
    FILE_BASE_NAME=$1
fi

LILYPOND="$FILE_BASE_NAME.ly"
HTML="$FILE_BASE_NAME.html"

rm "$FILE_BASE_NAME*.svg"

lilypond -dbackend=svg $LILYPOND

echo "<html>" > $HTML
echo "<head><title>Editing Lilypond curves</title>" >> $HTML
echo "</head>" >> $HTML
echo "<body>" >> $HTML

for SVG in `ls -1 $FILE_BASE_NAME-*.svg`; do
    echo "SVG is $SVG"
    echo "" >> $HTML
    cat $SVG >> $HTML
done

echo "" >> $HTML
echo "<script src="lilyEasySlurs.js"></script>" >> $HTML
echo "</body>" >> $HTML
echo "</html>" >> $HTML
echo "" >> $HTML

open -a "Google Chrome" $HTML


HTH,

Elaine Alt
415 . 341 .4954                                           "*Confusion is
highly underrated*"
ela...@flaminghakama.com
Producer ~ Composer ~ Instrumentalist ~ Educator
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to