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)
19 (- (ly:pitch-semitones pitch)
21 ;; remove 1 because list index starts at 0 and guitar string at 1.
24 ;; The 5-string banjo has got a extra string, the fifth (duh), wich
25 ;; starts at the fifth fret on the neck. Frets on the fifth string
26 ;; are referred to relative to the other frets:
27 ;; the "first fret" on the fifth string is really the sixth fret
29 ;; We solve this by defining a new fret-number-tablature function:
30 (define-public (fret-number-tablature-format-banjo string tuning pitch)
31 (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (- string 1)))))
33 ((and (> fret 0) (= string 5))
37 (define-public (hammer-print-function grob)
38 (let* ((note-collums (ly:grob-property grob 'note-columns))
39 (note-column1 (cadr note-collums))
40 (note-column2 (car note-collums))
41 (note1 (car (ly:grob-property note-column1 'note-heads)))
42 (note2 (car (ly:grob-property note-column2 'note-heads)))
43 (text1 (ly:grob-property note1 'text))
44 (text2 (ly:grob-property note2 'text))
45 (fret1 (if (string? text1) (string->number text1) 0))
46 (fret2 (if (string? text2) (string->number text2) 0))
55 ;; FIXME: a hammer is not a slur.
57 (ly:make-stencil '() '(0 . 0) '(0 . 0)))
58 (layout (ly:grob-layout grob))
59 (text (interpret-markup
61 (ly:grob-alist-chain grob (ly:output-def-lookup layout 'text-font-defaults))
64 (let ((x (/ (- (cdr (ly:stencil-extent slur 0))
65 (/ (cdr (ly:stencil-extent text 0)) 2.0))
69 (ly:make-stencil (ly:stencil-expr text)
71 (ly:stencil-extent text Y)))
73 (ly:stencil-aligned-to text X RIGHT)))))
76 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
77 (define-public bass-tuning '(-17 -22 -27 -32))
79 ;; tunings for 5-string banjo
80 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
81 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
82 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
83 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
84 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
85 ;; convert 5-string banjo tunings to 4-string tunings by
86 ;; removing the 5th string
89 ;; \set TabStaff.stringTunings = #(four-string-banjo banjo-open-g-tuning)
90 (define-public (four-string-banjo tuning)
91 (reverse (cdr (reverse tuning))))
93 ;;; end of tablature functions
95 (define-public (make-stencil-boxer thickness padding callback)
96 "Return function that adds a box around the grob passed as argument."
97 (lambda (grob) (box-stencil (callback grob) thickness padding)))
99 (define-public (make-stencil-circler thickness padding callback)
100 "Return function that adds a circle around the grob passed as argument."
101 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
103 (define-public (arg->string arg)
104 (cond ((number? arg) (ly:inexact->string arg 10))
105 ((string? arg) (string-append "\"" arg "\""))
106 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
108 (define-public (print-circled-text-callback grob)
109 (let* ((text (ly:grob-property grob 'text))
110 (layout (ly:grob-layout grob))
111 (defs (ly:output-def-lookup layout 'text-font-defaults))
112 (props (ly:grob-alist-chain grob defs))
113 (circle (Text_interface::interpret_markup
114 layout props (make-draw-circle-markup 0.8 0.1 #f)))
115 (text-stencil (Text_interface::interpret_markup layout props text)))
117 (ly:stencil-add (centered-stencil text-stencil) circle)))
120 ;;(define (mm-to-pt x)
121 ;; (* (/ 72.27 25.40) x))
123 ;; do nothing in .scm output
125 (define-public (ly:numbers->string lst)
126 (string-join (map ly:number->string lst) " "))
128 (define (number->octal-string x)
129 (let* ((n (inexact->exact x))
130 (n64 (quotient n 64))
131 (n8 (quotient (- n (* n64 64)) 8)))
135 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
137 (define-public (ly:inexact->string x radix)
138 (let ((n (inexact->exact x)))
139 (number->string n radix)))
141 (define-public (ly:number-pair->string c)
142 (string-append (ly:number->string (car c)) " "
143 (ly:number->string (cdr c))))
147 (define-public (find-notehead-symbol duration style)
149 ((xcircle) "2xcircle")
150 ((harmonic) "0harmonic")
152 ;; Oops, I actually would not call this "baroque", but, for
153 ;; backwards compatibility to 1.4, this is supposed to take
154 ;; brevis, longa and maxima from the neo-mensural font and all
155 ;; other note heads from the default font. -- jr
157 (string-append (number->string duration) "neomensural")
158 (number->string duration)))
160 (string-append (number->string duration) (symbol->string style)))
162 (string-append (number->string duration) (symbol->string style)))
164 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
165 ;; neither a longa nor a maxima. Hence let us, for the moment,
166 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
167 ;; should define at least a longa for the default font. The longa
168 ;; should look exactly like the brevis of the default font, but
169 ;; with a stem exactly like that of the quarter note. -- jr
171 (string-append (number->string duration) "neomensural")
172 (number->string duration)))
174 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
175 (symbol->string style)
176 (string-append (number->string (max 0 duration))
177 (symbol->string style))))))
179 ;; TODO junk completely?
180 (define (note-head-style->attachment-coordinates grob axis)
181 "Return pair (X . Y), containing multipliers for the note head
182 bounding box, where to attach the stem. e.g.: X==0 means horizontally
183 centered, X==1 is at the right, X == -1 is at the left."
187 (define-public (string-encode-integer i)
190 ((< i 0) (string-append "n" (string-encode-integer (- i))))
192 (make-string 1 (integer->char (+ 65 (modulo i 26))))
193 (string-encode-integer (quotient i 26))))))
195 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
197 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
199 (define-public ((set-bar-number-visibility n) tr)
200 (let* ((bn (ly:context-property tr 'currentBarNumber)))
201 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
203 (define-public (default-bar-number-visibility barnum) (> barnum 1))
205 ;; See documentation of Item::visibility_lambda_
206 (define-safe-public (begin-of-line-visible d) (if (= d 1) '(#f . #f) '(#t . #t)))
207 (define-safe-public (end-of-line-visible d) (if (= d -1) '(#f . #f) '(#t . #t)))
208 (define-safe-public (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
210 (define-safe-public (all-visible d) '(#f . #f))
211 (define-safe-public (all-invisible d) '(#t . #t))
212 (define-safe-public (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
213 (define-safe-public (center-invisible d) (if (= d 0) '(#t . #t) '(#f . #f)))
214 (define-safe-public (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
221 ;; How should a bar line behave at a break?
223 ;; Why prepend `default-' to every scm identifier?
224 (define-public (default-break-barline glyph dir)
225 (let ((result (assoc glyph
226 '((":|:" . (":|" . "|:"))
227 ("||:" . ("||" . "|:"))
229 ("||:" . ("||" . "|:"))
231 ("|:" . ("|" . "|:"))
234 ;; hmm... should we end with a bar line here?
235 (".|" . ("|" . ".|"))
238 (".|." . (".|." . ()))
241 ("empty" . (() . ()))
242 ("brace" . (() . "brace"))
243 ("bracket" . (() . "bracket")) ))))
245 (if (equal? result #f)
246 (ly:warning (_ "unknown bar glyph: `~S'" glyph))
247 (index-cell (cdr result) dir))))
249 (define-public (shift-right-at-line-begin g)
250 "Shift an item to the right, but only at the start of the line."
251 (if (and (ly:item? g) (equal? (ly:item-break-dir g) RIGHT))
252 (ly:grob-translate-axis! g 3.5 X)))
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
258 (define-public color? list?)
261 (define-public black '(0.0 0.0 0.0))
262 (define-public white '(1.0 1.0 1.0))
263 (define-public red '(1.0 0.0 0.0))
264 (define-public green '(0.0 1.0 0.0))
265 (define-public blue '(0.0 0.0 1.0))
266 (define-public cyan '(1.0 1.0 0.0))
267 (define-public magenta '(1.0 0.0 1.0))
268 (define-public yellow '(0.0 1.0 1.0))
270 (define-public grey '(0.5 0.5 0.5))
271 (define-public darkred '(0.5 0.0 0.0))
272 (define-public darkgreen '(0.0 0.5 0.0))
273 (define-public darkblue '(0.0 0.0 0.5))
274 (define-public darkcyan '(0.5 0.5 0.0))
275 (define-public darkmagenta '(0.5 0.0 0.5))
276 (define-public darkyellow '(0.0 0.5 0.5))