]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/lily.scm
release: 1.1.54
[lilypond.git] / scm / lily.scm
index 9c57c962c9905f6f56ecb9247074372fbb06596f..dbc8381e439061ae3a54a53a59c003b2a0a71c0b 100644 (file)
   (string-append 
    (map (lambda (n) (string-append (number->string n ) " ")) l)))
 
+(define (reduce operator list)
+      (if (null? (cdr list)) (car list)
+         (operator (car list) (reduce operator (cdr list)))
+         )
+      )
+
+
+(define (glue-2-strings a b) (string-append a " " b))
+
 (define
   (numbers->string l)
-  (apply string-append 
-        (map (lambda (n) (string-append (number->string n) " ")) l)))
+  (reduce glue-2-strings (map number->string l)))
 
 (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
 
@@ -41,8 +49,7 @@
    (string-append (number->string (cadr c)) " ")))
 
 
-(define
-  (font i)
+(define (font i)
   (string-append
    "font"
    (make-string 1 (integer->char (+ (char->integer #\A) i)))
 (define Piano_bar_engraver_visibility postbreak_only_visibility)
 (define Staff_group_bar_engraver_visibility postbreak_only_visibility)
 
-
-
+;; Spacing constants for prefatory matter.
+;;
+;; rules for this spacing are much more complicated than this. See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
+;;
+;;
+
+(define space-alist
+ '(
+   (("" "Clef_item") . (minimum_space 1.0))
+   (("" "Staff_bar") . (minimum_space 0.0))
+   (("" "Clef_item") . (minimum_space 1.0))
+   (("" "Key_item") . (minimum_space 0.5))
+   (("" "Span_bar") . (extra_space 0.0))
+   (("" "Time_signature") . (extra_space 0.0))
+   (("" "begin-of-note") . (minimum_space 1.5))
+   (("Clef_item" "Key_item") . (minimum_space 3.5))
+   (("Key_item" "Time_signature") . (extra_space 2.0))
+   (("Clef_item"  "Time_signature") . (minimum_space 3.5))
+   (("Staff_bar" "Clef_item") .   (minimum_space 1.0))
+   (("Clef_item"  "Staff_bar") .  (minimum_space 3.7))
+   (("Time_signature" "Staff_bar") .  (minimum_space 2.0))
+   (("Key_item"  "Staff_bar") .  (extra_space 1.0))
+   (("Span_bar" "Clef_item") .   (extra_space 1.0))
+   (("Clef_item"  "Span_bar") . (minimum_space 3.7))
+   (("Time_signature" "Span_bar") . (minimum_space 2.0))
+   (("Key_item"  "Span_bar") . (minimum_space 2.5))
+   (("Staff_bar" "Time_signature") . (minimum_space 2.0))
+   (("Time_signature" "begin-of-note") . (extra_space 1.0))    ; Huh? see twinkle.ly
+   (("Key_item" "begin-of-note") . (extra_space 2.5))
+   (("Staff_bar" "begin-of-note") . (extra_space 1.0))
+   (("Clef_item" "begin-of-note") . (minimum_space 5.0))
+   (("" "Breathing_sign") . (minimum_space 0.0))
+   (("Breathing_sign" "Key_item") . (minimum_space 1.5))
+   (("Breathing_sign" "begin-of-note") . (minimum_space 1.0))
+   (("Breathing_sign" "Staff_bar") . (minimum_space 1.5))
+   (("Breathing_sign" "Clef_item") . (minimum_space 2.0))
+   )
+)
+
+(define (break-align-spacer this next)
+  (let ((entry (assoc `(,this ,next) space-alist)))
+    (if entry
+       (cdr entry)
+       (begin (ly-warn (string-append "Unknown spacing pair `" this "', `" next "'"))
+              '(minimum_space 0.0)))))
+  
+       
 
 ;;;;;;;; TeX
 
 
   (define (number->dim x)
     (string-append 
-     (number->string  (chop-decimal x)) "pt "))
+     (number->string  (chop-decimal x)) " pt "))
 
   (define (placebox x y s) 
     (string-append 
      "\\placebox{"
      (number->dim y) "}{" (number->dim x) "}{" s "}"))
 
+
+  ;;;; UGH! Junk \\bracefont !
   (define (pianobrace y)
     (define step 1.0)
     (define minht (* 2 mudelapaperstaffheight))
     )
   (define (stop-line) 
     "}\\vss}\\interscoreline")
-
+  (define (stop-last-line)
+    "}\\vss}")
   (define (filledbox breapth width depth height) 
     (string-append 
      "\\kern" (number->dim (- breapth))
   (define (text s)
     (string-append "\\hbox{" (output-tex-string s) "}"))
   
-  (define (tuplet dx dy thick dir)
-    (embedded-ps ((ps-scm 'tuplet) dx dy thick dir)))
+  (define (tuplet ht gapx dx dy thick dir)
+    (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
 
-  (define (volta w thick last)
-    (embedded-ps ((ps-scm 'volta) w thick last)))
+  (define (volta w thick last)
+    (embedded-ps ((ps-scm 'volta) w thick last)))
 
   ;; TeX
   ;; The procedures listed below form the public interface of TeX-scm.
            (define select-font ,select-font)
            (define start-line ,start-line)
            (define stop-line ,stop-line)
+           (define stop-last-line ,stop-last-line)
            (define text ,text)
            (define tuplet ,tuplet)
            (define volta ,volta)
        ((eq? action-name 'start-line) start-line)
        ((eq? action-name 'stem) stem)
        ((eq? action-name 'stop-line) stop-line)
+       ((eq? action-name 'stop-last-line) stop-last-line)
        ((eq? action-name 'volta) volta)
        (else (error "unknown tag -- PS-TEX " action-name))
        )
      (numbers->string (list width slope thick)) " draw_beam " ))
 
   (define (bracket h)
-    (invoke-dim1 "draw_bracket" h))
+    (invoke-dim1 " draw_bracket" h))
 
   (define (char i)
-    (invoke-char "show" i))
+    (invoke-char " show" i))
 
   (define (crescendo w h cont)
     (string-append 
      (numbers->string (list w h (inexact->exact cont)))
-     "draw_crescendo"))
+     " draw_crescendo"))
 
   (define (dashed-slur thick dash l)
     (string-append 
   (define (decrescendo w h cont)
     (string-append 
      (numbers->string (list w h (inexact->exact cont)))
-     "draw_decrescendo"))
+     " draw_decrescendo"))
 
 
   (define (end-output)
   
   (define (filledbox breapth width depth height) 
     (string-append (numbers->string (list breapth width depth height))
-                  "draw_stem" ))
+                  " draw_box" ))
 
   ;; obsolete?
   (define (font-def i s)
 
   (define (header-end) "")
   (define (lily-def key val)
-    (string-append
-     "/" key " {" val "} bind def\n"))
 
+     (if (string=? (substring  key 0 (string-length "mudelapaper") ) "mudelapaper")
+        (string-append "/" key " {" val "} bind def\n")
+        (string-append "/" key " (" val ") def\n")
+        )
+     )
   (define (header creator generate) 
     (string-append
      "%!PS-Adobe-3.0\n"
     (string-append 
      (number->string x) " "
      (number->string y) " "
-     "rulesym"))
+     " rulesym"))
 
   (define (bezier-sandwich l)
     (string-append 
      (apply string-append (map control->string l)) 
      " draw_bezier_sandwich"))
 
-  (define (start-line)
+  (define (start-line height)
     (begin
       (clear-fontcache)
       "\nstart_line {\n"))
   
   (define (stem breapth width depth height) 
     (string-append (numbers->string (list breapth width depth height))
-                  "draw_stem" ))
+                  " draw_box" ))
 
   (define (stop-line)
       "}\nstop_line\n")
     (string-append "(" s ") show  "))
 
 
-  (define (volta w thick last)
+  (define (volta w thick last)
     (string-append 
-     (numbers->string (list w thick (inexact->exact last)))
-     "draw_volta"))
+     (numbers->string (list w thick (inexact->exact last)))
+     " draw_volta"))
 
-  (define (tuplet dx dy thick dir)
+  (define (tuplet ht gap dx dy thick dir)
     (string-append 
-     (numbers->string (list dx dy thick (inexact->exact dir)))
-     "draw_tuplet"))
+     (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
+     " draw_tuplet"))
 
 
   (define (unknown) 
            (define start-line ,start-line)
            (define stem ,stem)
            (define stop-line ,stop-line)
+           (define stop-last-line ,stop-line)
            (define text ,text)
            ))
        ((eq? action-name 'tuplet) tuplet)
        ((null? alist) #t)
       (set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
 
+
+;;;; print a SCM expression.  Isn't this part of the std lib?
+
+(define (scmlist->string exp)
+  (cond
+   ((pair? (cdr exp)) (string-append (scm->string (car exp)) " " (scmlist->string (cdr exp))))
+   ((eq? '() (cdr exp)) (string-append (scm->string (car exp)) ")"))
+   (else (string-append (scm->string (car exp)) " . " (scm->string (cdr exp)) ")"))
+   ))
+
+(define (scm->string exp)
+  (cond
+   ((pair? exp) (string-append "(" (scmlist->string exp)))
+   ((number? exp) (number->string exp))
+   ((symbol? exp) (symbol->string exp))
+   ((string? exp) (string-append "\"" exp "\""))
+   ))
+
+(define (test-scm->string)
+(list (scmlist->string '(a))
+(scmlist->string '(a b))
+(scmlist->string '(a b . c))
+
+
+(scm->string '(a))
+(scm->string '(a b ))
+(scm->string '(a b . c))
+(scm->string '(a b (c . d)))
+(scm->string '(a "bla" (c . 1.5)))
+)
+)