1 ; lily.scm -- implement Scheme output routines for TeX and PostScript
3 ; source file of the GNU LilyPond music typesetter
5 ; (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
9 ; - ready ps code (draw_bracket) vs tex/ps macros/calls (pianobrace),
10 ; all preparations from ps,tex to scm
16 (map (lambda (n) (string-append (number->string n ) " ")) l)))
21 (map (lambda (n) (string-append (number->string n) " ")) l)))
23 (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
25 (define (number->octal-string x)
26 (let* ((n (inexact->exact x))
28 (n8 (quotient (- n (* n64 64)) 8)))
32 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
34 (define (inexact->string x radix)
35 (let ((n (inexact->exact x)))
36 (number->string n radix)))
42 (string-append (number->string (car c)) " ")
43 (string-append (number->string (cadr c)) " ")))
51 (make-string 1 (integer->char (+ (char->integer #\A) i)))
56 (define (scm-scm action-name)
71 (define emptybar empty1)
72 (define setdynamic empty1)
73 (define settext empty1)
74 (define setnumber empty1)
79 (define (tex-scm action-name)
84 (define (beam width slope thick)
85 (embedded-ps ((ps-scm 'beam) width slope thick)))
88 (embedded-ps ((ps-scm 'bracket) h)))
90 (define (dashed-slur thick dash l)
91 (embedded-ps ((ps-scm 'dashed-slur) thick dash l)))
93 (define (crescendo w h cont)
94 (embedded-ps ((ps-scm 'crescendo) w h cont)))
96 (define (decrescendo w h cont)
97 (embedded-ps ((ps-scm 'decrescendo) w h cont)))
99 (define (embedded-ps s)
100 (string-append "\\embeddedps{" s "}"))
104 "\n\\EndLilyPondOutput")
106 (define (experimental-on) "\\turnOnExperimentalFeatures")
108 (define (extender o h)
109 ((invoke-output o "invoke-dim1") "extender" h))
111 (define (font-switch i)
115 (define (font-def i s)
117 "\\font" (font-switch i) "=" s "\n"))
119 (define (generalmeter num den)
121 "\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
123 (define (header-end) "\\turnOnPostScript")
125 (define (header creator generate)
127 "%created by: " creator generate "\n"))
129 (define (invoke-char s i)
131 "\n\\" s "{" (inexact->string i 10) "}" ))
133 (string-append "\\show{" (inexact->string i 10) "}"))
135 (define (invoke-dim1 s d)
137 "\n\\" s "{" (number->dim d) "}"))
139 (define (lily-def key val)
141 "\\def\\" key "{" val "}\n"))
143 (define (number->dim x)
145 (number->string (chop-decimal x)) "pt "))
147 (define (placebox x y s)
150 (number->dim y) "}{" (number->dim x) "}{" s "}"))
152 (define (pianobrace y)
154 (define minht mudelapaperstaffheight)
155 (define maxht (* 6 minht))
157 "{\\bracefont " (char (/ (- (max y (- maxht step)) minht) step)) "}"))
159 (define (rulesym h w)
161 "\\vrule height " (number->dim (/ h 2))
162 " depth " (number->dim (/ h 2))
163 " width " (number->dim w)
168 (embedded-ps ((ps-scm 'slur) l)))
175 (define (stem kern width height depth)
177 "\\kern" (number->dim kern)
178 "\\vrule width " (number->dim width)
179 "depth " (number->dim depth)
180 "height " (number->dim height) " "))
186 (string-append "\\set" f "{" s "}"))
188 (define (tuplet dx dy dir)
189 (embedded-ps ((ps-scm 'tuplet) dx dy dir)))
191 (define (volta w last)
192 (embedded-ps ((ps-scm 'volta) w last)))
194 (define (maatstreep h)
195 (string-append "\\maatstreep{" (number->dim h) "}"))
197 (cond ((eq? action-name 'all-definitions)
200 (define tuplet ,tuplet)
201 (define bracket ,bracket)
202 (define crescendo ,crescendo)
203 (define volta ,volta)
205 (define dashed-slur ,dashed-slur)
206 (define decrescendo ,decrescendo)
207 (define empty ,empty)
208 (define end-output ,end-output)
209 (define font-def ,font-def)
210 (define font-switch ,font-switch)
211 (define generalmeter ,generalmeter)
212 (define header-end ,header-end)
213 (define lily-def ,lily-def)
214 (define header ,header)
215 (define invoke-char ,invoke-char)
216 (define invoke-dim1 ,invoke-dim1)
217 (define placebox ,placebox)
218 (define rulesym ,rulesym)
219 (define start-line ,start-line)
221 (define stop-line ,stop-line)
223 (define experimental-on ,experimental-on)
225 (define maatstreep ,maatstreep)
226 (define pianobrace ,pianobrace)
229 ((eq? action-name 'experimental-on) experimental-on)
230 ((eq? action-name 'beam) beam)
231 ((eq? action-name 'tuplet) tuplet)
232 ((eq? action-name 'bracket) bracket)
233 ((eq? action-name 'crescendo) crescendo)
234 ((eq? action-name 'volta) volta)
235 ((eq? action-name 'slur) slur)
236 ((eq? action-name 'dashed-slur) dashed-slur)
237 ((eq? action-name 'decrescendo) decrescendo)
238 ((eq? action-name 'empty) empty)
239 ((eq? action-name 'end-output) end-output)
240 ((eq? action-name 'font-def) font-def)
241 ((eq? action-name 'font-switch) font-switch)
242 ((eq? action-name 'generalmeter) generalmeter)
243 ((eq? action-name 'header-end) header-end)
244 ((eq? action-name 'lily-def) lily-def)
245 ((eq? action-name 'header) header)
246 ((eq? action-name 'invoke-char) invoke-char)
247 ((eq? action-name 'invoke-dim1) invoke-dim1)
248 ((eq? action-name 'placebox) placebox)
249 ((eq? action-name 'rulesym) rulesym)
250 ((eq? action-name 'start-line) start-line)
251 ((eq? action-name 'stem) stem)
252 ((eq? action-name 'stop-line) stop-line)
253 (else (error "unknown tag -- PS-TEX " action-name))
259 (define (ps-scm action-name)
260 (define (beam width slope thick)
262 (numbers->string (list width slope thick)) " draw_beam " ))
265 (invoke-dim1 "draw_bracket" h))
267 (define (crescendo w h cont)
269 (numbers->string (list w h (inexact->exact cont)))
272 (define (dashed-slur thick dash l)
274 (apply string-append (map control->string l))
275 (number->string thick)
277 (if (> 1 dash) (number->string (- (* thick dash) thick)) "0") " "
278 (number->string (* 2 thick))
279 " ] 0 draw_dashed_slur"))
281 (define (decrescendo w h cont)
283 (numbers->string (list w h (inexact->exact cont)))
292 (define (experimental-on) "")
294 (define (font-def i s)
297 (substring s 0 (- (string-length s) 4))
298 " findfont 12 scalefont setfont} bind def\n"))
300 (define (font-switch i)
301 (string-append (font i) " "))
303 (define (generalmeter num den)
304 (string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
306 (define (header-end) "")
307 (define (lily-def key val)
309 "/" key " {" val "} bind def\n"))
311 (define (header creator generate)
314 "%%Creator: " creator generate "\n"))
316 (define (invoke-char s i)
318 "(\\" (inexact->string i 8) ") " s " " ))
320 (define (invoke-dim1 s d)
322 (number->string d) " " s ))
324 (define (placebox x y s)
326 (number->string x) " " (number->string y) " {" s "} placebox "))
328 (define (rulesym x y)
330 (number->string x) " "
331 (number->string y) " "
336 (apply string-append (map control->string l))
342 (define (stem kern width height depth)
343 (string-append (numbers->string (list kern width height depth))
350 (string-append "(" s ") set" f " "))
353 (define (volta w last)
355 (numbers->string (list w (inexact->exact last)))
357 (define (tuplet dx dy dir)
359 (numbers->string (list dx dy (inexact->exact dir)))
367 ; dispatch on action-name
368 (cond ((eq? action-name 'all-definitions)
371 (define tuplet ,tuplet)
372 (define bracket ,bracket)
373 (define crescendo ,crescendo)
374 (define volta ,volta)
376 (define dashed-slur ,dashed-slur)
377 (define decrescendo ,decrescendo)
378 (define empty ,empty)
379 (define end-output ,end-output)
380 (define font-def ,font-def)
381 (define font-switch ,font-switch)
382 (define generalmeter ,generalmeter)
383 (define header-end ,header-end)
384 (define lily-def ,lily-def)
385 (define header ,header)
386 (define invoke-char ,invoke-char)
387 (define invoke-dim1 ,invoke-dim1)
388 (define placebox ,placebox)
389 (define rulesym ,rulesym)
390 (define start-line ,start-line)
392 (define stop-line ,stop-line)
395 ((eq? action-name 'tuplet) tuplet)
396 ((eq? action-name 'beam) beam)
397 ((eq? action-name 'bracket) bracket)
398 ((eq? action-name 'crescendo) crescendo)
399 ((eq? action-name 'volta) volta)
400 ((eq? action-name 'slur) slur)
401 ((eq? action-name 'dashed-slur) dashed-slur)
402 ((eq? action-name 'decrescendo) decrescendo)
403 (else (error "unknown tag -- PS-SCM " action-name))