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)))
34 ;; All functions have the signature
36 ;; NAME X Y ARGUMENTS-PASSED-BY-LILYPOND
39 ;; guile <= 1.4.x compatibility for eval
40 (if (or (equal? (minor-version) "4.1")
41 (equal? (minor-version) "4")
42 (equal? (minor-version) "3.4"))
48 (define-module (scm sketch))
49 (debug-enable 'backtrace)
51 (define this-module (current-module))
53 (define-public (sketch-output-expression expr port)
54 (display (dispatch expr) port))
59 (use-modules (ice-9 format))
62 (define (dispatch expr)
63 (let ((keyword (car expr)))
65 ((eq? keyword 'placebox)
66 (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
68 (apply (ly-eval keyword this-module) (cdr expr))))))
70 (define (dispatch-x-y x y expr)
71 (apply (ly-eval (car expr) this-module) (append (list x y) (cdr expr))))
73 (define (ascii->string i) (make-string 1 (integer->char i)))
75 (define (control->list x y c)
76 (list (+ x (car c)) (+ y (cdr c))))
78 (define (control-flip-y c)
79 (cons (car c) (* -1 (cdr c))))
82 (define (sketch-numbers->string l)
84 (number->string (car l))
87 (string-append "," (sketch-numbers->string (cdr l))))))
90 (define output-scale 1.0)
91 (define (mul-scale x) (* output-scale x))
93 (define (sketch-filled-rectangle width dy dx height x y)
98 (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
102 (define (roundfilledbox x y dx dy w h b)
103 (filled-rectangle w 0 0 h x y))
105 (define (sketch-bezier x y l)
106 (let* ((c0 (car (list-tail l 3)))
107 (c123 (list-head l 3))
108 (start (control->list x y c0))
109 (control (apply append
110 (map (lambda (c) (control->list x y c)) c123))))
112 "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
113 "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
117 (define (sketch-beziers x y l thick)
118 (let* ((first (list-tail l 4))
119 (second (list-head l 4)))
124 (sketch-bezier x y first)
125 (sketch-bezier x y second))))
128 ;; alist containing fontname -> fontcommand assoc (both strings)
129 (define font-alist '())
130 (define font-count 0)
131 (define current-font "")
133 (define (fontify x y name-mag-pair exp)
134 (string-append (select-font name-mag-pair)
135 (apply (ly-eval (car exp) this-module)
136 (append (list x y) (cdr exp)))))
137 ;; (if (string? exp) exp "")))
139 (define (define-fonts x) "")
145 (define (cached-fontname i)
148 (define (select-font name-mag-pair)
149 (set! font (car name-mag-pair))
152 (define (font-load-command name-mag command)
155 (define (beam x y width slope thick)
156 (apply sketch-filled-rectangle
158 (list width (* slope width) 0 thick x y))))
161 (string-append "# " s))
163 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
165 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
172 ;; "Fn('" global-font "')\n"
173 ;; "Fn('Times-Roman')\n"
176 ;; chars > 128 don't work yet
177 (format #f "txt('\\~o',(" (modulo i 128))
178 ;; "char(" ,(number->string i) ",("
179 (sketch-numbers->string (map mul-scale (list x y)))
183 ;; what the heck is this interface ?
184 (define (dashed-slur thick dash l)
186 (apply string-append (map number-pair->string l))
187 (ly-number->string thick)
189 (ly-number->string dash)
191 (ly-number->string (* 10 thick)) ;UGH. 10 ?
192 " ] 0 draw_dashed_slur"))
194 (define (dashed-line thick on off dx dy)
196 (ly-number->string dx)
198 (ly-number->string dy)
200 (ly-number->string thick)
202 (ly-number->string on)
204 (ly-number->string off)
205 " ] 0 draw_dashed_line"))
207 (define (repeat-slash wid slope thick)
208 (string-append (numbers->string (list wid slope thick))
209 " draw_repeat_slash"))
212 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
213 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
215 (define (experimental-on) "")
217 (define (font-switch i)
223 (define (lily-def key val)
224 (if (equal? key "lilypondpaperoutputscale")
226 (set! output-scale (string->number val)))
230 (define (header creator generate)
235 layer('Layer 1',1,1,0,0,(0,0,0))
238 (define (invoke-char s i)
241 ;; TODO: bezier-ending, see ps.scm
242 (define (bezier-bow x y l thick)
243 (bezier-sandwich x y l thick))
245 (define (bezier-sandwich x y l thick)
247 sketch-beziers (list x y (primitive-eval l) thick)))
249 ; TODO: use HEIGHT argument
250 (define (start-system width height)
254 ;; r((520.305,0,0,98.0075,51.8863,10.089))
255 ;; width, 0, 0, height, x, y
256 (define (filledbox x y breapth width depth height)
257 (apply sketch-filled-rectangle
259 (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
261 (define (stem x y z w) (filledbox x y z w))
264 (define (stop-system)
268 (define (stop-last-system)
272 (string-append "txt('" s "',(" (sketch-numbers->string
273 (map mul-scale (list x y))) "))\n"))
279 (define (ez-ball ch letter-col ball-col)
282 (numbers->string (list letter-col ball-col))
283 " /Helvetica-Bold " ;; ugh
286 (define (define-origin a b c ) "")
287 (define (no-origin) "")