]> git.donarmstrong.com Git - lilypond.git/blob - input/new/adding-text-indications-to-metronome-marks.ly
Merge branch 'lilypond/translation' of ssh://trettig@git.sv.gnu.org/srv/git/lilypond...
[lilypond.git] / input / new / adding-text-indications-to-metronome-marks.ly
1 \version "2.11.45"
2 \header {
3   lsrtags = "expressive-marks,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{\movement} is called with three
8 arguments: the text label, note duration, and beats per minute.
9 "
10   doctitle = "Adding text indications to metronome marks"
11 }
12
13 #(define-markup-command (mvt layout props arg) (markup?)
14   (interpret-markup layout props
15      (markup #:huge #:bold arg)))
16
17 #(define (string->duration duration-string)
18   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a duration object."
19   (let* ((length (string-length duration-string))
20          (dot-index (or (string-index duration-string #\.) length))
21          (len (substring duration-string 0 dot-index))
22          (dots (- length dot-index)))
23    (ly:make-duration (cond ((string=? len "breve") -1)
24                            ((string=? len "longa") -2)
25                            ((string=? len "maxima") -3)
26                            (else (log2 (string->number len))))
27                      dots 1 1)))
28
29 movement = #(define-music-function (parser location text duration count music)
30                         (string? string? integer? ly:music?)
31    (define (format-movement-markup dur count context)
32      (markup #:mvt text #:hspace 1
33              #:concat ("(" #:general-align Y DOWN #:smaller #:note duration 1)
34              "="
35              #:concat ((number->string count) ")")))
36   #{
37     \set Score.metronomeMarkFormatter = #$format-movement-markup
38     \set Score.tempoWholesPerMinute = #$(ly:moment-mul (ly:make-moment count 1)
39                                          (ly:duration-length
40                                            (string->duration duration)))
41     \set Score.tempoUnitDuration = #$(string->duration duration)
42     \set Score.tempoUnitCount = $count
43     $music
44     \set Score.metronomeMarkFormatter = #format-metronome-markup
45   #})
46
47 \layout { ragged-right = ##f }
48
49 \relative c' { 
50   \time 3/4
51   \movement "Allegro" "2." #92
52   c2 e4
53   g2.
54   \movement "Moderato" "4" #104
55   f4 e d
56   \tempo 4 = 92
57   c2.
58 }