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 startrepeat empty1)
74 (define repeatbar empty1)
75 (define finishbar empty1)
76 (define extender empty1)
77 (define startbar empty1)
78 (define repeatbarstartrepeat empty1)
79 (define fatdoublebar empty1)
80 (define setfinger empty1)
83 (define (settext s) (text "text" s))
84 (define (setnumber s) (text "number" s))
85 (define (setbold s) (text "bold" s))
86 (define (setitalic s) (text "italic" s))
87 (define (setnumber-1 s) (text "numberj" s))
93 (define (tex-scm action-name)
98 (define (beam width slope thick)
99 (embedded-ps ((ps-scm 'beam) width slope thick)))
102 (embedded-ps ((ps-scm 'bracket) h)))
104 (define (dashed-slur thick dash l)
105 (embedded-ps ((ps-scm 'dashed-slur) thick dash l)))
107 (define (crescendo w h cont)
108 (embedded-ps ((ps-scm 'crescendo) w h cont)))
110 (define (decrescendo w h cont)
111 (embedded-ps ((ps-scm 'decrescendo) w h cont)))
113 (define (embedded-ps s)
114 (string-append "\\embeddedps{" s "}"))
118 "\n\\EndLilyPondOutput")
120 (define (experimental-on) "\\turnOnExperimentalFeatures")
122 (define (extender o h)
123 ((invoke-output o "invoke-dim1") "extender" h))
125 (define (font-switch i)
129 (define (font-def i s)
131 "\\font" (font-switch i) "=" s "\n"))
133 (define (generalmeter num den)
135 "\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
137 (define (header-end) "\\turnOnPostScript")
139 (define (header creator generate)
141 "%created by: " creator generate "\n"))
143 (define (invoke-char s i)
145 "\n\\" s "{" (inexact->string i 10) "}" ))
147 (string-append "\\show{" (inexact->string i 10) "}"))
149 (define (invoke-dim1 s d)
151 "\n\\" s "{" (number->dim d) "}"))
153 (define (lily-def key val)
155 "\\def\\" key "{" val "}\n"))
157 (define (number->dim x)
159 (number->string (chop-decimal x)) "pt "))
161 (define (placebox x y s)
164 (number->dim y) "}{" (number->dim x) "}{" s "}"))
166 (define (pianobrace y)
168 (define minht mudelapaperstaffheight)
169 (define maxht (* 6 minht))
171 "{\\bracefont " (char (/ (- (max y (- maxht step)) minht) step)) "}"))
173 (define (rulesym h w)
175 "\\vrule height " (number->dim (/ h 2))
176 " depth " (number->dim (/ h 2))
177 " width " (number->dim w)
182 (embedded-ps ((ps-scm 'slur) l)))
189 (define (stem kern width height depth)
191 "\\kern" (number->dim kern)
192 "\\vrule width " (number->dim width)
193 "depth " (number->dim depth)
194 "height " (number->dim height) " "))
200 (string-append "\\set" f "{" s "}"))
203 (define (tuplet dx dy dir)
204 (embedded-ps ((ps-scm 'tuplet) dx dy dir)))
206 (define (volta w last)
207 (embedded-ps ((ps-scm 'volta) w last)))
209 (define (maatstreep h)
210 (string-append "\\maatstreep{" (number->dim h) "}"))
212 (cond ((eq? action-name 'all-definitions)
215 (define tuplet ,tuplet)
216 (define bracket ,bracket)
217 (define crescendo ,crescendo)
218 (define volta ,volta)
220 (define dashed-slur ,dashed-slur)
221 (define decrescendo ,decrescendo)
222 (define empty ,empty)
223 (define end-output ,end-output)
224 (define font-def ,font-def)
225 (define font-switch ,font-switch)
226 (define generalmeter ,generalmeter)
227 (define header-end ,header-end)
228 (define lily-def ,lily-def)
229 (define header ,header)
230 (define invoke-char ,invoke-char)
231 (define invoke-dim1 ,invoke-dim1)
232 (define placebox ,placebox)
233 (define rulesym ,rulesym)
234 (define start-line ,start-line)
236 (define stop-line ,stop-line)
238 (define experimental-on ,experimental-on)
240 (define maatstreep ,maatstreep)
241 (define pianobrace ,pianobrace)
244 ((eq? action-name 'experimental-on) experimental-on)
245 ((eq? action-name 'beam) beam)
246 ((eq? action-name 'tuplet) tuplet)
247 ((eq? action-name 'bracket) bracket)
248 ((eq? action-name 'crescendo) crescendo)
249 ((eq? action-name 'volta) volta)
250 ((eq? action-name 'slur) slur)
251 ((eq? action-name 'dashed-slur) dashed-slur)
252 ((eq? action-name 'decrescendo) decrescendo)
253 ((eq? action-name 'empty) empty)
254 ((eq? action-name 'end-output) end-output)
255 ((eq? action-name 'font-def) font-def)
256 ((eq? action-name 'font-switch) font-switch)
257 ((eq? action-name 'generalmeter) generalmeter)
258 ((eq? action-name 'header-end) header-end)
259 ((eq? action-name 'lily-def) lily-def)
260 ((eq? action-name 'header) header)
261 ((eq? action-name 'invoke-char) invoke-char)
262 ((eq? action-name 'invoke-dim1) invoke-dim1)
263 ((eq? action-name 'placebox) placebox)
264 ((eq? action-name 'rulesym) rulesym)
265 ((eq? action-name 'start-line) start-line)
266 ((eq? action-name 'stem) stem)
267 ((eq? action-name 'stop-line) stop-line)
268 (else (error "unknown tag -- PS-TEX " action-name))
274 (define (ps-scm action-name)
275 (define (beam width slope thick)
277 (numbers->string (list width slope thick)) " draw_beam " ))
280 (invoke-dim1 "draw_bracket" h))
282 (define (crescendo w h cont)
284 (numbers->string (list w h (inexact->exact cont)))
287 (define (dashed-slur thick dash l)
289 (apply string-append (map control->string l))
290 (number->string thick)
292 (if (> 1 dash) (number->string (- (* thick dash) thick)) "0") " "
293 (number->string (* 2 thick))
294 " ] 0 draw_dashed_slur"))
296 (define (decrescendo w h cont)
298 (numbers->string (list w h (inexact->exact cont)))
307 (define (experimental-on) "")
309 (define (font-def i s)
312 (substring s 0 (- (string-length s) 4))
313 " findfont 12 scalefont setfont} bind def\n"))
315 (define (font-switch i)
316 (string-append (font i) " "))
318 (define (generalmeter num den)
319 (string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
321 (define (header-end) "")
322 (define (lily-def key val)
324 "/" key " {" val "} bind def\n"))
326 (define (header creator generate)
329 "%%Creator: " creator generate "\n"))
331 (define (invoke-char s i)
333 "(\\" (inexact->string i 8) ") " s " " ))
335 (define (invoke-dim1 s d)
337 (number->string d) " " s ))
339 (define (placebox x y s)
341 (number->string x) " " (number->string y) " {" s "} placebox "))
343 (define (rulesym x y)
345 (number->string x) " "
346 (number->string y) " "
351 (apply string-append (map control->string l))
357 (define (stem kern width height depth)
358 (string-append (numbers->string (list kern width height depth))
365 (string-append "(" s ") set" f " "))
368 (define (volta w last)
370 (numbers->string (list w (inexact->exact last)))
372 (define (tuplet dx dy dir)
374 (numbers->string (list dx dy (inexact->exact dir)))
382 ; dispatch on action-name
383 (cond ((eq? action-name 'all-definitions)
386 (define tuplet ,tuplet)
387 (define bracket ,bracket)
388 (define crescendo ,crescendo)
389 (define volta ,volta)
391 (define dashed-slur ,dashed-slur)
392 (define decrescendo ,decrescendo)
393 (define empty ,empty)
394 (define end-output ,end-output)
395 (define font-def ,font-def)
396 (define font-switch ,font-switch)
397 (define generalmeter ,generalmeter)
398 (define header-end ,header-end)
399 (define lily-def ,lily-def)
400 (define header ,header)
401 (define invoke-char ,invoke-char)
402 (define invoke-dim1 ,invoke-dim1)
403 (define placebox ,placebox)
404 (define rulesym ,rulesym)
405 (define start-line ,start-line)
407 (define stop-line ,stop-line)
410 ((eq? action-name 'tuplet) tuplet)
411 ((eq? action-name 'beam) beam)
412 ((eq? action-name 'bracket) bracket)
413 ((eq? action-name 'crescendo) crescendo)
414 ((eq? action-name 'volta) volta)
415 ((eq? action-name 'slur) slur)
416 ((eq? action-name 'dashed-slur) dashed-slur)
417 ((eq? action-name 'decrescendo) decrescendo)
418 (else (error "unknown tag -- PS-SCM " action-name))