]> git.donarmstrong.com Git - lilypond.git/blob - scm/lily.scm
patch::: 1.3.96.jcn9
[lilypond.git] / scm / 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
8 ;
9 ; This file contains various routines in Scheme that are easier to 
10 ; do here than in C++.  At present it is an unorganised mess. Sorry. 
11 ;
12
13
14 ; We should repartition the entire scm side of lily in a
15 ; more sane way, using namesspaces/modules?
16
17 ;(debug-enable 'backtrace)
18
19 ;;; library funtions
20
21 (use-modules (ice-9 regex))
22
23 ;; The regex module may not be available, or may be broken.
24 (define use-regex
25   (let ((os (string-downcase (vector-ref (uname) 0))))
26     (not (equal? "cygwin" (substring os 0 (min 6 (string-length os)))))))
27
28 ;; If you have trouble with regex, define #f
29 (define use-regex #t)
30 ;;(define use-regex #f)
31
32 ;; do nothing in .scm output
33 (define (comment s) "")
34
35 ;; URG guile-1.3/1.4 compatibility
36 (define (ly-eval x) (eval2 x #f))
37
38 (define (comment s) "")
39
40 (define (mm-to-pt x)
41   (* (/ 72.27 25.40) x)
42   )
43
44 (define (cons-map f x)
45   (cons (f (car x)) (f (cdr x))))
46
47 (define (reduce operator list)
48       (if (null? (cdr list)) (car list)
49           (operator (car list) (reduce operator (cdr list)))
50           )
51       )
52
53
54 (define (numbers->string l)
55   (apply string-append (map ly-number->string l)))
56
57 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
58
59 (define (number->octal-string x)
60   (let* ((n (inexact->exact x))
61          (n64 (quotient n 64))
62          (n8 (quotient (- n (* n64 64)) 8)))
63     (string-append
64      (number->string n64)
65      (number->string n8)
66      (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
67
68 (define (inexact->string x radix)
69   (let ((n (inexact->exact x)))
70     (number->string n radix)))
71
72
73 (define (control->string c)
74   (string-append (number->string (car c)) " "
75                  (number->string (cdr c)) " "))
76
77 (define (font i)
78   (string-append
79    "font"
80    (make-string 1 (integer->char (+ (char->integer #\A) i)))
81    ))
82
83 (define (scm-scm action-name)
84   1)
85
86 (define security-paranoia #f)
87
88
89 ;; silly, use alist? 
90 (define (find-notehead-symbol duration style)
91   (case style
92    ((cross) "2cross")
93    ((harmonic) "0mensural")
94    ((baroque) 
95     (string-append (number->string duration)
96                    (if (< duration 0) "mensural" "")))
97    ((default) (number->string duration))
98    (else
99     (string-append (number->string duration) (symbol->string style)))))
100
101
102 ;;;;;;;; TeX
103
104 ;; this is silly, can't we use something like
105 ;; roman-0, roman-1 roman+1 ?
106 (define cmr-alist 
107   '(("bold" . "cmbx") 
108     ("brace" . "feta-braces")
109     ("default" . "cmr10")
110     ("dynamic" . "feta-din") 
111     ("feta" . "feta") 
112     ("feta-1" . "feta") 
113     ("feta-2" . "feta") 
114     ("typewriter" . "cmtt") 
115     ("italic" . "cmti") 
116     ("msam" . "msam") 
117     ("roman" . "cmr") 
118     ("script" . "cmr") 
119     ("large" . "cmbx") 
120     ("Large" . "cmbx") 
121     ("mark" . "feta-nummer") 
122     ("finger" . "feta-nummer")
123     ("timesig" . "feta-nummer")
124     ("number" . "feta-nummer") 
125     ("volta" . "feta-nummer"))
126 )
127
128 (define (string-encode-integer i)
129   (cond
130    ((= i  0) "o")
131    ((< i 0)   (string-append "n" (string-encode-integer (- i))))
132    (else (string-append
133           (make-string 1 (integer->char (+ 65 (modulo i 26))))
134           (string-encode-integer (quotient i 26))
135          )
136    )
137   )
138   )
139
140 (define (magstep i)
141   (cdr (assoc i '((-4 . 482)
142                   (-3 . 579)
143                   (-2 . 694)
144                   (-1 . 833)
145                   (0 . 1000)
146                   (1 . 1200) 
147                   (2 . 1440)
148                   (3 . 1728)
149                   (4 . 2074))
150               )
151        )
152   )
153              
154 (define default-script-alist '())
155
156 (define font-name-alist  '())
157 (define (font-command name-mag)
158     (cons name-mag
159           (string-append  "magfont"
160                           (string-encode-integer (hashq (car name-mag) 1000000))
161                           "m"
162                           (string-encode-integer (cdr name-mag)))
163
164           )
165     )
166 (define (define-fonts names)
167   (set! font-name-alist (map font-command names))
168   (apply string-append
169          (map (lambda (x)
170                 (font-load-command (car x) (cdr x))) font-name-alist)
171   ))
172
173 (define (fontify name exp)
174   (string-append (select-font name)
175                  exp)
176   )
177
178 ;;;;;;;;;;;;;;;;;;;;
179
180
181 ; Make a function that checks score element for being of a specific type. 
182 (define (make-type-checker symbol)
183   (lambda (elt)
184     ;;(display  symbol)
185     ;;(eq? #t (ly-get-elt-property elt symbol))
186     (not (eq? #f (memq symbol (ly-get-elt-property elt 'interfaces))))
187     ))
188
189 ;;;;;;;;;;;;;;;;;;; TeX output
190 (define (tex-scm action-name)
191   (define (unknown) 
192     "%\n\\unknown%\n")
193
194
195   (define (select-font font-name-symbol)
196     (let*
197         (
198          (c (assoc font-name-symbol font-name-alist))
199          )
200
201       (if (eq? c #f)
202           (begin
203             (ly-warn (string-append
204                       "Programming error: No such font known " (car font-name-symbol)))
205             "")                         ; issue no command
206           (string-append "\\" (cdr c)))
207       
208       
209       ))
210   
211   (define (beam width slope thick)
212     (embedded-ps ((ps-scm 'beam) width slope thick)))
213
214   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
215     (embedded-ps ((ps-scm 'bracket) arch_angle arch_width arch_height width height arch_thick thick)))
216
217   (define (dashed-slur thick dash l)
218     (embedded-ps ((ps-scm 'dashed-slur)  thick dash l)))
219
220   (define (crescendo thick w h cont)
221     (embedded-ps ((ps-scm 'crescendo) thick w h cont)))
222
223   (define (char i)
224     (string-append "\\char" (inexact->string i 10) " "))
225   
226   (define (dashed-line thick on off dx dy)
227     (embedded-ps ((ps-scm 'dashed-line) thick on off dx dy)))
228
229   (define (decrescendo thick w h cont)
230     (embedded-ps ((ps-scm 'decrescendo) thick w h cont)))
231
232   (define (font-load-command name-mag command)
233     (string-append
234      "\\font\\" command "="
235      (symbol->string (car name-mag))
236      " scaled "
237      (number->string (magstep (cdr name-mag)))
238      "\n"))
239
240   (define (embedded-ps s)
241     (string-append "\\embeddedps{" s "}"))
242
243   (define (comment s)
244     (string-append "% " s))
245   
246   (define (end-output) 
247         (begin
248 ; uncomment for some stats about lily memory      
249 ;               (display (gc-stats))
250     (string-append "\n\\EndLilyPondOutput"
251                    ; Put GC stats here.
252                    )))
253   
254   (define (experimental-on)
255     "")
256
257   (define (font-switch i)
258     (string-append
259      "\\" (font i) "\n"))
260
261   (define (font-def i s)
262     (string-append
263      "\\font" (font-switch i) "=" s "\n"))
264
265   (define (header-end)
266     (string-append
267      "\\special{! "
268
269      ;; URG: ly-gulp-file: now we can't use scm output without Lily
270      (if use-regex
271          ;; fixed in 1.3.4 for powerpc -- broken on Windows
272          (regexp-substitute/global #f "\n"
273                                    (ly-gulp-file "lily.ps") 'pre " %\n" 'post)
274          (ly-gulp-file "lily.ps"))
275      "}"
276      "\\input lilyponddefs \\turnOnPostScript"))
277
278   (define (header creator generate) 
279     (string-append
280      "%created by: " creator generate "\n"))
281
282   (define (invoke-char s i)
283     (string-append 
284      "\n\\" s "{" (inexact->string i 10) "}" ))
285
286   (define (invoke-dim1 s d)
287     (string-append
288      "\n\\" s "{" (number->dim d) "}"))
289   (define (pt->sp x)
290     (* 65536 x))
291   
292   ;;
293   ;; need to do something to make this really safe.
294   ;;
295   (define (output-tex-string s)
296       (if security-paranoia
297           (if use-regex
298               (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
299               (begin (display "warning: not paranoid") (newline) s))
300           s))
301       
302   (define (lily-def key val)
303     (string-append
304      "\\def\\"
305      (if use-regex
306          ;; fixed in 1.3.4 for powerpc -- broken on Windows
307          (regexp-substitute/global #f "_"
308                                    (output-tex-string key) 'pre "X" 'post)
309          (output-tex-string key))
310      "{" (output-tex-string val) "}\n"))
311
312   (define (number->dim x)
313     (string-append 
314      (ly-number->string x) " pt "))
315
316   (define (placebox x y s) 
317     (string-append 
318      "\\placebox{"
319      (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
320
321   (define (bezier-sandwich l thick)
322     (embedded-ps ((ps-scm 'bezier-sandwich) l thick)))
323
324   (define (start-line ht)
325       (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
326
327   (define (stop-line) 
328     "}\\vss}\\interscoreline\n")
329   (define (stop-last-line)
330     "}\\vss}")
331   (define (filledbox breapth width depth height) 
332     (string-append 
333      "\\kern" (number->dim (- breapth))
334      "\\vrule width " (number->dim (+ breapth width))
335      "depth " (number->dim depth)
336      "height " (number->dim height) " "))
337
338   (define (text s)
339     (string-append "\\hbox{" (output-tex-string s) "}"))
340   
341   (define (tuplet ht gapx dx dy thick dir)
342     (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
343
344   (define (volta h w thick vert_start vert_end)
345     (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
346
347   (define (define-origin file line col)
348     ; use this for column positions
349      (string-append "\\special{src:" (number->string line) ":"
350         (number->string col) " " file "}"
351          ;; arg, the clueless take over the mailing list...
352 ;        "\\special{-****-These-warnings-are-harmless-***}"
353 ;        "\\special{-****-PLEASE-read-http://appel.lilypond.org/wiki/index.php3?PostProcessing-****}"
354         )
355
356      ; line numbers only:
357     ;(string-append "\\special{src:" (number->string line) " " file "}")
358 )
359     ; no origin  info: return empty string
360     ; ""
361   ; no-origin not yet supported by Xdvi
362   (define (no-origin) "")
363   
364   ;; TeX
365   ;; The procedures listed below form the public interface of TeX-scm.
366   ;; (should merge the 2 lists)
367   (cond ((eq? action-name 'all-definitions)
368          `(begin
369             (define font-load-command ,font-load-command)
370             (define beam ,beam)
371             (define bezier-sandwich ,bezier-sandwich)
372             (define bracket ,bracket)
373             (define char ,char)
374             (define crescendo ,crescendo)
375             (define dashed-line ,dashed-line) 
376             (define dashed-slur ,dashed-slur) 
377             (define decrescendo ,decrescendo) 
378             (define end-output ,end-output)
379             (define experimental-on ,experimental-on)
380             (define filledbox ,filledbox)
381             (define font-def ,font-def)
382             (define font-switch ,font-switch)
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 select-font ,select-font)
390             (define start-line ,start-line)
391             (define stop-line ,stop-line)
392             (define stop-last-line ,stop-last-line)
393             (define text ,text)
394             (define tuplet ,tuplet)
395             (define volta ,volta)
396             (define define-origin ,define-origin)
397             (define no-origin ,no-origin)
398             ))
399
400         ((eq? action-name 'beam) beam)
401         ((eq? action-name 'tuplet) tuplet)
402         ((eq? action-name 'bracket) bracket)
403         ((eq? action-name 'crescendo) crescendo)
404         ((eq? action-name 'dashed-line) dashed-line) 
405         ((eq? action-name 'dashed-slur) dashed-slur) 
406         ((eq? action-name 'decrescendo) decrescendo) 
407         ((eq? action-name 'end-output) end-output)
408         ((eq? action-name 'experimental-on) experimental-on)
409         ((eq? action-name 'font-def) font-def)
410         ((eq? action-name 'font-switch) font-switch)
411         ((eq? action-name 'header-end) header-end)
412         ((eq? action-name 'lily-def) lily-def)
413         ((eq? action-name 'header) header) 
414         ((eq? action-name 'invoke-char) invoke-char) 
415         ((eq? action-name 'invoke-dim1) invoke-dim1)
416         ((eq? action-name 'placebox) placebox)
417         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
418         ((eq? action-name 'start-line) start-line)
419         ((eq? action-name 'stem) stem)
420         ((eq? action-name 'stop-line) stop-line)
421         ((eq? action-name 'stop-last-line) stop-last-line)
422         ((eq? action-name 'volta) volta)
423         (else (error "unknown tag -- PS-TEX " action-name))
424         )
425   )
426
427
428 ;;;;;;;;;;;; PS
429 (define (ps-scm action-name)
430
431   ;; alist containing fontname -> fontcommand assoc (both strings)
432   (define font-alist '())
433   (define font-count 0)
434   (define current-font "")
435
436   
437   (define (cached-fontname i)
438     (string-append
439      "lilyfont"
440      (make-string 1 (integer->char (+ 65 i)))))
441     
442   (define (mag-to-size m)
443     (number->string (case m 
444                       (0 12)
445                       (1 12)
446                       (2 14) ; really: 14.400
447                       (3 17) ; really: 17.280
448                       (4 21) ; really: 20.736
449                       (5 24) ; really: 24.888
450                       (6 30) ; really: 29.856
451                       )))
452   
453   
454   (define (select-font font-name-symbol)
455     (let*
456         (
457          (c (assoc font-name-symbol font-name-alist))
458          )
459
460       (if (eq? c #f)
461           (begin
462             (ly-warn (string-append
463                       "Programming error: No such font known " (car font-name-symbol)))
464             "")                         ; issue no command
465           (string-append " " (cdr c) " "))
466       
467       
468       ))
469
470     (define (font-load-command name-mag command)
471       (string-append
472        "/" command
473        " { /"
474        (symbol->string (car name-mag))
475        " findfont "
476        (number->string (magstep (cdr name-mag)))
477        " 1000 div 12 mul  scalefont setfont } bind def "
478        "\n"))
479
480
481   (define (beam width slope thick)
482     (string-append
483      (numbers->string (list width slope thick)) " draw_beam" ))
484
485   (define (comment s)
486     (string-append "% " s))
487
488   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
489     (string-append
490      (numbers->string (list arch_angle arch_width arch_height width height arch_thick thick)) " draw_bracket" ))
491
492   (define (char i)
493     (invoke-char " show" i))
494
495   (define (crescendo thick w h cont )
496     (string-append 
497      (numbers->string (list w h (inexact->exact cont) thick))
498      " draw_crescendo"))
499
500   ;; what the heck is this interface ?
501   (define (dashed-slur thick dash l)
502     (string-append 
503      (apply string-append (map control->string l)) 
504      (number->string thick) 
505      " [ "
506      (number->string dash)
507      " "
508      (number->string (* 10 thick))      ;UGH.  10 ?
509      " ] 0 draw_dashed_slur"))
510
511   (define (dashed-line thick on off dx dy)
512     (string-append 
513      (number->string dx)
514      " "
515      (number->string dy)
516      " "
517      (number->string thick) 
518      " [ "
519      (number->string on)
520      " "
521      (number->string off)
522      " ] 0 draw_dashed_line"))
523
524   (define (decrescendo thick w h cont)
525     (string-append 
526      (numbers->string (list w h (inexact->exact cont) thick))
527      " draw_decrescendo"))
528
529
530   (define (end-output)
531     "\nshowpage\n")
532   
533   (define (experimental-on) "")
534   
535   (define (filledbox breapth width depth height) 
536     (string-append (numbers->string (list breapth width depth height))
537                    " draw_box" ))
538
539   ;; obsolete?
540   (define (font-def i s)
541     (string-append
542      "\n/" (font i) " {/" 
543      (substring s 0 (- (string-length s) 4))
544      " findfont 12 scalefont setfont} bind def \n"))
545
546   (define (font-switch i)
547     (string-append (font i) " "))
548
549   (define (header-end)
550     (string-append
551      ;; URG: now we can't use scm output without Lily
552      (ly-gulp-file "lilyponddefs.ps")
553      " {exch pop //systemdict /run get exec} "
554      (ly-gulp-file "lily.ps")
555      "{ exch pop //systemdict /run get exec } "
556     ))
557   
558   (define (lily-def key val)
559
560      (if (string=? (substring key 0 (min (string-length "mudelapaper") (string-length key))) "mudelapaper")
561          (string-append "/" key " {" val "} bind def\n")
562          (string-append "/" key " (" val ") def\n")
563          )
564      )
565
566   (define (header creator generate) 
567     (string-append
568      "%!PS-Adobe-3.0\n"
569      "%%Creator: " creator generate "\n"))
570   
571   (define (invoke-char s i)
572     (string-append 
573      "(\\" (inexact->string i 8) ") " s " " ))
574   
575   (define (invoke-dim1 s d) 
576     (string-append
577      (number->string (* d  (/ 72.27 72))) " " s ))
578
579   (define (placebox x y s) 
580     (string-append 
581      (number->string x) " " (number->string y) " {" s "} placebox "))
582
583   (define (bezier-sandwich l thick)
584     (string-append 
585      (apply string-append (map control->string l))
586      (number->string  thick)
587      " draw_bezier_sandwich"))
588
589   (define (start-line height)
590           "\nstart_line {\n")
591   
592   (define (stem breapth width depth height) 
593     (string-append (numbers->string (list breapth width depth height))
594                    " draw_box" ))
595
596   (define (stop-line)
597       "}\nstop_line\n")
598
599   (define (text s)
600     (string-append "(" s ") show  "))
601
602
603   (define (volta h w thick vert_start vert_end)
604     (string-append 
605      (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
606      " draw_volta"))
607
608   (define (tuplet ht gap dx dy thick dir)
609     (string-append 
610      (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
611      " draw_tuplet"))
612
613
614   (define (unknown) 
615     "\n unknown\n")
616
617
618   (define (define-origin a b c ) "")
619   (define (no-origin) "")
620   
621   ;; PS
622   (cond ((eq? action-name 'all-definitions)
623          `(begin
624             (define beam ,beam)
625             (define tuplet ,tuplet)
626             (define bracket ,bracket)
627             (define char ,char)
628             (define crescendo ,crescendo)
629             (define volta ,volta)
630             (define bezier-sandwich ,bezier-sandwich)
631             (define dashed-line ,dashed-line) 
632             (define dashed-slur ,dashed-slur) 
633             (define decrescendo ,decrescendo) 
634             (define end-output ,end-output)
635             (define experimental-on ,experimental-on)
636             (define filledbox ,filledbox)
637             (define font-def ,font-def)
638             (define font-switch ,font-switch)
639             (define header-end ,header-end)
640             (define lily-def ,lily-def)
641             (define font-load-command ,font-load-command)
642             (define header ,header) 
643             (define invoke-char ,invoke-char) 
644             (define invoke-dim1 ,invoke-dim1)
645             (define placebox ,placebox)
646             (define select-font ,select-font)
647             (define start-line ,start-line)
648             (define stem ,stem)
649             (define stop-line ,stop-line)
650             (define stop-last-line ,stop-line)
651             (define text ,text)
652             (define no-origin ,no-origin)
653             (define define-origin ,define-origin)
654             ))
655         ((eq? action-name 'tuplet) tuplet)
656         ((eq? action-name 'beam) beam)
657         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
658         ((eq? action-name 'bracket) bracket)
659         ((eq? action-name 'char) char)
660         ((eq? action-name 'crescendo) crescendo)
661         ((eq? action-name 'dashed-line) dashed-line) 
662         ((eq? action-name 'dashed-slur) dashed-slur) 
663         ((eq? action-name 'decrescendo) decrescendo)
664         ((eq? action-name 'experimental-on) experimental-on)
665         ((eq? action-name 'filledbox) filledbox)
666         ((eq? action-name 'select-font) select-font)
667         ((eq? action-name 'volta) volta)
668         (else (error "unknown tag -- PS-SCM " action-name))
669         )
670   )
671
672
673 (define (arg->string arg)
674   (cond ((number? arg) (inexact->string arg 10))
675         ((string? arg) (string-append "\"" arg "\""))
676         ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
677
678 (define (func name . args)
679   (string-append 
680    "(" name 
681    (if (null? args) 
682        ""
683        (apply string-append 
684               (map (lambda (x) (string-append " " (arg->string x))) args)))
685    ")\n"))
686
687 (define (sign x)
688   (if (= x 0)
689       1
690       (if (< x 0) -1 1)))
691
692 ;;;; AsciiScript as
693 (define (as-scm action-name)
694
695   (define (beam width slope thick)
696           (string-append
697            (func "set-line-char" "#")
698            (func "rline-to" width (* width slope))
699            ))
700
701   ; simple flat slurs
702   (define (bezier-sandwich l thick)
703           (let (
704                 (c0 (cadddr l))
705                 (c1 (cadr l))
706                 (c3 (caddr l)))
707                (let* ((x (car c0))
708                       (dx (- (car c3) x))
709                       (dy (- (cdr c3) (cdr c0)))
710                       (rc (/ dy dx))
711                       (c1-dx (- (car c1) x))
712                       (c1-line-y (+ (cdr c0) (* c1-dx rc)))
713                       (dir (if (< c1-line-y (cdr c1)) 1 -1))
714                       (y (+ -1 (* dir (max (* dir (cdr c0)) (* dir (cdr c3)))))))
715                      (string-append
716                       (func "rmove-to" x y)
717                       (func "put" (if (< 0 dir) "/" "\\\\"))
718                       (func "rmove-to" 1 (if (< 0 dir) 1 0))
719                       (func "set-line-char" "_")
720                       (func "h-line" (- dx 1))
721                       (func "rmove-to" (- dx 1) (if (< 0 dir) -1 0))
722                       (func "put" (if (< 0 dir) "\\\\" "/"))))))
723
724   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
725           (string-append
726            (func "rmove-to" (+ width 1) (- (/ height -2) 1))
727            (func "put" "\\\\")
728            (func "set-line-char" "|")
729            (func "rmove-to" 0 1)
730            (func "v-line" (+ height 1))
731            (func "rmove-to" 0 (+ height 1))
732            (func "put" "/")
733            ))
734
735   (define (char i)
736     (func "char" i))
737
738   (define (define-origin a b c ) "")
739
740   (define (end-output) 
741     (func "end-output"))
742   
743   (define (experimental-on)
744           "")
745
746   (define (filledbox breapth width depth height)
747           (let ((dx (+ width breapth))
748                 (dy (+ depth height)))
749                (string-append 
750                 (func "rmove-to" (* -1 breapth) (* -1 depth))
751                 (if (< dx dy)
752                     (string-append
753                      (func "set-line-char" 
754                            (if (<= dx 1) "|" "#"))
755                      (func "v-line" dy))
756                     (string-append
757                      (func "set-line-char" 
758                            (if (<= dy 1) "-" "="))
759                     (func "h-line" dx))))))
760
761   (define (font-load-command name-mag command)
762     (func "load-font" (car name-mag) (magstep (cdr name-mag))))
763
764   (define (header creator generate) 
765     (func "header" creator generate))
766
767   (define (header-end) 
768     (func "header-end"))
769
770   ;; urg: this is good for half of as2text's execution time
771   (define (xlily-def key val)
772           (string-append "(define " key " " (arg->string val) ")\n"))
773
774   (define (lily-def key val)
775           (if 
776            (or (equal? key "mudelapaperlinewidth")
777                (equal? key "mudelapaperstaffheight"))
778            (string-append "(define " key " " (arg->string val) ")\n")
779            ""))
780
781   (define (no-origin) "")
782   
783   (define (placebox x y s) 
784     (let ((ey (inexact->exact y)))
785           (string-append "(move-to " (number->string (inexact->exact x)) " "
786                          (if (= 0.5 (- (abs y) (abs ey)))
787                              (number->string y)
788                              (number->string ey))
789                          ")\n" s)))
790                        
791   (define (select-font font-name-symbol)
792     (let* ((c (assoc font-name-symbol font-name-alist)))
793       (if (eq? c #f)
794           (begin
795             (ly-warn 
796              (string-append 
797               "Programming error: No such font known " 
798               (car font-name-symbol)))
799             "")                         ; issue no command
800           (func "select-font" (car font-name-symbol)))))
801
802   (define (start-line height)
803           (func "start-line" height))
804
805   (define (stop-line)
806           (func "stop-line"))
807
808   (define (text s)
809           (func "text" s))
810
811   (define (tuplet ht gap dx dy thick dir) "")
812
813   (define (volta h w thick vert-start vert-end)
814           ;; urg
815           (string-append
816            (func "set-line-char" "|")
817            (func "rmove-to" 0 -4)
818            ;; definition strange-way around
819            (if (= 0 vert-start)
820               (func "v-line" h)
821                "")
822            (func "rmove-to" 1 h)
823            (func "set-line-char" "_")
824            (func "h-line" (- w 1))
825            (func "set-line-char" "|")
826            (if (= 0 vert-end)
827                (string-append
828                 (func "rmove-to" (- w 1) (* -1 h))
829                 (func "v-line" (* -1 h)))
830                "")))
831
832   (cond ((eq? action-name 'all-definitions)
833          `(begin
834             (define beam ,beam)
835             (define bracket ,bracket)
836             (define char ,char)
837             (define define-origin ,define-origin)
838             ;;(define crescendo ,crescendo)
839             (define bezier-sandwich ,bezier-sandwich)
840             ;;(define dashed-slur ,dashed-slur) 
841             ;;(define decrescendo ,decrescendo) 
842             (define end-output ,end-output)
843             (define experimental-on ,experimental-on)
844             (define filledbox ,filledbox)
845             ;;(define font-def ,font-def)
846             (define font-load-command ,font-load-command)
847             ;;(define font-switch ,font-switch)
848             (define header ,header) 
849             (define header-end ,header-end)
850             (define lily-def ,lily-def)
851             ;;(define invoke-char ,invoke-char) 
852             ;;(define invoke-dim1 ,invoke-dim1)
853             (define no-origin ,no-origin)
854             (define placebox ,placebox)
855             (define select-font ,select-font)
856             (define start-line ,start-line)
857             ;;(define stem ,stem)
858             (define stop-line ,stop-line)
859             (define stop-last-line ,stop-line)
860             (define text ,text)
861             (define tuplet ,tuplet)
862             (define volta ,volta)
863             ))
864         ((eq? action-name 'tuplet) tuplet)
865         ;;((eq? action-name 'beam) beam)
866         ;;((eq? action-name 'bezier-sandwich) bezier-sandwich)
867         ;;((eq? action-name 'bracket) bracket)
868         ((eq? action-name 'char) char)
869         ;;((eq? action-name 'crescendo) crescendo)
870         ;;((eq? action-name 'dashed-slur) dashed-slur) 
871         ;;((eq? action-name 'decrescendo) decrescendo)
872         ;;((eq? action-name 'experimental-on) experimental-on)
873         ((eq? action-name 'filledbox) filledbox)
874         ((eq? action-name 'select-font) select-font)
875         ;;((eq? action-name 'volta) volta)
876         (else (error "unknown tag -- MUSA-SCM " action-name))
877         )
878   )
879
880
881 (define (gulp-file name)
882   (let* ((port (open-file name "r"))
883          (content (let loop ((text ""))
884                        (let ((line (read-line port)))
885                             (if (or (eof-object? line)
886                                     (not line)) 
887                                 text
888                                 (loop (string-append text line "\n")))))))
889         (close port)
890         content))
891
892 ;; urg: Use when standalone, do:
893 ;; (define ly-gulp-file scm-gulp-file)
894 (define (scm-gulp-file name)
895   (set! %load-path 
896         (cons (string-append (getenv 'LILYPONDPREFIX) "/ly")
897               (cons (string-append (getenv 'LILYPONDPREFIX) "/ps")
898                     %load-path)))
899   (let ((path (%search-load-path name)))
900        (if path
901            (gulp-file path)
902            (gulp-file name))))
903
904 (define (scm-tex-output)
905   (ly-eval (tex-scm 'all-definitions)))
906                                 
907 (define (scm-ps-output)
908   (ly-eval (ps-scm 'all-definitions)))
909
910 (define (scm-as-output)
911   (ly-eval (as-scm 'all-definitions)))
912         
913 (define (index-cell cell dir)
914   (if (equal? dir 1)
915       (cdr cell)
916       (car cell)))
917
918 (define major-scale
919   '(
920     (0 . 0)
921     (1 . 0)
922     (2 . 0)
923     (3 . 0)
924     (4 . 0)
925     (5 . 0)
926     (6 . 0)
927     )
928   )
929
930 (begin
931   (eval-string (ly-gulp-file "interface.scm"))
932   (eval-string (ly-gulp-file "slur.scm"))
933   (eval-string (ly-gulp-file "font.scm"))  
934   (eval-string (ly-gulp-file "generic-property.scm"))
935   (eval-string (ly-gulp-file "basic-properties.scm"))
936   (eval-string (ly-gulp-file "chord-names.scm"))
937   (eval-string (ly-gulp-file "element-descriptions.scm"))  
938  )