]> git.donarmstrong.com Git - lilypond.git/blob - input/lsr/adding-text-indications-to-metronome-marks.ly
Merge branch 'lilypond/translation' of ssh://trettig@git.sv.gnu.org/srv/git/lilypond...
[lilypond.git] / input / lsr / adding-text-indications-to-metronome-marks.ly
1 %% Do not edit this file; it is auto-generated from input/new
2 %% This file is in the public domain.
3 \version "2.11.45"
4 \header {
5   lsrtags = "expressive-marks,tweaks-and-overrides"
6   texidoc = "
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.
11 "
12   doctitle = "Adding text indications to metronome marks"
13 } % begin verbatim
14
15 #(define-markup-command (mvt layout props arg) (markup?)
16   (interpret-markup layout props
17      (markup #:huge #:bold arg)))
18
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))))
29                      dots 1 1)))
30
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)
36              "="
37              #:concat ((number->string count) ")")))
38   #{
39     \set Score.metronomeMarkFormatter = #$format-movement-markup
40     \set Score.tempoWholesPerMinute = #$(ly:moment-mul (ly:make-moment count 1)
41                                          (ly:duration-length
42                                            (string->duration duration)))
43     \set Score.tempoUnitDuration = #$(string->duration duration)
44     \set Score.tempoUnitCount = $count
45     $music
46     \set Score.metronomeMarkFormatter = #format-metronome-markup
47   #})
48
49 \layout { ragged-right = ##f }
50
51 \relative c' { 
52   \time 3/4
53   \movement "Allegro" "2." #92
54   c2 e4
55   g2.
56   \movement "Moderato" "4" #104
57   f4 e d
58   \tempo 4 = 92
59   c2.
60 }