]> git.donarmstrong.com Git - lilypond.git/blobdiff - 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
index 1c39226b6cc575679480ac8dd6bc3afbff98e77c..817446ecd11fe08d14fa3219ce85de22e9409e8c 100644 (file)
@@ -1,61 +1,60 @@
 %% Do not edit this file; it is auto-generated from input/new
 %% This file is in the public domain.
-\version "2.11.43"
+\version "2.11.45"
 \header {
-  lsrtags = "expressive-marks,text,tweaks-and-overrides"
+  lsrtags = "expressive-marks,tweaks-and-overrides"
   texidoc = "
 Using Scheme code to override the stencil for @code{MetronomeMark}
 objects, this example allows the creation of metronome marks which include
-text directions.  The function @code{\tempoChangeMarkup} is called with three
-strings: the text label, note duration, and beats per minute.  To print the
-new metronome mark, this is followed by the standard @code{\tempo} command.
+text directions.  The function @code{\movement} is called with three
+arguments: the text label, note duration, and beats per minute.
 "
   doctitle = "Adding text indications to metronome marks"
 } % begin verbatim
 
-% Thanks to Alexander Kobel for this snippet
+#(define-markup-command (mvt layout props arg) (markup?)
+  (interpret-markup layout props
+     (markup #:huge #:bold arg)))
 
-tempoMarkLabelSize = #0
-tempoMarkNoteSize = #-6
+#(define (string->duration duration-string)
+  "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a duration object."
+  (let* ((length (string-length duration-string))
+         (dot-index (or (string-index duration-string #\.) length))
+         (len (substring duration-string 0 dot-index))
+         (dots (- length dot-index)))
+   (ly:make-duration (cond ((string=? len "breve") -1)
+                           ((string=? len "longa") -2)
+                           ((string=? len "maxima") -3)
+                           (else (log2 (string->number len))))
+                     dots 1 1)))
 
-#(define (tempoChangeMarkupFactory grob label noteValue tempo)
- (interpret-markup
-  (ly:grob-layout grob)
-  (ly:grob-alist-chain grob (ly:output-def-lookup (ly:grob-layout grob) 'text-font-defaults))
-  (markup
-   #:fontsize tempoMarkLabelSize #:italic #:concat (label (if (string-null? label) "(" " (" ))
-   #:hspace -1
-   #:fontsize tempoMarkNoteSize #:general-align Y DOWN #:note noteValue UP
-   #:fontsize tempoMarkLabelSize #:italic #:concat( "= " tempo ")" )
-  )
- ))
+movement = #(define-music-function (parser location text duration count music)
+                        (string? string? integer? ly:music?)
+   (define (format-movement-markup dur count context)
+     (markup #:mvt text #:hspace 1
+             #:concat ("(" #:general-align Y DOWN #:smaller #:note duration 1)
+             "="
+             #:concat ((number->string count) ")")))
+  #{
+    \set Score.metronomeMarkFormatter = #$format-movement-markup
+    \set Score.tempoWholesPerMinute = #$(ly:moment-mul (ly:make-moment count 1)
+                                         (ly:duration-length
+                                           (string->duration duration)))
+    \set Score.tempoUnitDuration = #$(string->duration duration)
+    \set Score.tempoUnitCount = $count
+    $music
+    \set Score.metronomeMarkFormatter = #format-metronome-markup
+  #})
 
-#(define (tempoChangeStencil label noteValue tempo)
- (lambda (grob)
-  (tempoChangeMarkupFactory grob label noteValue tempo)
- ))
+\layout { ragged-right = ##f }
 
-tempoChangeMarkup = #(define-music-function (parser location label noteValue tempo) (string? string? string?)
-       #{
-         \once \override Score.MetronomeMark #'stencil = #(tempoChangeStencil $label $noteValue $tempo)
-       #})
-
-\relative c' {
-  \time 4/4
-  \clef treble
-  % initialize the override
-  \tempoChangeMarkup #"Moderato" #"4" #"63"
-  % markup is printed
-  \tempo 4 = 63
-  c4 d e f
-  g a b c
-  \time 6/4
-  \mark \default
-  \tempoChangeMarkup #"presto" #"2." #"90"
-  \tempo 2. = 90
-  c2. g \break
-  e \tempoChangeMarkup #"handling collision with RehearsalMark" #"4" #"120" \tempo 4 = 120 c
-  \time 4/4
-  \mark \default
-  c1
+\relative c' { 
+  \time 3/4
+  \movement "Allegro" "2." #92
+  c2 e4
+  g2.
+  \movement "Moderato" "4" #104
+  f4 e d
+  \tempo 4 = 92
+  c2.
 }