]> git.donarmstrong.com Git - lilypond.git/blob - scm/lily.scm
release: 1.3.24
[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))
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     (begin
354       (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
355     )
356   (define (stop-line) 
357     "}\\vss}\\interscoreline")
358   (define (stop-last-line)
359     "}\\vss}")
360   (define (filledbox breapth width depth height) 
361     (string-append 
362      "\\kern" (number->dim (- breapth))
363      "\\vrule width " (number->dim (+ breapth width))
364      "depth " (number->dim depth)
365      "height " (number->dim height) " "))
366
367   (define (text s)
368     (string-append "\\hbox{" (output-tex-string s) "}"))
369   
370   (define (tuplet ht gapx dx dy thick dir)
371     (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
372
373   (define (volta h w thick vert_start vert_end)
374     (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
375
376   ;; TeX
377   ;; The procedures listed below form the public interface of TeX-scm.
378   ;; (should merge the 2 lists)
379   (cond ((eq? action-name 'all-definitions)
380          `(begin
381             (define font-load-command ,font-load-command)
382             (define beam ,beam)
383             (define bezier-sandwich ,bezier-sandwich)
384             (define bracket ,bracket)
385             (define char ,char)
386             (define crescendo ,crescendo)
387             (define dashed-slur ,dashed-slur) 
388             (define decrescendo ,decrescendo) 
389             (define end-output ,end-output)
390             (define experimental-on ,experimental-on)
391             (define filledbox ,filledbox)
392             (define font-def ,font-def)
393             (define font-switch ,font-switch)
394             (define header-end ,header-end)
395             (define lily-def ,lily-def)
396             (define header ,header) 
397             (define invoke-char ,invoke-char) 
398             (define invoke-dim1 ,invoke-dim1)
399             (define placebox ,placebox)
400             (define select-font ,select-font)
401             (define start-line ,start-line)
402             (define stop-line ,stop-line)
403             (define stop-last-line ,stop-last-line)
404             (define text ,text)
405             (define tuplet ,tuplet)
406             (define volta ,volta)
407             ))
408
409         ((eq? action-name 'beam) beam)
410         ((eq? action-name 'tuplet) tuplet)
411         ((eq? action-name 'bracket) bracket)
412         ((eq? action-name 'crescendo) crescendo)
413         ((eq? action-name 'dashed-slur) dashed-slur) 
414         ((eq? action-name 'decrescendo) decrescendo) 
415         ((eq? action-name 'end-output) end-output)
416         ((eq? action-name 'experimental-on) experimental-on)
417         ((eq? action-name 'font-def) font-def)
418         ((eq? action-name 'font-switch) font-switch)
419         ((eq? action-name 'header-end) header-end)
420         ((eq? action-name 'lily-def) lily-def)
421         ((eq? action-name 'header) header) 
422         ((eq? action-name 'invoke-char) invoke-char) 
423         ((eq? action-name 'invoke-dim1) invoke-dim1)
424         ((eq? action-name 'placebox) placebox)
425         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
426         ((eq? action-name 'start-line) start-line)
427         ((eq? action-name 'stem) stem)
428         ((eq? action-name 'stop-line) stop-line)
429         ((eq? action-name 'stop-last-line) stop-last-line)
430         ((eq? action-name 'volta) volta)
431         (else (error "unknown tag -- PS-TEX " action-name))
432         )
433   )
434
435
436 ;;;;;;;;;;;; PS
437 (define (ps-scm action-name)
438
439
440   ;; alist containing fontname -> fontcommand assoc (both strings)
441   (define font-alist '())
442   (define font-count 0)
443   (define current-font "")
444
445   
446   (define (cached-fontname i)
447     (string-append
448      "lilyfont"
449      (make-string 1 (integer->char (+ 65 i)))))
450     
451   (define (mag-to-size m)
452     (number->string (case m 
453                       (0 12)
454                       (1 12)
455                       (2 14) ; really: 14.400
456                       (3 17) ; really: 17.280
457                       (4 21) ; really: 20.736
458                       (5 24) ; really: 24.888
459                       (6 30) ; really: 29.856
460                       )))
461   
462   
463   (define (select-font font-name-symbol)
464     (let*
465         (
466          (c (assoc font-name-symbol font-name-alist))
467          )
468
469       (if (eq? c #f)
470           (begin
471             (ly-warn (string-append
472                       "Programming error: No such font known " (car font-name-symbol)))
473             "")                         ; issue no command
474           (string-append " " (cdr c) " "))
475       
476       
477       ))
478
479     (define (font-load-command name-mag command)
480       (string-append
481        "/" command
482        " { /"
483        (symbol->string (car name-mag))
484        " findfont "
485        (number->string (magstep (cdr name-mag)))
486        " 1000 div 12 mul  scalefont setfont } bind def "
487        "\n"))
488
489
490   (define (beam width slope thick)
491     (string-append
492      (numbers->string (list width slope thick)) " draw_beam" ))
493
494   (define (comment s)
495     (string-append "% " s))
496
497   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
498     (string-append
499      (numbers->string (list arch_angle arch_width arch_height width height arch_thick thick)) " draw_bracket" ))
500
501   (define (char i)
502     (invoke-char " show" i))
503
504   (define (crescendo thick w h cont )
505     (string-append 
506      (numbers->string (list w h (inexact->exact cont) thick))
507      " draw_crescendo"))
508
509   ;; what the heck is this interface ?
510   (define (dashed-slur thick dash l)
511     (string-append 
512      (apply string-append (map control->string l)) 
513      (number->string thick) 
514      " [ "
515      (number->string dash)
516      " "
517      (number->string (* 10 thick))      ;UGH.  10 ?
518      " ] 0 draw_dashed_slur"))
519
520   (define (decrescendo thick w h cont)
521     (string-append 
522      (numbers->string (list w h (inexact->exact cont) thick))
523      " draw_decrescendo"))
524
525
526   (define (end-output)
527     "\nshowpage\n")
528   
529   (define (experimental-on) "")
530   
531   (define (filledbox breapth width depth height) 
532     (string-append (numbers->string (list breapth width depth height))
533                    " draw_box" ))
534
535   ;; obsolete?
536   (define (font-def i s)
537     (string-append
538      "\n/" (font i) " {/" 
539      (substring s 0 (- (string-length s) 4))
540      " findfont 12 scalefont setfont} bind def \n"))
541
542   (define (font-switch i)
543     (string-append (font i) " "))
544
545   (define (header-end)
546     (string-append
547      (ly-gulp-file "lilyponddefs.ps")
548      " {exch pop //systemdict /run get exec} "
549      (ly-gulp-file "lily.ps")
550      "{ exch pop //systemdict /run get exec } "
551     ))
552   
553   (define (lily-def key val)
554
555      (if (string=? (substring key 0 (min (string-length "mudelapaper") (string-length key))) "mudelapaper")
556          (string-append "/" key " {" val "} bind def\n")
557          (string-append "/" key " (" val ") def\n")
558          )
559      )
560
561   (define (header creator generate) 
562     (string-append
563      "%!PS-Adobe-3.0\n"
564      "%%Creator: " creator generate "\n"))
565   
566   (define (invoke-char s i)
567     (string-append 
568      "(\\" (inexact->string i 8) ") " s " " ))
569   
570   (define (invoke-dim1 s d) 
571     (string-append
572      (number->string (* d  (/ 72.27 72))) " " s ))
573
574   (define (placebox x y s) 
575     (string-append 
576      (number->string x) " " (number->string y) " {" s "} placebox "))
577
578   (define (bezier-sandwich l thick)
579     (string-append 
580      (apply string-append (map control->string l))
581      (number->string  thick)
582      " draw_bezier_sandwich"))
583
584   (define (start-line height)
585     (begin
586       "\nstart_line {\n"))
587   
588   (define (stem breapth width depth height) 
589     (string-append (numbers->string (list breapth width depth height))
590                    " draw_box" ))
591
592   (define (stop-line)
593       "}\nstop_line\n")
594
595   (define (text s)
596     (string-append "(" s ") show  "))
597
598
599   (define (volta h w thick vert_start vert_end)
600     (string-append 
601      (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
602      " draw_volta"))
603
604   (define (tuplet ht gap dx dy thick dir)
605     (string-append 
606      (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
607      " draw_tuplet"))
608
609
610   (define (unknown) 
611     "\n unknown\n")
612
613
614   ;; PS
615   (cond ((eq? action-name 'all-definitions)
616          `(begin
617             (define beam ,beam)
618             (define tuplet ,tuplet)
619             (define bracket ,bracket)
620             (define char ,char)
621             (define crescendo ,crescendo)
622             (define volta ,volta)
623             (define bezier-sandwich ,bezier-sandwich)
624             (define dashed-slur ,dashed-slur) 
625             (define decrescendo ,decrescendo) 
626             (define end-output ,end-output)
627             (define experimental-on ,experimental-on)
628             (define filledbox ,filledbox)
629             (define font-def ,font-def)
630             (define font-switch ,font-switch)
631             (define header-end ,header-end)
632             (define lily-def ,lily-def)
633             (define font-load-command ,font-load-command)
634             (define header ,header) 
635             (define invoke-char ,invoke-char) 
636             (define invoke-dim1 ,invoke-dim1)
637             (define placebox ,placebox)
638             (define select-font ,select-font)
639             (define start-line ,start-line)
640             (define stem ,stem)
641             (define stop-line ,stop-line)
642             (define stop-last-line ,stop-line)
643             (define text ,text)
644             ))
645         ((eq? action-name 'tuplet) tuplet)
646         ((eq? action-name 'beam) beam)
647         ((eq? action-name 'bezier-sandwich) bezier-sandwich)
648         ((eq? action-name 'bracket) bracket)
649         ((eq? action-name 'char) char)
650         ((eq? action-name 'crescendo) crescendo)
651         ((eq? action-name 'dashed-slur) dashed-slur) 
652         ((eq? action-name 'decrescendo) decrescendo)
653         ((eq? action-name 'experimental-on) experimental-on)
654         ((eq? action-name 'filledbox) filledbox)
655         ((eq? action-name 'select-font) select-font)
656         ((eq? action-name 'volta) volta)
657         (else (error "unknown tag -- PS-SCM " action-name))
658         )
659   )
660
661
662 (define (gulp-file name)
663   (let* ((port (open-file name "r"))
664          (content (let loop ((text ""))
665                        (let ((line (read-line port)))
666                             (if (or (eof-object? line)
667                                     (not line)) 
668                                 text
669                                 (loop (string-append text line "\n")))))))
670         (close port)
671         content))
672
673 (define (scm-gulp-file name)
674   (set! %load-path 
675         (cons (string-append 
676                (getenv 'LILYPONDPREFIX) "/ps") %load-path))
677   (let ((path (%search-load-path name)))
678        (if path
679            (gulp-file path)
680            (gulp-file name))))
681
682 (define (scm-tex-output)
683   (eval (tex-scm 'all-definitions)))
684                                 
685 (define (scm-ps-output)
686   (eval (ps-scm 'all-definitions)))
687
688                                 
689 ; Russ McManus, <mcmanus@IDT.NET>  
690
691 ; I use the following, which should definitely be provided somewhere
692 ; in guile, but isn't, AFAIK:
693
694
695
696 (define (hash-table-for-each fn ht)
697   (do ((i 0 (+ 1 i)))
698       ((= i (vector-length ht)))
699     (do ((alist (vector-ref ht i) (cdr alist)))
700         ((null? alist) #t)
701       (fn (car (car alist)) (cdr (car alist))))))
702
703 (define (hash-table-map fn ht)
704   (do ((i 0 (+ 1 i))
705        (ret-ls '()))
706       ((= i (vector-length ht)) (reverse ret-ls))
707     (do ((alist (vector-ref ht i) (cdr alist)))
708         ((null? alist) #t)
709       (set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
710
711
712 ;; guile-1.3.4 has list->string
713 (define (scmlist->string exp)
714   (list->string exp))
715
716 ;; obsolete, maybe handy for testing
717 ;; print a SCM expression.  Isn't this part of the std lib?
718 (define (xxscmlist->string exp)
719   (cond
720    ((null? (car exp)) (begin (display ("urg:") (newline))))
721    ((pair? (cdr exp)) (string-append (scm->string (car exp)) " " (scmlist->string (cdr exp))))
722    ((eq? '() (cdr exp)) (string-append (scm->string (car exp)) ")"))
723    ;; howto check for quote?
724    (else (string-append (scm->string (car exp)) " . " (scm->string (cdr exp)) ")"))
725    ))
726
727 (define (scm->string exp)
728   (cond
729    ((pair? exp) (string-append "(" (scmlist->string exp)))
730    ((number? exp) (number->string exp))
731    ((symbol? exp) (symbol->string exp))
732    ((string? exp) (string-append "\"" exp "\""))
733    ;; probably: #@quote
734    (else (begin (display "programming error: scm->string: ") (newline) "'"))
735    ))
736
737 (define (index-cell cell dir)
738   (if (equal? dir 1)
739       (cdr cell)
740       (car cell))
741   )
742
743
744 ;
745 ; How should a  bar line behave at a break? 
746 ;
747 (define (break-barline glyph dir)
748    (let ((result (assoc glyph 
749                         '((":|:" . (":|" . "|:"))
750                           ("|" . ("|" . ""))
751                           ("|s" . (nil . "|"))
752                           ("|:" . ("|" . "|:"))
753                           ("|." . ("|." . nil))
754                           (":|" . (":|" . nil))
755                           ("||" . ("||" . nil))
756                           (".|." . (".|." . nil))
757                           ("scorebar" . (nil . "scorepostbreak"))
758                           ("brace" . (nil . "brace"))
759                           ("bracket" . (nil . "bracket"))  
760                           )
761                         )))
762
763      (if (equal? result #f)
764          (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
765          (index-cell (cdr result) dir))
766      )
767    )
768      
769
770 (define (slur-ugly ind ht)
771   (if (and
772 ;       (< ht 4.0)
773        (< ht (* 4 ind))
774        (> ht (* 0.4 ind))
775        (> ht (+ (* 2 ind) -4))
776        (< ht (+ (* -2 ind) 8)))
777       #f
778       (cons ind  ht)
779   ))