2 ;;; sketch.scm -- implement Scheme output routines for Sketch
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 ;; def dispats (out,x,y,expr):
13 ;; (symbol, rest) = expr
14 ;; if symbol == 'placebox':
15 ;; (dx,dy,expr) = rest
16 ;; dispats (out, x + dx, y + dy, expr)
17 ;; # hier wordt (X+DX) dus eerder gedaan dan dispats van EXPR.
18 ;; # er zijn geen "globale" variabelen.
19 ;; elif symbol == 'char':
20 ;; out.write ('moveto( %f %f); char(%d)' % (x,y,rest))
23 ;; (define (dispatch x y expr)
24 ;; (let ((keyword (car expr)))
26 ;; ((eq? keyword 'placebox)
27 ;; (dispatch (+ x (cadr expr)) (+ y (caddr expr) (cadddr expr)))
33 ;; guile < 1.4 compatibility for eval
34 (if (or (equal? (minor-version) "4")
35 (equal? (minor-version) "3.4"))
41 (define-module (scm sketch))
42 (debug-enable 'backtrace)
44 (define this-module (current-module))
46 (define-public (sketch-output-expression expr port)
47 (display (dispatch expr) port))
52 (use-modules (ice-9 format))
55 (define (dispatch expr)
56 (let ((keyword (car expr)))
58 ((eq? keyword 'placebox)
59 (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
61 (apply (ly-eval keyword this-module) (cdr expr))))))
63 (define (dispatch-x-y x y expr)
64 (apply (ly-eval (car expr) this-module) (append (list x y) (cdr expr))))
69 (define (ascii->string i) (make-string 1 (integer->char i)))
71 (define (control->list x y c)
72 (list (+ x (car c)) (+ y (cdr c))))
74 (define (control-flip-y c)
75 (cons (car c) (* -1 (cdr c))))
78 (define (sketch-numbers->string l)
80 (number->string (car l))
83 (string-append "," (sketch-numbers->string (cdr l))))))
86 (define output-scale 1.0)
87 (define (mul-scale x) (* output-scale x))
89 (define (sketch-filled-rectangle width dy dx height x y)
94 (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
97 (define (sketch-bezier x y l)
98 (let* ((c0 (car (list-tail l 3)))
99 (c123 (list-head l 3))
100 (start (control->list x y c0))
101 (control (apply append
102 (map (lambda (c) (control->list x y c)) c123))))
104 "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
105 "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
108 (define (sketch-beziers x y l thick)
109 (let* ((first (list-tail l 4))
110 (second (list-head l 4)))
115 (sketch-bezier x y first)
116 (sketch-bezier x y second))))
119 ;; alist containing fontname -> fontcommand assoc (both strings)
120 (define font-alist '())
121 (define font-count 0)
122 (define current-font "")
124 (define (fontify x y name-mag-pair exp)
125 (string-append (select-font name-mag-pair)
126 (apply (ly-eval (car exp) this-module)
127 (append (list x y) (cdr exp)))))
128 ;; (if (string? exp) exp "")))
130 (define (define-fonts x) "")
136 (define (cached-fontname i)
139 (define (select-font name-mag-pair)
140 (set! font (car name-mag-pair))
143 (define (font-load-command name-mag command)
146 (define (beam x y width slope thick)
147 (apply sketch-filled-rectangle
149 (list width (* slope width) 0 thick x y))))
152 (string-append "# " s))
154 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
156 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
163 ;; "Fn('" global-font "')\n"
164 ;; "Fn('Times-Roman')\n"
167 ;; chars > 128 don't work yet
168 (format #f "txt('\\~o',(" (modulo i 128))
169 ;; "char(" ,(number->string i) ",("
170 (sketch-numbers->string (map mul-scale (list x y)))
174 ;; what the heck is this interface ?
175 (define (dashed-slur thick dash l)
177 (apply string-append (map control->string l))
178 (ly-number->string thick)
180 (ly-number->string dash)
182 (ly-number->string (* 10 thick)) ;UGH. 10 ?
183 " ] 0 draw_dashed_slur"))
185 (define (dashed-line thick on off dx dy)
187 (ly-number->string dx)
189 (ly-number->string dy)
191 (ly-number->string thick)
193 (ly-number->string on)
195 (ly-number->string off)
196 " ] 0 draw_dashed_line"))
198 (define (repeat-slash wid slope thick)
199 (string-append (numbers->string (list wid slope thick))
200 " draw_repeat_slash"))
203 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
204 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
206 (define (experimental-on) "")
208 (define (font-switch i)
214 (define (lily-def key val)
215 (if (equal? key "lilypondpaperoutputscale")
217 (set! output-scale (string->number val)))
221 (define (header creator generate)
226 layer('Layer 1',1,1,0,0,(0,0,0))
229 (define (invoke-char s i)
233 (define (bezier-sandwich x y l thick)
235 sketch-beziers (list x y (primitive-eval l) thick)))
237 ; TODO: use HEIGHT argument
238 (define (start-system height)
242 ;; r((520.305,0,0,98.0075,51.8863,10.089))
243 ;; width, 0, 0, height, x, y
244 (define (filledbox x y breapth width depth height)
245 (apply sketch-filled-rectangle
247 (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
249 (define (stem x y z w) (filledbox x y z w))
252 (define (stop-system)
256 (define (stop-last-system)
260 (string-append "txt('" s "',(" (sketch-numbers->string
261 (map mul-scale (list x y))) "))\n"))
267 (define (ez-ball ch letter-col ball-col)
270 (numbers->string (list letter-col ball-col))
271 " /Helvetica-Bold " ;; ugh
274 (define (define-origin a b c ) "")
275 (define (no-origin) "")