4 (use-modules (ice-9 format))
6 (define (ascii->string i) (make-string 1 (integer->char i)))
8 (define (control->list c)
9 (list (+ global-x (car c)) (+ global-y (cdr c))))
11 (define (control-flip-y c)
12 (cons (car c) (* -1 (cdr c))))
15 (define (sk-numbers->string l)
17 (number->string (car l))
20 (string-append "," (sk-numbers->string (cdr l))))))
24 (define global-list '())
25 (define global-font "")
27 (define global-scale 1.0)
28 (define (global-mul-scale x) (* global-scale x))
30 ;; hmm, global is global
31 (define (global-filledbox width dy dx height x y)
37 (map global-mul-scale (list width dy dx height x y)))
40 (define (global-bezier l)
41 (let* ((c0 (car (list-tail l 3)))
42 (c123 (list-head l 3))
43 (start (control->list c0))
44 (control (apply append (map control->list c123))))
46 "bs(" (sk-numbers->string (map global-mul-scale start)) ",0)\n"
47 "bc(" (sk-numbers->string (map global-mul-scale control)) ",2)\n")))
50 (define (global-beziers l thick)
51 (let* (;;(burp (set! global-y (+ global-y (* 2 (cdar l)))))
62 (global-bezier second)
67 (define (sketch-scm action-name)
69 ;; alist containing fontname -> fontcommand assoc (both strings)
70 (define font-alist '())
72 (define current-font "")
77 (define (cached-fontname i)
80 (define (select-font name-mag-pair)
81 (set! global-font (car name-mag-pair))
84 (define (font-load-command name-mag command)
87 (define (beam width slope thick)
100 (string-append "% " s))
102 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
104 (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
108 ;; `(string-append "txt(" ,(number->string i) ",("
109 ;; (sk-numbers->string (list global-x global-y))
114 ;; "Fn('" global-font "')\n"
115 ;; "Fn('Times-Roman')\n"
118 ;; chars > 128 don't work yet
119 "txt('" ,(ascii->string (modulo i 128)) "',("
120 ;; "char(" ,(number->string i) ",("
121 (sk-numbers->string (list (* global-scale global-x)
122 (* global-scale global-y)))
125 (define (hairpin thick width starth endh )
127 (numbers->string (list width starth endh thick))
130 ;; what the heck is this interface ?
131 (define (dashed-slur thick dash l)
133 (apply string-append (map control->string l))
134 (ly-number->string thick)
136 (ly-number->string dash)
138 (ly-number->string (* 10 thick)) ;UGH. 10 ?
139 " ] 0 draw_dashed_slur"))
141 (define (dashed-line thick on off dx dy)
143 (ly-number->string dx)
145 (ly-number->string dy)
147 (ly-number->string thick)
149 (ly-number->string on)
151 (ly-number->string off)
152 " ] 0 draw_dashed_line"))
154 (define (repeat-slash wid slope thick)
155 (string-append (numbers->string (list wid slope thick))
156 " draw_repeat_slash"))
159 "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
160 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
162 (define (experimental-on) "")
164 (define (font-switch i)
170 (define (lily-def key val)
171 (if (equal? key "lilypondpaperoutputscale")
172 (set! global-scale (string->number val)))
176 (define (header creator generate)
181 layer('Layer 1',1,1,0,0,(0,0,0))
184 (define (invoke-char s i)
187 (define (invoke-dim1 s d)
189 (ly-number->string (* d (/ 72.27 72))) " " s ))
192 (define (placebox x y s)
193 ;; (format (current-error-port) "placebox: ~S, ~S, ~S\n" x y s)
194 (set! global-x (+ x 0))
195 (set! global-y (+ y 100))
196 (let ((s (primitive-eval global-s)))
200 (define (bezier-sandwich l thick)
206 (set! global-list l))
209 ; TODO: use HEIGHT argument
210 (define (start-line height)
214 ;; r((520.305,0,0,98.0075,51.8863,10.089))
215 ;; width, 0, 0, height, x, y
216 (define (filledbox breapth width depth height)
222 `(- global-x ,breapth)
223 `(- global-y ,depth))))
224 ;; (format (current-error-port) "filledbox: ~S\n" s)
228 (define (stem x y z w) (filledbox x y z w))
236 `(string-append "txt('" ,s "',("
237 (sk-numbers->string (list global-x global-y))
241 (define (volta h w thick vert_start vert_end)
243 (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
246 (define (tuplet ht gap dx dy thick dir)
248 (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
255 (define (ez-ball ch letter-col ball-col)
258 (numbers->string (list letter-col ball-col))
259 " /Helvetica-Bold " ;; ugh
262 (define (define-origin a b c ) "")
263 (define (no-origin) "")
266 (cond ((eq? action-name 'all-definitions)
269 (define tuplet ,tuplet)
270 (define bracket ,bracket)
272 (define hairpin ,hairpin)
273 (define volta ,volta)
274 (define bezier-sandwich ,bezier-sandwich)
275 (define dashed-line ,dashed-line)
276 (define dashed-slur ,dashed-slur)
277 (define end-output ,end-output)
278 (define experimental-on ,experimental-on)
279 (define filledbox ,filledbox)
281 (define font-def ,font-def)
282 (define font-switch ,font-switch)
283 (define header-end ,header-end)
284 (define lily-def ,lily-def)
285 (define font-load-command ,font-load-command)
286 (define header ,header)
287 (define invoke-char ,invoke-char)
288 (define invoke-dim1 ,invoke-dim1)
289 (define placebox ,placebox)
290 (define select-font ,select-font)
291 (define start-line ,start-line)
293 (define stop-line ,stop-line)
294 (define stop-last-line ,stop-line)
295 (define repeat-slash ,repeat-slash)
297 (define no-origin ,no-origin)
298 (define define-origin ,define-origin)
299 (define ez-ball ,ez-ball)
301 ((eq? action-name 'repeat-slash) repeat-slash)
302 ((eq? action-name 'tuplet) tuplet)
303 ((eq? action-name 'beam) beam)
304 ((eq? action-name 'bezier-sandwich) bezier-sandwich)
305 ((eq? action-name 'bracket) bracket)
306 ((eq? action-name 'char) char)
307 ((eq? action-name 'dashed-line) dashed-line)
308 ((eq? action-name 'dashed-slur) dashed-slur)
309 ((eq? action-name 'hairpin) hairpin)
310 ((eq? action-name 'experimental-on) experimental-on)
311 ((eq? action-name 'filledbox) filledbox)
312 ((eq? action-name 'ez-ball) ez-ball)
313 ((eq? action-name 'select-font) select-font)
314 ((eq? action-name 'volta) volta)
315 (else (error "unknown tag -- SKETCH-SCM " action-name))