]> git.donarmstrong.com Git - lilypond.git/blob - scm/sketch.scm
patch::: 1.5.23.jcn1
[lilypond.git] / scm / sketch.scm
1
2 ;;; sketch.scm -- implement Scheme output routines for Sketch
3 ;;;
4 ;;;  source file of the GNU LilyPond music typesetter
5 ;;; 
6 ;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8
9
10 ;; als in: 
11
12 ;; def dispats (out,x,y,expr):
13 ;;     (symbol, rest) = expr
14 ;;     if symbol == 'placebox':
15 ;;      (dx,dy,expr) = rest
16 ;;      dispats (out, x + dx, y + dy, expr)
17 ;;         # hier wordt (X+DX) dus eerder gedaan dan dispats van EXPR.
18 ;;         # er zijn geen "globale" variabelen.
19 ;;     elif symbol == 'char':
20 ;;         out.write ('moveto( %f %f); char(%d)' % (x,y,rest))
21
22
23 ;; (define (dispatch x y expr)
24 ;;  (let ((keyword (car expr))) 
25 ;;   (cond
26 ;;    ((eq? keyword 'placebox)
27 ;;          (dispatch (+ x (cadr expr)) (+ y (caddr expr) (cadddr expr)))
28
29 ;;      [etc.]
30 ;;    ))
31
32
33 ;; guile < 1.4 compatibility for eval
34 (define (ly-eval e m)
35   (eval-in-module e m))
36
37 (define-module (scm sketch))
38 (debug-enable 'backtrace)
39
40 (define this-module (current-module))
41
42 (define-public (sketch-output-expression expr port)
43   (display (dispatch expr) port))
44
45 (use-modules
46  (guile))
47
48 (use-modules (ice-9 format))
49
50
51 (define (dispatch expr)
52   (let ((keyword (car expr))) 
53     (cond
54      ((eq? keyword 'placebox)
55       (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
56      (else
57       (apply (ly-eval keyword this-module) (cdr expr))))))
58
59 (define (dispatch-x-y x y expr)
60   (apply (ly-eval (car expr) this-module) (append (list x y) (cdr expr))))
61
62
63
64       
65 (define (ascii->string i) (make-string 1 (integer->char i)))
66
67 (define (control->list x y c)
68   (list (+ x (car c)) (+ y (cdr c))))
69
70 (define (control-flip-y c)
71   (cons (car c) (* -1 (cdr c))))
72
73 ;;; urg.
74 (define (sketch-numbers->string l)
75   (string-append
76    (number->string (car l))
77    (if (null? (cdr l))
78        ""
79        (string-append ","  (sketch-numbers->string (cdr l))))))
80
81 (define font "")
82 (define output-scale 1.0)
83 (define (mul-scale x) (* output-scale x))
84
85 (define (sketch-filled-rectangle width dy dx height x y)
86   (string-append
87    "fp((0,0,0))\n"
88    "lw(0.1)\n"
89    "r("
90    (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
91    ")\n"))
92
93 (define (sketch-bezier x y l)
94   (let* ((c0 (car (list-tail l 3)))
95          (c123 (list-head l 3))
96          (start (control->list x y c0))
97          (control (apply append
98                          (map (lambda (c) (control->list x y c)) c123))))
99     (string-append
100      "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
101      "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
102   
103
104 (define (sketch-beziers x y l thick)
105   (let* ((first (list-tail l 4))
106          (second (list-head l 4)))
107     (string-append
108      "fp((0,0,0))\n"
109      "lw(0.1)\n"
110      "b()\n"
111      (sketch-bezier x y first)
112      (sketch-bezier x y second))))
113          
114
115 ;; alist containing fontname -> fontcommand assoc (both strings)
116 (define font-alist '())
117 (define font-count 0)
118 (define current-font "")
119
120 (define (fontify x y name-mag-pair exp)
121   (string-append (select-font name-mag-pair)
122                  (apply (ly-eval (car exp) this-module)
123                         (append (list x y) (cdr exp)))))
124 ;;               (if (string? exp) exp "")))
125
126 (define (define-fonts x) "")
127
128 (define (font-def x)
129 "")
130
131
132 (define (cached-fontname i)
133   "")
134
135 (define (select-font name-mag-pair)
136   (set! font (car name-mag-pair))
137   "")
138
139 (define (font-load-command name-mag command)
140   "")
141
142 (define (beam x y width slope thick)
143   (apply sketch-filled-rectangle
144          (map mul-scale
145               (list width (* slope width) 0 thick x y))))
146
147 (define (comment s)
148   (string-append "# " s))
149
150 (define (bracket arch_angle arch_width arch_height  height arch_thick thick)
151   (string-append
152    (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
153
154 (define (char x y i)
155   (string-append
156    "fp((0,0,0))\n"
157    "le()\n"
158    "lw(0.1)\n"
159    ;; "Fn('" global-font "')\n"
160    ;; "Fn('Times-Roman')\n"
161    "Fn('TeX-feta20')\n"
162    "Fs(20)\n"
163    ;; chars > 128 don't work yet
164    (format #f "txt('\\~o',(" (modulo i 128))
165    ;;       "char(" ,(number->string i)  ",("
166    (sketch-numbers->string (map mul-scale (list x y)))
167    "))\n"))
168
169 (define (hairpin x y thick width starth endh )
170   (string-append
171    "#"
172    (numbers->string (list width starth endh thick))
173    " draw_hairpin"))
174
175 ;; what the heck is this interface ?
176 (define (dashed-slur thick dash l)
177   (string-append 
178    (apply string-append (map control->string l)) 
179    (ly-number->string thick) 
180    " [ "
181    (ly-number->string dash)
182    " "
183    (ly-number->string (* 10 thick))     ;UGH.  10 ?
184    " ] 0 draw_dashed_slur"))
185
186 (define (dashed-line thick on off dx dy)
187   (string-append 
188    (ly-number->string dx)
189    " "
190    (ly-number->string dy)
191    " "
192    (ly-number->string thick) 
193    " [ "
194    (ly-number->string on)
195    " "
196    (ly-number->string off)
197    " ] 0 draw_dashed_line"))
198
199 (define (repeat-slash wid slope thick)
200  (string-append (numbers->string (list wid slope thick))
201   " draw_repeat_slash"))
202
203 (define (end-output)
204   "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
205 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
206
207 (define (experimental-on) "")
208
209 (define (font-switch i)
210   "")
211
212 (define (header-end)
213   "")
214
215 (define (lily-def key val)
216   (if (equal? key "lilypondpaperoutputscale")
217       ;; ugr
218       (set! output-scale (string->number val)))
219   "")
220
221
222 (define (header creator generate)
223   (string-append
224    "##Sketch 1 2
225 document()
226 layout('A4',0)
227 layer('Layer 1',1,1,0,0,(0,0,0))
228 "))
229
230 (define (invoke-char s i)
231   "")
232
233 (define (invoke-dim1 s d) 
234   (string-append
235    (ly-number->string (* d  (/ 72.27 72))) " " s ))
236
237 (define (bezier-sandwich x y l thick)
238   (apply
239    sketch-beziers (list x y (primitive-eval l) thick)))
240
241 ; TODO: use HEIGHT argument
242 (define (start-line height)
243    "G()\n"
244    )
245
246 ;;  r((520.305,0,0,98.0075,51.8863,10.089))
247 ;;  width, 0, 0, height, x, y
248 (define (filledbox x y breapth width depth height)
249   (apply sketch-filled-rectangle
250          (list
251           (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
252
253 (define (stem x y z w) (filledbox x y z w))
254
255
256 (define (stop-line)
257     "G_()\n")
258
259 ;; huh?
260 (define (stop-last-line)
261    (stop-line))
262
263 (define (text x y s)
264   (string-append "txt('" s "',(" (sketch-numbers->string
265                                   (map mul-scale (list x y))) "))\n"))
266
267
268 (define (volta x y h w thick vert_start vert_end)
269   (string-append "#"
270    (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
271    " draw_volta"))
272
273 (define (tuplet x y ht gap dx dy thick dir)
274   (string-append "#"
275    (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
276    " draw_tuplet"))
277
278
279 (define (unknown) 
280   "\n unknown\n")
281
282 (define (ez-ball ch letter-col ball-col)
283   (string-append
284    " (" ch ") "
285    (numbers->string (list letter-col ball-col))
286    " /Helvetica-Bold " ;; ugh
287    " draw_ez_ball"))
288
289 (define (define-origin a b c ) "")
290 (define (no-origin) "")
291
292
293