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-molecule-callback 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-molecule-callback 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 (fret1 (string->number (ly:get-grob-property note1 'text)))
41 (fret2 (string->number (ly:get-grob-property note2 'text)))
42 (letter (if (< fret1 fret2) "H"
43 (if (> fret1 fret2) "P"
46 (let ((slur (Slur::brew_molecule grob))
47 (text (fontify-text (ly:get-default-font grob) letter)))
49 (let ((x (/ (- (cdr (ly:molecule-get-extent slur 0))
50 (/ (cdr (ly:molecule-get-extent text 0)) 2.0)
54 (ly:molecule-set-extent! text 0 (cons x x))
55 (ly:molecule-align-to! text 0 1)
58 (ly:molecule-combine-at-edge slur 1 1 text -0.6)
63 (define-public guitar-tunings '(4 -1 -5 -10 -15 -20))
65 ; end of tablature functions
68 (define-public (make-molecule-boxer line-thick x-padding y-padding callback)
69 "Makes a routine that adds a box around the grob parsed as argument"
70 (define (molecule-boxer grob)
74 (x-ext (interval-widen (ly:molecule-get-extent mol 0) x-padding))
75 (y-ext (interval-widen (ly:molecule-get-extent mol 1) y-padding))
76 (x-rule (make-filled-box-molecule (interval-widen x-ext line-thick)
78 (y-rule (make-filled-box-molecule (cons 0 line-thick) y-ext))
81 (set! mol (ly:molecule-combine-at-edge mol 0 1 y-rule x-padding))
82 (set! mol (ly:molecule-combine-at-edge mol 0 -1 y-rule x-padding))
83 (set! mol (ly:molecule-combine-at-edge mol 1 1 x-rule 0))
84 (set! mol (ly:molecule-combine-at-edge mol 1 -1 x-rule 0))
91 (define-public (arg->string arg)
92 (cond ((number? arg) (inexact->string arg 10))
93 ((string? arg) (string-append "\"" arg "\""))
94 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
96 (define-public (func name . args)
102 (map (lambda (x) (string-append " " (arg->string x))) args)))
105 ;;(define (mm-to-pt x)
106 ;; (* (/ 72.27 25.40) x))
108 ;; do nothing in .scm output
109 (define-public (comment s) "")
111 (define-public (numbers->string l)
112 (apply string-append (map ly:number->string l)))
114 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
116 (define (number->octal-string x)
117 (let* ((n (inexact->exact x))
118 (n64 (quotient n 64))
119 (n8 (quotient (- n (* n64 64)) 8)))
123 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
125 (define-public (inexact->string x radix)
126 (let ((n (inexact->exact x)))
127 (number->string n radix)))
130 (define-public (number-pair->string c)
131 (string-append (ly:number->string (car c)) " "
132 (ly:number->string (cdr c)) " "))
137 (make-string 1 (integer->char (+ (char->integer #\A) i)))))
139 (define (scm-scm action-name)
144 (define-public (find-notehead-symbol duration style)
146 ((xcircle) "2xcircle")
147 ((harmonic) "0neo_mensural")
149 ;; Oops, I actually would not call this "baroque", but, for
150 ;; backwards compatibility to 1.4, this is supposed to take
151 ;; brevis, longa and maxima from the neo-mensural font and all
152 ;; other note heads from the default font. -- jr
154 (string-append (number->string duration) "neo_mensural")
155 (number->string duration)))
157 (string-append (number->string duration) (symbol->string style)))
159 (string-append (number->string duration) (symbol->string style)))
161 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
162 ;; neither a longa nor a maxima. Hence let us, for the moment,
163 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
164 ;; should define at least a longa for the default font. The longa
165 ;; should look exactly like the brevis of the default font, but
166 ;; with a stem exactly like that of the quarter note. -- jr
168 (string-append (number->string duration) "neo_mensural")
169 (number->string duration)))
171 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
172 (symbol->string style)
173 (string-append (number->string (max 0 duration))
174 (symbol->string style))))))
177 ;; TODO junk completely?
178 (define (note-head-style->attachment-coordinates grob axis)
179 "Return pair (X . Y), containing multipliers for the note head
180 bounding box, where to attach the stem. e.g.: X==0 means horizontally
181 centered, X==1 is at the right, X == -1 is at the left."
186 (define-public (string-encode-integer i)
189 ((< i 0) (string-append "n" (string-encode-integer (- i))))
191 (make-string 1 (integer->char (+ 65 (modulo i 26))))
192 (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:get-context-property tr 'currentBarNumber)))
201 (ly:set-context-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-public (begin-of-line-visible d) (if (= d 1) '(#f . #f) '(#t . #t)))
207 (define-public (end-of-line-visible d) (if (= d -1) '(#f . #f) '(#t . #t)))
208 (define-public (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
210 (define-public (all-visible d) '(#f . #f))
211 (define-public (all-invisible d) '(#t . #t))
212 (define-public (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
213 (define-public (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220 ; How should a bar line behave at a break?
222 ;; Why prepend `default-' to every scm identifier?
223 (define-public (default-break-barline glyph dir)
224 (let ((result (assoc glyph
225 '((":|:" . (":|" . "|:"))
226 ("||:" . ("||" . "|:"))
228 ("||:" . ("||" . "|:"))
230 ("|:" . ("|" . "|:"))
233 ;; hmm... should we end with a barline here?
234 (".|" . ("|" . ".|"))
237 (".|." . (".|." . ()))
239 ("empty" . (() . ()))
240 ("brace" . (() . "brace"))
241 ("bracket" . (() . "bracket"))
245 (if (equal? result #f)
246 (ly:warn (string-append "Unknown bar glyph: `" glyph "'"))
247 (index-cell (cdr result) dir))