Three questions about Scheme functions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Three questions about Scheme functions

Jérôme Plût-2
I have a few questions about using Scheme to build Lilypond data.

1. I have some Scheme code that builds custom articulations (more
precisely, it attaches metadata to NoteEvents, and the only way I found
to make this possible is via putting it in a custom, invisible
articulation, but let's not digress too much).

The code I use to declare this custom articulation is:

\layout { \context { \Score
  scriptDefinitions = #(append default-script-alist `(
  ("void" . ((stencil . #f) (direction . ,UP) (avoid-slur . ignore)))
)) } }

However, this is Lilypond code, not Scheme code. My code is in a .scm
file, which is read in the user files as #(load "code.scm").

Does there exist a way to modify the articulations table from inside a
Scheme code block (such as (begin <code...>) )? I tried wrapping this
inside #{ ... #}, but to no effect.


2. A variant of 1. above: say I have a music expression such as

voiceone = \relative {
  c d e f g \mymacro { a b c }
}

where mymacro is defined as

mymacro = #(define-music-function (parser location music) (ly:music?)
  ; ...
  (let (music-rel #{ \relative $music #}) ...))

This works as intended (i.e. the third note is interpreted as a c', not a
c). However, trying to build the exact same expression using the
Scheme constructor does not work:
  (let (music-rel (make-music 'RelativeOctaveMusic 'element music)) ...)
leaves the music expression untouched.

  So the two questions are:
  2.1 From within the \mymacro function, does there exist a way to know
      that we are called in a \relative scope?
  2.2 Does there exist a “clean Scheme” (no #{ #}) way to interpret the
      parameter as relative music?


3. I have a function that takes some music as input and produces a lyrics
variable, for instance:

voiceone = \relative {
  % the \metadata macro adds some invisible articulation, nothing is
  produced
  c4 d e\metadata "foobar" f g ...
  %    ^ HERE ^
}

#(define (myfunction music) ... )

 ; this produces a Lyrics variable containing text "foobar" at the
 appropriate position
\score { \new PianoStaff <<
  \new Staff << \voiceone >>
  % this produces something equivalent to \lyrics { ""2 "grux"4 }
  \new Lyrics << #(myfunction voiceone) >>
}

I would like to add info to the PDF file so that a mouse click on the
"grux" lyrics goes to the place where \metadata is called (at the HERE
comment above). How would this be possible?

(Maybe something with “ly:set-origin!” ? The documentation of this
function is not crystal clear...)

Thanks in advance,

--
        Jérôme

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Three questions about Scheme functions

Thomas Morley-2
Am Mo., 29. Okt. 2018 um 15:30 Uhr schrieb Jérôme Plût <[hidden email]>:

>
> I have a few questions about using Scheme to build Lilypond data.
>
> 1. I have some Scheme code that builds custom articulations (more
> precisely, it attaches metadata to NoteEvents, and the only way I found
> to make this possible is via putting it in a custom, invisible
> articulation, but let's not digress too much).
>
> The code I use to declare this custom articulation is:
>
> \layout { \context { \Score
>   scriptDefinitions = #(append default-script-alist `(
>   ("void" . ((stencil . #f) (direction . ,UP) (avoid-slur . ignore)))
> )) } }
>
> However, this is Lilypond code, not Scheme code. My code is in a .scm
> file, which is read in the user files as #(load "code.scm").
>
> Does there exist a way to modify the articulations table from inside a
> Scheme code block (such as (begin <code...>) )? I tried wrapping this
> inside #{ ... #}, but to no effect.

Hi Jérôme,

below works for me.
I'm quite confident it will work with (load ...), not tested, though.

\version "2.19.82"

#(define test-stencil
  (make-circle-stencil 0.5 0.1 #f))

#(let ((mod (ly:output-def-scope $defaultlayout)))
  (module-set! mod 'Score
    (ly:context-def-modify
      (module-ref mod 'Score)
      (ly:make-context-mod
        (list
          (list 'assign 'scriptDefinitions
           (cons
             `("void"
               . (
                  ;; to give some ink on the paper...
                  (stencil . ,test-stencil)
                  (direction . ,UP)
                  (avoid-slur . ignore)))
             (ly:output-def-lookup $defaultlayout 'scriptDefinitions))))))))

"void" = #(make-articulation "void")

{
  c''-\"void" c''^\"void" c''_\"void"
}

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user