1 ;;; sketch.scm -- implement Scheme output routines for Sketch
3 ;;; source file of the GNU LilyPond music typesetter
5 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 ;; def dispats (out,x,y,expr):
12 ;; (symbol, rest) = expr
13 ;; if symbol == 'placebox':
14 ;; (dx,dy,expr) = rest
15 ;; dispats (out, x + dx, y + dy, expr)
16 ;; # hier wordt (X+DX) dus eerder gedaan dan dispats van EXPR.
17 ;; # er zijn geen "globale" variabelen.
18 ;; elif symbol == 'char':
19 ;; out.write ('moveto( %f %f); char(%d)' % (x,y,rest))
22 ;; (define (dispatch x y expr)
23 ;; (let ((keyword (car expr)))
25 ;; ((eq? keyword 'placebox)
26 ;; (dispatch (+ x (cadr expr)) (+ y (caddr expr) (cadddr expr)))
33 (define-module (scm sketch)
34 :export (sketch-output-expression)
37 (define this-module (current-module))
39 (define (sketch-output-expression expr port)
40 (display (dispatch expr) port))
46 (use-modules (ice-9 format))
49 (define (dispatch expr)
50 (let ((keyword (car expr)))
52 ((eq? keyword 'placebox)
53 (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
55 (apply (eval keyword this-module) (cdr expr))))))
57 (define (dispatch-x-y x y expr)
58 (apply (eval (car expr) this-module) (append (list x y) (cdr expr))))
63 (define (ascii->string i) (make-string 1 (integer->char i)))
65 (define (control->list x y c)
66 (list (+ x (car c)) (+ y (cdr c))))
68 (define (control-flip-y c)
69 (cons (car c) (* -1 (cdr c))))
72 (define (sketch-numbers->string l)
74 (number->string (car l))
77 (string-append "," (sketch-numbers->string (cdr l))))))
80 (define output-scale 1.0)
81 (define (mul-scale x) (* output-scale x))
83 (define (sketch-filled-rectangle width dy dx height x y)
88 (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
91 (define (sketch-bezier x y l)
92 (let* ((c0 (car (list-tail l 3)))
93 (c123 (list-head l 3))
94 (start (control->list x y c0))
95 (control (apply append
96 (map (lambda (c) (control->list x y c)) c123))))
98 "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
99 "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
102 (define (sketch-beziers x y l thick)
103 (let* ((first (list-tail l 4))
104 (second (list-head l 4)))
109 (sketch-bezier x y first)
110 (sketch-bezier x y second))))
113 ;; alist containing fontname -> fontcommand assoc (both strings)
114 (define font-alist '())
115 (define font-count 0)
116 (define current-font "")
118 (define (fontify x y name-mag-pair exp)
119 (string-append (select-font name-mag-pair)
120 (apply (eval (car exp) this-module)
121 (append (list x y) (cdr exp)))))
122 ;; (if (string? exp) exp "")))
124 (define (define-fonts x) "")
130 (define (cached-fontname i)
133 (define (select-font name-mag-pair)
134 (set! font (car name-mag-pair))
137 (define (font-load-command name-mag command)
140 (define (beam x y width slope thick)
141 (apply sketch-filled-rectangle
143 (list width (* slope width) 0 thick x y))))
146 (string-append "# " s))
148 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
150 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
157 ;; "Fn('" global-font "')\n"
158 ;; "Fn('Times-Roman')\n"
161 ;; chars > 128 don't work yet
162 (format #f "txt('\\~o',(" (modulo i 128))
163 ;; "char(" ,(number->string i) ",("
164 (sketch-numbers->string (map mul-scale (list x y)))
167 (define (hairpin x y thick width starth endh )
170 (numbers->string (list width starth endh thick))
173 ;; what the heck is this interface ?
174 (define (dashed-slur thick dash l)
176 (apply string-append (map control->string l))
177 (ly-number->string thick)
179 (ly-number->string dash)
181 (ly-number->string (* 10 thick)) ;UGH. 10 ?
182 " ] 0 draw_dashed_slur"))
184 (define (dashed-line thick on off dx dy)
186 (ly-number->string dx)
188 (ly-number->string dy)
190 (ly-number->string thick)
192 (ly-number->string on)
194 (ly-number->string off)
195 " ] 0 draw_dashed_line"))
197 (define (repeat-slash wid slope thick)
198 (string-append (numbers->string (list wid slope thick))
199 " draw_repeat_slash"))
202 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
203 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
205 (define (experimental-on) "")
207 (define (font-switch i)
213 (define (lily-def key val)
214 (if (equal? key "lilypondpaperoutputscale")
216 (set! output-scale (string->number val)))
220 (define (header creator generate)
225 layer('Layer 1',1,1,0,0,(0,0,0))
228 (define (invoke-char s i)
231 (define (invoke-dim1 s d)
233 (ly-number->string (* d (/ 72.27 72))) " " s ))
235 (define (bezier-sandwich x y l thick)
237 sketch-beziers (list x y (primitive-eval l) thick)))
239 ; TODO: use HEIGHT argument
240 (define (start-line height)
244 ;; r((520.305,0,0,98.0075,51.8863,10.089))
245 ;; width, 0, 0, height, x, y
246 (define (filledbox x y breapth width depth height)
247 (apply sketch-filled-rectangle
249 (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
251 (define (stem x y z w) (filledbox x y z w))
258 (define (stop-last-line)
262 (string-append "txt('" s "',(" (sketch-numbers->string
263 (map mul-scale (list x y))) "))\n"))
266 (define (volta x y h w thick vert_start vert_end)
268 (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
271 (define (tuplet x y ht gap dx dy thick dir)
273 (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
280 (define (ez-ball ch letter-col ball-col)
283 (numbers->string (list letter-col ball-col))
284 " /Helvetica-Bold " ;; ugh
287 (define (define-origin a b c ) "")
288 (define (no-origin) "")