Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister lucaswerkmeister/README.md
Last active Mar 15, 2018

Embed
What would you like to do?
Workaround for \displaceHeads on notes with beams

The \displaceHeads command from LilyPond snippet 861 doesn’t work correctly with notes that have beams – it removes the beam, probably due to a LilyPond bug (see here for details). This version can be used instead – it’s not as correct (the width of the beam is hard-coded), but it seems to work. (Only use it if you’re actually affected by this problem, of course, otherwise stick with the original!)

#(define ((shift offsets) grob)
"Defines how NoteHeads should be moved according to the given list of offsets."
(let* (
;; NoteHeads
;; Get the NoteHeads of the NoteColumn
(note-heads (ly:grob-array->list (ly:grob-object grob 'note-heads)))
;; Get their durations
(nh-duration-log
(map
(lambda (note-head-grobs)
(ly:grob-property note-head-grobs 'duration-log))
note-heads))
;; Get the stencils of the NoteHeads
(nh-stencils
(map
(lambda (note-head-grobs)
(ly:grob-property note-head-grobs 'stencil))
note-heads))
;; Get their length in X-axis-direction
(stencils-x-lengths
(map
(lambda (x)
(let* ((stencil (ly:grob-property x 'stencil))
(stencil-X-exts (ly:stencil-extent stencil X))
(stencil-lengths (interval-length stencil-X-exts)))
stencil-lengths))
note-heads))
)
;; Final Calculation for moving the NoteHeads
(for-each
(lambda (nh nh-x-length off)
(if (= off 0)
#f
(ly:grob-translate-axis! nh (* off (- nh-x-length 0.065)) X)))
note-heads stencils-x-lengths offsets)))
displaceHeads =
#(define-music-function (parser location offsets) (list?)
"
Moves the NoteHeads, using (shift offsets)
"
#{
\once \override NoteColumn.before-line-breaking = #(shift offsets)
#})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.