3 (use-modules (ice-9 format))
5 (define (ascii->string i) (make-string 1 (integer->char i)))
7 (define (control->list c)
8 (list (+ global-x (car c)) (+ global-y (cdr c))))
10 (define (control-flip-y c)
11 (cons (car c) (* -1 (cdr c))))
14 (define (sk-numbers->string l)
16 (number->string (car l))
19 (string-append "," (sk-numbers->string (cdr l))))))
23 (define global-list '())
24 (define global-font "")
26 (define global-scale 1.0)
27 (define (global-mul-scale x) (* global-scale x))
29 ;; hmm, global is global
30 (define (global-filledbox width dy dx height x y)
36 (map global-mul-scale (list width dy dx height x y)))
39 (define (global-bezier l)
40 (let* ((c0 (car (list-tail l 3)))
41 (c123 (list-head l 3))
42 (start (control->list c0))
43 (control (apply append (map control->list c123))))
45 "bs(" (sk-numbers->string (map global-mul-scale start)) ",0)\n"
46 "bc(" (sk-numbers->string (map global-mul-scale control)) ",2)\n")))
49 (define (global-beziers l thick)
50 (let* (;;(burp (set! global-y (+ global-y (* 2 (cdar l)))))
61 (global-bezier second)
66 (define (sketch-scm action-name)
68 ;; alist containing fontname -> fontcommand assoc (both strings)
69 (define font-alist '())
71 (define current-font "")
76 (define (cached-fontname i)
79 (define (select-font name-mag-pair)
80 (set! global-font (car name-mag-pair))
83 (define (font-load-command name-mag command)
86 (define (beam width slope thick)
99 (string-append "% " s))
101 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
103 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
107 ;; `(string-append "txt(" ,(number->string i) ",("
108 ;; (sk-numbers->string (list global-x global-y))
113 ;; urg, Sketch can't handle non-text fonts
114 ;; "Fn('" global-font "')\n"
115 "Fn('Times-Roman')\n"
117 "txt('" ,(ascii->string i) "',("
118 (sk-numbers->string (list (* global-scale global-x)
119 (* global-scale global-y)))
122 (define (hairpin thick width starth endh )
124 (numbers->string (list width starth endh thick))
127 ;; what the heck is this interface ?
128 (define (dashed-slur thick dash l)
130 (apply string-append (map control->string l))
131 (ly-number->string thick)
133 (ly-number->string dash)
135 (ly-number->string (* 10 thick)) ;UGH. 10 ?
136 " ] 0 draw_dashed_slur"))
138 (define (dashed-line thick on off dx dy)
140 (ly-number->string dx)
142 (ly-number->string dy)
144 (ly-number->string thick)
146 (ly-number->string on)
148 (ly-number->string off)
149 " ] 0 draw_dashed_line"))
151 (define (repeat-slash wid slope thick)
152 (string-append (numbers->string (list wid slope thick))
153 " draw_repeat_slash"))
156 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
157 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
159 (define (experimental-on) "")
161 (define (font-switch i)
167 (define (lily-def key val)
168 (if (equal? key "lilypondpaperoutputscale")
169 (set! global-scale (string->number val)))
173 (define (header creator generate)
178 layer('Layer 1',1,1,0,0,(0,0,0))
181 (define (invoke-char s i)
184 (define (invoke-dim1 s d)
186 (ly-number->string (* d (/ 72.27 72))) " " s ))
189 (define (placebox x y s)
190 ;; (format (current-error-port) "placebox: ~S, ~S, ~S\n" x y s)
191 (set! global-x (+ x 0))
192 (set! global-y (+ y 100))
193 (let ((s (primitive-eval global-s)))
197 (define (bezier-sandwich l thick)
203 (set! global-list l))
206 ; TODO: use HEIGHT argument
207 (define (start-line height)
211 ;; r((520.305,0,0,98.0075,51.8863,10.089))
212 ;; width, 0, 0, height, x, y
213 (define (filledbox breapth width depth height)
219 `(- global-x ,breapth)
220 `(- global-y ,depth))))
221 ;; (format (current-error-port) "filledbox: ~S\n" s)
225 (define (stem x y z w) (filledbox x y z w))
233 `(string-append "txt('" ,s "',("
234 (sk-numbers->string (list global-x global-y))
238 (define (volta h w thick vert_start vert_end)
240 (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
243 (define (tuplet ht gap dx dy thick dir)
245 (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
252 (define (ez-ball ch letter-col ball-col)
255 (numbers->string (list letter-col ball-col))
256 " /Helvetica-Bold " ;; ugh
259 (define (define-origin a b c ) "")
260 (define (no-origin) "")
263 (cond ((eq? action-name 'all-definitions)
266 (define tuplet ,tuplet)
267 (define bracket ,bracket)
269 (define hairpin ,hairpin)
270 (define volta ,volta)
271 (define bezier-sandwich ,bezier-sandwich)
272 (define dashed-line ,dashed-line)
273 (define dashed-slur ,dashed-slur)
274 (define end-output ,end-output)
275 (define experimental-on ,experimental-on)
276 (define filledbox ,filledbox)
278 (define font-def ,font-def)
279 (define font-switch ,font-switch)
280 (define header-end ,header-end)
281 (define lily-def ,lily-def)
282 (define font-load-command ,font-load-command)
283 (define header ,header)
284 (define invoke-char ,invoke-char)
285 (define invoke-dim1 ,invoke-dim1)
286 (define placebox ,placebox)
287 (define select-font ,select-font)
288 (define start-line ,start-line)
290 (define stop-line ,stop-line)
291 (define stop-last-line ,stop-line)
292 (define repeat-slash ,repeat-slash)
294 (define no-origin ,no-origin)
295 (define define-origin ,define-origin)
296 (define ez-ball ,ez-ball)
298 ((eq? action-name 'repeat-slash) repeat-slash)
299 ((eq? action-name 'tuplet) tuplet)
300 ((eq? action-name 'beam) beam)
301 ((eq? action-name 'bezier-sandwich) bezier-sandwich)
302 ((eq? action-name 'bracket) bracket)
303 ((eq? action-name 'char) char)
304 ((eq? action-name 'dashed-line) dashed-line)
305 ((eq? action-name 'dashed-slur) dashed-slur)
306 ((eq? action-name 'hairpin) hairpin)
307 ((eq? action-name 'experimental-on) experimental-on)
308 ((eq? action-name 'filledbox) filledbox)
309 ((eq? action-name 'ez-ball) ez-ball)
310 ((eq? action-name 'select-font) select-font)
311 ((eq? action-name 'volta) volta)
312 (else (error "unknown tag -- SKETCH-SCM " action-name))