[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A few questions about Scheme functions
From: |
Jérôme Plût |
Subject: |
A few questions about Scheme functions |
Date: |
Mon, 29 Oct 2018 10:23:22 +0100 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
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 in a Scheme way
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
c 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 "foobar"4 }
\new Lyrics << #(myfunction voiceone) >>
}
My code for now works as I intend it to, but I would like to add info to
the PDF file so that a mouse click on the "foobar" lyrics goes to the
place where \metadata is called (at the HERE comment above)?
(Maybe something with “ly:set-origin!” ? The documentation of this
function is not crystal clear...)
- A few questions about Scheme functions,
Jérôme Plût <=