1 ;;;; output-lib.scm -- implement Scheme output helper functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 (define-public (make-stencil-boxer thickness padding callback)
16 "Return function that adds a box around the grob passed as argument."
19 (box-stencil (callback grob) thickness padding)))
21 (define-public (make-stencil-circler thickness padding callback)
22 "Return function that adds a circle around the grob passed as argument."
24 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
26 (define-public (print-circled-text-callback grob)
27 (let* ((text (ly:grob-property grob 'text))
29 (layout (ly:grob-layout grob))
30 (defs (ly:output-def-lookup layout 'text-font-defaults))
31 (props (ly:grob-alist-chain grob defs))
32 (circle (ly:text-interface::interpret-markup
33 layout props (make-circle-markup text))))
37 (define-public (event-cause grob)
39 ((cause (ly:grob-property grob 'cause)))
42 ((ly:stream-event? cause) cause)
43 ((ly:grob? cause) (event-cause cause))
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 ;; The TabNoteHead tablatureFormat callback.
50 ;; Compute the text grob-property
51 (define-public (fret-number-tablature-format string tuning pitch)
55 (- (ly:pitch-semitones pitch)
57 ;; remove 1 because list index starts at 0 and guitar string at 1.
60 ;; The 5-string banjo has got a extra string, the fifth (duh), wich
61 ;; starts at the fifth fret on the neck. Frets on the fifth string
62 ;; are referred to relative to the other frets:
63 ;; the "first fret" on the fifth string is really the sixth fret
65 ;; We solve this by defining a new fret-number-tablature function:
66 (define-public (fret-number-tablature-format-banjo string tuning pitch)
69 (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (- string 1)))))
71 ((and (> fret 0) (= string 5))
76 ; default tunings for common string instruments
77 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
78 (define-public guitar-open-g-tuning '(2 -1 -5 -10 -17 -22))
79 (define-public bass-tuning '(-17 -22 -27 -32))
80 (define-public mandolin-tuning '(16 9 2 -5))
82 ;; tunings for 5-string banjo
83 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
84 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
85 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
86 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
87 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
88 ;; convert 5-string banjo tuning to 4-string by removing the 5th string
89 (define-public (four-string-banjo tuning)
90 (reverse (cdr (reverse tuning))))
92 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
95 (define-public (note-head::calc-duration-log grob)
97 (ly:event-property (event-cause grob) 'duration)))
99 (define-public (dots::calc-dot-count grob)
100 (ly:duration-dot-count
101 (ly:event-property (event-cause grob) 'duration)))
103 (define (note-head::calc-tablature-stem-attachment grob)
109 (define-public (note-head::calc-glyph-name grob)
111 ((style (ly:grob-property grob 'style))
112 (log (min 2 (ly:grob-property grob 'duration-log))))
115 ((xcircle) "2xcircle")
116 ((harmonic) "0harmonic")
118 ;; Oops, I actually would not call this "baroque", but, for
119 ;; backwards compatibility to 1.4, this is supposed to take
120 ;; brevis, longa and maxima from the neo-mensural font and all
121 ;; other note heads from the default font. -- jr
123 (string-append (number->string log) "neomensural")
124 (number->string log)))
126 (string-append (number->string log) (symbol->string style)))
129 (string-append (number->string log) "mensural")
130 (string-append (number->string log) (symbol->string style))))
132 (string-append (number->string log) (symbol->string style)))
134 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
135 ;; neither a longa nor a maxima. Hence let us, for the moment,
136 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
137 ;; should define at least a longa for the default font. The longa
138 ;; should look exactly like the brevis of the default font, but
139 ;; with a stem exactly like that of the quarter note. -- jr
141 (string-append (number->string log) "neomensural")
142 (number->string log)))
144 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
145 (symbol->string style)
146 (string-append (number->string (max 0 log))
147 (symbol->string style)))))))
149 ;; TODO junk completely?
150 (define (note-head-style->attachment-coordinates grob axis)
151 "Return pair (X . Y), containing multipliers for the note head
152 bounding box, where to attach the stem. e.g.: X==0 means horizontally
153 centered, X==1 is at the right, X == -1 is at the left."
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
163 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
165 (define-public ((set-bar-number-visibility n) tr)
166 (let* ((bn (ly:context-property tr 'currentBarNumber)))
167 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
169 (define-public (first-bar-number-invisible barnum) (> barnum 1))
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 (define-public begin-of-line-visible
176 (define-public end-of-line-visible
178 (define-public end-of-line-invisible
180 (define-public spanbar-begin-of-line-invisible
182 (define-public all-visible #(#t #t #t))
183 (define-public all-invisible #(#f #f #f))
184 (define-public begin-of-line-invisible
186 (define-public center-invisible #(#t #f #t))
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 ;; How should a bar line behave at a break?
194 ;; Why prepend `default-' to every scm identifier?
195 (define-public (bar-line::calc-glyph-name grob)
197 (glyph (ly:grob-property grob 'glyph))
198 (dir (ly:item-break-dir grob))
200 '((":|:" . (":|" . "|:"))
201 ("||:" . ("||" . "|:"))
202 ("dashed" . ("dashed" . '()))
204 ("||:" . ("||" . "|:"))
206 ("|:" . ("|" . "|:"))
209 ;; hmm... should we end with a bar line here?
210 (".|" . ("|" . ".|"))
213 (".|." . (".|." . ()))
217 ("empty" . (() . ()))
218 ("brace" . (() . "brace"))
219 ("bracket" . (() . "bracket")) )))
220 (glyph-name (if (= dir CENTER)
222 (if (and result (string? (index-cell (cdr result) dir)))
223 (index-cell (cdr result) dir)
228 (ly:grob-suicide! grob))
233 (define-public (shift-right-at-line-begin g)
234 "Shift an item to the right, but only at the start of the line."
235 (if (and (ly:item? g)
236 (equal? (ly:item-break-dir g) RIGHT))
237 (ly:grob-translate-axis! g 3.5 X)))
240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243 (define-public (tuplet-number::calc-denominator-text grob)
244 (number->string (ly:event-property (event-cause grob) 'denominator)))
246 (define-public (tuplet-number::calc-fraction-text grob)
248 ((ev (event-cause grob)))
251 (ly:event-property ev 'denominator)
252 (ly:event-property ev 'numerator))))
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 (define-public color? list?)
260 (define-public black '(0.0 0.0 0.0))
261 (define-public white '(1.0 1.0 1.0))
262 (define-public red '(1.0 0.0 0.0))
263 (define-public green '(0.0 1.0 0.0))
264 (define-public blue '(0.0 0.0 1.0))
265 (define-public cyan '(0.0 1.0 1.0))
266 (define-public magenta '(1.0 0.0 1.0))
267 (define-public yellow '(1.0 1.0 0.0))
269 (define-public grey '(0.5 0.5 0.5))
270 (define-public darkred '(0.5 0.0 0.0))
271 (define-public darkgreen '(0.0 0.5 0.0))
272 (define-public darkblue '(0.0 0.0 0.5))
273 (define-public darkcyan '(0.0 0.5 0.5))
274 (define-public darkmagenta '(0.5 0.0 0.5))
275 (define-public darkyellow '(0.5 0.5 0.0))
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 ;; * Pitch Trill Heads
281 (define (parenthesize-elements grob . rest)
283 ((refp (if (null? rest)
286 (elts (ly:grob-object grob 'elements))
287 (x-ext (ly:relative-group-extent elts refp X))
289 (font (ly:grob-default-font grob))
290 (lp (ly:font-get-glyph font "accidentals.leftparen"))
291 (rp (ly:font-get-glyph font "accidentals.rightparen"))
292 (padding (ly:grob-property grob 'padding 0.1)))
295 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
296 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
300 (define (parentheses-item::print me)
302 ((elts (ly:grob-object me 'elements))
303 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
304 (x-ref (ly:grob-common-refpoint-of-array me elts X))
305 (stencil (parenthesize-elements me x-ref))
306 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
307 (y-center (interval-center elt-y-ext)))
309 (ly:stencil-translate
313 (ly:grob-relative-coordinate me x-ref X))
316 (ly:grob-relative-coordinate me y-ref Y))))
322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325 (define-public (chain-grob-member-functions grob value . funcs)
328 (set! value (func grob value)))
333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
336 (define-public (fall::print spanner)
338 ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
339 (left-span (ly:spanner-bound spanner LEFT))
340 (right-span (ly:spanner-bound spanner RIGHT))
341 (thickness (* (ly:grob-property spanner 'thickness)
342 (ly:output-def-lookup (ly:grob-layout spanner)
344 (padding (ly:grob-property spanner 'padding 0.5))
345 (common (ly:grob-common-refpoint right-span
346 (ly:grob-common-refpoint spanner
349 (left-x (+ padding (interval-end (ly:grob-robust-relative-extent left-span common X))))
350 (right-x (- (interval-start (ly:grob-robust-relative-extent right-span common X)) padding))
351 (self-x (ly:grob-relative-coordinate spanner common X))
352 (dx (- right-x left-x))
353 (exp (list 'path thickness
361 ,dx ,(* 0.66 delta-y)
369 (cons (min 0 delta-y)
372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376 (define-public (grace-spacing::calc-shortest-duration grob)
378 ((cols (ly:grob-object grob 'columns))
381 (ly:moment-sub (ly:grob-property (ly:grob-array-ref cols (1+ idx)) 'when)
382 (ly:grob-property (ly:grob-array-ref cols idx) 'when))))
384 (moment-min (lambda (x y)
387 (if (ly:moment<? x y)
393 (fold moment-min #f (map get-difference
394 (iota (1- (ly:grob-array-length cols)))))))
398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
401 (define-public (fingering::calc-text grob)
403 ((event (event-cause grob))
404 (digit (ly:event-property event 'digit)))
407 (ly:input-message (ly:music-property event 'origin)
408 "Music for the martians"))
410 (number->string digit 10)
413 (define-public (string-number::calc-text grob)
415 ((digit (ly:event-property (event-cause grob) 'string-number)))
417 (number->string digit 10)
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
422 (define-public (hairpin::calc-grow-direction grob)
423 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)