1 %% Do not edit this file; it is auto-generated from input/new
2 %% This file is in the public domain.
5 lsrtags = "expressive-marks,tweaks-and-overrides"
7 Using Scheme code to override the stencil for @code{MetronomeMark}
8 objects, this example allows the creation of metronome marks which include
9 text directions. The function @code{\movement} is called with three
10 arguments: the text label, note duration, and beats per minute.
12 doctitle = "Adding text indications to metronome marks"
15 #(define-markup-command (mvt layout props arg) (markup?)
16 (interpret-markup layout props
17 (markup #:huge #:bold arg)))
19 #(define (string->duration duration-string)
20 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a duration object."
21 (let* ((length (string-length duration-string))
22 (dot-index (or (string-index duration-string #\.) length))
23 (len (substring duration-string 0 dot-index))
24 (dots (- length dot-index)))
25 (ly:make-duration (cond ((string=? len "breve") -1)
26 ((string=? len "longa") -2)
27 ((string=? len "maxima") -3)
28 (else (log2 (string->number len))))
31 movement = #(define-music-function (parser location text duration count music)
32 (string? string? integer? ly:music?)
33 (define (format-movement-markup dur count context)
34 (markup #:mvt text #:hspace 1
35 #:concat ("(" #:general-align Y DOWN #:smaller #:note duration 1)
37 #:concat ((number->string count) ")")))
39 \set Score.metronomeMarkFormatter = #$format-movement-markup
40 \set Score.tempoWholesPerMinute = #$(ly:moment-mul (ly:make-moment count 1)
42 (string->duration duration)))
43 \set Score.tempoUnitDuration = #$(string->duration duration)
44 \set Score.tempoUnitCount = $count
46 \set Score.metronomeMarkFormatter = #format-metronome-markup
49 \layout { ragged-right = ##f }
53 \movement "Allegro" "2." #92
56 \movement "Moderato" "4" #104