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