1 ;;;; output-lib.scm -- implement Scheme output helper functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2003 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)
14 ; The TabNoteHead molecule callback.
15 ; Create a text molecule
16 (define-public (tablature-print-function grob)
17 (let ((molecule (fontify-text
18 (ly:get-default-font grob)
19 (ly:get-grob-property grob 'text)
21 molecule ; return the molecule.
24 ; The TabNoteHead tablatureFormat callback.
25 ; Compute the text grob-property
26 (define-public (fret-number-tablature-format string tuning pitch)
28 (- (ly:pitch-semitones pitch)
30 (- string 1) ; remove 1 because list index starts at 0 and guitar string at 1.
34 (define-public (hammer-print-function grob)
35 (let* ((note-collums (ly:get-grob-property grob 'note-columns))
36 (note-column1 (cadr note-collums))
37 (note-column2 (car note-collums))
38 (note1 (car (ly:get-grob-property note-column1 'note-heads)))
39 (note2 (car (ly:get-grob-property note-column2 'note-heads)))
40 (text1 (ly:get-grob-property note1 'text))
41 (text2 (ly:get-grob-property note2 'text))
42 (fret1 (if (string? text1) (string->number text1) 0))
43 (fret2 (if (string? text2) (string->number text2) 0))
50 (let ((slur (Slur::brew_molecule grob))
51 (text (fontify-text (ly:get-default-font grob) letter)))
53 (let ((x (/ (- (cdr (ly:molecule-get-extent slur 0))
54 (/ (cdr (ly:molecule-get-extent text 0)) 2.0)
58 (ly:molecule-set-extent! text 0 (cons x x))
59 (ly:molecule-align-to! text 0 1)
62 (ly:molecule-combine-at-edge slur 1 1 text -0.6)
67 (define-public guitar-tunings '(4 -1 -5 -10 -15 -20))
69 ; end of tablature functions
72 (define-public (make-molecule-boxer line-thick x-padding y-padding callback)
73 "Makes a routine that adds a box around the grob parsed as argument"
74 (define (molecule-boxer grob)
78 (x-ext (interval-widen (ly:molecule-get-extent mol 0) x-padding))
79 (y-ext (interval-widen (ly:molecule-get-extent mol 1) y-padding))
80 (x-rule (make-filled-box-molecule (interval-widen x-ext line-thick)
82 (y-rule (make-filled-box-molecule (cons 0 line-thick) y-ext))
85 (set! mol (ly:molecule-combine-at-edge mol 0 1 y-rule x-padding))
86 (set! mol (ly:molecule-combine-at-edge mol 0 -1 y-rule x-padding))
87 (set! mol (ly:molecule-combine-at-edge mol 1 1 x-rule 0))
88 (set! mol (ly:molecule-combine-at-edge mol 1 -1 x-rule 0))
95 (define-public (arg->string arg)
96 (cond ((number? arg) (inexact->string arg 10))
97 ((string? arg) (string-append "\"" arg "\""))
98 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
100 (define-public (func name . args)
106 (map (lambda (x) (string-append " " (arg->string x))) args)))
109 ;;(define (mm-to-pt x)
110 ;; (* (/ 72.27 25.40) x))
112 ;; do nothing in .scm output
113 (define-public (comment s) "")
115 (define-public (numbers->string l)
116 (apply string-append (map ly:number->string l)))
118 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
120 (define (number->octal-string x)
121 (let* ((n (inexact->exact x))
122 (n64 (quotient n 64))
123 (n8 (quotient (- n (* n64 64)) 8)))
127 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
129 (define-public (inexact->string x radix)
130 (let ((n (inexact->exact x)))
131 (number->string n radix)))
134 (define-public (number-pair->string c)
135 (string-append (ly:number->string (car c)) " "
136 (ly:number->string (cdr c)) " "))
141 (make-string 1 (integer->char (+ (char->integer #\A) i)))))
143 (define (scm-scm action-name)
148 (define-public (find-notehead-symbol duration style)
150 ((xcircle) "2xcircle")
151 ((harmonic) "0harmonic")
153 ;; Oops, I actually would not call this "baroque", but, for
154 ;; backwards compatibility to 1.4, this is supposed to take
155 ;; brevis, longa and maxima from the neo-mensural font and all
156 ;; other note heads from the default font. -- jr
158 (string-append (number->string duration) "neo_mensural")
159 (number->string duration)))
161 (string-append (number->string duration) (symbol->string style)))
163 (string-append (number->string duration) (symbol->string style)))
165 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
166 ;; neither a longa nor a maxima. Hence let us, for the moment,
167 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
168 ;; should define at least a longa for the default font. The longa
169 ;; should look exactly like the brevis of the default font, but
170 ;; with a stem exactly like that of the quarter note. -- jr
172 (string-append (number->string duration) "neo_mensural")
173 (number->string duration)))
175 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
176 (symbol->string style)
177 (string-append (number->string (max 0 duration))
178 (symbol->string style))))))
181 ;; TODO junk completely?
182 (define (note-head-style->attachment-coordinates grob axis)
183 "Return pair (X . Y), containing multipliers for the note head
184 bounding box, where to attach the stem. e.g.: X==0 means horizontally
185 centered, X==1 is at the right, X == -1 is at the left."
190 (define-public (string-encode-integer i)
193 ((< i 0) (string-append "n" (string-encode-integer (- i))))
195 (make-string 1 (integer->char (+ 65 (modulo i 26))))
196 (string-encode-integer (quotient i 26))))))
199 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
201 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
203 (define-public ((set-bar-number-visibility n) tr)
204 (let* ((bn (ly:get-context-property tr 'currentBarNumber)))
205 (ly:set-context-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
207 (define-public (default-bar-number-visibility barnum) (> barnum 1))
209 ;; See documentation of Item::visibility_lambda_
210 (define-public (begin-of-line-visible d) (if (= d 1) '(#f . #f) '(#t . #t)))
211 (define-public (end-of-line-visible d) (if (= d -1) '(#f . #f) '(#t . #t)))
212 (define-public (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
214 (define-public (all-visible d) '(#f . #f))
215 (define-public (all-invisible d) '(#t . #t))
216 (define-public (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
217 (define-public (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
224 ; How should a bar line behave at a break?
226 ;; Why prepend `default-' to every scm identifier?
227 (define-public (default-break-barline glyph dir)
228 (let ((result (assoc glyph
229 '((":|:" . (":|" . "|:"))
230 ("||:" . ("||" . "|:"))
232 ("||:" . ("||" . "|:"))
234 ("|:" . ("|" . "|:"))
237 ;; hmm... should we end with a barline here?
238 (".|" . ("|" . ".|"))
241 (".|." . (".|." . ()))
244 ("empty" . (() . ()))
245 ("brace" . (() . "brace"))
246 ("bracket" . (() . "bracket"))
250 (if (equal? result #f)
251 (ly:warn (string-append "Unknown bar glyph: `" glyph "'"))
252 (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)