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