]> git.donarmstrong.com Git - lilypond.git/blob - init/lily.scm
patch::: 1.1.5.jcn2: extender
[lilypond.git] / init / lily.scm
1 ; lily.scm -- implement Scheme output routines for TeX and PostScript
2 ;
3 ;  source file of the GNU LilyPond music typesetter
4
5 ; (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
6
7 ; TODO
8 ;   - naming
9 ;   - ready ps code (draw_bracket) vs tex/ps macros/calls (pianobrace),
10 ;     all preparations from ps,tex to scm
11
12 ;;; library funtions
13 (define
14   (numbers->string l)
15   (apply string-append 
16   (map (lambda (n) (string-append (number->string n) " ")) l)))
17
18 (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
19
20 (define (number->octal-string x)
21   (let* ((n (inexact->exact x))
22          (n64 (quotient n 64))
23          (n8 (quotient (- n (* n64 64)) 8)))
24         (string-append
25          (number->string n64)
26          (number->string n8)
27          (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
28
29 (define (inexact->string x radix)
30   (let ((n (inexact->exact x)))
31        (number->string n radix)))
32
33 (define 
34   (number->dim-tex x)
35   (string-append 
36    (number->string (chop-decimal x)) "pt "))
37
38 (define
39   (control->string c)
40   (string-append
41     (string-append (number->string (car c)) " ")
42     (string-append (number->string (cadr c)) " ")))
43
44 (define 
45   (embedded-ps-tex s)
46   (string-append "\\embeddedps{" s "}"))
47
48 (define 
49   (invoke-char-ps s i)
50   (string-append 
51    "(\\" (inexact->string i 8) ") " s " " ))
52
53 (define 
54   (invoke-char-tex s i)
55   (string-append 
56    "\n\\" s "{" (inexact->string i 10) "}" ))
57
58 (define 
59   (invoke-dim1-ps s d) 
60   (string-append
61    (number->string d) " " s ))
62
63 (define 
64   (invoke-dim1-tex s d)
65   (string-append
66    "\n\\" s "{" (number->dim-tex d) "}"))
67
68 (define
69   (invoke-output o s)
70    (eval-string (string-append s "-" o)))
71
72 ;;; output definitions
73
74 (define 
75   (beam o width slope thick) 
76   ((invoke-output o "beam") width slope thick))
77
78 (define 
79   (beam-ps width slope thick)
80   (string-append
81    (numbers->string (list width slope thick)) " draw_beam " ))
82
83 (define 
84   (beam-tex width slope thick)
85   (embedded-ps-tex (beam-ps width slope thick)))
86
87 (define 
88   (bracket o h)
89   ((invoke-output o "bracket") h))
90
91 (define 
92   (bracket-ps h)
93   (invoke-dim1-ps "draw_bracket" h))
94
95 (define 
96   (bracket-tex h)
97   (embedded-ps-tex (bracket-ps h)))
98
99 (define 
100   (char o n) 
101   ((invoke-output o "invoke-char") "show" n))
102
103 (define 
104   (dashed-slur o thick dash l) 
105   ((invoke-output o "dashed-slur") thick dash l))
106
107 (define 
108   (dashed-slur-ps thick dash l)
109   (string-append 
110     (apply string-append (map control->string l)) 
111     (number->string thick) 
112    " [ "
113    (if (> 1 dash) (number->string (- (* thick dash) thick)) "0") " "
114    (number->string (* 2 thick))
115    " ] 0 draw_dashed_slur"))
116
117 (define 
118   (dashed-slur-tex thick dash l)
119   (embedded-ps-tex (dashed-slur-ps thick dash l)))
120
121 (define 
122   (doublebar o h)
123   ((invoke-output o "invoke-dim1") "doublebar" h))
124
125 (define 
126   (empty o) 
127   ((invoke-output o "empty")))
128
129 (define 
130   (empty-ps) 
131   "\n empty\n")
132
133 (define 
134   (empty-tex) 
135   "%\n\\empty%\n")
136
137 (define 
138   (emptybar o h) (empty o))
139
140 (define 
141   (end-output o) 
142   ((invoke-output o "end-output")))
143
144 (define 
145   (end-output-ps)
146   "\nshowpage\n")
147
148 (define 
149   (end-output-tex) 
150   "\n\\EndLilyPondOutput")
151
152 (define 
153   (experimental-on o) 
154   ((invoke-output o "experimental-on")))
155
156 (define
157   (experimental-on-ps) "")
158
159 (define
160   (experimental-on-tex) "\\turnOnExperimentalFeatures")
161
162 (define 
163   (extender o h)
164   ((invoke-output o "invoke-dim1") "extender" h))
165
166 (define
167   (fatdoublebar o h)
168   ((invoke-output o "invoke-dim1") "fatdoublebar" h))
169
170 (define
171   (finishbar o h)
172   ((invoke-output o "invoke-dim1") "finishbar" h))
173
174 (define
175   (font i)
176   (string-append
177    "font"
178    (make-string 1 (integer->char (+ (char->integer #\A) i)))
179    ))
180
181 (define 
182   (font-def o i s) 
183   ((invoke-output o "font-def") i s))
184
185 (define 
186   (font-def-ps i s)
187   (string-append
188    "\n/" (font i) " {/" 
189    (substring s 0 (- (string-length s) 4))
190    " findfont 12 scalefont setfont} bind def\n"))
191
192 (define 
193   (font-def-tex i s)
194   (string-append
195    "\\font" (font-switch-tex i) "=" s "\n"))
196
197 (define 
198   (font-switch o i) 
199   ((invoke-output o "font-switch") i))
200
201 (define 
202   (font-switch-ps i)
203   (string-append (font i) " "))
204
205 (define 
206   (font-switch-tex i)
207   (string-append
208    "\\" (font i) "\n"))
209
210 (define 
211   (generalmeter o num den)
212    ((invoke-output o "generalmeter") num den))
213
214 (define 
215   (generalmeter-ps num den)
216   (string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
217
218 (define 
219   (generalmeter-tex num den)
220   (string-append 
221    "\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
222
223 (define 
224   (header o creator generate) 
225   ((invoke-output o "header") creator generate))
226
227 (define 
228   (header-ps creator generate) 
229   (string-append
230    "%!PS-Adobe-3.0\n"
231    "%%Creator: " creator generate "\n"))
232
233 (define 
234   (header-tex creator generate) 
235   (string-append
236    "%created by: " creator generate "\n"))
237
238 (define 
239   (header-end o) 
240   ((invoke-output o "header-end")))
241
242 (define
243   (header-end-ps) "")
244
245 (define
246   (header-end-tex) "\\turnOnPostScript")
247
248 (define
249   (lily-def o key val)
250   ((invoke-output o "lily-def") key val))
251
252 (define
253   (lily-def-ps key val)
254   (string-append
255    "/" key " {" val "} bind def\n"))
256
257 (define
258   (lily-def-tex key val)
259   (string-append
260    "\\def\\" key "{" val "}\n"))
261
262 (define 
263   (maatstreep o h) 
264   ((invoke-output o "invoke-dim1") "maatstreep" h))
265
266 (define 
267   (pianobrace o i)
268   ((invoke-output o "invoke-char") "pianobrace" i))
269
270 (define 
271   (placebox o x y b) 
272   ((invoke-output o "placebox") x y (b o)))
273
274 (define 
275   (placebox-ps x y s) 
276   (string-append 
277    (number->string x) " " (number->string y) " {" s "} placebox "))
278
279 (define 
280   (placebox-tex x y s) 
281   (string-append 
282    "\\placebox{"
283    (number->dim-tex y) "}{" (number->dim-tex x) "}{" s "}"))
284
285 (define
286   (repeatbar o h)
287   ((invoke-output o "invoke-dim1") "repeatbar" h))
288
289 (define
290   (repeatbarstartrepeat o h)
291   ((invoke-output o "invoke-dim1") "repeatbarstartrepeat" h))
292
293 (define 
294   (rulesym o x y) 
295   ((invoke-output o "rulesym") x y))
296
297 (define 
298   (rulesym-ps x y) 
299   (string-append 
300    (number->string x) " "
301    (number->string y) " "
302    "rulesym"))
303
304 (define 
305   (rulesym-tex x y) 
306   (string-append 
307    "\\rulesym{" (number->dim-tex x) "}{" (number->dim-tex y) "}"))
308
309 (define 
310   (setbold o s) 
311   ((invoke-output o "text") "bold" s))
312
313 (define
314   (setdynamic o s) (empty o))
315
316 (define 
317   (setfinger o s) 
318   ((invoke-output o "text") "finger" s))
319
320 (define 
321   (sethuge o s) 
322   ((invoke-output o "text") "huge" s))
323
324 (define 
325   (setitalic o s) 
326   ((invoke-output o "text") "italic" s))
327
328 (define 
329   (setlarge o s) 
330   ((invoke-output o "text") "large" s))
331
332 (define 
333   (setLarge o s) 
334   ((invoke-output o "text") "Large" s))
335
336 (define 
337   (setnumber o s) 
338   ((invoke-output o "text") "number" s))
339
340 (define 
341   (settext o s) 
342   ((invoke-output o "text") "text" s))
343
344 (define 
345   (settypewriter o s) 
346   ((invoke-output o "text") "typewriter" s))
347
348 (define 
349   (slur o l) 
350   ((invoke-output o "slur") l))
351
352 (define 
353   (slur-ps l)
354   (string-append 
355    (apply string-append (map control->string l)) 
356    " draw_slur"))
357
358 (define 
359   (slur-tex l)
360   (embedded-ps-tex (slur-ps l)))
361
362 (define 
363   (stem o kern width height depth) 
364   ((invoke-output o "stem") kern width height depth))
365
366 (define 
367   (stem-ps kern width height depth) 
368   (string-append (numbers->string (list kern width height depth))
369                  "draw_stem" ))
370
371 (define 
372   (stem-tex kern width height depth) 
373   (string-append 
374    "\\kern" (number->dim-tex kern)
375    "\\vrule width " (number->dim-tex width)
376    "depth " (number->dim-tex depth)
377    "height " (number->dim-tex height) " "))
378
379 (define 
380   (start-line o) 
381   ((invoke-output o "start-line")))
382
383 (define 
384   (start-line-ps) 
385    "\nstart_line {\n")
386
387 (define 
388   (start-line-tex) 
389   (string-append 
390    "\\hbox{%\n")
391   )
392
393
394 (define
395   (startbar o h)
396   ((invoke-output o "invoke-dim1") "startbar" h))
397
398 (define
399   (startrepeat o h)
400   ((invoke-output o "invoke-dim1") "startrepeat" h))
401
402 (define 
403   (stop-line o) 
404   ((invoke-output o "stop-line")))
405
406 (define 
407   (stop-line-ps) 
408   "}\nstop_line\n")
409
410 (define 
411   (stop-line-tex) 
412   "}\\interscoreline")
413
414 (define
415   (stoprepeat o h)
416   ((invoke-output o "invoke-dim1") "stoprepeat" h))
417
418 (define
419   (text-ps f s)
420   (string-append "(" s ") set" f " "))
421
422 (define
423   (text-tex f s)
424   (string-append "\\set" f "{" s "}"))
425
426
427