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))
42 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
43 (define-public bass-tuning '(-17 -22 -27 -32))
45 ;; tunings for 5-string banjo
46 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
47 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
48 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
49 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
50 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
51 ;; convert 5-string banjo tunings to 4-string tunings by
52 ;; removing the 5th string
55 ;; \set TabStaff.stringTunings = #(four-string-banjo banjo-open-g-tuning)
56 (define-public (four-string-banjo tuning)
57 (reverse (cdr (reverse tuning))))
59 ;;; end of tablature functions
61 (define-public (make-stencil-boxer thickness padding callback)
62 "Return function that adds a box around the grob passed as argument."
63 (lambda (grob) (box-stencil (callback grob) thickness padding)))
65 (define-public (make-stencil-circler thickness padding callback)
66 "Return function that adds a circle around the grob passed as argument."
67 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
69 (define-public (arg->string arg)
70 (cond ((number? arg) (ly:inexact->string arg 10))
71 ((string? arg) (string-append "\"" arg "\""))
72 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
74 (define-public (print-circled-text-callback grob)
75 (let* ((text (ly:grob-property grob 'text))
76 (layout (ly:grob-layout grob))
77 (defs (ly:output-def-lookup layout 'text-font-defaults))
78 (props (ly:grob-alist-chain grob defs))
79 (circle (Text_interface::interpret_markup
80 layout props (make-draw-circle-markup 0.8 0.1 #f)))
81 (text-stencil (Text_interface::interpret_markup layout props text)))
83 (ly:stencil-add (centered-stencil text-stencil) circle)))
86 ;;(define (mm-to-pt x)
87 ;; (* (/ 72.27 25.40) x))
89 ;; do nothing in .scm output
91 (define-public (ly:numbers->string lst)
92 (string-join (map ly:number->string lst) " "))
94 (define (number->octal-string x)
95 (let* ((n (inexact->exact x))
97 (n8 (quotient (- n (* n64 64)) 8)))
101 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
103 (define-public (ly:inexact->string x radix)
104 (let ((n (inexact->exact x)))
105 (number->string n radix)))
107 (define-public (ly:number-pair->string c)
108 (string-append (ly:number->string (car c)) " "
109 (ly:number->string (cdr c))))
113 (define-public (find-notehead-symbol duration style)
115 ((xcircle) "2xcircle")
116 ((harmonic) "0harmonic")
118 ;; Oops, I actually would not call this "baroque", but, for
119 ;; backwards compatibility to 1.4, this is supposed to take
120 ;; brevis, longa and maxima from the neo-mensural font and all
121 ;; other note heads from the default font. -- jr
123 (string-append (number->string duration) "neomensural")
124 (number->string duration)))
126 (string-append (number->string duration) (symbol->string style)))
129 (string-append (number->string duration) "mensural")
130 (string-append (number->string duration) (symbol->string style))))
132 (string-append (number->string duration) (symbol->string style)))
134 ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
135 ;; neither a longa nor a maxima. Hence let us, for the moment,
136 ;; take these from the neo-mensural font. TODO: mf/feta-bolletjes
137 ;; should define at least a longa for the default font. The longa
138 ;; should look exactly like the brevis of the default font, but
139 ;; with a stem exactly like that of the quarter note. -- jr
141 (string-append (number->string duration) "neomensural")
142 (number->string duration)))
144 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
145 (symbol->string style)
146 (string-append (number->string (max 0 duration))
147 (symbol->string style))))))
149 ;; TODO junk completely?
150 (define (note-head-style->attachment-coordinates grob axis)
151 "Return pair (X . Y), containing multipliers for the note head
152 bounding box, where to attach the stem. e.g.: X==0 means horizontally
153 centered, X==1 is at the right, X == -1 is at the left."
157 (define-public (string-encode-integer i)
160 ((< i 0) (string-append "n" (string-encode-integer (- i))))
162 (make-string 1 (integer->char (+ 65 (modulo i 26))))
163 (string-encode-integer (quotient i 26))))))
165 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
167 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
169 (define-public ((set-bar-number-visibility n) tr)
170 (let* ((bn (ly:context-property tr 'currentBarNumber)))
171 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
173 (define-public (default-bar-number-visibility barnum) (> barnum 1))
175 ;; See documentation of Item::visibility_lambda_
176 (define-public begin-of-line-visible
178 (define-public end-of-line-visible
180 (define-public end-of-line-invisible
182 (define-public spanbar-begin-of-line-invisible
184 (define-public all-visible #(#t #t #t))
185 (define-public all-invisible #(#f #f #f))
186 (define-public begin-of-line-invisible
188 (define-public center-invisible #(#t #f #t))
190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
194 ;; How should a bar line behave at a break?
196 ;; Why prepend `default-' to every scm identifier?
197 (define-public (default-break-barline glyph dir)
198 (let ((result (assoc glyph
199 '((":|:" . (":|" . "|:"))
200 ("||:" . ("||" . "|:"))
202 ("||:" . ("||" . "|:"))
204 ("|:" . ("|" . "|:"))
207 ;; hmm... should we end with a bar line here?
208 (".|" . ("|" . ".|"))
211 (".|." . (".|." . ()))
214 ("empty" . (() . ()))
215 ("brace" . (() . "brace"))
216 ("bracket" . (() . "bracket")) ))))
218 (if (equal? result #f)
219 (ly:warning (_ "unknown bar glyph: `~S'" glyph))
220 (index-cell (cdr result) dir))))
222 (define-public (shift-right-at-line-begin g)
223 "Shift an item to the right, but only at the start of the line."
224 (if (and (ly:item? g) (equal? (ly:item-break-dir g) RIGHT))
225 (ly:grob-translate-axis! g 3.5 X)))
228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231 (define-public color? list?)
234 (define-public black '(0.0 0.0 0.0))
235 (define-public white '(1.0 1.0 1.0))
236 (define-public red '(1.0 0.0 0.0))
237 (define-public green '(0.0 1.0 0.0))
238 (define-public blue '(0.0 0.0 1.0))
239 (define-public cyan '(1.0 1.0 0.0))
240 (define-public magenta '(1.0 0.0 1.0))
241 (define-public yellow '(0.0 1.0 1.0))
243 (define-public grey '(0.5 0.5 0.5))
244 (define-public darkred '(0.5 0.0 0.0))
245 (define-public darkgreen '(0.0 0.5 0.0))
246 (define-public darkblue '(0.0 0.0 0.5))
247 (define-public darkcyan '(0.5 0.5 0.0))
248 (define-public darkmagenta '(0.5 0.0 0.5))
249 (define-public darkyellow '(0.0 0.5 0.5))
251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254 (define (parenthesize-elements grob)
256 ((elts (ly:grob-object grob 'elements))
257 (x-ext (ly:relative-group-extent elts grob X))
258 (font (ly:grob-default-font grob))
259 (lp (ly:font-get-glyph font "accidentals.leftparen"))
260 (rp (ly:font-get-glyph font "accidentals.rightparen"))
264 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
265 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))