1 ;;;; sketch.scm -- implement Scheme output routines for Sketch
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 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)
110 (define (mul-scale x) (* scale-to-unit output-scale x))
112 (define (sketch-filled-rectangle width dy dx height x y)
117 (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
121 (define (sketch-bezier x y lst)
122 (let* ((c0 (car (list-tail lst 3)))
123 (c123 (list-head lst 3))
124 (start (control->list x y c0))
125 (control (apply append
126 (map (lambda (c) (control->list x y c)) c123))))
128 "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
129 "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
133 (define (sketch-beziers x y lst thick)
134 (let* ((first (list-tail lst 4))
135 (second (list-head lst 4)))
140 (sketch-bezier x y first)
141 (sketch-bezier x y second))))
144 ;; alist containing fontname -> fontcommand assoc (both strings)
146 ;;(define font-alist '(("feta13" . ("feta13" . "13"))
147 ;; ("feta20" . ("feta20" . "20"))))
148 (define font-alist '(("feta13" . ("LilyPond-Feta13" . "13"))
149 ;; ("feta20" . ("LilyPond-Feta-20" . "20")
150 ("feta20" . ("GNU-LilyPond-feta-20" . "20")
154 (define font (cdar font-alist))
156 (define font-count 0)
157 (define current-font "")
159 (define (define-fonts x) "")
165 (define (cached-fontname i)
169 (define (round-filled-box x y dx dy w h b)
170 (sketch-filled-rectangle w 0 0 h x y))
172 (define (polygon points blotdiameter) "") ;; TODO
174 (define (select-font name-mag-pair)
175 ;; name-mag-pair: (quote ("feta20" . 0.569055118110236))"feta20"(quote ("feta20" . 0.569055118110236))
176 (let ((f (assoc (caadr name-mag-pair) font-alist)))
179 (format #t "font not found: ~s\n" (caadr name-mag-pair))))
183 (define (font-load-command name-mag command)
186 (define (beam x y width slope thick blot)
187 (apply sketch-filled-rectangle
188 (list width (* slope width) 0 thick x y)))
191 (string-append "# " s "\n"))
193 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
195 (ly:numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
202 "Fn('" (car font) "')\n"
203 "Fs(" (cdr font) ")\n"
204 ;; how to get zero-left padding with ``Guile's fprintf'' ?
205 ;;(format #f "txt('\\x~2x',(" i)
206 ;;(format #f "txt('\\x~02x',(" i)
207 ;; ugh: python's '%02x' % i
208 (format #f "&#x~2,'0x;" i)
209 (sketch-numbers->string (map mul-scale (list x y)))
213 ;; what the heck is this interface ?
214 (define (dashed-slur thick on off l)
217 (define (dashed-line thick on off dx dy)
219 (ly:number->string dx)
221 (ly:number->string dy)
223 (ly:number->string thick)
225 (ly:number->string on)
227 (ly:number->string off)
228 " ] 0 draw_dashed_line"))
230 (define (repeat-slash wid slope thick)
231 (string-append (ly:numbers->string (list wid slope thick))
232 " draw_repeat_slash"))
235 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
236 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
238 (define (experimental-on) "")
240 (define (font-switch i)
246 (define output-scale 1)
248 (define (lily-def key val)
249 (if (equal? key "lilypondpaperoutputscale")
251 (set! output-scale (string->number val))
256 (define (header creator generate)
261 layer('Layer 1',1,1,0,0,(0,0,0))
264 (define (invoke-char s i)
267 (define (bezier-sandwich x y lst thick)
269 sketch-beziers (list x y (primitive-eval lst) thick)))
271 (define (start-system width height)
272 (set! current-y (- current-y height))
275 ;; r((520.305,0,0,98.0075,51.8863,10.089))
276 ;; width, 0, 0, height, x, y
277 (define (filledbox x y breapth width depth height)
278 (apply sketch-filled-rectangle
280 (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
282 (define (stem x y z w) (filledbox x y z w))
285 (define (stop-system)
289 (define (stop-last-system)
297 "Fn('" (car font) "')\n"
298 "Fs(" (cdr font) ")\n"
300 "txt('" s "',(" (sketch-numbers->string
301 (map mul-scale (list x y))) "))\n"))
306 (define (ez-ball ch letter-col ball-col)
309 (ly:numbers->string (list letter-col ball-col))
310 " /Helvetica-Bold " ;; ugh
313 (define (define-origin a b c ) "")
314 (define (no-origin) "")