]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-sketch.scm
* scm/output-gnome.scm (FIXME-glyph-string): New function. Cannot
[lilypond.git] / scm / output-sketch.scm
1 ;;;; sketch.scm -- implement Scheme output routines for Sketch
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
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))
18
19
20
21
22 ;;
23 ;; All functions have the signature 
24 ;;
25 ;;  NAME X Y ARGUMENTS-PASSED-BY-LILYPOND
26 ;;
27
28 (define-module (scm output-sketch))
29 (debug-enable 'backtrace)
30
31 (define this-module (current-module))
32
33 (define-public (sketch-output-expression expr port)
34   (display (dispatch expr) port))
35
36 (use-modules (ice-9 format) (guile) (lily))
37
38 ;; hmm
39 ; (define (dispatch x y expr)
40 ;  (let ((keyword (car expr))) 
41 ;    (cond
42 ; ((eq? keyword 'beam x y width slope thick)
43 ; ((eq? keyword 'bezier-sandwich x y l 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 l)
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)
72
73 ;     )))
74
75
76 (define current-y 150)
77
78 (define (dispatch expr)
79   (let ((keyword (car expr))) 
80     (cond
81      ((eq? keyword 'placebox)
82       (dispatch-x-y (cadr expr) (+ current-y (caddr expr)) (cadddr expr)))
83      (else
84       (apply (eval keyword this-module) (cdr expr))))))
85
86 (define (dispatch-x-y x y expr)
87   (apply (eval (car expr) this-module) (append (list x y) (cdr expr))))
88       
89 (define (ascii->string i) (make-string 1 (integer->char i)))
90
91 (define (control->list x y c)
92   (list (+ x (car c)) (+ y (cdr c))))
93
94 (define (control-flip-y c)
95   (cons (car c) (* -1 (cdr c))))
96
97 ;;; urg.
98 (define (sketch-numbers->string l)
99   (string-append
100    (ly:number->string (car l))
101    (if (null? (cdr l))
102        ""
103        (string-append ","  (sketch-numbers->string (cdr l))))))
104
105 ;;;\def\scaletounit{ 2.83464566929134 mul }%
106
107 ;;(define output-scale 2.83464566929134)
108
109 (define scale-to-unit
110   (cond
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)))
114    ))
115
116 (define (mul-scale x) (* scale-to-unit output-scale x))
117
118 (define (sketch-filled-rectangle width dy dx height x y)
119   (string-append
120    "fp((0,0,0))\n"
121    "lw(0.1)\n"
122    "r("
123    (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
124    ")\n"))
125
126
127 (define (sketch-bezier x y l)
128   (let* ((c0 (car (list-tail l 3)))
129          (c123 (list-head l 3))
130          (start (control->list x y c0))
131          (control (apply append
132                          (map (lambda (c) (control->list x y c)) c123))))
133     (string-append
134      "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
135      "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
136   
137
138
139 (define (sketch-beziers x y l thick)
140   (let* ((first (list-tail l 4))
141          (second (list-head l 4)))
142     (string-append
143      "fp((0,0,0))\n"
144      "lw(0.1)\n"
145      "b()\n"
146      (sketch-bezier x y first)
147      (sketch-bezier x y second))))
148          
149
150 ;; alist containing fontname -> fontcommand assoc (both strings)
151 ;; old scheme
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")
157                       )))
158
159 ;;(define font "")
160 (define font (cdar font-alist))
161
162 (define font-count 0)
163 (define current-font "")
164
165 (define (define-fonts x) "")
166
167 (define (font-def x)
168 "")
169
170
171 (define (cached-fontname i)
172   "")
173
174
175 (define (round-filled-box x y dx dy w h b)
176   (sketch-filled-rectangle w 0 0 h x y))
177
178 (define (polygon points blotdiameter) "") ;; TODO
179
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)))
183     (if (pair? f)
184         (set! font (cdr f))
185         (format #t "font not found: ~s\n" (caadr name-mag-pair))))
186   ;;(write font)
187   "")
188
189 (define (font-load-command name-mag command)
190   "")
191
192 (define (beam x y width slope thick blot)
193   (apply sketch-filled-rectangle
194          (list width (* slope width) 0 thick x y)))
195
196 (define (comment s)
197   (string-append "# " s "\n"))
198
199 (define (bracket arch_angle arch_width arch_height  height arch_thick thick)
200   (string-append
201    (ly:numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
202
203 (define (char x y i)
204   (string-append
205    "fp((0,0,0))\n"
206    "le()\n"
207    "lw(0.1)\n"
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)))
216    "))\n"))
217
218
219 ;; what the heck is this interface ?
220 (define (dashed-slur thick dash l)
221   (string-append 
222    (string-join (map ly:number-pair->string l) " ")
223    " "
224    (ly:number->string thick) 
225    " [ "
226    (ly:number->string dash)
227    " "
228    (ly:number->string (* 10 thick))     ;UGH.  10 ?
229    " ] 0 draw_dashed_slur"))
230
231 (define (dashed-line thick on off dx dy)
232   (string-append 
233    (ly:number->string dx)
234    " "
235    (ly:number->string dy)
236    " "
237    (ly:number->string thick) 
238    " [ "
239    (ly:number->string on)
240    " "
241    (ly:number->string off)
242    " ] 0 draw_dashed_line"))
243
244 (define (repeat-slash wid slope thick)
245  (string-append (ly:numbers->string (list wid slope thick))
246   " draw_repeat_slash"))
247
248 (define (end-output)
249   "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
250 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
251
252 (define (experimental-on) "")
253
254 (define (font-switch i)
255   "")
256
257 (define (header-end)
258   "")
259
260 (define output-scale 1)
261
262 (define (lily-def key val)
263   (if (equal? key "lilypondpaperoutputscale")
264       ;; ugr
265       (set! output-scale (string->number val))
266       )
267   "")
268
269
270 (define (header creator generate)
271   (string-append
272    "##Sketch 1 2
273 document()
274 layout('A4',0)
275 layer('Layer 1',1,1,0,0,(0,0,0))
276 "))
277
278 (define (invoke-char s i)
279   "")
280
281 (define (bezier-sandwich x y l thick)
282   (apply
283    sketch-beziers (list x y (primitive-eval l) thick)))
284
285 (define (start-system width height)
286   (set! current-y (- current-y height))
287   "G()\n")
288
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
293          (list
294           (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
295
296 (define (stem x y z w) (filledbox x y z w))
297
298
299 (define (stop-system)
300     "G_()\n")
301
302 ;; huh?
303 (define (stop-last-system)
304    (stop-system))
305
306 (define (text x y s)
307   (string-append
308    "fp((0,0,0))\n"
309    "le()\n"
310    "lw(0.1)\n"
311    "Fn('" (car font) "')\n"
312    "Fs(" (cdr font) ")\n"
313    ;; Hmm
314    "txt('" s "',(" (sketch-numbers->string
315                                   (map mul-scale (list x y))) "))\n"))
316
317 (define (unknown) 
318   "\n unknown\n")
319
320 (define (ez-ball ch letter-col ball-col)
321   (string-append
322    " (" ch ") "
323    (ly:numbers->string (list letter-col ball-col))
324    " /Helvetica-Bold " ;; ugh
325    " draw_ez_ball"))
326
327 (define (define-origin a b c ) "")
328 (define (no-origin) "")
329
330
331
332 ;;;;;;;;;;;;;;;;;;;;
333 ;;;;;;;;;;;;;;;;;;;;
334
335