]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/centering-markup-on-note-heads-automatically.ly
Merge remote-tracking branch 'origin/master' into translation
[lilypond.git] / Documentation / snippets / centering-markup-on-note-heads-automatically.ly
1 %% DO NOT EDIT this file manually; it is automatically
2 %% generated from LSR http://lsr.di.unimi.it
3 %% Make any changes in LSR itself, or in Documentation/snippets/new/ ,
4 %% and then run scripts/auxiliar/makelsr.py
5 %%
6 %% This file is in the public domain.
7 \version "2.18.0"
8
9 \header {
10   lsrtags = "contexts-and-engravers, text, tweaks-and-overrides"
11
12   texidoc = "
13 For technical reasons, text scripts attached to note heads cannot
14 easily be centered on a note head's width, unlike articulations.
15
16 Instead of using trial-and-error offset tweaks, this snippet uses a
17 Scheme engraver to reset the horizontal parent of each markup to a
18 @code{NoteColumn}.  This also allows text to follow note heads which
19 have been shifted via @code{force-hshift}.
20
21
22
23 "
24   doctitle = "Centering markup on note heads automatically"
25 } % begin verbatim
26
27 #(define (Text_align_engraver ctx)
28   (let ((scripts '())
29         (note-column #f))
30     (make-engraver
31      (acknowledgers
32       ((note-column-interface trans grob source)
33        ;; cache NoteColumn in this Voice context
34        (set! note-column grob))
35       ((text-script-interface trans grob source)
36        ;; whenever a TextScript is acknowledged,
37        ;; add it to `scripts' list
38        (set! scripts (cons grob scripts))))
39      ((stop-translation-timestep trans)
40       ;; if any TextScript grobs exist,
41       ;; set NoteColumn as X-parent
42       (for-each (lambda (script)
43                   (set! (ly:grob-parent script X) note-column))
44                 scripts)
45       ;; clear scripts ready for next timestep
46       (set! scripts '())))))
47
48 \layout {
49   \context {
50     \Voice
51     \consists #Text_align_engraver
52     \override TextScript.X-offset =
53       #ly:self-alignment-interface::aligned-on-x-parent
54     \override TextScript.self-alignment-X = #CENTER
55   }
56 }
57
58 \new Staff <<
59   \relative c'' {
60     \override NoteColumn.force-hshift = #3
61     c1-\markup { \arrow-head #Y #DOWN ##t }
62   }
63   \\
64   \relative c' {
65     a4 a-\markup { \huge ^ } a a
66   }
67 >>