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))
79 (layout (ly:grob-layout grob))
80 (defs (ly:output-def-lookup layout 'text-font-defaults))
81 (props (ly:grob-alist-chain grob defs))
82 (circle (Text_interface::interpret_markup
83 layout props (make-draw-circle-markup 0.8 0.1 #f)))
84 (text-stencil (Text_interface::interpret_markup layout props text)))
86 (ly:stencil-add (centered-stencil text-stencil) circle)))
89 ;;(define (mm-to-pt x)
90 ;; (* (/ 72.27 25.40) x))
92 ;; do nothing in .scm output
94 (define-public (ly:numbers->string lst)
95 (string-join (map ly:number->string lst) " "))
97 (define (number->octal-string x)
98 (let* ((n (inexact->exact x))
100 (n8 (quotient (- n (* n64 64)) 8)))
104 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
106 (define-public (ly:inexact->string x radix)
107 (let ((n (inexact->exact x)))
108 (number->string n radix)))
110 (define-public (ly:number-pair->string c)
111 (string-append (ly:number->string (car c)) " "
112 (ly:number->string (cdr c))))
116 (define-public (note-head::calc-glyph-name grob)
118 ((style (ly:grob-property grob 'style))
119 (log (min 2 (ly:grob-property grob 'duration-log))))
122 ((xcircle) "2xcircle")
123 ((harmonic) "0harmonic")
125 ;; Oops, I actually would not call this "baroque", but, for
126 ;; backwards compatibility to 1.4, this is supposed to take
127 ;; brevis, longa and maxima from the neo-mensural font and all
128 ;; other note heads from the default font. -- jr
130 (string-append (number->string log) "neomensural")
131 (number->string log)))
133 (string-append (number->string log) (symbol->string style)))
136 (string-append (number->string log) "mensural")
137 (string-append (number->string log) (symbol->string style))))
139 (string-append (number->string log) (symbol->string style)))
141 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
142 ;; neither a longa nor a maxima. Hence let us, for the moment,
143 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
144 ;; should define at least a longa for the default font. The longa
145 ;; should look exactly like the brevis of the default font, but
146 ;; with a stem exactly like that of the quarter note. -- jr
148 (string-append (number->string log) "neomensural")
149 (number->string log)))
151 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
152 (symbol->string style)
153 (string-append (number->string (max 0 log))
154 (symbol->string style)))))))
156 ;; TODO junk completely?
157 (define (note-head-style->attachment-coordinates grob axis)
158 "Return pair (X . Y), containing multipliers for the note head
159 bounding box, where to attach the stem. e.g.: X==0 means horizontally
160 centered, X==1 is at the right, X == -1 is at the left."
164 (define-public (string-encode-integer i)
167 ((< i 0) (string-append "n" (string-encode-integer (- i))))
169 (make-string 1 (integer->char (+ 65 (modulo i 26))))
170 (string-encode-integer (quotient i 26))))))
172 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
174 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
176 (define-public ((set-bar-number-visibility n) tr)
177 (let* ((bn (ly:context-property tr 'currentBarNumber)))
178 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
180 (define-public (first-bar-number-invisible barnum) (> barnum 1))
182 ;; See documentation of Item::visibility_lambda_
183 (define-public begin-of-line-visible
185 (define-public end-of-line-visible
187 (define-public end-of-line-invisible
189 (define-public spanbar-begin-of-line-invisible
191 (define-public all-visible #(#t #t #t))
192 (define-public all-invisible #(#f #f #f))
193 (define-public begin-of-line-invisible
195 (define-public center-invisible #(#t #f #t))
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
201 ;; How should a bar line behave at a break?
203 ;; Why prepend `default-' to every scm identifier?
204 (define-public (bar-line::calc-glyph-name grob)
206 (glyph (ly:grob-property grob 'glyph))
207 (dir (ly:item-break-dir grob))
209 '((":|:" . (":|" . "|:"))
210 ("||:" . ("||" . "|:"))
212 ("||:" . ("||" . "|:"))
214 ("|:" . ("|" . "|:"))
217 ;; hmm... should we end with a bar line here?
218 (".|" . ("|" . ".|"))
221 (".|." . (".|." . ()))
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 (set! (ly:grob-property grob 'glyph-name) glyph-name)
236 (ly:grob-suicide! grob))))
239 (define-public (shift-right-at-line-begin g)
240 "Shift an item to the right, but only at the start of the line."
241 (if (and (ly:item? g)
242 (equal? (ly:item-break-dir g) RIGHT))
243 (ly:grob-translate-axis! g 3.5 X)))
246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 (define-public color? list?)
252 (define-public black '(0.0 0.0 0.0))
253 (define-public white '(1.0 1.0 1.0))
254 (define-public red '(1.0 0.0 0.0))
255 (define-public green '(0.0 1.0 0.0))
256 (define-public blue '(0.0 0.0 1.0))
257 (define-public cyan '(1.0 1.0 0.0))
258 (define-public magenta '(1.0 0.0 1.0))
259 (define-public yellow '(0.0 1.0 1.0))
261 (define-public grey '(0.5 0.5 0.5))
262 (define-public darkred '(0.5 0.0 0.0))
263 (define-public darkgreen '(0.0 0.5 0.0))
264 (define-public darkblue '(0.0 0.0 0.5))
265 (define-public darkcyan '(0.5 0.5 0.0))
266 (define-public darkmagenta '(0.5 0.0 0.5))
267 (define-public darkyellow '(0.0 0.5 0.5))
269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
272 (define (parenthesize-elements grob)
274 ((elts (ly:grob-object grob 'elements))
275 (x-ext (ly:relative-group-extent elts grob X))
276 (font (ly:grob-default-font grob))
277 (lp (ly:font-get-glyph font "accidentals.leftparen"))
278 (rp (ly:font-get-glyph font "accidentals.rightparen"))
282 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
283 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))