]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/incipit.ly
1d5de3a04b770b50bdb3b7551b0342523d79b53f
[lilypond.git] / input / regression / incipit.ly
1 \version "2.14.0"
2
3 \header {
4   texidoc = "Incipits can be printed using an @code{InstrumentName}
5 grob."
6 }
7
8 %% to prevent warnings/programming errors:
9 #(begin
10    (set-object-property! 'music 'backend-type? ly:music?)
11    (set-object-property! 'music 'backend-doc "Incipit music")
12    (ly:add-interface 'incipit-interface "An incipit." '(music))
13    (let* ((instrument-def (assoc 'InstrumentName all-grob-descriptions))
14           (meta-def (assoc 'meta (cdr instrument-def)))
15           (interfaces-def (assoc 'interfaces (cdr meta-def)))
16           (interfaces (cdr interfaces-def)))
17      (set-cdr! interfaces-def (cons 'incipit-interface interfaces))))
18
19 \score {
20   \new Staff {
21     %% All this would be shortcuted by an appropriate music function:
22     \override Staff.InstrumentName #'music = ##{ \clef "petrucci-c1" c'4 d' e' f' #}
23     \override Staff.InstrumentName #'self-alignment-X = #RIGHT
24     \override Staff.InstrumentName #'padding = #0
25     \override Staff.InstrumentName #'stencil =
26       #(lambda (grob)
27          (let* ((instrument-name (ly:grob-property grob 'long-text))
28                 (layout (ly:output-def-clone (ly:grob-layout grob)))
29                 (music (make-sequential-music
30                         (list (context-spec-music
31                                (make-sequential-music
32                                 (list (make-property-set
33                                        'instrumentName instrument-name)
34                                       (make-grob-property-set
35                                        'VerticalAxisGroup
36                                        'Y-extent '(-4 . 4))))
37                                'MensuralStaff)
38                               (ly:grob-property grob 'music))))
39                 (score (ly:make-score music))
40                 (mm (ly:output-def-lookup layout 'mm))
41                 (indent (ly:output-def-lookup layout 'indent))
42                 (incipit-width (ly:output-def-lookup layout 'incipit-width))
43                 (scaled-incipit-width (if (number? incipit-width)
44                                           (* incipit-width mm)
45                                           (* indent 0.5))))
46            (ly:output-def-set-variable! layout 'indent (- indent scaled-incipit-width))
47            (ly:output-def-set-variable! layout 'line-width indent)
48            (ly:output-def-set-variable! layout 'ragged-right #f)
49            (ly:score-add-output-def! score layout)
50            (set! (ly:grob-property grob 'long-text)
51                  (markup #:score score))
52            (system-start-text::print grob)))
53
54     %% the instrument name definition is separated:
55     \set Staff.instrumentName = #"Instrument"
56     c'4 d' e' f'
57     g'1
58   }
59   \layout {
60     indent = 5\cm
61     incipit-width = 3\cm
62   }
63 }