1 ;;;; output-lib.scm -- implement Scheme output helper functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 ;;; Tablature functions, by Jiba (jiba@tuxfamily.org)
11 ;; The TabNoteHead stem attachment function.
12 (define (note-head::calc-tablature-stem-attachment grob)
15 ;; The TabNoteHead tablatureFormat callback.
16 ;; Compute the text grob-property
17 (define-public (fret-number-tablature-format string tuning pitch)
21 (- (ly:pitch-semitones pitch)
23 ;; remove 1 because list index starts at 0 and guitar string at 1.
26 ;; The 5-string banjo has got a extra string, the fifth (duh), wich
27 ;; starts at the fifth fret on the neck. Frets on the fifth string
28 ;; are referred to relative to the other frets:
29 ;; the "first fret" on the fifth string is really the sixth fret
31 ;; We solve this by defining a new fret-number-tablature function:
32 (define-public (fret-number-tablature-format-banjo string tuning pitch)
35 (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (- string 1)))))
37 ((and (> fret 0) (= string 5))
42 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
43 (define-public bass-tuning '(-17 -22 -27 -32))
45 ;; tunings for 5-string banjo
46 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
47 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
48 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
49 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
50 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
51 ;; convert 5-string banjo tunings to 4-string tunings by
52 ;; removing the 5th string
55 ;; \set TabStaff.stringTunings = #(four-string-banjo banjo-open-g-tuning)
56 (define-public (four-string-banjo tuning)
57 (reverse (cdr (reverse tuning))))
59 ;;; end of tablature functions
61 (define-public (make-stencil-boxer thickness padding callback)
63 "Return function that adds a box around the grob passed as argument."
66 (box-stencil (callback grob) thickness padding)))
68 (define-public (make-stencil-circler thickness padding callback)
69 "Return function that adds a circle around the grob passed as argument."
70 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
72 (define-public (arg->string arg)
73 (cond ((number? arg) (ly:inexact->string arg 10))
74 ((string? arg) (string-append "\"" arg "\""))
75 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
77 (define-public (print-circled-text-callback grob)
78 (let* ((text (ly:grob-property grob 'text))
80 (layout (ly:grob-layout grob))
81 (defs (ly:output-def-lookup layout 'text-font-defaults))
82 (props (ly:grob-alist-chain grob defs))
83 (circle (Text_interface::interpret_markup
84 layout props (make-circle-markup text))))
88 ;;(define (mm-to-pt x)
89 ;; (* (/ 72.27 25.40) x))
91 ;; do nothing in .scm output
93 (define-public (ly:numbers->string lst)
94 (string-join (map ly:number->string lst) " "))
96 (define (number->octal-string x)
97 (let* ((n (inexact->exact x))
99 (n8 (quotient (- n (* n64 64)) 8)))
103 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
105 (define-public (ly:inexact->string x radix)
106 (let ((n (inexact->exact x)))
107 (number->string n radix)))
109 (define-public (ly:number-pair->string c)
110 (string-append (ly:number->string (car c)) " "
111 (ly:number->string (cdr c))))
115 (define-public (note-head::calc-glyph-name grob)
117 ((style (ly:grob-property grob 'style))
118 (log (min 2 (ly:grob-property grob 'duration-log))))
121 ((xcircle) "2xcircle")
122 ((harmonic) "0harmonic")
124 ;; Oops, I actually would not call this "baroque", but, for
125 ;; backwards compatibility to 1.4, this is supposed to take
126 ;; brevis, longa and maxima from the neo-mensural font and all
127 ;; other note heads from the default font. -- jr
129 (string-append (number->string log) "neomensural")
130 (number->string log)))
132 (string-append (number->string log) (symbol->string style)))
135 (string-append (number->string log) "mensural")
136 (string-append (number->string log) (symbol->string style))))
138 (string-append (number->string log) (symbol->string style)))
140 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
141 ;; neither a longa nor a maxima. Hence let us, for the moment,
142 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
143 ;; should define at least a longa for the default font. The longa
144 ;; should look exactly like the brevis of the default font, but
145 ;; with a stem exactly like that of the quarter note. -- jr
147 (string-append (number->string log) "neomensural")
148 (number->string log)))
150 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
151 (symbol->string style)
152 (string-append (number->string (max 0 log))
153 (symbol->string style)))))))
155 ;; TODO junk completely?
156 (define (note-head-style->attachment-coordinates grob axis)
157 "Return pair (X . Y), containing multipliers for the note head
158 bounding box, where to attach the stem. e.g.: X==0 means horizontally
159 centered, X==1 is at the right, X == -1 is at the left."
163 (define-public (string-encode-integer i)
166 ((< i 0) (string-append "n" (string-encode-integer (- i))))
168 (make-string 1 (integer->char (+ 65 (modulo i 26))))
169 (string-encode-integer (quotient i 26))))))
171 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
173 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
175 (define-public ((set-bar-number-visibility n) tr)
176 (let* ((bn (ly:context-property tr 'currentBarNumber)))
177 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
179 (define-public (first-bar-number-invisible barnum) (> barnum 1))
181 ;; See documentation of Item::visibility_lambda_
182 (define-public begin-of-line-visible
184 (define-public end-of-line-visible
186 (define-public end-of-line-invisible
188 (define-public spanbar-begin-of-line-invisible
190 (define-public all-visible #(#t #t #t))
191 (define-public all-invisible #(#f #f #f))
192 (define-public begin-of-line-invisible
194 (define-public center-invisible #(#t #f #t))
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
200 ;; How should a bar line behave at a break?
202 ;; Why prepend `default-' to every scm identifier?
203 (define-public (bar-line::calc-glyph-name grob)
205 (glyph (ly:grob-property grob 'glyph))
206 (dir (ly:item-break-dir grob))
208 '((":|:" . (":|" . "|:"))
209 ("||:" . ("||" . "|:"))
211 ("||:" . ("||" . "|:"))
213 ("|:" . ("|" . "|:"))
216 ;; hmm... should we end with a bar line here?
217 (".|" . ("|" . ".|"))
220 (".|." . (".|." . ()))
224 ("empty" . (() . ()))
225 ("brace" . (() . "brace"))
226 ("bracket" . (() . "bracket")) )))
227 (glyph-name (if (= dir CENTER)
229 (if (and result (string? (index-cell (cdr result) dir)))
230 (index-cell (cdr result) dir)
235 (ly:grob-suicide! grob))
240 (define-public (shift-right-at-line-begin g)
241 "Shift an item to the right, but only at the start of the line."
242 (if (and (ly:item? g)
243 (equal? (ly:item-break-dir g) RIGHT))
244 (ly:grob-translate-axis! g 3.5 X)))
247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250 (define-public color? list?)
253 (define-public black '(0.0 0.0 0.0))
254 (define-public white '(1.0 1.0 1.0))
255 (define-public red '(1.0 0.0 0.0))
256 (define-public green '(0.0 1.0 0.0))
257 (define-public blue '(0.0 0.0 1.0))
258 (define-public cyan '(1.0 1.0 0.0))
259 (define-public magenta '(1.0 0.0 1.0))
260 (define-public yellow '(0.0 1.0 1.0))
262 (define-public grey '(0.5 0.5 0.5))
263 (define-public darkred '(0.5 0.0 0.0))
264 (define-public darkgreen '(0.0 0.5 0.0))
265 (define-public darkblue '(0.0 0.0 0.5))
266 (define-public darkcyan '(0.5 0.5 0.0))
267 (define-public darkmagenta '(0.5 0.0 0.5))
268 (define-public darkyellow '(0.0 0.5 0.5))
270 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
273 (define (parenthesize-elements grob)
275 ((elts (ly:grob-object grob 'elements))
276 (x-ext (ly:relative-group-extent elts grob X))
277 (font (ly:grob-default-font grob))
278 (lp (ly:font-get-glyph font "accidentals.leftparen"))
279 (rp (ly:font-get-glyph font "accidentals.rightparen"))
283 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
284 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
290 (define-public (chain-grob-member-functions grob value . funcs)
293 (set! value (func grob value)))