Musik als Text definieren

Zur Navigation springen Zur Suche springen

Man kann Musikbeispiele als Text („Markup“) definieren, z.B. für Fußnoten, Notationshinweise etc. Es empfiehlt sich, in die \score-Umgebung ein layout-Anweisung einzubauen, da ansonsten die Parameter aus der übergeordneten \paper-Umgebung übernommen werden, was unerwünschte Effekte haben kann. Z.B. dehnt sich eine Fußnote plötzlich über die gesamte Zeilenbreite aus, sobald sie eingebunden wird.

Anwendungsbeispiel

markupupscore=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
    line-width = #55
    ragged-right = ##t
    \context {
      \Score
      \override SpacingSpanner.common-shortest-duration = #(ly:make-moment 1/1)
    }
  }
}
\version "2.22.0"
\language "deutsch"

#(define-markup-command (dashed-full-line layout props)
   ()
   #:category graphic
   #:properties ((thickness 1)
                 (on .4)
                 (off .4)
                 (phase 0)
                 (line-width)
                 (full-length #t))
   ;A dashed line full horizontal width, no parameters
   ;derived from draw-dashed-line

   (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
          (line-width (ly:output-def-lookup layout 'line-width))
          ;; Calculate the thickness to be used.
          (th (* line-thickness thickness))
          (half-thick (/ th 2))
          ;; Get the extensions in x- and y-direction. x=line width, y=0
          (x line-width)
          (y 0)
          ;; Calculate the length of the dashed line.
          (line-length line-width))

     (if (and full-length (not (= (+ on off) 0)))
         (begin
          ;; Add double-thickness to avoid overlapping.
          (set! off (+ (* 2 th) off))
          (let* (;; Make a guess how often the off/on-pair should be printed
                  ;; after the initial `on´.
                  ;; Assume a minimum of 1 to avoid division by zero.
                  (guess (max 1 (round (/ (- line-length on) (+ off on)))))
                  ;; Not sure about the value or why corr is necessary at all,
                  ;; but it seems to be necessary.
                  (corr (if (= on 0)
                            (/ line-thickness 10)
                            0))
                  ;; Calculate a new value for off to fit the
                  ;; line-length.
                  (new-off (/ (- line-length corr (* (1+ guess) on)) guess))
                  )
            (cond

             ;; Settings for (= on 0). Resulting in a dotted line.

             ;; If line-length isn't shorter than `th´, change the given
             ;; value for `off´ to fit the line-length.
             ((and (= on 0) (< th line-length))
              (set! off new-off))

             ;; If the line-length is shorter than `th´, it makes no
             ;; sense to adjust `off´. The rounded edges of the lines
             ;; would prevent any nice output.
             ;; Do nothing.
             ;; This will result in a single dot for very short lines.
             ((and (= on 0) (>= th line-length))
              #f)

             ;; Settings for (not (= on 0)). Resulting in a dashed line.

             ;; If line-length isn't shorter than one go of on-off-on,
             ;; change the given value for `off´ to fit the line-length.
             ((< (+ (* 2 on) off) line-length)
              (set! off new-off))
             ;; If the line-length is too short, but greater than
             ;; (* 4 th) set on/off to (/ line-length 3)
             ((< (* 4 th) line-length)
              (set! on (/ line-length 3))
              (set! off (/ line-length 3)))
             ;; If the line-length is shorter than (* 4 th), it makes
             ;; no sense trying to adjust on/off. The rounded edges of
             ;; the lines would prevent any nice output.
             ;; Simply set `on´ to line-length.
             (else
              (set! on line-length))))))

     ;; If `on´ or `off´ is negative, or the sum of `on' and `off' equals zero a
     ;; ghostscript-error occurs while calling
     ;; (ly:make-stencil (list 'dashed-line th on off x y phase) x-ext y-ext)
     ;; Better be paranoid.
     (if (or (= (+ on off) 0)
             (negative? on)
             (negative? off))
         (begin
          (ly:warning (_ "Can't print a line - setting on/off to default"))
          (set! on 1)
          (set! off 1)))

     ;; To give the lines produced by \draw-line and \draw-dashed-line the same
     ;; length, half-thick has to be added to the stencil-extensions.
     (ly:make-stencil
      (list 'dashed-line th on off x y phase)
      (interval-widen (ordered-cons 0 x) half-thick)
      (interval-widen (ordered-cons 0 y) half-thick))))

\paper {
  evenHeaderMarkup =##f
  oddHeaderMarkup = ##f
  evenFooterMarkup = ##f
  oddFooterMarkup = ##f
  annotate-spacing = ##f
  print-all-headers = ##f
  top-margin = #20
  bottom-margin = #20
  ragged-bottom = ##t
  ragged-last-bottom = ##t
  ragged-right = ##f
  line-width = #165
  indent = #0
  system-system-spacing.padding = #5
  ragged-bottom = ##f
  markup-system-spacing.padding = #4
}

aaa=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
    line-width = #55
    ragged-right = ##f
  }
}

ccc=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
    line-width = #55
    ragged-right = ##t
  }
}

ddd=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
    line-width = #55
    ragged-right = ##t
    \context {
      \Score
      \override SpacingSpanner.common-shortest-duration = #(ly:make-moment 1/1)
    }
  }
}

fff=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
    line-width = #55
    ragged-right = ##f
    \context {
      \Score
      \override SpacingSpanner.common-shortest-duration = #(ly:make-moment 1/1)
    }
  }
}

bbb=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
    line-width = #19
    ragged-right = ##t
  }
}

eee=\markup
\score {
  \new Staff \with {
    \override Clef.stencil = ##f
    \override TimeSignature.stencil = ##f
  }
  \relative c'' {
    e4~^\markup \bold \italic \fontsize #1 "a)" 32 [ d e d c d8 ]
  }
  \layout {
    #(layout-set-staff-size 14)
  }
}

mus = \relative { c''4 c c c }

\score {
  \new StaffGroup
  <<
    \new Staff \repeat unfold 4 \mus
    \new Staff \repeat unfold 4 \transpose c g, \mus
    \new Staff \repeat unfold 4 \transpose c e, \mus
  >>
}

\markup \column { "kein Layout-Statement, line-width wird vom übergeordneten \paper-statment übernommen" \eee }
\markup \draw-hline
\markup \vspace #.5
\markup \column { "Layout-Statements mit unterschiedlichen Parametern" }
\markup \draw-hline
\markup \fill-line { "<--line-width = #55" \aaa "ragged-right = ##f-->" }
\markup \dashed-full-line
\markup \fill-line { "<--line-width = #55" \fff "ragged-right = ##f-->" }
\markup \fill-line { \null "Score.SpacingSpanner.common-shortest-duration = #(ly:make-moment 1/1)" \null }
\markup \dashed-full-line
\markup \fill-line { "<--line-width = #55" \ccc "ragged-right = ##t-->" }
\markup \dashed-full-line
\markup \fill-line { "<--line-width = #55" \ddd "ragged-right = ##t-->" }
\markup \fill-line { \null "Score.SpacingSpanner.common-shortest-duration = #(ly:make-moment 1/1)" \null }
\markup \dashed-full-line
\markup \fill-line { "<--line-width < 20" \bbb "ragged-right = egal-->" }