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