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