1 ;;;; sketch.scm -- implement Scheme output routines for Sketch
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 ;; def dispats (out,x,y,expr):
10 ;; (symbol, rest) = expr
11 ;; if symbol == 'placebox':
12 ;; (dx,dy,expr) = rest
13 ;; dispats (out, x + dx, y + dy, expr)
14 ;; # hier wordt (X+DX) dus eerder gedaan dan dispats van EXPR.
15 ;; # er zijn geen "globale" variabelen.
16 ;; elif symbol == 'char':
17 ;; out.write ('moveto( %f %f); char(%d)' % (x,y,rest))
23 ;; All functions have the signature
25 ;; NAME X Y ARGUMENTS-PASSED-BY-LILYPOND
28 (define-module (scm output-sketch))
29 (debug-enable 'backtrace)
31 (define this-module (current-module))
33 (define-public (sketch-output-expression expr port)
34 (display (dispatch expr) port))
36 (use-modules (ice-9 format) (guile) (lily))
39 ; (define (dispatch x y expr)
40 ; (let ((keyword (car expr)))
42 ; ((eq? keyword 'beam x y width slope thick)
43 ; ((eq? keyword 'bezier-sandwich x y lst thick)
44 ; ((eq? keyword 'bracket arch_angle arch_width arch_height height arch_thick thick)
45 ; ((eq? keyword 'char x y i)
46 ; ((eq? keyword 'comment s)
47 ; ((eq? keyword 'dashed-line thick on off dx dy)
48 ; ((eq? keyword 'dashed-slur thick dash lst)
49 ; ((eq? keyword 'define-origin a b c ) "")
50 ; ((eq? keyword 'experimental-on) "")
51 ; ((eq? keyword 'ez-ball ch letter-col ball-col)
52 ; ((eq? keyword 'filledbox x y breapth width depth height)
53 ; ((eq? keyword 'font-load-command name-mag command)
54 ; ((eq? keyword 'font-switch i)
55 ; ((eq? keyword 'header creator generate)
56 ; ((eq? keyword 'header-end)
57 ; ((eq? keyword 'invoke-char s i)
58 ; ((eq? keyword 'lily-def key val)
59 ; ((eq? keyword 'no-origin) "")
60 ; ((eq? keyword 'output-scale 1)
61 ; ((eq? keyword 'placebox)
62 ; (dispatch (+ x (cadr expr)) (+ y (caddr expr) (cadddr expr))))
63 ; ((eq? keyword 'repeat-slash wid slope thick)
64 ; ((eq? keyword 'round-filled-box x y dx dy w h b)
65 ; ((eq? keyword 'select-font name-mag-pair)
66 ; ((eq? keyword 'start-system width height)
67 ; ((eq? keyword 'stem x y z w) (filledbox x y z w))
68 ; ((eq? keyword 'stop-last-system)
69 ; ((eq? keyword 'stop-system)
70 ; ((eq? keyword 'text x y s)
71 ; ((eq? keyword 'unknown)
76 (define current-y 150)
78 (define (dispatch expr)
79 (let ((keyword (car expr)))
81 ((eq? keyword 'placebox)
82 (dispatch-x-y (cadr expr) (+ current-y (caddr expr)) (cadddr expr)))
84 (apply (eval keyword this-module) (cdr expr))))))
86 (define (dispatch-x-y x y expr)
87 (apply (eval (car expr) this-module) (append (list x y) (cdr expr))))
89 (define (ascii->string i) (make-string 1 (integer->char i)))
91 (define (control->list x y c)
92 (list (+ x (car c)) (+ y (cdr c))))
94 (define (control-flip-y c)
95 (cons (car c) (* -1 (cdr c))))
98 (define (sketch-numbers->string lst)
100 (ly:number->string (car lst))
101 (if (null? (cdr lst))
103 (string-append "," (sketch-numbers->string (cdr lst))))))
105 ;;;\def\scaletounit{ 2.83464566929134 mul }%
107 ;;(define output-scale 2.83464566929134)
109 (define scale-to-unit
111 ((equal? (ly:unit) "mm") (/ 72.0 25.4))
112 ((equal? (ly:unit) "pt") (/ 72.0 72.27))
113 (else (error "unknown unit" (ly:unit)))
116 (define (mul-scale x) (* scale-to-unit output-scale x))
118 (define (sketch-filled-rectangle width dy dx height x y)
123 (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
127 (define (sketch-bezier x y lst)
128 (let* ((c0 (car (list-tail lst 3)))
129 (c123 (list-head lst 3))
130 (start (control->list x y c0))
131 (control (apply append
132 (map (lambda (c) (control->list x y c)) c123))))
134 "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
135 "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
139 (define (sketch-beziers x y lst thick)
140 (let* ((first (list-tail lst 4))
141 (second (list-head lst 4)))
146 (sketch-bezier x y first)
147 (sketch-bezier x y second))))
150 ;; alist containing fontname -> fontcommand assoc (both strings)
152 ;;(define font-alist '(("feta13" . ("feta13" . "13"))
153 ;; ("feta20" . ("feta20" . "20"))))
154 (define font-alist '(("feta13" . ("LilyPond-Feta13" . "13"))
155 ;; ("feta20" . ("LilyPond-Feta-20" . "20")
156 ("feta20" . ("GNU-LilyPond-feta-20" . "20")
160 (define font (cdar font-alist))
162 (define font-count 0)
163 (define current-font "")
165 (define (define-fonts x) "")
171 (define (cached-fontname i)
175 (define (round-filled-box x y dx dy w h b)
176 (sketch-filled-rectangle w 0 0 h x y))
178 (define (polygon points blotdiameter) "") ;; TODO
180 (define (select-font name-mag-pair)
181 ;; name-mag-pair: (quote ("feta20" . 0.569055118110236))"feta20"(quote ("feta20" . 0.569055118110236))
182 (let ((f (assoc (caadr name-mag-pair) font-alist)))
185 (format #t "font not found: ~s\n" (caadr name-mag-pair))))
189 (define (font-load-command name-mag command)
192 (define (beam x y width slope thick blot)
193 (apply sketch-filled-rectangle
194 (list width (* slope width) 0 thick x y)))
197 (string-append "# " s "\n"))
199 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
201 (ly:numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
208 "Fn('" (car font) "')\n"
209 "Fs(" (cdr font) ")\n"
210 ;; how to get zero-left padding with ``Guile's fprintf'' ?
211 ;;(format #f "txt('\\x~2x',(" i)
212 ;;(format #f "txt('\\x~02x',(" i)
213 ;; ugh: python's '%02x' % i
214 (format #f "&#x~2,'0x;" i)
215 (sketch-numbers->string (map mul-scale (list x y)))
219 ;; what the heck is this interface ?
220 (define (dashed-slur thick dash lst)
222 (string-join (map ly:number-pair->string lst) " ")
224 (ly:number->string thick)
226 (ly:number->string dash)
228 (ly:number->string (* 10 thick)) ;UGH. 10 ?
229 " ] 0 draw_dashed_slur"))
231 (define (dashed-line thick on off dx dy)
233 (ly:number->string dx)
235 (ly:number->string dy)
237 (ly:number->string thick)
239 (ly:number->string on)
241 (ly:number->string off)
242 " ] 0 draw_dashed_line"))
244 (define (repeat-slash wid slope thick)
245 (string-append (ly:numbers->string (list wid slope thick))
246 " draw_repeat_slash"))
249 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
250 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
252 (define (experimental-on) "")
254 (define (font-switch i)
260 (define output-scale 1)
262 (define (lily-def key val)
263 (if (equal? key "lilypondpaperoutputscale")
265 (set! output-scale (string->number val))
270 (define (header creator generate)
275 layer('Layer 1',1,1,0,0,(0,0,0))
278 (define (invoke-char s i)
281 (define (bezier-sandwich x y lst thick)
283 sketch-beziers (list x y (primitive-eval lst) thick)))
285 (define (start-system width height)
286 (set! current-y (- current-y height))
289 ;; r((520.305,0,0,98.0075,51.8863,10.089))
290 ;; width, 0, 0, height, x, y
291 (define (filledbox x y breapth width depth height)
292 (apply sketch-filled-rectangle
294 (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
296 (define (stem x y z w) (filledbox x y z w))
299 (define (stop-system)
303 (define (stop-last-system)
311 "Fn('" (car font) "')\n"
312 "Fs(" (cdr font) ")\n"
314 "txt('" s "',(" (sketch-numbers->string
315 (map mul-scale (list x y))) "))\n"))
320 (define (ez-ball ch letter-col ball-col)
323 (ly:numbers->string (list letter-col ball-col))
324 " /Helvetica-Bold " ;; ugh
327 (define (define-origin a b c ) "")
328 (define (no-origin) "")