]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/centering-markup-on-note-heads-automatically.ly
Local updates from LSR
[lilypond.git] / Documentation / snippets / centering-markup-on-note-heads-automatically.ly
1 % DO NOT EDIT this file manually; it is automatically
2 % generated from Documentation/snippets/new
3 % Make any changes in Documentation/snippets/new/
4 % and then run scripts/auxiliar/makelsr.py
5 %
6 % This file is in the public domain.
7 %% Note: this file works from version 2.15.31
8 \version "2.15.31"
9
10 \header {
11 %% Translation of GIT committish: 1cda7b7b8219cb97399b8e7b56c1115aaf82c002
12   texidocfr = "
13 Des raisons techniques sont à l'origine de la difficulté de centrer des
14 scripts textuels attachés à des têtes de note, ce qui n'est pas le cas
15 des articulations.
16
17 Plutôt que de procéder par tâtonnement, voici comment élaborer un
18 graveur en Scheme, chargé de redéfinir le parent horizontal de chaque
19 @emph{markup} sur un empilement de notes (un @code{NoteColumn}).  Il
20 permet aussi au texte de suivre les têtes ayant été décalées par un
21 @code{force-hshift}.
22 "
23   doctitlefr = "Centrage automatique d'un @emph{markup} sur la tête de note"
24
25   lsrtags = "text, tweaks-and-overrides, contexts-and-engravers"
26   texidoc = "
27 For technical reasons, text scripts attached to note heads cannot
28 easily be centered on a note head's width, unlike articulations.
29
30 Instead of using trial-and-error offset tweaks, this snippet uses a
31 Scheme engraver to reset the horizontal parent of each markup to a
32 @code{NoteColumn}.  This also allows text to follow note heads which have
33 been shifted via @code{force-hshift}.
34 "
35   doctitle = "Centering markup on note heads automatically"
36 } % begin verbatim
37
38
39 #(define (Text_align_engraver ctx)
40   (let ((scripts '())
41         (note-column #f))
42     (make-engraver
43      (acknowledgers
44       ((note-column-interface trans grob source)
45        ;; cache NoteColumn in this Voice context
46        (set! note-column grob))
47       ((text-script-interface trans grob source)
48        ;; whenever a TextScript is acknowledged,
49        ;; add it to `scripts' list
50        (set! scripts (cons grob scripts))))
51      ((stop-translation-timestep trans)
52       ;; if any TextScript grobs exist,
53       ;; set NoteColumn as X-parent
54       (for-each (lambda (script)
55                   (set! (ly:grob-parent script X) note-column))
56                 scripts)
57       ;; clear scripts ready for next timestep
58       (set! scripts '())))))
59
60 \layout {
61   \context {
62     \Voice
63     \consists #Text_align_engraver
64     \override TextScript #'X-offset =
65       #ly:self-alignment-interface::aligned-on-x-parent
66     \override TextScript #'self-alignment-X = #CENTER
67   }
68 }
69
70 \new Staff <<
71   \relative c'' {
72     \override NoteColumn #'force-hshift = #3
73     c1-\markup { \arrow-head #Y #DOWN ##t }
74   }
75   \\
76   \relative c' {
77     a4 a-\markup { \huge ^ } a a
78   }
79 >>