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