;
; (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
-;;; graphical lisp element
-(define (add-column p) (display "adding column (in guile): ") (display p) (newline))
+; TODO
+; - naming
+; - ready ps code (draw_bracket) vs tex/ps macros/calls (pianobrace),
+; 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
(map (lambda (n) (string-append (number->string n) " ")) l)))
+(define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
+
(define (number->octal-string x)
(let* ((n (inexact->exact x))
(n64 (quotient n 64))
(let ((n (inexact->exact x)))
(number->string n radix)))
-(define
- (number->dim-tex x)
- (string-append
- (number->string x) "pt "))
(define
(control->string c)
(string-append (number->string (car c)) " ")
(string-append (number->string (cadr c)) " ")))
-(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)
- (string-append
- "\\embeddedps{"
- (beam-ps width slope thick)
- "}"))
-
-(define
- (char o n)
- ((invoke-output o "char") n))
-
-(define
- (char-ps n)
- (string-append
- "(\\" (inexact->string n 8) ") show"))
-
-(define
- (char-tex n)
- (string-append
- "\\char" (inexact->string n 10)))
-
-(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)
- (string-append
- "\\embeddedps{"
- (dashed-slur-ps thick dash l)
- "}"))
-
-(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
- (finishbar o h) (empty o))
(define
(font i)
(make-string 1 (integer->char (+ (char->integer #\A) i)))
))
-(define
- (font-def o i s)
- (empty o))
-; ((invoke-output o "font-def") i s))
-
-(define
- (font-def-ps i s)
- (string-append
- "\n/" (font i) " {/"
- (substring s 0 (- (string-length s) 3))
- " findfont 12 scalefont setfont} bind def\n"))
-
-(define
- (font-def-tex i s)
- (string-append
- "\\font" (font-switch-tex i) "=" s "\n"))
-
-(define
- (font-switch o i)
- ((invoke-output o "font-switch") i))
-
-(define
- (font-switch-ps i)
- (string-append (font i) " "))
-
-(define
- (font-switch-tex i)
- (string-append
- "\\" (font i) "\n"))
-
-(define
- (generalmeter o num den)
- ((invoke-output o "generalmeter") num den))
-
-(define
- (generalmeter-ps num den)
- (string-append (number->string (inexact->exact num)) " " (number->string (inexact->exact den)) " generalmeter "))
-
-(define
- (generalmeter-tex num den)
- (string-append
- "\\generalmeter{" (number->string (inexact->exact num)) "}{" (number->string (inexact->exact den)) "}"))
-
-(define
- (header o creator generate)
- ((invoke-output o "header") creator generate))
-
-(define
- (header-ps creator generate)
- (string-append
- "%!PS-Adobe-3.0\n"
- "%%Creator: " creator generate "\n"))
-
-(define
- (header-tex creator generate)
- (string-append
- "%created by: " creator generate "\n"))
-
-(define
- (header-end o)
- ((invoke-output o "header-end")))
-
-(define
- (header-end-ps) "")
-
-(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 "maatstreep") h))
-
-(define
- (maatstreep-ps h)
- (string-append
- (number->string h) " maatstreep " ))
-
-(define
- (maatstreep-tex h)
- (string-append
- "\n\\maatstreep{" (number->dim-tex h) "}"))
-
-(define
- (pianobrace o h) (empty o))
-
-(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) (empty o))
-(define
- (repeatbarstartrepeat o h) (empty o))
+(define (scm-scm action-name)
+ 1)
-(define
- (rulesym o x y)
- ((invoke-output o "rulesym") x y))
+;;;;;;;;
+ (define (emptybar h)
+ (string-append ""))
-(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) "}"))
+;;;;;;;; TeX
-(define
- (setbold o s)
- ((invoke-output o "text") "bold" s))
+(define (tex-scm action-name)
-(define
- (setfinger o s)
- ((invoke-output o "text") "finger" s))
+ (define (unknown)
+ "%\n\\unknown%\n")
-(define
- (sethuge o s)
- ((invoke-output o "text") "huge" s))
+ (define (beam width slope thick)
+ (embedded-ps ((ps-scm 'beam) width slope thick)))
-(define
- (setitalic o s)
- ((invoke-output o "text") "italic" s))
+ (define (bracket h)
+ (embedded-ps ((ps-scm 'bracket) h)))
-(define
- (setlarge o s)
- ((invoke-output o "text") "large" s))
+ (define (dashed-slur thick dash l)
+ (embedded-ps ((ps-scm 'dashed-slur) thick dash l)))
-(define
- (setLarge o s)
- ((invoke-output o "text") "Large" s))
+ (define (crescendo w h cont)
+ (embedded-ps ((ps-scm 'crescendo) w h cont)))
-(define
- (settext o s)
- ((invoke-output o "text") "text" s))
+ (define (decrescendo w h cont)
+ (embedded-ps ((ps-scm 'decrescendo) w h cont)))
-(define
- (slur o l)
- ((invoke-output o "slur") l))
+ (define (embedded-ps s)
+ (string-append "\\embeddedps{" s "}"))
-(define
- (slur-ps l)
- (string-append
- (apply string-append (map control->string l))
- " draw_slur"))
-(define
- (slur-tex l)
- (string-append
- "\\embeddedps{"
- (slur-ps l)
- "}"))
+ (define (end-output)
+ "\n\\EndLilyPondOutput")
-(define
- (stem o kern width height depth)
- ((invoke-output o "stem") kern width height depth))
+ (define (empty)
+ "%\n\\empty%\n")
-(define
- (stem-ps kern width height depth)
- (string-append (numbers->string (list kern width height depth))
- "draw_stem" ))
+ (define (experimental-on) "\\turnOnExperimentalFeatures")
-(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 (extender o h)
+ ((invoke-output o "invoke-dim1") "extender" h))
-(define
- (start-line o)
- ((invoke-output o "start-line")))
-
-(define
- (start-line-ps)
- (string-append
- (urg-fix-font-ps)
- "\nstart_line {\n"))
-
-(define
- (start-line-tex)
- (string-append
- (urg-fix-font-tex)
- "\\hbox{%\n"))
-
-(define
- (startrepeat o h) (empty o))
+ (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))
+ )
+
+ )
+
+;;;;;;;;;;;; PS
+(define (ps-scm action-name)
+ (define (beam width slope thick)
+ (string-append
+ (numbers->string (list width slope thick)) " draw_beam " ))
+
+ (define (bracket h)
+ (invoke-dim1 "draw_bracket" h))
+
+ (define (crescendo w h cont)
+ (string-append
+ (numbers->string (list w h (inexact->exact cont)))
+ "draw_crescendo"))
+
+ (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))
+ )
+)
-(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) (empty o))
-
-(define
- (text-ps f s)
- (string-append "(" s ") set" f " "))
-
-(define
- (text-tex f s)
- (string-append "\\set" f "{" s "}"))
-
-(define
- (urg-fix-font-ps)
- "/fontA { /feta20 findfont 12 scalefont setfont} bind def fontA\n")
-
-(define
- (urg-fix-font-tex)
- "\\font\\fontA=feta20.afm\\fontA\n")
-(define
- (urg-font-switch-ps i)
- "\n/feta20 findfont 12 scalefont setfont \n")