]> git.donarmstrong.com Git - lilypond.git/blob - input/new/adding-text-indications-to-metronome-marks.ly
Update from Neil
[lilypond.git] / input / new / adding-text-indications-to-metronome-marks.ly
1 \version "2.11.43"
2 \header {
3   lsrtags = "expressive-marks,text,tweaks-and-overrides"
4   texidoc = "
5 Using Scheme code to override the stencil for @code{MetronomeMark}
6 objects, this example allows the creation of metronome marks which include
7 text directions.  The function @code{\tempoChangeMarkup} is called with three
8 strings: the text label, note duration, and beats per minute.  To print the
9 new metronome mark, this is followed by the standard @code{\tempo} command.
10 "
11   doctitle = "Adding text indications to metronome marks"
12 }
13
14 % Thanks to Alexander Kobel for this snippet
15
16 tempoMarkLabelSize = #0
17 tempoMarkNoteSize = #-6
18
19 #(define (tempoChangeMarkupFactory grob label noteValue tempo)
20  (interpret-markup
21   (ly:grob-layout grob)
22   (ly:grob-alist-chain grob (ly:output-def-lookup (ly:grob-layout grob) 'text-font-defaults))
23   (markup
24    #:fontsize tempoMarkLabelSize #:italic #:concat (label (if (string-null? label) "(" " (" ))
25    #:hspace -1
26    #:fontsize tempoMarkNoteSize #:general-align Y DOWN #:note noteValue UP
27    #:fontsize tempoMarkLabelSize #:italic #:concat( "= " tempo ")" )
28   )
29  ))
30
31 #(define (tempoChangeStencil label noteValue tempo)
32  (lambda (grob)
33   (tempoChangeMarkupFactory grob label noteValue tempo)
34  ))
35
36 tempoChangeMarkup = #(define-music-function (parser location label noteValue tempo) (string? string? string?)
37        #{
38          \once \override Score.MetronomeMark #'stencil = #(tempoChangeStencil $label $noteValue $tempo)
39        #})
40
41 \relative c' {
42   \time 4/4
43   \clef treble
44   % initialize the override
45   \tempoChangeMarkup #"Moderato" #"4" #"63"
46   % markup is printed
47   \tempo 4 = 63
48   c4 d e f
49   g a b c
50   \time 6/4
51   \mark \default
52   \tempoChangeMarkup #"presto" #"2." #"90"
53   \tempo 2. = 90
54   c2. g \break
55   e \tempoChangeMarkup #"handling collision with RehearsalMark" #"4" #"120" \tempo 4 = 120 c
56   \time 4/4
57   \mark \default
58   c1
59 }