3 lsrtags = "expressive-marks,tweaks-and-overrides"
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.
10 doctitle = "Adding text indications to metronome marks"
13 #(define-markup-command (mvt layout props arg) (markup?)
14 (interpret-markup layout props
15 (markup #:huge #:bold arg)))
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))))
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)
35 #:concat ((number->string count) ")")))
37 \set Score.metronomeMarkFormatter = #$format-movement-markup
38 \set Score.tempoWholesPerMinute = #$(ly:moment-mul (ly:make-moment count 1)
40 (string->duration duration)))
41 \set Score.tempoUnitDuration = #$(string->duration duration)
42 \set Score.tempoUnitCount = $count
44 \set Score.metronomeMarkFormatter = #format-metronome-markup
47 \layout { ragged-right = ##f }
51 \movement "Allegro" "2." #92
54 \movement "Moderato" "4" #104