Hello,
On 07/08/2020 00:18, David Kastrup wrote:
Niols <ni...@niols.fr> writes:
I have not managed to override the "\repeat" music function.
It isn't a music function but a "reserved" word in LilyPond.
I know. Yet there is a "repeat" scheme function defined in
scm/ly-syntax-constructors.ly that I tried to redefine (by recompiling
LilyPond) and successfully managed to make it do what I wanted. I guess
the lambda it contains gets passed to a table of some kind that
associates reserved words to behaviours, but I could not locate such a
table.
I suspect there is something I do not understand in the order in which
things are executed in LilyPond.
I have however found a solution based on overriding "make-music". I
replace "make-music" by a wrapper around it that adds the callback
from the snippet to all 'VoltaRepeatedMusic and leaves the rest
alone. This is actually just a few lines:
#(define the-make-music make-music)
#(define (make-music-wrapped name . music-properties)
(let ((music (apply the-make-music (cons name music-properties))))
(if (equal? name 'VoltaRepeatedMusic)
(ly:music-set-property! music 'elements-callback new-volta-set))
music))
#(set! make-music make-music-wrapped)
It might not be the cleanest, but that is all I have, and that seems
to work.
It would be easier to do
music-descriptions.VoltaRepeatedMusic.elements-callback = ...
A cursory glance would suggest that might work (though its effect would
not be limited to one session).
Great idea! By reading scm/define-music-types.scm,I saw that
music-descriptions is fed to a hash table. I thus managed this with:
#(let ((props (hashq-ref music-name-to-property-table
'VoltaRepeatedMusic)))
(assoc-set! props 'elements-callback new-volta-set))
You could also try to redefine the make-volta-set function.
That, I did not manage to make work. I suppose that the music-properties
list and, later, the music-name-to-property-table only store the
contents of make-volta-set; overriding it later is thus of no use.
2. Maybe there is a way to define a function that will be ran before
processing on any music? But this I have no idea if this is
possible, or how to do it, and my research has proven ineffective so
far.
There are the scorification hooks.
That sounds really interesting, whatever that is, also for other hacks
around LilyPond. Would you happen to have any pointer for that?
3. Maybe there is a way to override the "make-volta-set" callback
instead of creating a new one? Such that then, in LilyPond's normal
execution, it uses the new definition and not and old one that then
needs to be replaced?
For 2. and 3., I still have no idea as this is far beyond my
understanding of the internals of LilyPond. I am not really looking
into it though.
Not a matter of internals.
#(define original-make-volta-set make-volta-set)
(define (make-volta-set ...) ...)
Possibly
(set! make-volta-set (lambda (...) ...))
but I think that the define probably works.
I suppose they work to override make-volta-set. As said earlier, though,
I did not manage to get the expected result from this. I suppose the
lambda is already fed to the music-name-to-property-table. Overriding
this thus does not give much useful things.
Thank you very much for you help!
— Niols