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@cs.uu.nl>
10 (define-public (event-cause grob)
12 ((cause (ly:grob-property grob 'cause)))
15 ((ly:stream-event? cause) cause)
16 ((ly:grob? cause) (event-cause cause))
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 (define-public (note-head::calc-duration-log grob)
24 (ly:event-property (event-cause grob) 'duration)))
26 (define-public (dots::calc-dot-count grob)
27 (ly:duration-dot-count
28 (ly:event-property (event-cause grob) 'duration)))
30 ;; The TabNoteHead stem attachment function.
31 (define (note-head::calc-tablature-stem-attachment grob)
34 ;; The TabNoteHead tablatureFormat callback.
35 ;; Compute the text grob-property
36 (define-public (fret-number-tablature-format string tuning pitch)
40 (- (ly:pitch-semitones pitch)
42 ;; remove 1 because list index starts at 0 and guitar string at 1.
45 ;; The 5-string banjo has got a extra string, the fifth (duh), wich
46 ;; starts at the fifth fret on the neck. Frets on the fifth string
47 ;; are referred to relative to the other frets:
48 ;; the "first fret" on the fifth string is really the sixth fret
50 ;; We solve this by defining a new fret-number-tablature function:
51 (define-public (fret-number-tablature-format-banjo string tuning pitch)
54 (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (- string 1)))))
56 ((and (> fret 0) (= string 5))
61 ; default tunings for common string instruments
62 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
63 (define-public guitar-open-g-tuning '(2 -1 -5 -10 -17 -22))
64 (define-public bass-tuning '(-17 -22 -27 -32))
65 (define-public mandolin-tuning '(16 9 2 -5))
67 ;; tunings for 5-string banjo
68 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
69 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
70 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
71 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
72 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
73 ;; convert 5-string banjo tuning to 4-string by removing the 5th string
74 (define-public (four-string-banjo tuning)
75 (reverse (cdr (reverse tuning))))
77 ;;; end of tablature functions
79 (define-public (make-stencil-boxer thickness padding callback)
81 "Return function that adds a box around the grob passed as argument."
84 (box-stencil (callback grob) thickness padding)))
86 (define-public (make-stencil-circler thickness padding callback)
87 "Return function that adds a circle around the grob passed as argument."
88 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
90 (define-public (arg->string arg)
91 (cond ((number? arg) (ly:inexact->string arg 10))
92 ((string? arg) (string-append "\"" arg "\""))
93 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
95 (define-public (print-circled-text-callback grob)
96 (let* ((text (ly:grob-property grob 'text))
98 (layout (ly:grob-layout grob))
99 (defs (ly:output-def-lookup layout 'text-font-defaults))
100 (props (ly:grob-alist-chain grob defs))
101 (circle (ly:text-interface::interpret-markup
102 layout props (make-circle-markup text))))
106 (define-public (note-head::calc-glyph-name grob)
108 ((style (ly:grob-property grob 'style))
109 (log (min 2 (ly:grob-property grob 'duration-log))))
112 ((xcircle) "2xcircle")
113 ((harmonic) "0harmonic")
115 ;; Oops, I actually would not call this "baroque", but, for
116 ;; backwards compatibility to 1.4, this is supposed to take
117 ;; brevis, longa and maxima from the neo-mensural font and all
118 ;; other note heads from the default font. -- jr
120 (string-append (number->string log) "neomensural")
121 (number->string log)))
123 (string-append (number->string log) (symbol->string style)))
126 (string-append (number->string log) "mensural")
127 (string-append (number->string log) (symbol->string style))))
129 (string-append (number->string log) (symbol->string style)))
131 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
132 ;; neither a longa nor a maxima. Hence let us, for the moment,
133 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
134 ;; should define at least a longa for the default font. The longa
135 ;; should look exactly like the brevis of the default font, but
136 ;; with a stem exactly like that of the quarter note. -- jr
138 (string-append (number->string log) "neomensural")
139 (number->string log)))
141 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
142 (symbol->string style)
143 (string-append (number->string (max 0 log))
144 (symbol->string style)))))))
146 ;; TODO junk completely?
147 (define (note-head-style->attachment-coordinates grob axis)
148 "Return pair (X . Y), containing multipliers for the note head
149 bounding box, where to attach the stem. e.g.: X==0 means horizontally
150 centered, X==1 is at the right, X == -1 is at the left."
154 (define-public (string-encode-integer i)
157 ((< i 0) (string-append "n" (string-encode-integer (- i))))
159 (make-string 1 (integer->char (+ 65 (modulo i 26))))
160 (string-encode-integer (quotient i 26))))))
162 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
164 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
166 (define-public ((set-bar-number-visibility n) tr)
167 (let* ((bn (ly:context-property tr 'currentBarNumber)))
168 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
170 (define-public (first-bar-number-invisible barnum) (> barnum 1))
172 ;; See documentation of ly:item::visibility-lambda-
173 (define-public begin-of-line-visible
175 (define-public end-of-line-visible
177 (define-public end-of-line-invisible
179 (define-public spanbar-begin-of-line-invisible
181 (define-public all-visible #(#t #t #t))
182 (define-public all-invisible #(#f #f #f))
183 (define-public begin-of-line-invisible
185 (define-public center-invisible #(#t #f #t))
187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191 ;; How should a bar line behave at a break?
193 ;; Why prepend `default-' to every scm identifier?
194 (define-public (bar-line::calc-glyph-name grob)
196 (glyph (ly:grob-property grob 'glyph))
197 (dir (ly:item-break-dir grob))
199 '((":|:" . (":|" . "|:"))
200 ("||:" . ("||" . "|:"))
201 ("dashed" . ("dashed" . '()))
203 ("||:" . ("||" . "|:"))
205 ("|:" . ("|" . "|:"))
208 ;; hmm... should we end with a bar line here?
209 (".|" . ("|" . ".|"))
212 (".|." . (".|." . ()))
216 ("empty" . (() . ()))
217 ("brace" . (() . "brace"))
218 ("bracket" . (() . "bracket")) )))
219 (glyph-name (if (= dir CENTER)
221 (if (and result (string? (index-cell (cdr result) dir)))
222 (index-cell (cdr result) dir)
227 (ly:grob-suicide! grob))
232 (define-public (shift-right-at-line-begin g)
233 "Shift an item to the right, but only at the start of the line."
234 (if (and (ly:item? g)
235 (equal? (ly:item-break-dir g) RIGHT))
236 (ly:grob-translate-axis! g 3.5 X)))
239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
242 (define-public (tuplet-number::calc-denominator-text grob)
244 ((ev (ly:grob-property grob 'cause)))
246 (number->string (ly:event-property ev 'denominator))))
249 (define-public (tuplet-number::calc-fraction-text grob)
251 ((ev (ly:grob-property grob 'cause)))
253 (ly:event-property ev 'denominator)
254 (ly:event-property ev 'numerator))))
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259 (define-public color? list?)
262 (define-public black '(0.0 0.0 0.0))
263 (define-public white '(1.0 1.0 1.0))
264 (define-public red '(1.0 0.0 0.0))
265 (define-public green '(0.0 1.0 0.0))
266 (define-public blue '(0.0 0.0 1.0))
267 (define-public cyan '(0.0 1.0 1.0))
268 (define-public magenta '(1.0 0.0 1.0))
269 (define-public yellow '(1.0 1.0 0.0))
271 (define-public grey '(0.5 0.5 0.5))
272 (define-public darkred '(0.5 0.0 0.0))
273 (define-public darkgreen '(0.0 0.5 0.0))
274 (define-public darkblue '(0.0 0.0 0.5))
275 (define-public darkcyan '(0.0 0.5 0.5))
276 (define-public darkmagenta '(0.5 0.0 0.5))
277 (define-public darkyellow '(0.5 0.5 0.0))
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
280 ;; * Pitch Trill Heads
283 (define (parenthesize-elements grob . rest)
285 ((refp (if (null? rest)
288 (elts (ly:grob-object grob 'elements))
289 (x-ext (ly:relative-group-extent elts refp X))
291 (font (ly:grob-default-font grob))
292 (lp (ly:font-get-glyph font "accidentals.leftparen"))
293 (rp (ly:font-get-glyph font "accidentals.rightparen"))
294 (padding (ly:grob-property grob 'padding 0.1)))
297 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
298 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
302 (define (parentheses-item::print me)
304 ((elts (ly:grob-object me 'elements))
305 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
306 (x-ref (ly:grob-common-refpoint-of-array me elts X))
307 (stencil (parenthesize-elements me x-ref))
308 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
309 (y-center (interval-center elt-y-ext)))
311 (ly:stencil-translate
315 (ly:grob-relative-coordinate me x-ref X))
318 (ly:grob-relative-coordinate me y-ref Y))))
324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327 (define-public (chain-grob-member-functions grob value . funcs)
330 (set! value (func grob value)))
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
338 (define-public (fall::print spanner)
340 ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
341 (left-span (ly:spanner-bound spanner LEFT))
342 (right-span (ly:spanner-bound spanner RIGHT))
343 (thickness (* (ly:grob-property spanner 'thickness)
344 (ly:output-def-lookup (ly:grob-layout spanner)
346 (padding (ly:grob-property spanner 'padding 0.5))
347 (common (ly:grob-common-refpoint right-span
348 (ly:grob-common-refpoint spanner
351 (left-x (+ padding (interval-end (ly:grob-robust-relative-extent left-span common X))))
352 (right-x (- (interval-start (ly:grob-robust-relative-extent right-span common X)) padding))
353 (self-x (ly:grob-relative-coordinate spanner common X))
354 (dx (- right-x left-x))
355 (exp (list 'path thickness
363 ,dx ,(* 0.66 delta-y)
371 (cons (min 0 delta-y)
374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378 (define-public (grace-spacing::calc-shortest-duration grob)
380 ((cols (ly:grob-object grob 'columns))
383 (ly:moment-sub (ly:grob-property (ly:grob-array-ref cols (1+ idx)) 'when)
384 (ly:grob-property (ly:grob-array-ref cols idx) 'when))))
386 (moment-min (lambda (x y)
389 (if (ly:moment<? x y)
395 (fold moment-min #f (map get-difference
396 (iota (1- (ly:grob-array-length cols)))))))
400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
403 (define-public (fingering::calc-text grob)
405 ((event (ly:grob-property grob 'cause))
406 (digit (ly:event-property event 'digit)))
409 (ly:input-message (ly:music-property event 'origin)
410 "Music for the martians"))
412 (number->string digit 10)
415 (define-public (string-number::calc-text grob)
417 ((event (ly:grob-property grob 'cause))
418 (digit (ly:event-property event 'string-number)))
420 (number->string digit 10)