1 ;;;; output-lib.scm -- implement Scheme output helper functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 ; Tablature functions, by Jiba (jiba@tuxfamily.org)
10 ; The TabNoteHead stem attachment function.
11 (define (tablature-stem-attachment-function style duration)
12 (cons 0.0 0.5) ;; UGH!
15 ; The TabNoteHead molecule callback.
16 ; Create a text molecule
17 (define-public (tablature-molecule-callback grob)
18 (let ((molecule (fontify-text
19 (ly-get-default-font grob)
20 (ly-get-grob-property grob 'text)
22 molecule ; return the molecule.
26 ; The TabNoteHead tablatureFormat callback.
27 ; Compute the text grob-property
28 (define-public (fret-number-tablature-format string tuning pitch)
30 (- (pitch-semitones pitch)
32 (- string 1) ; remove 1 because list index starts at 0 and guitar string at 1.
38 (define-public (hammer-molecule-callback grob)
39 (let* ((note-collums (ly-get-grob-property grob 'note-columns))
40 (note-column1 (cadr note-collums))
41 (note-column2 (car note-collums))
42 (note1 (car (ly-get-grob-property note-column1 'note-heads)))
43 (note2 (car (ly-get-grob-property note-column2 'note-heads)))
44 (fret1 (string->number (ly-get-grob-property note1 'text)))
45 (fret2 (string->number (ly-get-grob-property note2 'text)))
46 (letter (if (< fret1 fret2) "H"
47 (if (> fret1 fret2) "P"
50 (let ((slur (Slur::brew_molecule grob))
51 (text (fontify-text (ly-get-default-font grob) letter)))
53 (let ((x (/ (- (cdr (ly-get-molecule-extent slur 0))
54 (/ (cdr (ly-get-molecule-extent text 0)) 2.0)
58 (ly-set-molecule-extent! text 0 (cons x x))
59 (ly-align-to! text 0 1)
62 (ly-combine-molecule-at-edge slur 1 1 text -0.6)
69 (define-public guitar-tunings '(4 -1 -5 -10 -15 -20))
71 ; end of tablature functions
74 (define-public (make-molecule-boxer line-thick x-padding y-padding callback)
75 "Makes a routine that adds a box around the grob parsed as argument"
76 (define (molecule-boxer grob)
80 (x-ext (widen-interval (ly-get-molecule-extent mol 0) x-padding))
81 (y-ext (widen-interval (ly-get-molecule-extent mol 1) y-padding))
82 (x-rule (box-molecule (widen-interval x-ext line-thick)
84 (y-rule (box-molecule (cons 0 line-thick) y-ext))
87 (set! mol (ly-combine-molecule-at-edge mol 0 1 y-rule x-padding))
88 (set! mol (ly-combine-molecule-at-edge mol 0 -1 y-rule x-padding))
89 (set! mol (ly-combine-molecule-at-edge mol 1 1 x-rule 0))
90 (set! mol (ly-combine-molecule-at-edge mol 1 -1 x-rule 0))
97 ;;(define (mm-to-pt x)
98 ;; (* (/ 72.27 25.40) x))
100 ;; do nothing in .scm output
101 (define (comment s) "")
103 (define-public (numbers->string l)
104 (apply string-append (map ly-number->string l)))
106 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
108 (define (number->octal-string x)
109 (let* ((n (inexact->exact x))
110 (n64 (quotient n 64))
111 (n8 (quotient (- n (* n64 64)) 8)))
115 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
117 (define-public (inexact->string x radix)
118 (let ((n (inexact->exact x)))
119 (number->string n radix)))
122 (define-public (number-pair->string c)
123 (string-append (number->string (car c)) " "
124 (number->string (cdr c)) " "))
129 (make-string 1 (integer->char (+ (char->integer #\A) i)))))
131 (define (scm-scm action-name)
136 (define-public (find-notehead-symbol duration style)
138 ((xcircle) "2xcircle")
139 ((harmonic) "0neo_mensural")
141 ;; Oops, I actually would not call this "baroque", but, for
142 ;; backwards compatibility to 1.4, this is supposed to take
143 ;; brevis, longa and maxima from the neo-mensural font and all
144 ;; other note heads from the default font. -- jr
146 (string-append (number->string duration) "neo_mensural")
147 (number->string duration)))
149 (string-append (number->string duration) (symbol->string style)))
151 (string-append (number->string duration) (symbol->string style)))
153 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
154 ;; neither a longa nor a maxima. Hence let us, for the moment,
155 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
156 ;; should define at least a longa for the default font. The longa
157 ;; should look exactly like the brevis of the default font, but
158 ;; with a stem exactly like that of the quarter note. -- jr
160 (string-append (number->string duration) "neo_mensural")
161 (number->string duration)))
163 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
164 (symbol->string style)
165 (string-append (number->string (max 0 duration))
166 (symbol->string style))))))
169 (define (note-head-style->attachment-coordinates style duration)
170 "Return pair (X . Y), containing multipliers for the note head
171 bounding box, where to attach the stem. e.g.: X==0 means horizontally
172 centered, X==1 is at the right, X == -1 is at the left."
177 '(0.0 . 0.6) ;; neo-mensural
178 '(1.0 . 0.5) ;; default
180 ((cross) '(1.0 . 0.75))
181 ((mensural) '(0.0 . 0.6))
182 ((neo_mensural) '(0.0 . 0.6))
183 ((diamond) '(1.0 . 0.8))
184 ((transparent) '(1.0 . 1.0))
185 ((slash) '(1.0 . 1.0))
186 ((harmonic) '(1.0 0.0))
187 ((triangle) '(0.75 . 0.15))
190 '(0.0 . 0.6) ;; neo-mensural
191 '(1.0 . 0.5) ;; default
195 ;; this also works for easy notation.
199 (define-public (string-encode-integer i)
202 ((< i 0) (string-append "n" (string-encode-integer (- i))))
204 (make-string 1 (integer->char (+ 65 (modulo i 26))))
205 (string-encode-integer (quotient i 26))))))
208 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
210 (define-public (default-bar-number-visibility barnum) (> barnum 1))
212 ;; See documentation of Item::visibility_lambda_
213 (define-public (begin-of-line-visible d) (if (= d 1) '(#f . #f) '(#t . #t)))
214 (define-public (end-of-line-visible d) (if (= d -1) '(#f . #f) '(#t . #t)))
215 (define-public (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
217 (define-public (all-visible d) '(#f . #f))
218 (define-public (all-invisible d) '(#t . #t))
219 (define-public (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
220 (define-public (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
227 ; How should a bar line behave at a break?
229 ;; Why prepend `default-' to every scm identifier?
230 (define-public (default-break-barline glyph dir)
231 (let ((result (assoc glyph
232 '((":|:" . (":|" . "|:"))
233 ("||:" . ("||" . "|:"))
235 ("||:" . ("||" . "|:"))
237 ("|:" . ("|" . "|:"))
240 ;; hmm... should we end with a barline here?
241 (".|" . ("|" . ".|"))
244 (".|." . (".|." . ()))
246 ("empty" . (() . ()))
247 ("brace" . (() . "brace"))
248 ("bracket" . (() . "bracket"))
252 (if (equal? result #f)
253 (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
254 (index-cell (cdr result) dir))