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: Paolo Prete
Subject: Re: A Javascript test code for modifying ties and slurs with mouse
Date: Sun, 15 Dec 2019 02:09:08 +0100

To Stefano and Elaine:

really, it's better to avoid scripting on scripting on scripting, IMHO. SVG is designed to be lovely coupled with JS, and the output file should be all-inclusive. Nor HTML is required. Only Lilypond and any SVG viewer (including browsers).  The override of internal stuff proposed by Aaron should be the solution for that, taking care to contact the maintainer of the code, meanwhile. I'm waiting for some feedback.
About the reverse process, I have some ideas, but want to meditate on them before proposing a solution. I'm not even sure that it's a good idea to automate the process...

On Sun, Dec 15, 2019 at 12:31 AM Stefano Troncaro <address@hidden> wrote:
Hi Paolo, I was also having that concern.

Elaine replied in a new thread with a solution for that, in which instead of adding the script to the svg files with lilypond you just use an external script. I haven't tested it yet but it seems to me like that'll be a cleaner approach, you just include the file with the function to show the control points and the layout definitions and that's all you need.

I guess you could make it even cleaner and have the shell script put the include statement in the .ly file.

I'd go with that solution for now. Now what I'm curious about is if there's a way to automate the process of bringing the modified shapes into the lilypond file instead of having to manually paste every one. I have no clue on how to achieve that honestly, but that'd be incredible.

HTH,
Stéfano

El sáb., 14 dic. 2019 a las 20:08, Paolo Prete (<address@hidden>) escribió:
Hi Stefano,

your suggestion produces the script for every page, but it requires to manually add a property in the \paper scope. Instead, I would like to automatically set this property, and leave the user to set all the score properties (including the paper's one) without messing up the code adding pieces of the template of the script. So to obtain something like (which is much cleaner):

\include "JSSVGSlurTuner.ly"

{

     \addJSSVGSlurTuner

     ..... my score .....

}

Thanks for your help
P


On Sat, Dec 14, 2019 at 11:13 PM Stefano Troncaro <address@hidden> wrote:
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?

On Sat, Dec 14, 2019 at 4:26 AM Aaron Hill <address@hidden> wrote:
On 2019-12-13 5:59 pm, Paolo Pr wrote:
> First of all, I need to add with Lilypond a <script>  tag to the svg
> file
> just before the ending </svg> tag  in the following way:
>
> 1)
> ....
>  <script xlink:href=""> > </svg>
>
> OR in the following way:
>
> 2)
> ....
> <script>
> <![CDATA[
>     ..._javascript_ code...
> ]]>
> </script>
> </svg>

Well, one could use (abuse?) the embedded-svg stencil command:

%%%%
\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))))

{ g'4 a' \tweak Accidental.output-attributes #'((id . "flat")) bes'2 }

\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);"
%%%%

This adds a top-level \markup that contains a stencil to instruct
output-svg.scm to write the specified string to the output.


-- Aaron Hill


reply via email to

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