lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Javascript test code for modifying ties and slurs with mouse


From: Flaming Hakama by Elaine
Subject: Re: A Javascript test code for modifying ties and slurs with mouse
Date: Sat, 14 Dec 2019 14:53:24 -0800


From: Stefano Troncaro <address@hidden>
To: Paolo Prete <address@hidden>
Cc: Aaron Hill <address@hidden>, lilypond-user <address@hidden>
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 (<address@hidden>) 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="" >> $HTML
echo "</body>" >> $HTML
echo "</html>" >> $HTML
echo "" >> $HTML

open -a "Google Chrome" $HTML
 

HTH, 

Elaine Alt
415 . 341 .4954                                           "Confusion is highly underrated"
address@hidden
Producer ~ Composer ~ Instrumentalist ~ Educator
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

reply via email to

[Prev in Thread] Current Thread [Next in Thread]