]> git.donarmstrong.com Git - lilypond.git/blob - scm/ascii-script.scm
patch::: 1.3.131.jcn2
[lilypond.git] / scm / ascii-script.scm
1 (debug-enable 'backtrace)
2
3 ;;;; AsciiScript as
4 (define (as-scm action-name)
5
6   (define (beam width slope thick)
7           (string-append
8            (func "set-line-char" "#")
9            (func "rline-to" width (* width slope))
10            ))
11
12   ; simple flat slurs
13   (define (bezier-sandwich l thick)
14           (let (
15                 (c0 (cadddr l))
16                 (c1 (cadr l))
17                 (c3 (caddr l)))
18                (let* ((x (car c0))
19                       (dx (- (car c3) x))
20                       (dy (- (cdr c3) (cdr c0)))
21                       (rc (/ dy dx))
22                       (c1-dx (- (car c1) x))
23                       (c1-line-y (+ (cdr c0) (* c1-dx rc)))
24                       (dir (if (< c1-line-y (cdr c1)) 1 -1))
25                       (y (+ -1 (* dir (max (* dir (cdr c0)) (* dir (cdr c3)))))))
26                      (string-append
27                       (func "rmove-to" x y)
28                       (func "put" (if (< 0 dir) "/" "\\\\"))
29                       (func "rmove-to" 1 (if (< 0 dir) 1 0))
30                       (func "set-line-char" "_")
31                       (func "h-line" (- dx 1))
32                       (func "rmove-to" (- dx 1) (if (< 0 dir) -1 0))
33                       (func "put" (if (< 0 dir) "\\\\" "/"))))))
34
35   (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
36           (string-append
37            (func "rmove-to" (+ width 1) (- (/ height -2) 1))
38            (func "put" "\\\\")
39            (func "set-line-char" "|")
40            (func "rmove-to" 0 1)
41            (func "v-line" (+ height 1))
42            (func "rmove-to" 0 (+ height 1))
43            (func "put" "/")
44            ))
45
46   (define (char i)
47     (func "char" i))
48
49   (define (define-origin a b c ) "")
50
51   (define (end-output) 
52     (func "end-output"))
53   
54   (define (experimental-on)
55           "")
56
57   (define (filledbox breapth width depth height)
58           (let ((dx (+ width breapth))
59                 (dy (+ depth height)))
60                (string-append 
61                 (func "rmove-to" (* -1 breapth) (* -1 depth))
62                 (if (< dx dy)
63                     (string-append
64                      (func "set-line-char" 
65                            (if (<= dx 1) "|" "#"))
66                      (func "v-line" dy))
67                     (string-append
68                      (func "set-line-char" 
69                            (if (<= dy 1) "-" "="))
70                     (func "h-line" dx))))))
71
72   (define (font-load-command name-mag command)
73     (func "load-font" (car name-mag) (cdr name-mag)))
74
75   (define (header creator generate) 
76     (func "header" creator generate))
77
78   (define (header-end) 
79     (func "header-end"))
80
81   ;; urg: this is good for half of as2text's execution time
82   (define (xlily-def key val)
83           (string-append "(define " key " " (arg->string val) ")\n"))
84
85   (define (lily-def key val)
86           (if 
87            (or (equal? key "lilypondpaperlinewidth")
88                (equal? key "lilypondpaperstaffheight"))
89            (string-append "(define " key " " (arg->string val) ")\n")
90            ""))
91
92   (define (no-origin) "")
93   
94   (define (placebox x y s) 
95     (let ((ey (inexact->exact y)))
96           (string-append "(move-to " (number->string (inexact->exact x)) " "
97                          (if (= 0.5 (- (abs y) (abs ey)))
98                              (number->string y)
99                              (number->string ey))
100                          ")\n" s)))
101                        
102   (define (select-font name-mag-pair)
103     (let* ((c (assoc name-mag-pair font-name-alist)))
104       (if (eq? c #f)
105           (begin
106             (ly-warn 
107              (string-append 
108               "Programming error: No such font known " 
109               (car name-mag-pair))))
110             "")                         ; issue no command
111           (func "select-font" (car name-mag-pair))))
112
113   (define (start-line height)
114           (func "start-line" height))
115
116   (define (stop-line)
117           (func "stop-line"))
118
119   (define (text s)
120           (func "text" s))
121
122   (define (tuplet ht gap dx dy thick dir) "")
123
124   (define (volta h w thick vert-start vert-end)
125           ;; urg
126           (string-append
127            (func "set-line-char" "|")
128            (func "rmove-to" 0 -4)
129            ;; definition strange-way around
130            (if (= 0 vert-start)
131               (func "v-line" h)
132                "")
133            (func "rmove-to" 1 h)
134            (func "set-line-char" "_")
135            (func "h-line" (- w 1))
136            (func "set-line-char" "|")
137            (if (= 0 vert-end)
138                (string-append
139                 (func "rmove-to" (- w 1) (* -1 h))
140                 (func "v-line" (* -1 h)))
141                "")))
142
143 (cond ((eq? action-name 'all-definitions)
144          `(begin
145             (define beam ,beam)
146             (define bracket ,bracket)
147             (define char ,char)
148             (define define-origin ,define-origin)
149             ;;(define crescendo ,crescendo)
150             (define bezier-sandwich ,bezier-sandwich)
151             ;;(define dashed-slur ,dashed-slur) 
152             ;;(define decrescendo ,decrescendo) 
153             (define end-output ,end-output)
154             (define experimental-on ,experimental-on)
155             (define filledbox ,filledbox)
156             ;;(define font-def ,font-def)
157             (define font-load-command ,font-load-command)
158             ;;(define font-switch ,font-switch)
159             (define header ,header) 
160             (define header-end ,header-end)
161             (define lily-def ,lily-def)
162             ;;(define invoke-char ,invoke-char) 
163             ;;(define invoke-dim1 ,invoke-dim1)
164             (define no-origin ,no-origin)
165             (define placebox ,placebox)
166             (define select-font ,select-font)
167             (define start-line ,start-line)
168             ;;(define stem ,stem)
169             (define stop-line ,stop-line)
170             (define stop-last-line ,stop-line)
171             (define text ,text)
172             (define tuplet ,tuplet)
173             (define volta ,volta)
174             ))
175         ((eq? action-name 'tuplet) tuplet)
176         ;;((eq? action-name 'beam) beam)
177         ;;((eq? action-name 'bezier-sandwich) bezier-sandwich)
178         ;;((eq? action-name 'bracket) bracket)
179         ((eq? action-name 'char) char)
180         ;;((eq? action-name 'crescendo) crescendo)
181         ;;((eq? action-name 'dashed-slur) dashed-slur) 
182         ;;((eq? action-name 'decrescendo) decrescendo)
183         ;;((eq? action-name 'experimental-on) experimental-on)
184         ((eq? action-name 'filledbox) filledbox)
185         ((eq? action-name 'select-font) select-font)
186         ;;((eq? action-name 'volta) volta)
187         (else (error "unknown tag -- MUSA-SCM " action-name))
188         )
189   )
190
191 (define (scm-as-output)
192   (ly-eval (as-scm 'all-definitions)))