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