]> git.donarmstrong.com Git - lilypond.git/blobdiff - init/lily.scm
patch::: 1.1.8.hwn2
[lilypond.git] / init / lily.scm
index aadf071f12a16e889eef21e74415ba90c7d34cf6..be28d088f943702d7338ac1c740067ea8aaec221 100644 (file)
 ;     all preparations from ps,tex to scm
 
 ;;; library funtions
+(define
+  (xnumbers->string l)
+  (string-append 
+   (map (lambda (n) (string-append (number->string n ) " ")) l)))
+
 (define
   (numbers->string l)
   (apply string-append 
   (let ((n (inexact->exact x)))
        (number->string n radix)))
 
-(define 
-  (number->dim-tex x)
-  (string-append 
-   (number->string (chop-decimal x)) "pt "))
 
 (define
   (control->string c)
     (string-append (number->string (car c)) " ")
     (string-append (number->string (cadr c)) " ")))
 
-(define 
-  (embedded-ps-tex s)
-  (string-append "\\embeddedps{" s "}"))
-
-(define 
-  (invoke-char-ps s i)
-  (string-append 
-   "(\\" (inexact->string i 8) ") " s " " ))
-
-(define 
-  (invoke-char-tex s i)
-  (string-append 
-   "\n\\" s "{" (inexact->string i 10) "}" ))
-
-(define 
-  (invoke-dim1-ps s d) 
-  (string-append
-   (number->string d) " " s ))
-
-(define 
-  (invoke-dim1-tex s d)
-  (string-append
-   "\n\\" s "{" (number->dim-tex d) "}"))
-
-(define
-  (invoke-output o s)
-   (eval-string (string-append s "-" o)))
-
-;;; output definitions
-
-(define 
-  (beam o width slope thick) 
-  ((invoke-output o "beam") width slope thick))
-
-(define 
-  (beam-ps width slope thick)
-  (string-append
-   (numbers->string (list width slope thick)) " draw_beam " ))
-
-(define 
-  (beam-tex width slope thick)
-  (embedded-ps-tex (beam-ps width slope thick)))
-
-(define 
-  (bracket o h)
-  ((invoke-output o "bracket") h))
-
-(define 
-  (bracket-ps h)
-  (invoke-dim1-ps "draw_bracket" h))
-
-(define 
-  (bracket-tex h)
-  (embedded-ps-tex (bracket-ps h)))
-
-(define 
-  (char o n) 
-  ((invoke-output o "invoke-char") "show" n))
-
-(define 
-  (dashed-slur o thick dash l) 
-  ((invoke-output o "dashed-slur") thick dash l))
-
-(define 
-  (dashed-slur-ps thick dash l)
-  (string-append 
-    (apply string-append (map control->string l)) 
-    (number->string thick) 
-   " [ "
-   (if (> 1 dash) (number->string (- (* thick dash) thick)) "0") " "
-   (number->string (* 2 thick))
-   " ] 0 draw_dashed_slur"))
-
-(define 
-  (dashed-slur-tex thick dash l)
-  (embedded-ps-tex (dashed-slur-ps thick dash l)))
-
-(define 
-  (doublebar o h)
-  ((invoke-output o "invoke-dim1") "doublebar" h))
-
-(define 
-  (empty o) 
-  ((invoke-output o "empty")))
-
-(define 
-  (empty-ps) 
-  "\n empty\n")
-
-(define 
-  (empty-tex) 
-  "%\n\\empty%\n")
-
-(define 
-  (emptybar o h) (empty o))
-
-(define 
-  (end-output o) 
-  ((invoke-output o "end-output")))
-
-(define 
-  (end-output-ps)
-  "\nshowpage\n")
-
-(define 
-  (end-output-tex) 
-  "\n\\EndLilyPondOutput")
-
-(define 
-  (experimental-on o) 
-  ((invoke-output o "experimental-on")))
-
-(define
-  (experimental-on-ps) "")
-
-(define
-  (experimental-on-tex) "\\turnOnExperimentalFeatures")
-
-(define 
-  (extender o h)
-  ((invoke-output o "invoke-dim1") "extender" h))
 
