X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Documentation%2Fsnippets%2Fcentering-markup-on-note-heads-automatically.ly;h=ff1a10b22956a7c994da5951caefdefa693592ed;hb=9fe18536fe333c167fe1bd87f76a30b20f603dd0;hp=7e0caf90e1e73a28c4b41861e4d576536611e06a;hpb=248b82c3b9dcecf96351ad5f22540325fa54ad88;p=lilypond.git diff --git a/Documentation/snippets/centering-markup-on-note-heads-automatically.ly b/Documentation/snippets/centering-markup-on-note-heads-automatically.ly index 7e0caf90e1..ff1a10b229 100644 --- a/Documentation/snippets/centering-markup-on-note-heads-automatically.ly +++ b/Documentation/snippets/centering-markup-on-note-heads-automatically.ly @@ -1,48 +1,79 @@ -%% Do not edit this file; it is automatically -%% generated from LSR http://lsr.dsi.unimi.it -%% This file is in the public domain. -\version "2.13.10" +% DO NOT EDIT this file manually; it is automatically +% generated from Documentation/snippets/new +% Make any changes in Documentation/snippets/new/ +% and then run scripts/auxiliar/makelsr.py +% +% This file is in the public domain. +%% Note: this file works from version 2.15.31 +\version "2.15.31" \header { - lsrtags = "text, tweaks-and-overrides" +%% Translation of GIT committish: 1cda7b7b8219cb97399b8e7b56c1115aaf82c002 + texidocfr = " +Des raisons techniques sont à l'origine de la difficulté de centrer des +scripts textuels attachés à des têtes de note, ce qui n'est pas le cas +des articulations. +Plutôt que de procéder par tâtonnement, voici comment élaborer un +graveur en Scheme, chargé de redéfinir le parent horizontal de chaque +@emph{markup} sur un empilement de notes (un @code{NoteColumn}). Il +permet aussi au texte de suivre les têtes ayant été décalées par un +@code{force-hshift}. +" + doctitlefr = "Centrage automatique d'un @emph{markup} sur la tête de note" + + lsrtags = "text, tweaks-and-overrides, contexts-and-engravers" texidoc = " For technical reasons, text scripts attached to note heads cannot easily be centered on a note head's width, unlike articulations. -Instead of using trial-and-error offset tweaks, this snippet accesses a -note head (or rest) from the @code{TextScript} object's horizontal -parent (a paper column), using its extent to correct the positioning. - - - +Instead of using trial-and-error offset tweaks, this snippet uses a +Scheme engraver to reset the horizontal parent of each markup to a +@code{NoteColumn}. This also allows text to follow note heads which have +been shifted via @code{force-hshift}. " doctitle = "Centering markup on note heads automatically" } % begin verbatim -textScriptCenterOnNote = \override TextScript #'X-offset = -#(lambda (grob) - (let* ((paper-col (ly:grob-parent grob X)) - (elts (ly:grob-object paper-col 'elements)) - (rhythmic-head grob)) - - (for-each - (lambda (idx) - (let ((elt (ly:grob-array-ref elts idx))) - (if (grob::has-interface elt - 'rhythmic-grob-interface) - (set! rhythmic-head elt)))) - (reverse (iota (ly:grob-array-length elts)))) - - (+ - (ly:self-alignment-interface::x-aligned-on-self grob) - (interval-center - (ly:grob-robust-relative-extent rhythmic-head rhythmic-head X))))) - -\relative c' { - \override TextScript #'self-alignment-X = #CENTER - \textScriptCenterOnNote - 1-\markup \arrow-head #Y #UP ##t - 1-\markup \huge "^" + +#(define (Text_align_engraver ctx) + (let ((scripts '()) + (note-column #f)) + (make-engraver + (acknowledgers + ((note-column-interface trans grob source) + ;; cache NoteColumn in this Voice context + (set! note-column grob)) + ((text-script-interface trans grob source) + ;; whenever a TextScript is acknowledged, + ;; add it to `scripts' list + (set! scripts (cons grob scripts)))) + ((stop-translation-timestep trans) + ;; if any TextScript grobs exist, + ;; set NoteColumn as X-parent + (for-each (lambda (script) + (set! (ly:grob-parent script X) note-column)) + scripts) + ;; clear scripts ready for next timestep + (set! scripts '()))))) + +\layout { + \context { + \Voice + \consists #Text_align_engraver + \override TextScript #'X-offset = + #ly:self-alignment-interface::aligned-on-x-parent + \override TextScript #'self-alignment-X = #CENTER + } } +\new Staff << + \relative c'' { + \override NoteColumn #'force-hshift = #3 + c1-\markup { \arrow-head #Y #DOWN ##t } + } + \\ + \relative c' { + a4 a-\markup { \huge ^ } a a + } +>>