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
37 (define-module (scm sketch))
38 (debug-enable 'backtrace)
40 (define this-module (current-module))
42 (define-public (sketch-output-expression expr port)
43 (display (dispatch expr) port))
48 (use-modules (ice-9 format))
51 (define (dispatch expr)
52 (let ((keyword (car expr)))
54 ((eq? keyword 'placebox)
55 (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
57 (apply (ly-eval keyword this-module) (cdr expr))))))
59 (define (dispatch-x-y x y expr)
60 (apply (ly-eval (car expr) this-module) (append (list x y) (cdr expr))))
65 (define (ascii->string i) (make-string 1 (integer->char i)))
67 (define (control->list x y c)
68 (list (+ x (car c)) (+ y (cdr c))))
70 (define (control-flip-y c)
71 (cons (car c) (* -1 (cdr c))))
74 (define (sketch-numbers->string l)
76 (number->string (car l))
79 (string-append "," (sketch-numbers->string (cdr l))))))
82 (define output-scale 1.0)
83 (define (mul-scale x) (* output-scale x))
85 (define (sketch-filled-rectangle width dy dx height x y)
90 (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
93 (define (sketch-bezier x y l)
94 (let* ((c0 (car (list-tail l 3)))
95 (c123 (list-head l 3))
96 (start (control->list x y c0))
97 (control (apply append
98 (map (lambda (c) (control->list x y c)) c123))))
100 "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
101 "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
104 (define (sketch-beziers x y l thick)
105 (let* ((first (list-tail l 4))
106 (second (list-head l 4)))
111 (sketch-bezier x y first)
112 (sketch-bezier x y second))))
115 ;; alist containing fontname -> fontcommand assoc (both strings)
116 (define font-alist '())
117 (define font-count 0)
118 (define current-font "")
120 (define (fontify x y name-mag-pair exp)
121 (string-append (select-font name-mag-pair)
122 (apply (ly-eval (car exp) this-module)
123 (append (list x y) (cdr exp)))))
124 ;; (if (string? exp) exp "")))
126 (define (define-fonts x) "")
132 (define (cached-fontname i)
135 (define (select-font name-mag-pair)
136 (set! font (car name-mag-pair))
139 (define (font-load-command name-mag command)
142 (define (beam x y width slope thick)
143 (apply sketch-filled-rectangle
145 (list width (* slope width) 0 thick x y))))
148 (string-append "# " s))
150 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
152 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
159 ;; "Fn('" global-font "')\n"
160 ;; "Fn('Times-Roman')\n"
163 ;; chars > 128 don't work yet
164 (format #f "txt('\\~o',(" (modulo i 128))
165 ;; "char(" ,(number->string i) ",("
166 (sketch-numbers->string (map mul-scale (list x y)))
169 (define (hairpin x y thick width starth endh )
172 (numbers->string (list width starth endh thick))
175 ;; what the heck is this interface ?
176 (define (dashed-slur thick dash l)
178 (apply string-append (map control->string l))
179 (ly-number->string thick)
181 (ly-number->string dash)
183 (ly-number->string (* 10 thick)) ;UGH. 10 ?
184 " ] 0 draw_dashed_slur"))
186 (define (dashed-line thick on off dx dy)
188 (ly-number->string dx)
190 (ly-number->string dy)
192 (ly-number->string thick)
194 (ly-number->string on)
196 (ly-number->string off)
197 " ] 0 draw_dashed_line"))
199 (define (repeat-slash wid slope thick)
200 (string-append (numbers->string (list wid slope thick))
201 " draw_repeat_slash"))
204 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
205 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
207 (define (experimental-on) "")
209 (define (font-switch i)
215 (define (lily-def key val)
216 (if (equal? key "lilypondpaperoutputscale")
218 (set! output-scale (string->number val)))
222 (define (header creator generate)
227 layer('Layer 1',1,1,0,0,(0,0,0))
230 (define (invoke-char s i)
233 (define (invoke-dim1 s d)
235 (ly-number->string (* d (/ 72.27 72))) " " s ))
237 (define (bezier-sandwich x y l thick)
239 sketch-beziers (list x y (primitive-eval l) thick)))
241 ; TODO: use HEIGHT argument
242 (define (start-line height)
246 ;; r((520.305,0,0,98.0075,51.8863,10.089))
247 ;; width, 0, 0, height, x, y
248 (define (filledbox x y breapth width depth height)
249 (apply sketch-filled-rectangle
251 (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
253 (define (stem x y z w) (filledbox x y z w))
260 (define (stop-last-line)
264 (string-append "txt('" s "',(" (sketch-numbers->string
265 (map mul-scale (list x y))) "))\n"))
268 (define (volta x y h w thick vert_start vert_end)
270 (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
273 (define (tuplet x y ht gap dx dy thick dir)
275 (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
282 (define (ez-ball ch letter-col ball-col)
285 (numbers->string (list letter-col ball-col))
286 " /Helvetica-Bold " ;; ugh
289 (define (define-origin a b c ) "")
290 (define (no-origin) "")