Re: What’s up with this snippet?
Tina Petzel <[email protected]>
| Newsgroups | gmane.comp.gnu.lilypond.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Harm,
> Well, transposability is crucial for many.
> See https://archiv.lilypondforum.de/index.php/topic,721.msg5798.html#msg5798
> and the attachments for a general attempt.
This looks ... complicated. I thought of simply doing this
%%%
lower =
#(define-music-function (p arg) (ly:pitch? ly:music?)
(ly:music-set-property! arg 'element (make-music 'NoteEvent 'pitch p))
arg)
upper =
#(define-music-function (p arg) (ly:pitch? ly:music?)
(ly:music-set-property! arg 'pitch p)
arg)
\transpose c cis {
\temporary\override Script.stencil =
#(grob-transformer
'stencil
(lambda (grob orig)
(let* ((cause (ly:grob-property grob 'cause))
(mcause (ly:event-property cause 'music-cause))
(pitch (ly:music-property mcause 'pitch #f))
(elt (ly:music-property mcause 'element #f))
(upper-pitch pitch)
(lower-pitch (and elt (ly:music-property elt 'pitch)))
(dsharp (grob-interpret-markup grob (markup #:center-align
#:fontsize -5 #:doublesharp)))
(sharp (grob-interpret-markup grob (markup #:center-align
#:fontsize -5 #:sharp)))
(natural (grob-interpret-markup grob (markup #:center-align
#:fontsize -5 #:natural)))
(flat (grob-interpret-markup grob (markup #:center-align
#:fontsize -5 #:flat)))
(dflat (grob-interpret-markup grob (markup #:center-align
#:fontsize -5 #:doubleflat)))
(upper-acc (and upper-pitch (ly:pitch-alteration upper-pitch)))
(lower-acc (and lower-pitch (ly:pitch-alteration lower-pitch)))
(upper-stc (and upper-acc
(cond ((< upper-acc -1/2) dflat)
((< upper-acc 0) flat)
((> upper-acc 1/2) dsharp)
((> upper-acc 0) sharp)
(else natural))))
(lower-stc (and lower-acc
(cond ((< lower-acc -1/2) dflat)
((< lower-acc 0) flat)
((> lower-acc 1/2) dsharp)
((> lower-acc 0) sharp)
(else natural))))
(stc orig))
(if lower-stc
(set! stc (ly:stencil-combine-at-edge stc Y DOWN lower-stc 0.2)))
(if upper-stc
(set! stc (ly:stencil-combine-at-edge stc Y UP upper-stc 0.2)))
stc)))
\key c\minor
c''-\upper des-\lower b -\turn
c''-\upper des -\trill
c''-\lower b -\mordent
}
%%%
This abuses the availabilty of existing properties managed by transposition —
namely pitch and element — to annoted upper and lower neighboring tone to an
ornament. The logic is then to display the accidental derived from that pitch
(assuming that if it is set the printing of this accidental is desired).
And yes, this code is not quite perfect, it misses individual placement
corrections for different scripts. But that could be solved easily, e.g. by
adding an `details.accidental-alignment.upper/lower.X/Y` to some alignment
value int the `scriptDefinitions` and then aligning by this (rather than
assuming CENTER-UP/DOWN alignment.
Cheers,
Tina
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQS0sdUK2Lu8of48K2+FHhaCPe7BywUCairc5wAKCRCFHhaCPe7B y5l7AQDPNlEOrpUBjZR62+hEfpEgDOzgJ7w2/bdG7clc08kG+gD/YOHMXMwK0obV qEbrCNobJ1iFKrsS7SpQtH4voH/rqAE= =yCd1 -----END PGP SIGNATURE-----