1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
; lily.scm -- implement Scheme output routines for TeX and PostScript
;
; source file of the GNU LilyPond music typesetter
;
; (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
(debug-enable 'backtrace)
;;; library funtions
(define
(xnumbers->string l)
(string-append
(map (lambda (n) (string-append (number->string n ) " ")) l)))
(define
(numbers->string l)
(apply string-append
(map (lambda (n) (string-append (number->string n) " ")) l)))
(define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
(define (number->octal-string x)
(let* ((n (inexact->exact x))
(n64 (quotient n 64))
(n8 (quotient (- n (* n64 64)) 8)))
(string-append
(number->string n64)
(number->string n8)
(number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
(define (inexact->string x radix)
(let ((n (inexact->exact x)))
(number->string n radix)))
(define
(control->string c)
(string-append
(string-append (number->string (car c)) " ")
(string-append (number->string (cadr c)) " ")))
(define
(font i)
(string-append
"font"
(make-string 1 (integer->char (+ (char->integer #\A) i)))
))
(define (scm-scm action-name)
1)
(define security-paranoia #f)
;; See documentation of Item::visibility_lambda_
(define (postbreak_only_visibility d) (if (= d 1) '(#f . #f) '(#t . #t)))
(define (non_postbreak_visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
(define (spanbar_non_postbreak_visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
(define (spanbar_postbreak_only_visibility d) (if (= d 1) '(#f . #f) '(#t . #t)))
;;;;;;;; TeX
(define (tex-scm action-name)
(define (unknown)
"%\n\\unknown%\n")
(define font-alist '())
(define font-count 0)
(define current-font "")
(define (clear-fontcache)
(begin
(set! font-alist '())
(set! font-count 0)
(set! current-font "")))
(define (cached-fontname i)
(string-append
"\\lilyfont"
(make-string 1 (integer->char (+ 65 i)))
)
)
(define (select-font font-name)
(if (not (equal? font-name current-font))
(begin
(set! current-font font-name)
(define font-cmd (assoc font-name font-alist))
(if (eq? font-cmd #f)
(begin
(set! font-cmd (cached-fontname font-count))
(set! font-alist (acons font-name font-cmd font-alist))
(set! font-count (+ 1 font-count))
(string-append "\\font" font-cmd "=" font-name font-cmd)
)
(cdr font-cmd))
)
"" ;no switch needed
)
)
(define (beam width slope thick)
(embedded-ps ((ps-scm 'beam) width slope thick)))
(define (bracket h)
(embedded-ps ((ps-scm 'bracket) h)))
(define (dashed-slur thick dash l)
(embedded-ps ((ps-scm 'dashed-slur) thick dash l)))
(define (crescendo w h cont)
(embedded-ps ((ps-scm 'crescendo) w h cont)))
(define (decrescendo w h cont)
(embedded-ps ((ps-scm 'decrescendo) w h cont)))
(define (embedded-ps s)
(string-append "\\embeddedps{" s "}"))
(define (end-output)
"\n\\EndLilyPondOutput")
(define (experimental-on) "\\turnOnExperimentalFeatures")
(define (font-switch i)
(string-append
"\\" (font i) "\n"))
(define (font-def i s)
(string-append
"\\font" (font-switch i) "=" s "\n"))
(define (generalmeter num den)
(string-append
"\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
(define (header-end) "\\turnOnPostScript")
(define (header creator generate)
(string-append
"%created by: " creator generate "\n"))
(define (invoke-char s i)
(string-append
"\n\\" s "{" (inexact->string i 10) "}" ))
(define (char i)
(string-append "\\show{" (inexact->string i 10) "}"))
(define (invoke-dim1 s d)
(string-append
"\n\\" s "{" (number->dim d) "}"))
(define (pt->sp x)
(* 65536 x))
;;
;; need to do something to make this really safe.
;;
(if security-paranoia
(define (output-tex-string s)
(regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post))
(define (output-tex-string s) s))
(define (lily-def key val)
(string-append
"\\def\\" (output-tex-string key) "{" (output-tex-string val) "}\n"))
(define (number->dim x)
(string-append
(number->string (chop-decimal x)) "pt "))
(define (placebox x y s)
(string-append
"\\placebox{"
(number->dim y) "}{" (number->dim x) "}{" s "}"))
(define (pianobrace y)
(define step 1.0)
(define minht (* 2 mudelapaperstaffheight))
(define maxht (* 7 minht))
(string-append
"{\\bracefont " (char (/ (- (min y (- maxht step)) minht) step)) "}"))
(define (rulesym h w)
(string-append
"\\vrule height " (number->dim (/ h 2))
" depth " (number->dim (/ h 2))
" width " (number->dim w)
)
)
(define (bezier-sandwich l)
(embedded-ps ((ps-scm 'bezier-sandwich) l)))
(define (start-line)
(begin
(clear-fontcache)
"\\hbox{%\n")
)
(define (filledbox breapth width depth height)
(string-append
"\\kern" (number->dim (- breapth))
"\\vrule width " (number->dim (+ breapth width))
"depth " (number->dim depth)
"height " (number->dim height) " "))
(define (stop-line)
"}\\interscoreline")
(define (text s)
(string-append "\\hbox{" (output-tex-string s) "}"))
(define (tuplet dx dy thick dir)
(embedded-ps ((ps-scm 'tuplet) dx dy thick dir)))
(define (volta w thick last)
(embedded-ps ((ps-scm 'volta) w thick last)))
;; The procedures listed below form the public interface of TeX-scm.
;; (should merge the 2 lists)
(cond ((eq? action-name 'all-definitions)
`(begin
(define beam ,beam)
(define tuplet ,tuplet)
(define bracket ,bracket)
(define crescendo ,crescendo)
(define dashed-slur ,dashed-slur)
(define decrescendo ,decrescendo)
(define end-output ,end-output)
(define font-def ,font-def)
(define font-switch ,font-switch)
(define generalmeter ,generalmeter)
(define header-end ,header-end)
(define lily-def ,lily-def)
(define header ,header)
(define invoke-char ,invoke-char)
(define invoke-dim1 ,invoke-dim1)
(define placebox ,placebox)
(define rulesym ,rulesym)
(define bezier-sandwich ,bezier-sandwich)
(define select-font ,select-font)
(define start-line ,start-line)
(define filledbox ,filledbox)
(define stop-line ,stop-line)
(define text ,text)
(define experimental-on ,experimental-on)
(define char ,char)
(define pianobrace ,pianobrace)
(define volta ,volta)
))
((eq? action-name 'experimental-on) experimental-on)
((eq? action-name 'beam) beam)
((eq? action-name 'tuplet) tuplet)
((eq? action-name 'bracket) bracket)
((eq? action-name 'crescendo) crescendo)
((eq? action-name 'dashed-slur) dashed-slur)
((eq? action-name 'decrescendo) decrescendo)
((eq? action-name 'end-output) end-output)
((eq? action-name 'font-def) font-def)
((eq? action-name 'font-switch) font-switch)
((eq? action-name 'generalmeter) generalmeter)
((eq? action-name 'header-end) header-end)
((eq? action-name 'lily-def) lily-def)
((eq? action-name 'header) header)
((eq? action-name 'invoke-char) invoke-char)
((eq? action-name 'invoke-dim1) invoke-dim1)
((eq? action-name 'placebox) placebox)
((eq? action-name 'rulesym) rulesym)
((eq? action-name 'bezier-sandwich) bezier-sandwich)
((eq? action-name 'start-line) start-line)
((eq? action-name 'stem) stem)
((eq? action-name 'stop-line) stop-line)
((eq? action-name 'volta) volta)
(else (error "unknown tag -- PS-TEX " action-name))
)
)
;;;;;;;;;;;; PS
(define (ps-scm action-name)
(define (beam width slope thick)
(string-append
(numbers->string (list width slope thick)) " draw_beam " ))
(define (bracket h)
(invoke-dim1 "draw_bracket" h))
(define (crescendo w h cont)
(string-append
(numbers->string (list w h (inexact->exact cont)))
"draw_crescendo"))
(define (dashed-slur thick dash l)
(string-append
(apply string-append (map control->string l))
(number->string thick)
" [ "
(if (> 1 dash) (number->string (- (* thick dash) thick)) "0") " "
(number->string (* 2 thick))
" ] 0 draw_dashed_slur"))
(define (decrescendo w h cont)
(string-append
(numbers->string (list w h (inexact->exact cont)))
"draw_decrescendo"))
(define (end-output)
"\nshowpage\n")
(define (experimental-on) "")
(define (font-def i s)
(string-append
"\n/" (font i) " {/"
(substring s 0 (- (string-length s) 4))
" findfont 12 scalefont setfont} bind def\n"))
(define (font-switch i)
(string-append (font i) " "))
(define (generalmeter num den)
(string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
(define (header-end) "")
(define (lily-def key val)
(string-append
"/" key " {" val "} bind def\n"))
(define (header creator generate)
(string-append
"%!PS-Adobe-3.0\n"
"%%Creator: " creator generate "\n"))
(define (invoke-char s i)
(string-append
"(\\" (inexact->string i 8) ") " s " " ))
(define (invoke-dim1 s d)
(string-append
(number->string (* d (/ 72.27 72))) " " s ))
(define (placebox x y s)
(string-append
(number->string x) " " (number->string y) " {" s "} placebox "))
(define (rulesym x y)
(string-append
(number->string x) " "
(number->string y) " "
"rulesym"))
(define (bezier-sandwich l)
(string-append
(apply string-append (map control->string l))
" draw_bezier_sandwich"))
(define (start-line)
(begin
(clear-fontcache)
"\nstart_line {\n"))
(define (stem kern width height depth)
(string-append (numbers->string (list kern width height depth))
"draw_stem" ))
(define (stop-line)
"}\nstop_line\n")
(define (text f s)
(string-append "(" s ") set" f " "))
(define (volta w thick last)
(string-append
(numbers->string (list w thick (inexact->exact last)))
"draw_volta"))
(define (tuplet dx dy thick dir)
(string-append
(numbers->string (list dx dy thick (inexact->exact dir)))
"draw_tuplet"))
(define (unknown)
"\n unknown\n")
; dispatch on action-name
(cond ((eq? action-name 'all-definitions)
`(begin
(define beam ,beam)
(define tuplet ,tuplet)
(define bracket ,bracket)
(define crescendo ,crescendo)
(define volta ,volta)
(define bezier-sandwich ,bezier-sandwich)
(define dashed-slur ,dashed-slur)
(define decrescendo ,decrescendo)
(define end-output ,end-output)
(define font-def ,font-def)
(define font-switch ,font-switch)
(define generalmeter ,generalmeter)
(define header-end ,header-end)
(define lily-def ,lily-def)
(define header ,header)
(define invoke-char ,invoke-char)
(define invoke-dim1 ,invoke-dim1)
(define placebox ,placebox)
(define rulesym ,rulesym)
(define start-line ,start-line)
(define stem ,stem)
(define stop-line ,stop-line)
(define text ,text)
))
((eq? action-name 'tuplet) tuplet)
((eq? action-name 'beam) beam)
((eq? action-name 'bracket) bracket)
((eq? action-name 'crescendo) crescendo)
((eq? action-name 'volta) volta)
((eq? action-name 'bezier-sandwich) bezier-sandwich)
((eq? action-name 'dashed-slur) dashed-slur)
((eq? action-name 'decrescendo) decrescendo)
(else (error "unknown tag -- PS-SCM " action-name))
)
)
;
; Russ McManus, <mcmanus@IDT.NET>
;
; I use the following, which should definitely be provided somewhere
; in guile, but isn't, AFAIK:
;
;
(define (hash-table-for-each fn ht)
(do ((i 0 (+ 1 i)))
((= i (vector-length ht)))
(do ((alist (vector-ref ht i) (cdr alist)))
((null? alist) #t)
(fn (car (car alist)) (cdr (car alist))))))
(define (hash-table-map fn ht)
(do ((i 0 (+ 1 i))
(ret-ls '()))
((= i (vector-length ht)) (reverse ret-ls))
(do ((alist (vector-ref ht i) (cdr alist)))
((null? alist) #t)
(set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
|