-(define
-  (fatdoublebar o h)
-  ((invoke-output o "invoke-dim1") "fatdoublebar" h))
-
-(define
-  (finishbar o h)
-  ((invoke-output o "invoke-dim1") "finishbar" h))
 
 (define
   (font i)
    (make-string 1 (integer->char (+ (char->integer #\A) i)))
    ))
 
-(define 
-  (font-def o i s) 
-  ((invoke-output o "font-def") i s))
 
-(define 
-  (font-def-ps i s)
-  (string-append
-   "\n/" (font i) " {/" 
-   (substring s 0 (- (string-length s) 4))
-   " findfont 12 scalefont setfont} bind def\n"))
 
-(define 
-  (font-def-tex i s)
-  (string-append
-   "\\font" (font-switch-tex i) "=" s "\n"))
+(define (scm-scm action-name)
+  1)
 
-(define 
-  (font-switch o i) 
-  ((invoke-output o "font-switch") i))
+;;;;;;;;
+  (define (emptybar h)
+    (string-append ""))
 
-(define 
-  (font-switch-ps i)
-  (string-append (font i) " "))
 
-(define 
-  (font-switch-tex i)
-  (string-append
-   "\\" (font i) "\n"))
+;;;;;;;; TeX
 
-(define 
-  (generalmeter o num den)
-   ((invoke-output o "generalmeter") num den))
+(define (tex-scm action-name)
 
-(define 
-  (generalmeter-ps num den)
-  (string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
+  (define (unknown) 
+    "%\n\\unknown%\n")
 
-(define 
-  (generalmeter-tex num den)
-  (string-append 
-   "\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
+  (define (beam width slope thick)
+    (embedded-ps ((ps-scm 'beam) width slope thick)))
 
-(define 
-  (header o creator generate) 
-  ((invoke-output o "header") creator generate))
+  (define (bracket h)
+    (embedded-ps ((ps-scm 'bracket) h)))
 
-(define 
-  (header-ps creator generate) 
-  (string-append
-   "%!PS-Adobe-3.0\n"
-   "%%Creator: " creator generate "\n"))
+  (define (dashed-slur thick dash l)
+    (embedded-ps ((ps-scm 'dashed-slur)  thick dash l)))
 
-(define 
-  (header-tex creator generate) 
-  (string-append
-   "%created by: " creator generate "\n"))
+  (define (crescendo w h cont)
+    (embedded-ps ((ps-scm 'crescendo) w h cont)))
 
-(define 
-  (header-end o) 
-  ((invoke-output o "header-end")))
+  (define (decrescendo w h cont)
+    (embedded-ps ((ps-scm 'decrescendo) w h cont)))
 
-(define
-  (header-end-ps) "")
+  (define (embedded-ps s)
+    (string-append "\\embeddedps{" s "}"))
 
-(define
-  (header-end-tex) "\\turnOnPostScript")
 
-(define
-  (lily-def o key val)
-  ((invoke-output o "lily-def") key val))
-
-(define
-  (lily-def-ps key val)
-  (string-append
-   "/" key " {" val "} bind def\n"))
-
-(define
-  (lily-def-tex key val)
-  (string-append
-   "\\def\\" key "{" val "}\n"))
-
-(define 
-  (maatstreep o h) 
-  ((invoke-output o "invoke-dim1") "maatstreep" h))
-
-(define 
-  (pianobrace o i)
-  ((invoke-output o "invoke-char") "pianobrace" i))
-
-(define 
-  (placebox o x y b) 
-  ((invoke-output o "placebox") x y (b o)))
-
-(define 
-  (placebox-ps x y s) 
-  (string-append 
-   (number->string x) " " (number->string y) " {" s "} placebox "))
-
-(define 
-  (placebox-tex x y s) 
-  (string-append 
-   "\\placebox{"
-   (number->dim-tex y) "}{" (number->dim-tex x) "}{" s "}"))
-
-(define
-  (repeatbar o h)
-  ((invoke-output o "invoke-dim1") "repeatbar" h))
-
-(define
-  (repeatbarstartrepeat o h)
-  ((invoke-output o "invoke-dim1") "repeatbarstartrepeat" h))
-
-(define 
-  (rulesym o x y) 
-  ((invoke-output o "rulesym") x y))
-
-(define 
-  (rulesym-ps x y) 
-  (string-append 
-   (number->string x) " "
-   (number->string y) " "
-   "rulesym"))
-
-(define 
-  (rulesym-tex x y) 
-  (string-append 
-   "\\rulesym{" (number->dim-tex x) "}{" (number->dim-tex y) "}"))
-
-(define 
-  (setbold o s) 
-  ((invoke-output o "text") "bold" s))
-
-(define
-  (setdynamic o s) (empty o))
+  (define (end-output) 
+    "\n\\EndLilyPondOutput")
 
-(define 
-  (setfinger o s) 
-  ((invoke-output o "text") "finger" s))
+  (define (empty) 
+    "%\n\\empty%\n")
 
-(define 
-  (sethuge o s) 
-  ((invoke-output o "text") "huge" s))
+  (define (experimental-on) "\\turnOnExperimentalFeatures")
 
-(define 
-  (setitalic o s) 
-  ((invoke-output o "text") "italic" s))
+  (define (extender o h)
+    ((invoke-output o "invoke-dim1") "extender" h))
 
-(define 
-  (setlarge o s) 
-  ((invoke-output o "text") "large" s))
+  (define (font-switch i)
+    (string-append
+     "\\" (font i) "\n"))
+
+  (define (font-def i s)
+    (string-append
+     "\\font" (font-switch i) "=" s "\n"))
+
+  (define (generalmeter num den)
+    (string-append 
+     "\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
+
+  (define (header-end) "\\turnOnPostScript")
+
+  (define (header creator generate) 
+    (string-append
+     "%created by: " creator generate "\n"))
+
+  (define (invoke-char s i)
+    (string-append 
+     "\n\\" s "{" (inexact->string i 10) "}" ))
+  (define (char i)
+    (string-append "\\show{" (inexact->string i 10) "}"))
+    
+  (define (invoke-dim1 s d)
+    (string-append
+     "\n\\" s "{" (number->dim d) "}"))
+
+  (define (lily-def key val)
+    (string-append
+     "\\def\\" key "{" val "}\n"))
+
+  (define (number->dim x)
+    (string-append 
+     (number->string (chop-decimal x)) "pt "))
+
+  (define (placebox x y s) 
+    (string-append 
+     "\\placebox{"
+     (number->dim y) "}{" (number->dim x) "}{" s "}"))
+
+  (define (pianobrace y)
+    (define step 1.0)
+    (define minht mudelapaperstaffheight)
+    (define maxht (* 6 minht))
+    (string-append
+     "{\\bracefont " (char  (/  (- (max y (- maxht step)) minht)   step)) "}"))
+  
+  (define (rulesym h w) 
+    (string-append 
+     "\\vrule height " (number->dim (/ h 2))
+     " depth " (number->dim (/ h 2))
+     " width " (number->dim w)
+     )
+    )
+
+  (define (slur l)
+    (embedded-ps ((ps-scm 'slur) l)))
+
+  (define (start-line) 
+    (string-append 
+     "\\hbox{%\n")
+    )
+
+  (define (stem kern width height depth) 
+    (string-append 
+     "\\kern" (number->dim kern)
+     "\\vrule width " (number->dim width)
+     "depth " (number->dim depth)
+     "height " (number->dim height) " "))
+
+  (define (stop-line) 
+    "}\\interscoreline")
+
+  (define (text f s)
+    (string-append "\\set" f "{" s "}"))
+
+  (define (tuplet dx dy dir)
+    (embedded-ps ((ps-scm 'tuplet) dx dy dir)))
+
+  (define (volta w last)
+    (embedded-ps ((ps-scm 'volta)  w last)))
+
+  (define (maatstreep h)
+    (string-append "\\maatstreep{" (number->dim h) "}"))
+  
+  (cond ((eq? action-name 'all-definitions)
+        `(begin
+          (define beam ,beam)
+          (define tuplet ,tuplet)
+          (define bracket ,bracket)
+          (define crescendo ,crescendo)
+          (define volta ,volta)
+          (define slur ,slur)
+          (define dashed-slur ,dashed-slur) 
+          (define decrescendo ,decrescendo) 
+          (define empty ,empty)
+          (define end-output ,end-output)
+          (define font-def ,font-def)
+          (define font-switch ,font-switch)
+          (define generalmeter ,generalmeter)
+          (define header-end ,header-end)
+          (define lily-def ,lily-def)
+          (define header ,header) 
+          (define invoke-char ,invoke-char) 
+          (define invoke-dim1 ,invoke-dim1)
+          (define placebox ,placebox)
+          (define rulesym ,rulesym)
+          (define start-line ,start-line)
+          (define stem ,stem)
+          (define stop-line ,stop-line)
+          (define text ,text)
+          (define experimental-on  ,experimental-on)
+          (define char  ,char)
+          (define maatstreep ,maatstreep)
+          (define pianobrace ,pianobrace)
+          ))
+
+       ((eq? action-name 'experimental-on) experimental-on)
+       ((eq? action-name 'beam) beam)
+       ((eq? action-name 'tuplet) tuplet)
+       ((eq? action-name 'bracket) bracket)
+       ((eq? action-name 'crescendo) crescendo)
+       ((eq? action-name 'volta) volta)
+       ((eq? action-name 'slur) slur)
+       ((eq? action-name 'dashed-slur) dashed-slur) 
+       ((eq? action-name 'decrescendo) decrescendo) 
+       ((eq? action-name 'empty) empty)
+       ((eq? action-name 'end-output) end-output)
+       ((eq? action-name 'font-def) font-def)
+       ((eq? action-name 'font-switch) font-switch)
+       ((eq? action-name 'generalmeter) generalmeter)
+       ((eq? action-name 'header-end) header-end)
+       ((eq? action-name 'lily-def) lily-def)
+       ((eq? action-name 'header) header) 
+       ((eq? action-name 'invoke-char) invoke-char) 
+       ((eq? action-name 'invoke-dim1) invoke-dim1)
+       ((eq? action-name 'placebox) placebox)
+       ((eq? action-name 'rulesym) rulesym)
+       ((eq? action-name 'start-line) start-line)
+       ((eq? action-name 'stem) stem)
+       ((eq? action-name 'stop-line) stop-line)
+       (else (error "unknown tag -- PS-TEX " action-name))
+       )
 
-(define 
-  (setLarge o s) 
-  ((invoke-output o "text") "Large" s))
-
-(define 
-  (setnumber o s) 
-  ((invoke-output o "text") "number" s))
-
-(define 
-  (settext o s) 
-  ((invoke-output o "text") "text" s))
-
-(define 
-  (settypewriter o s) 
-  ((invoke-output o "text") "typewriter" s))
-
-(define 
-  (slur o l) 
-  ((invoke-output o "slur") l))
-
-(define 
-  (slur-ps l)
-  (string-append 
-   (apply string-append (map control->string l)) 
-   " draw_slur"))
-
-(define 
-  (slur-tex l)
-  (embedded-ps-tex (slur-ps l)))
-
-(define 
-  (stem o kern width height depth) 
-  ((invoke-output o "stem") kern width height depth))
-
-(define 
-  (stem-ps kern width height depth) 
-  (string-append (numbers->string (list kern width height depth))
-                "draw_stem" ))
-
-(define 
-  (stem-tex kern width height depth) 
-  (string-append 
-   "\\kern" (number->dim-tex kern)
-   "\\vrule width " (number->dim-tex width)
-   "depth " (number->dim-tex depth)
-   "height " (number->dim-tex height) " "))
-
-(define 
-  (start-line o) 
-  ((invoke-output o "start-line")))
-
-(define 
-  (start-line-ps) 
-   "\nstart_line {\n")
-
-(define 
-  (start-line-tex) 
-  (string-append 
-   "\\hbox{%\n")
   )
 
+;;;;;;;;;;;; PS
+(define (ps-scm action-name)
+  (define (beam width slope thick)
+    (string-append
+     (numbers->string (list width slope thick)) " draw_beam " ))
 
-(define
-  (startbar o h)
-  ((invoke-output o "invoke-dim1") "startbar" h))
-
-(define
-  (startrepeat o h)
-  ((invoke-output o "invoke-dim1") "startrepeat" h))
-
-(define 
-  (stop-line o) 
-  ((invoke-output o "stop-line")))
-
-(define 
-  (stop-line-ps) 
-  "}\nstop_line\n")
-
-(define 
-  (stop-line-tex) 
-  "}\\interscoreline")
-
-(define
-  (stoprepeat o h)
-  ((invoke-output o "invoke-dim1") "stoprepeat" h))
+  (define (bracket h)
+    (invoke-dim1 "draw_bracket" h))
 
-(define
-  (text-ps f s)
-  (string-append "(" s ") set" f " "))
+  (define (crescendo w h cont)
+    (string-append 
+     (numbers->string (list w h (inexact->exact cont)))
+     "draw_crescendo"))
 
-(define
-  (text-tex f s)
-  (string-append "\\set" f "{" s "}"))
+  (define (dashed-slur thick dash l)
+    (string-append 
+     (apply string-append (map control->string l)) 
+     (number->string thick) 
+     " [ "
+     (if (> 1 dash) (number->string (- (* thick dash) thick)) "0") " "
+     (number->string (* 2 thick))
+     " ] 0 draw_dashed_slur"))
+
+  (define (decrescendo w h cont)
+    (string-append 
+     (numbers->string (list w h (inexact->exact cont)))
+     "draw_decrescendo"))
+
+  (define (empty) 
+    "\n empty\n")
+
+  (define (end-output)
+    "\nshowpage\n")
+
+  (define (experimental-on) "")
+
+  (define (font-def i s)
+    (string-append
+     "\n/" (font i) " {/" 
+     (substring s 0 (- (string-length s) 4))
+     " findfont 12 scalefont setfont} bind def\n"))
+
+  (define (font-switch i)
+    (string-append (font i) " "))
+
+  (define (generalmeter num den)
+    (string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
+
+  (define (header-end) "")
+  (define (lily-def key val)
+    (string-append
+     "/" key " {" val "} bind def\n"))
+
+  (define (header creator generate) 
+    (string-append
+     "%!PS-Adobe-3.0\n"
+     "%%Creator: " creator generate "\n"))
+
+  (define (invoke-char s i)
+    (string-append 
+     "(\\" (inexact->string i 8) ") " s " " ))
+
+  (define (invoke-dim1 s d) 
+    (string-append
+     (number->string d) " " s ))
+
+  (define (placebox x y s) 
+    (string-append 
+     (number->string x) " " (number->string y) " {" s "} placebox "))
+
+  (define (rulesym x y) 
+    (string-append 
+     (number->string x) " "
+     (number->string y) " "
+     "rulesym"))
+
+  (define (slur l)
+    (string-append 
+     (apply string-append (map control->string l)) 
+     " draw_slur"))
+
+  (define (start-line) 
+    "\nstart_line {\n")
+
+  (define (stem kern width height depth) 
+    (string-append (numbers->string (list kern width height depth))
+                  "draw_stem" ))
+
+  (define (stop-line) 
+    "}\nstop_line\n")
+
+  (define (text f s)
+    (string-append "(" s ") set" f " "))
+
+
+  (define (volta w last)
+    (string-append 
+     (numbers->string (list w (inexact->exact last)))
+     "draw_volta"))
+  (define   (tuplet dx dy dir)
+    (string-append 
+     (numbers->string (list dx dy (inexact->exact dir)))
+     "draw_tuplet"))
+
+
+  (define (unknown) 
+    "\n unknown\n")
+
+
+  ; dispatch on action-name
+  (cond ((eq? action-name 'all-definitions)
+       `(begin
+         (define beam ,beam)
+         (define tuplet ,tuplet)
+         (define bracket ,bracket)
+         (define crescendo ,crescendo)
+         (define volta ,volta)
+         (define slur ,slur)
+         (define dashed-slur ,dashed-slur) 
+         (define decrescendo ,decrescendo) 
+         (define empty ,empty)
+         (define end-output ,end-output)
+         (define font-def ,font-def)
+         (define font-switch ,font-switch)
+         (define generalmeter ,generalmeter)
+         (define header-end ,header-end)
+         (define lily-def ,lily-def)
+         (define header ,header) 
+         (define invoke-char ,invoke-char) 
+         (define invoke-dim1 ,invoke-dim1)
+         (define placebox ,placebox)
+         (define rulesym ,rulesym)
+         (define start-line ,start-line)
+         (define stem ,stem)
+         (define stop-line ,stop-line)
+         (define text ,text)
+         ))
+       ((eq? action-name 'tuplet) tuplet)
+       ((eq? action-name 'beam) beam)
+       ((eq? action-name 'bracket) bracket)
+       ((eq? action-name 'crescendo) crescendo)
+       ((eq? action-name 'volta) volta)
+       ((eq? action-name 'slur) slur)
+       ((eq? action-name 'dashed-slur) dashed-slur) 
+       ((eq? action-name 'decrescendo) decrescendo)
+       (else (error "unknown tag -- PS-SCM " action-name))
+       )
+)