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 (tablature-stem-attachment-function style duration)
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))
41 (define-public (hammer-print-function grob)
42 (let* ((note-collums (ly:grob-property grob 'note-columns))
43 (note-column1 (cadr note-collums))
44 (note-column2 (car note-collums))
45 (note1 (car (ly:grob-property note-column1 'note-heads)))
46 (note2 (car (ly:grob-property note-column2 'note-heads)))
47 (text1 (ly:grob-property note1 'text))
48 (text2 (ly:grob-property note2 'text))
49 (fret1 (if (string? text1) (string->number text1) 0))
50 (fret2 (if (string? text2) (string->number text2) 0))
59 ;; FIXME: a hammer is not a slur.
61 (ly:make-stencil '() '(0 . 0) '(0 . 0)))
62 (layout (ly:grob-layout grob))
63 (text (interpret-markup
65 (ly:grob-alist-chain grob (ly:output-def-lookup layout 'text-font-defaults))
68 (let ((x (/ (- (cdr (ly:stencil-extent slur 0))
69 (/ (cdr (ly:stencil-extent text 0)) 2.0))
73 (ly:make-stencil (ly:stencil-expr text)
75 (ly:stencil-extent text Y)))
77 (ly:stencil-aligned-to text X RIGHT)))))
80 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
81 (define-public bass-tuning '(-17 -22 -27 -32))
83 ;; tunings for 5-string banjo
84 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
85 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
86 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
87 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
88 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
89 ;; convert 5-string banjo tunings to 4-string tunings by
90 ;; removing the 5th string
93 ;; \set TabStaff.stringTunings = #(four-string-banjo banjo-open-g-tuning)
94 (define-public (four-string-banjo tuning)
95 (reverse (cdr (reverse tuning))))
97 ;;; end of tablature functions
99 (define-public (make-stencil-boxer thickness padding callback)
100 "Return function that adds a box around the grob passed as argument."
101 (lambda (grob) (box-stencil (callback grob) thickness padding)))
103 (define-public (make-stencil-circler thickness padding callback)
104 "Return function that adds a circle around the grob passed as argument."
105 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
107 (define-public (arg->string arg)
108 (cond ((number? arg) (ly:inexact->string arg 10))
109 ((string? arg) (string-append "\"" arg "\""))
110 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
112 (define-public (print-circled-text-callback grob)
113 (let* ((text (ly:grob-property grob 'text))
114 (layout (ly:grob-layout grob))
115 (defs (ly:output-def-lookup layout 'text-font-defaults))
116 (props (ly:grob-alist-chain grob defs))
117 (circle (Text_interface::interpret_markup
118 layout props (make-draw-circle-markup 0.8 0.1 #f)))
119 (text-stencil (Text_interface::interpret_markup layout props text)))
121 (ly:stencil-add (centered-stencil text-stencil) circle)))
124 ;;(define (mm-to-pt x)
125 ;; (* (/ 72.27 25.40) x))
127 ;; do nothing in .scm output
129 (define-public (ly:numbers->string lst)
130 (string-join (map ly:number->string lst) " "))
132 (define (number->octal-string x)
133 (let* ((n (inexact->exact x))
134 (n64 (quotient n 64))
135 (n8 (quotient (- n (* n64 64)) 8)))
139 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
141 (define-public (ly:inexact->string x radix)
142 (let ((n (inexact->exact x)))
143 (number->string n radix)))
145 (define-public (ly:number-pair->string c)
146 (string-append (ly:number->string (car c)) " "
147 (ly:number->string (cdr c))))
151 (define-public (find-notehead-symbol duration style)
153 ((xcircle) "2xcircle")
154 ((harmonic) "0harmonic")
156 ;; Oops, I actually would not call this "baroque", but, for
157 ;; backwards compatibility to 1.4, this is supposed to take
158 ;; brevis, longa and maxima from the neo-mensural font and all
159 ;; other note heads from the default font. -- jr
161 (string-append (number->string duration) "neomensural")
162 (number->string duration)))
164 (string-append (number->string duration) (symbol->string style)))
167 (string-append (number->string duration) "mensural")
168 (string-append (number->string duration) (symbol->string style))))
170 (string-append (number->string duration) (symbol->string style)))
172 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
173 ;; neither a longa nor a maxima. Hence let us, for the moment,
174 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
175 ;; should define at least a longa for the default font. The longa
176 ;; should look exactly like the brevis of the default font, but
177 ;; with a stem exactly like that of the quarter note. -- jr
179 (string-append (number->string duration) "neomensural")
180 (number->string duration)))
182 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
183 (symbol->string style)
184 (string-append (number->string (max 0 duration))
185 (symbol->string style))))))
187 ;; TODO junk completely?
188 (define (note-head-style->attachment-coordinates grob axis)
189 "Return pair (X . Y), containing multipliers for the note head
190 bounding box, where to attach the stem. e.g.: X==0 means horizontally
191 centered, X==1 is at the right, X == -1 is at the left."
195 (define-public (string-encode-integer i)
198 ((< i 0) (string-append "n" (string-encode-integer (- i))))
200 (make-string 1 (integer->char (+ 65 (modulo i 26))))
201 (string-encode-integer (quotient i 26))))))
203 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
205 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
207 (define-public ((set-bar-number-visibility n) tr)
208 (let* ((bn (ly:context-property tr 'currentBarNumber)))
209 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
211 (define-public (default-bar-number-visibility barnum) (> barnum 1))
213 ;; See documentation of Item::visibility_lambda_
214 (define-safe-public (begin-of-line-visible d) (if (= d 1) '(#f . #f) '(#t . #t)))
215 (define-safe-public (end-of-line-visible d) (if (= d -1) '(#f . #f) '(#t . #t)))
216 (define-safe-public (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
218 (define-safe-public (all-visible d) '(#f . #f))
219 (define-safe-public (all-invisible d) '(#t . #t))
220 (define-safe-public (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
221 (define-safe-public (center-invisible d) (if (= d 0) '(#t . #t) '(#f . #f)))
222 (define-safe-public (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
229 ;; How should a bar line behave at a break?
231 ;; Why prepend `default-' to every scm identifier?
232 (define-public (default-break-barline glyph dir)
233 (let ((result (assoc glyph
234 '((":|:" . (":|" . "|:"))
235 ("||:" . ("||" . "|:"))
237 ("||:" . ("||" . "|:"))
239 ("|:" . ("|" . "|:"))
242 ;; hmm... should we end with a bar line here?
243 (".|" . ("|" . ".|"))
246 (".|." . (".|." . ()))
249 ("empty" . (() . ()))
250 ("brace" . (() . "brace"))
251 ("bracket" . (() . "bracket")) ))))
253 (if (equal? result #f)
254 (ly:warning (_ "unknown bar glyph: `~S'" glyph))
255 (index-cell (cdr result) dir))))
257 (define-public (shift-right-at-line-begin g)
258 "Shift an item to the right, but only at the start of the line."
259 (if (and (ly:item? g) (equal? (ly:item-break-dir g) RIGHT))
260 (ly:grob-translate-axis! g 3.5 X)))
263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
266 (define-public color? list?)
269 (define-public black '(0.0 0.0 0.0))
270 (define-public white '(1.0 1.0 1.0))
271 (define-public red '(1.0 0.0 0.0))
272 (define-public green '(0.0 1.0 0.0))
273 (define-public blue '(0.0 0.0 1.0))
274 (define-public cyan '(1.0 1.0 0.0))
275 (define-public magenta '(1.0 0.0 1.0))
276 (define-public yellow '(0.0 1.0 1.0))
278 (define-public grey '(0.5 0.5 0.5))
279 (define-public darkred '(0.5 0.0 0.0))
280 (define-public darkgreen '(0.0 0.5 0.0))
281 (define-public darkblue '(0.0 0.0 0.5))
282 (define-public darkcyan '(0.5 0.5 0.0))
283 (define-public darkmagenta '(0.5 0.0 0.5))
284 (define-public darkyellow '(0.0 0.5 0.5))