Hi David,
Am 07.07.2018 um 16:15 schrieb David Kastrup:
Urs Liska <[email protected]> writes:
Hi all,
I want a music function to produce an ossia staff. The NR states that
in order to place that above alignAboveContext should be used:
\new Staff = "main" \relative {
c''4 b d c
<<
{ c4 b d c }
\new Staff \with {
\remove "Time_signature_engraver"
alignAboveContext = #"main"
\magnifyStaff #2/3
firstClef = ##f
}
{ e4 d f e }
>>
c4 b c2
}
But is that also possible when I (or my music-function) doesn't know
the staff's name
You can use \applyContext for getting it before you initiate your own
(hopefully uniquely named) Staff.
Thank you for the suggestion, which looks like it's what I need.
However, unfortunately I didn't get anywhere looking at the various
examples in the docs. It's still a mystery to me what does what and
evaluates to what and when that happens or not ...
OK, \applyContext passes the current context as the single argument to a
function. Within that function one can access (retrieve and set) the
properties of that context. I can sort of understand what that does in
the example with "desaturating" colors.
But that function call always returns a (make-music 'ApplyContext ...)
music expression, which is nothing I can use for my purposes, it seems
everything is about the side-effects.
So I thought I'd define a variable and have the \applyContext function
populate that variable with the context name, so I could use that later.
But that doesn't work either, it looks like the \applyContext is only
executed *after* I would need to use the variable:
\version "2.19.80"
ossia =
#(define-music-function
(music ossia-music) (ly:music? ly:music?)
(let ((name "initialized"))
#{
\applyContext
#(lambda (context)
(set! name (ly:context-id (ly:context-parent context))) ; I know this
has to be more robust ...
(ly:message "1. context name inside \\applyContext: ~a" name)
; the following \new Staff has no effect
#{ \new Staff { c' } #})
#(ly:message "2. context name after \\applyContext was called: ~a" name)
#music
% Create \new Staff with ossia-music
#}))
\new Staff = "My Staff"
\relative {
g'8 a b c
\ossia { d c b a } { c b a g }
g b d b g2
}
=>
Parsing...
2. context name after \applyContext was called: initialized
Interpreting music...
1. context name inside \applyContext: My Staff
I'm sorry, but I need more concrete pointers or even an example.
Thanks
Urs
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user