]> git.donarmstrong.com Git - lilypond.git/blob - scm/lily.scm
release: 1.3.25
[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 ;(debug-enable 'backtrace)
9
10 ;;; library funtions
11
12 (use-modules (ice-9 regex))
13
14 ;; do nothing in .scm output
15 (define (comment s) "")
16
17 (define (mm-to-pt x)
18   (* (/ 72.27 25.40) x)
19   )
20
21 (define (cons-map f x)
22   (cons (f (car x)) (f (cdr x))))
23
24 (define (reduce operator list)
25       (if (null? (cdr list)) (car list)
26           (operator (car list) (reduce operator (cdr list)))
27           )
28       )
29
30 (define (glue-2-strings a b) 
31   (string-append a " " b))
32
33 (define (numbers->string l)
34   (reduce glue-2-strings (map number->string l)))
35
36 (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
37
38 (define (number->octal-string x)
39   (let* ((n (inexact->exact x))
40          (n64 (quotient n 64))
41          (n8 (quotient (- n (* n64 64)) 8)))
42     (string-append
43      (number->string n64)
44      (number->string n8)
45      (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
46
47 (define (inexact->string x radix)
48   (let ((n (inexact->exact x)))
49     (number->string n radix)))
50
51
52 (define
53   (control->string c)
54   (string-append
55    (string-append (number->string (car c)) " ")
56    (string-append (number->string (cdr c)) " ")))
57
58
59 (define (font i)
60   (string-append
61    "font"
62    (make-string 1 (integer->char (+ (char->integer #\A) i)))
63    ))
64
65
66
67 (define (scm-scm action-name)
68   1)
69
70 (define security-paranoia #f)
71
72
73 ;; See documentation of Item::visibility_lambda_
74 (define (postbreak-only-visibility d) (if (= d 1) '(#f . #f) '(#t . #t)))
75 (define (spanbar-non-postbreak-visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
76 (define (all-visibility d) '(#f . #f))
77 (define (non-postbreak-visibility d) (if (= d 1) '(#t . #t) '(#f . #f)))
78 (define (non-prebreak-visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
79
80
81 ;; Score_span_bars are only visible at start of line
82 ;; i.e. if break_dir == RIGHT == 1
83 (define Span_bar_engraver-visibility non-postbreak-visibility)
84 (define Base_span_bar_engraver-visibility non-postbreak-visibility)
85 (define mark-visibility non-prebreak-visibility)
86 (define Span_score_bar_engraver-visibility postbreak-only-visibility)
87 (define Piano_bar_engraver-visibility postbreak-only-visibility)
88 (define Staff_group_bar_engraver-visibility postbreak-only-visibility)
89
90 ;; Spacing constants for prefatory matter.
91 ;;
92 ;; rules for this spacing are much more complicated than this. See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
93 ;;
94 ;;
95
96 ;; (Measured in interlines? -- jcn)
97 (define space-alist
98  '(
99    (("" "Clef_item") . (minimum-space 1.0))
100    (("" "Staff_bar") . (minimum-space 0.0))
101    (("" "Clef_item") . (minimum-space 1.0))
102    (("" "Key_item") . (minimum-space 0.5))
103    (("" "Span_bar") . (extra-space 0.0))
104    (("" "Time_signature") . (extra-space 0.0))
105    (("" "begin-of-note") . (minimum-space 1.5))
106    (("Clef_item" "Key_item") . (minimum-space 4.0))
107    (("Key_item" "Time_signature") . (extra-space 1.0))
108    (("Clef_item"  "Time_signature") . (minimum-space 3.5))
109    (("Staff_bar" "Clef_item") .   (minimum-space 1.0))
110    (("Clef_item"  "Staff_bar") .  (minimum-space 3.7))
111    (("Time_signature" "Staff_bar") .  (minimum-space 2.0))
112    (("Key_item"  "Staff_bar") .  (extra-space 1.0))
113    (("Span_bar" "Clef_item") .   (extra-space 1.0))
114    (("Clef_item"  "Span_bar") . (minimum-space 3.7))
115    (("Time_signature" "Span_bar") . (minimum-space 2.0))
116    (("Key_item"  "Span_bar") . (minimum-space 2.5))
117    (("Staff_bar" "Time_signature") . (minimum-space 1.5)) ;double check this.
118    (("Time_signature" "begin-of-note") . (extra-space 2.0)) ;double check this.
119    (("Key_item" "begin-of-note") . (extra-space 2.5))
120    (("Staff_bar" "begin-of-note") . (extra-space 1.0))
121    (("Clef_item" "begin-of-note") . (minimum-space 5.0))
122    (("" "Breathing_sign") . (minimum-space 0.0))
123    (("Breathing_sign" "Key_item") . (minimum-space 1.5))
124    (("Breathing_sign" "begin-of-note") . (minimum-space 1.0))
125    (("Breathing_sign" "Staff_bar") . (minimum-space 1.5))
126    (("Breathing_sign" "Clef_item") . (minimum-space 2.0))
127    )
128 )
129  
130 (define (break-align-spacer this next)
131   (let ((entry (assoc `(,this ,next) space-alist)))
132     (if entry
133         (cdr entry)
134         (begin (ly-warn (string-append "Unknown spacing pair `" this "', `" next "'"))
135                '(minimum-space 0.0)))))
136   
137
138
139 ;;;;;;;; TeX
140
141 ;; this is silly, can't we use something like
142 ;; roman-0, roman-1 roman+1 ?
143 (define cmr-alist 
144   '(("bold" . "cmbx") 
145     ("brace" . "feta-braces")
146     ("dynamic" . "feta-din") 
147     ("feta" . "feta") 
148     ("feta-1" . "feta") 
149     ("feta-2" . "feta") 
150     ("finger" . "feta-nummer") 
151     ("typewriter" . "cmtt") 
152     ("italic" . "cmti") 
153     ("roman" . "cmr") 
154     ("script" . "cmr") 
155     ("large" . "cmbx") 
156     ("Large" . "cmbx") 
157     ("mark" . "feta-nummer") 
158     ("number" . "feta-nummer") 
159     ("volta" . "feta-nummer"))
160 )
161
162 (define (string-encode-integer i)
163   (cond
164    ((= i  0) "o")
165    ((< i 0)   (string-append "n" (string-encode-integer (- i))))
166    (else (string-append
167           (make-string 1 (integer->char (+ 65 (modulo i 26))))
168           (string-encode-integer (quotient i 26))
169          )
170    )
171   )
172   )
173
174 (define (magstep i)
175   (cdr (assoc i '((-4 . 482)
176                   (-3 . 579)
177                   (-2 . 694)
178                   (-1 . 833)
179                   (0 . 1000)
180                   (1 . 1200) 
181                   (2 . 1440)
182                   (3 . 1728)
183                   (4 . 2074))
184               )
185        )
186   )
187              
188 (define script-alist '())
189 (define (articulation-to-scriptdef a)
190   (assoc a script-alist)
191   )
192
193 ;; Map style names to TeX font names.  Return false if 
194 ;; no font name found. 
195 (define (style-to-cmr s)
196   (assoc s cmr-alist )
197   )
198             
199
200
201 (define font-name-alist  '())
202 (define (font-command name-mag)
203     (cons name-mag
204           (string-append  "magfont"
205                           (string-encode-integer (hashq (car name-mag) 1000000))
206                           "m"
207                           (string-encode-integer (cdr name-mag)))
208
209           )
210     )
211 (define (define-fonts names)
212   (set! font-name-alist (map font-command names))
213   (apply string-append
214          (map (lambda (x)
215                 (font-load-command (car x) (cdr x))) font-name-alist)
216   ))
217   
218
219 (define (tex-scm action-name)
220   (define (unknown) 
221     "%\n\\unknown%\n")
222
223
224   (define (select-font font-name-symbol)
225     (let*
226         (
227          (c (assoc font-name-symbol font-name-alist))
228          )
229
230       (if (eq? c #f)
231           (begin
232             (ly-warn (string-append
233                       "Programming error: No such font known " (car font-name-symbol)))
234             "")                         ; issue no command
235           (string-append "\\" (cdr c)))
236       
237       
238       ))
239   
240   (define (beam width slope thick)
241     (embedded-ps ((ps-scm 'beam) width slope thick)))
242
243   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
244     (embedded-ps ((ps-scm 'bracket) arch_angle arch_width arch_height width height arch_thick thick)))
245
246   (define (dashed-slur thick dash l)
247     (embedded-ps ((ps-scm 'dashed-slur)  thick dash l)))
248
249   (define (crescendo thick w h cont)
250     (embedded-ps ((ps-scm 'crescendo) thick w h cont)))
251
252   (define (char i)
253     (string-append "\\char" (inexact->string i 10) " "))
254   
255   (define (decrescendo thick w h cont)
256     (embedded-ps ((ps-scm 'decrescendo) thick w h cont)))
257
258    ;This sets CTM so that you get to the currentpoint
259   ; by executing a 0 0 moveto
260
261   
262  
263
264   (define (font-load-command name-mag command)
265     (string-append
266      "\\font\\" command "="
267      (symbol->string (car name-mag))
268      " scaled "
269      (number->string (magstep (cdr name-mag)))
270      "\n"))
271
272
273   (define (embedded-ps s)
274     (string-append "\\embeddedps{" s "}"))
275
276   (define (comment s)
277     (string-append "% " s))
278   
279   (define (end-output) 
280     "\n\\EndLilyPondOutput")
281   
282   (define (experimental-on)
283     "")
284
285   (define (font-switch i)
286     (string-append
287      "\\" (font i) "\n"))
288
289   (define (font-def i s)
290     (string-append
291      "\\font" (font-switch i) "=" s "\n"))
292
293   (define (header-end)
294     (string-append
295      "\\special{! "
296      ; fixed in 1.3.4
297      ;(ly-gulp-file "lily.ps")
298
299      (regexp-substitute/global #f "\n" (ly-gulp-file "lily.ps") 'pre " %\n" 'post)
300      "}"
301      "\\input lilyponddefs \\turnOnPostScript"))
302
303   (define (header creator generate) 
304     (string-append
305      "%created by: " creator generate "\n"))
306
307   (define (invoke-char s i)
308     (string-append 
309      "\n\\" s "{" (inexact->string i 10) "}" ))
310
311   (define (invoke-dim1 s d)
312     (string-append
313      "\n\\" s "{" (number->dim d) "}"))
314   (define (pt->sp x)
315     (* 65536 x))
316   
317   ;;
318   ;; need to do something to make this really safe.
319   ;;
320   (define (output-tex-string s)
321       (if security-paranoia
322           (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
323           s))
324       
325   (define (lily-def key val)
326     (string-append
327      "\\def\\"
328      ; fixed in 1.3.4
329      (regexp-substitute/global #f "_" (output-tex-string key) 'pre "X" 'post)
330      ;(output-tex-string key)
331      "{" (output-tex-string val) "}\n"))
332
333   (define (number->dim x)
334     (string-append 
335      (number->string  (chop-decimal x)) " pt "))
336
337   (define (placebox x y s) 
338     (string-append 
339      "\\placebox{"
340      (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
341
342   (define (bezier-sandwich l thick)
343     (embedded-ps ((ps-scm 'bezier-sandwich) l thick)))
344
345   (define (start-line ht)
346       (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
347
348   (define (stop-line) 
349     "}\\vss}\\interscoreline")
350   (define (stop-last-line)
351     "}\\vss}")
352   (define (filledbox breapth width depth height) 
353     (string-append 
354      "\\kern" (number->dim (- breapth))
355      "\\vrule width " (number->dim (+ breapth width))
356      "depth " (number->dim depth)
357      "height " (number->dim height) " "))
358
359   (define (text s)
360     (string-append "\\hbox{" (output-tex-string s) "}"))
361   
362   (define (tuplet ht gapx dx dy thick dir)
363     (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
364
365   (define (volta h w thick vert_start vert_end)
366     (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
367
368   ;; TeX
369   ;; The procedures listed below form the public interface of TeX-scm.
370   ;; (should merge the 2 lists)
371   (cond ((eq? action-name 'all-definitions)
372          `(begin
373             (define font-load-command ,font-load-command)
374             (define beam ,beam)
375             (define bezier-sandwich ,bezier-sandwich)
376             (define bracket ,bracket)
377             (define char ,char)
378             (define crescendo ,crescendo)
379             (define dashed-slur ,dashed-slur) 
380             (define decrescendo ,decrescendo) 
381             (define end-output ,end-output)
382             (define experimental-on ,experimental-on)
383             (define filledbox ,filledbox)
384             (define font-def ,font-def)
385             (define font-switch ,font-switch)
386             (define header-end ,header-end)
387             (define lily-def ,lily-def)
388             (define header ,header) 
389             (define invoke-char ,invoke-char) 
390             (define invoke-dim1 ,invoke-dim1)
391             (define placebox ,placebox)
392             (define select-font ,select-font)
393             (define start-line ,start-line)
394             (define stop-line ,stop-line)
395             (define stop-last-line ,stop-last-line)
396             (define text ,text)
397             (define tuplet ,tuplet)
398             (define volta ,volta)
399             ))
400
401         ((eq? action-name 'beam) beam)
402         ((eq? action-name 'tuplet) tuplet)
403         ((eq? action-name 'bracket) bracket)
404         ((eq? action-name 'crescendo) crescendo)
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
432   ;; alist containing fontname -> fontcommand assoc (both strings)
433   (define font-alist '())
434   (define font-count 0)
435   (define current-font "")
436
437   
438   (define (cached-fontname i)
439     (string-append
440      "lilyfont"
441      (make-string 1 (integer->char (+ 65 i)))))
442     
443   (define (mag-to-size m)
444     (number->string (case m 
445                       (0 12)
446                       (1 12)
447                       (2 14) ; really: 14.400
448                       (3 17) ; really: 17.280
449                       (4 21) ; really: 20.736
450                       (5 24) ; really: 24.888
451                       (6 30) ; really: 29.856
452                       )))
453   
454   
455   (define (select-font font-name-symbol)
456     (let*
457         (
458          (c (assoc font-name-symbol font-name-alist))
459          )
460
461       (if (eq? c #f)
462           (begin
463             (ly-warn (string-append
464                       "Programming error: No such font known " (car font-name-symbol)))
465             "")                         ; issue no command
466           (string-append " " (cdr c) " "))
467       
468       
469       ))
470
471     (define (font-load-command name-mag command)
472       (string-append
473        "/" command
474        " { /"
475        (symbol->string (car name-mag))
476        " findfont "
477        (number->string (magstep (cdr name-mag)))
478        " 1000 div 12 mul  scalefont setfont } bind def "
479        "\n"))
480
481
482   (define (beam width slope thick)
483     (string-append
484      (numbers->string (list width slope thick)) " draw_beam" ))
485
486   (define (comment s)
487     (string-append "% " s))
488
489   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
490     (string-append
491      (numbers->string (list arch_angle arch_width arch_height width height arch_thick thick)) " draw_bracket" ))
492
493   (define (char i)
494     (invoke-char " show" i))
495
496   (define (crescendo thick w h cont )
497     (string-append 
498      (numbers->string (list w h (inexact->exact cont) thick))
499      " draw_crescendo"))
500
501   ;; what the heck is this interface ?
502   (define (dashed-slur thick dash l)
503     (string-append 
504      (apply string-append (map control->string l)) 
505      (number->string thick) 
506      " [ "
507      (number->string dash)
508      " "
509      (number->string (* 10 thick))      ;UGH.  10 ?
510      " ] 0 draw_dashed_slur"))
511
512   (define (decrescendo thick w h cont)
513     (string-append 
514      (numbers->string (list w h (inexact->exact cont) thick))
515      " draw_decrescendo"))
516
517
518   (define (end-output)
519     "\nshowpage\n")
520   
521   (define (experimental-on) "")
522   
523   (define (filledbox breapth width depth height) 
524     (string-append (numbers->string (list breapth width depth height))
525                    " draw_box" ))
526
527   ;; obsolete?
528   (define (font-def i s)
529     (string-append
530      "\n/" (font i) " {/" 
531      (substring s 0 (- (string-length s) 4))
532      " findfont 12 scalefont setfont} bind def \n"))
533
534   (define (font-switch i)
535     (string-append (font i) " "))
536
537   (define (header-end)
538     (string-append
539      (ly-gulp-file "lilyponddefs.ps")
540      " {exch pop //systemdict /run get exec} "
541      (ly-gulp-file "lily.ps")
542      "{ exch pop //systemdict /run get exec } "
543     ))
544   
545   (define (lily-def key val)
546
547      (if (string=? (substring key 0 (min (string-length "mudelapaper") (string-length key))) "mudelapaper")
548          (string-append "/" key " {" val "} bind def\n")
549          (string-append "/" key " (" val ") def\n")
550          )
551      )
552
553   (define (header creator generate) 
554     (string-append
555      "%!PS-Adobe-3.0\n"
556      "%%Creator: " creator generate "\n"))
557   
558   (define (invoke-char s i)
559     (string-append 
560      "(\\" (inexact->string i 8) ") " s " " ))
561   
562   (define (invoke-dim1 s d) 
563     (string-append
564      (number->string (* d  (/ 72.27 72))) " " s ))
565
566   (define (placebox x y s) 
567     (string-append 
568      (number->string x) " " (number->string y) " {" s "} placebox "))
569
570   (define (bezier-sandwich l thick)
571     (string-append 
572      (apply string-append (map control->string l))
573      (number->string  thick)
574      " draw_bezier_sandwich"))
575
576   (define (start-line height)
577           "\nstart_line {\n")
578   
579   (define (stem breapth width depth height) 
580     (string-append (numbers->string (list breapth width depth height))
581                    " draw_box" ))
582
583   (define (stop-line)
584       "}\nstop_line\n")
585
586   (define (text s)
587     (string-append "(" s ") show  "))
588
589
590   (define (volta h w thick vert_start vert_end)
591     (string-append 
592      (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
593      " draw_volta"))
594
595   (define (tuplet ht gap dx dy thick dir)
596     (string-append 
597      (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
598      " draw_tuplet"))
599
600
601   (define (unknown) 
602     "\n unknown\n")
603
604
605   ;; PS
606   (cond ((eq? action-name 'all-definitions)
607          `(begin
608             (define beam ,beam)
609             (define tuplet ,tuplet)
610             (define bracket ,bracket)
611             (define char ,char)
612             (define crescendo ,crescendo)
613             (define volta ,volta)
614             (define bezier-sandwich ,bezier-sandwich)
615             (define dashed-slur ,dashed-slur) 
616             (define decrescendo ,decrescendo) 
617             (define end-output ,end-output)
618             (define experimental-on ,experimental-on)
619             (define filledbox ,filledbox)
620             (define font-def ,font-def)
621             (define font-switch ,font-switch)
622             (define header-end ,header-end)
623             (define lily-def ,lily-def)
624             (define font-load-command ,font-load-command)
625             (define header ,header) 
626             (define invoke-char ,invoke-char) 
627             (define invoke-dim1 ,invoke-dim1)
628             (define placebox ,placebox)
629             (define select-font ,select-font)
630             (define start-line ,start-line)
631             (define stem ,stem)
632             (define stop-line ,stop-line)
633             (define stop-last-line ,stop-line)
634             (define text ,text)
635             ))
636         ((eq? action-name 'tuplet) tuplet)
637         ((eq? action-name 'beam) beam)
638         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
639         ((eq? action-name 'bracket) bracket)
640         ((eq? action-name 'char) char)
641         ((eq? action-name 'crescendo) crescendo)
642         ((eq? action-name 'dashed-slur) dashed-slur) 
643         ((eq? action-name 'decrescendo) decrescendo)
644         ((eq? action-name 'experimental-on) experimental-on)
645         ((eq? action-name 'filledbox) filledbox)
646         ((eq? action-name 'select-font) select-font)
647         ((eq? action-name 'volta) volta)
648         (else (error "unknown tag -- PS-SCM " action-name))
649         )
650   )
651
652
653 (define (arg->string arg)
654   (cond ((number? arg) (inexact->string arg 10))
655         ((string? arg) (string-append "\"" arg "\""))
656         ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
657
658 (define (func name . args)
659   (string-append 
660    "(" name 
661    (if (null? args) 
662        ""
663        (apply string-append 
664               (map (lambda (x) (string-append " " (arg->string x))) args)))
665    ")\n"))
666
667
668 ;;;; AsciiScript as
669 (define (as-scm action-name)
670
671   (define (beam width slope thick)
672           (string-append
673            (func "set-line-char" "#")
674            (func "rline-to" width (* width slope))
675            ))
676
677   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
678           (string-append
679            (func "rmove-to" (+ width 1) (- (/ height -2) 1))
680            (func "put" "\\\\")
681            (func "set-line-char" "|")
682            (func "rmove-to" 0 1)
683            (func "v-line" (+ height 1))
684            (func "rmove-to" 0 (+ height 1))
685            (func "put" "/")
686            ))
687
688   (define (char i)
689     (func "char" i))
690
691   (define (end-output) 
692     (func "end-output"))
693   
694   (define (experimental-on)
695           "")
696
697   (define (filledbox breapth width depth height)
698           (let ((dx (+ width breapth))
699                 (dy (+ depth height)))
700                (string-append 
701                 (func "rmove-to" (* -1 breapth) (* -1 depth))
702                 (if (< dx dy)
703                     (string-append
704                      (func "set-line-char" 
705                            (if (<= dx 1) "|" "#"))
706                      (func "v-line" dy))
707                     (string-append
708                      (func "set-line-char" 
709                            (if (<= dy 1) "-" "="))
710                     (func "h-line" dx))))))
711
712   (define (font-load-command name-mag command)
713     (func "load-font" (car name-mag) (magstep (cdr name-mag))))
714
715   (define (header creator generate) 
716     (func "header" creator generate))
717
718   (define (header-end) 
719     (func "header-end"))
720
721   (define (lily-def key val)
722           (string-append "(define " key " " (arg->string val) ")\n"))
723
724   (define (placebox x y s) 
725     (string-append (func "move-to" x y) s))
726
727   (define (select-font font-name-symbol)
728     (let* ((c (assoc font-name-symbol font-name-alist)))
729       (if (eq? c #f)
730           (begin
731             (ly-warn 
732              (string-append 
733               "Programming error: No such font known " 
734               (car font-name-symbol)))
735             "")                         ; issue no command
736           (func "select-font" (car font-name-symbol)))))
737
738   (define (start-line height)
739           (func "start-line" height))
740
741   (define (stop-line)
742           (func "stop-line"))
743
744   (define (text s)
745           (func "text" s))
746
747 ;  (define (volta h w thick vert_start vert_end)
748 ;     (func "draw-volta" h w thick vert_start vert_end))
749
750   (define (volta h w thick vert-start vert-end)
751           (string-append
752            (if #t  ;(= 0 vert-start)
753                ""
754               (func "v-line" h))
755            ""
756            ;(func "rmove-to" 0 h)
757            ;(func "h-line" w)
758            (if #t ;(= 0 vert-end)
759                ""
760                (string-append
761                 (func "rmove-to" w 0)
762                 (func "v-line" (* -1 h))))))
763
764   (cond ((eq? action-name 'all-definitions)
765          `(begin
766             (define beam ,beam)
767             (define bracket ,bracket)
768             (define char ,char)
769             ;;(define crescendo ,crescendo)
770             ;(define bezier-sandwich ,bezier-sandwich)
771             ;;(define dashed-slur ,dashed-slur) 
772             ;;(define decrescendo ,decrescendo) 
773             (define end-output ,end-output)
774             (define experimental-on ,experimental-on)
775             (define filledbox ,filledbox)
776             ;;(define font-def ,font-def)
777             (define font-load-command ,font-load-command)
778             ;;(define font-switch ,font-switch)
779             (define header ,header) 
780             (define header-end ,header-end)
781             (define lily-def ,lily-def)
782             ;;(define invoke-char ,invoke-char) 
783             ;;(define invoke-dim1 ,invoke-dim1)
784             (define placebox ,placebox)
785             (define select-font ,select-font)
786             (define start-line ,start-line)
787             ;;(define stem ,stem)
788             (define stop-line ,stop-line)
789             (define stop-last-line ,stop-line)
790             (define text ,text)
791             ;;(define tuplet ,tuplet)
792             (define volta ,volta)
793             ))
794         ;;((eq? action-name 'tuplet) tuplet)
795         ;;((eq? action-name 'beam) beam)
796         ;;((eq? action-name 'bezier-sandwich) bezier-sandwich)
797         ;;((eq? action-name 'bracket) bracket)
798         ((eq? action-name 'char) char)
799         ;;((eq? action-name 'crescendo) crescendo)
800         ;;((eq? action-name 'dashed-slur) dashed-slur) 
801         ;;((eq? action-name 'decrescendo) decrescendo)
802         ;;((eq? action-name 'experimental-on) experimental-on)
803         ((eq? action-name 'filledbox) filledbox)
804         ((eq? action-name 'select-font) select-font)
805         ;;((eq? action-name 'volta) volta)
806         (else (error "unknown tag -- MUSA-SCM " action-name))
807         )
808   )
809
810
811 (define (gulp-file name)
812   (let* ((port (open-file name "r"))
813          (content (let loop ((text ""))
814                        (let ((line (read-line port)))
815                             (if (or (eof-object? line)
816                                     (not line)) 
817                                 text
818                                 (loop (string-append text line "\n")))))))
819         (close port)
820         content))
821
822 (define (scm-gulp-file name)
823   (set! %load-path 
824         (cons (string-append 
825                (getenv 'LILYPONDPREFIX) "/ps") %load-path))
826   (let ((path (%search-load-path name)))
827        (if path
828            (gulp-file path)
829            (gulp-file name))))
830
831 (define (scm-tex-output)
832   (eval (tex-scm 'all-definitions)))
833                                 
834 (define (scm-ps-output)
835   (eval (ps-scm 'all-definitions)))
836
837 (define (scm-as-output)
838   (eval (as-scm 'all-definitions)))
839                                 
840 ; Russ McManus, <mcmanus@IDT.NET>  
841
842 ; I use the following, which should definitely be provided somewhere
843 ; in guile, but isn't, AFAIK:
844
845
846
847 (define (hash-table-for-each fn ht)
848   (do ((i 0 (+ 1 i)))
849       ((= i (vector-length ht)))
850     (do ((alist (vector-ref ht i) (cdr alist)))
851         ((null? alist) #t)
852       (fn (car (car alist)) (cdr (car alist))))))
853
854 (define (hash-table-map fn ht)
855   (do ((i 0 (+ 1 i))
856        (ret-ls '()))
857       ((= i (vector-length ht)) (reverse ret-ls))
858     (do ((alist (vector-ref ht i) (cdr alist)))
859         ((null? alist) #t)
860       (set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
861
862
863
864 (define (index-cell cell dir)
865   (if (equal? dir 1)
866       (cdr cell)
867       (car cell)))
868
869 ;
870 ; How should a  bar line behave at a break? 
871 ;
872 (define (break-barline glyph dir)
873    (let ((result (assoc glyph 
874                         '((":|:" . (":|" . "|:"))
875                           ("|" . ("|" . ""))
876                           ("|s" . (nil . "|"))
877                           ("|:" . ("|" . "|:"))
878                           ("|." . ("|." . nil))
879                           (":|" . (":|" . nil))
880                           ("||" . ("||" . nil))
881                           (".|." . (".|." . nil))
882                           ("scorebar" . (nil . "scorepostbreak"))
883                           ("brace" . (nil . "brace"))
884                           ("bracket" . (nil . "bracket"))  
885                           )
886                         )))
887
888      (if (equal? result #f)
889          (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
890          (index-cell (cdr result) dir))
891      )
892    )
893      
894
895 (define (slur-ugly ind ht)
896   (if (and
897 ;       (< ht 4.0)
898        (< ht (* 4 ind))
899        (> ht (* 0.4 ind))
900        (> ht (+ (* 2 ind) -4))
901        (< ht (+ (* -2 ind) 8)))
902       #f
903       (cons ind  ht)
904   ))