]> git.donarmstrong.com Git - lilypond.git/blob - scm/sketch.scm
''
[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.x compatibility for eval
34 (if (or (equal? (minor-version) "4.1")
35         (equal? (minor-version) "4")
36         (equal? (minor-version) "3.4"))
37     (define (ly-eval e m)
38       (eval-in-module e m))
39     (define (ly-eval e m)
40       (eval e m)))
41
42 (define-module (scm sketch))
43 (debug-enable 'backtrace)
44
45 (define this-module (current-module))
46
47 (define-public (sketch-output-expression expr port)
48   (display (dispatch expr) port))
49
50 (use-modules
51  (guile))
52
53 (use-modules (ice-9 format))
54
55
56 (define (dispatch expr)
57   (let ((keyword (car expr))) 
58     (cond
59      ((eq? keyword 'placebox)
60       (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
61      (else
62       (apply (ly-eval keyword this-module) (cdr expr))))))
63
64 (define (dispatch-x-y x y expr)
65   (apply (ly-eval (car expr) this-module) (append (list x y) (cdr expr))))
66
67
68
69       
70 (define (ascii->string i) (make-string 1 (integer->char i)))
71
72 (define (control->list x y c)
73   (list (+ x (car c)) (+ y (cdr c))))
74
75 (define (control-flip-y c)
76   (cons (car c) (* -1 (cdr c))))
77
78 ;;; urg.
79 (define (sketch-numbers->string l)
80   (string-append
81    (number->string (car l))
82    (if (null? (cdr l))
83        ""
84        (string-append ","  (sketch-numbers->string (cdr l))))))
85
86 (define font "")
87 (define output-scale 1.0)
88 (define (mul-scale x) (* output-scale x))
89
90 (define (sketch-filled-rectangle width dy dx height x y)
91   (string-append
92    "fp((0,0,0))\n"
93    "lw(0.1)\n"
94    "r("
95    (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
96    ")\n"))
97
98 (define (sketch-bezier x y l)
99   (let* ((c0 (car (list-tail l 3)))
100          (c123 (list-head l 3))
101          (start (control->list x y c0))
102          (control (apply append
103                          (map (lambda (c) (control->list x y c)) c123))))
104     (string-append
105      "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
106      "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
107   
108
109 (define (sketch-beziers x y l thick)
110   (let* ((first (list-tail l 4))
111          (second (list-head l 4)))
112     (string-append
113      "fp((0,0,0))\n"
114      "lw(0.1)\n"
115      "b()\n"
116      (sketch-bezier x y first)
117      (sketch-bezier x y second))))
118          
119
120 ;; alist containing fontname -> fontcommand assoc (both strings)
121 (define font-alist '())
122 (define font-count 0)
123 (define current-font "")
124
125 (define (fontify x y name-mag-pair exp)
126   (string-append (select-font name-mag-pair)
127                  (apply (ly-eval (car exp) this-module)
128                         (append (list x y) (cdr exp)))))
129 ;;               (if (string? exp) exp "")))
130
131 (define (define-fonts x) "")
132
133 (define (font-def x)
134 "")
135
136
137 (define (cached-fontname i)
138   "")
139
140 (define (select-font name-mag-pair)
141   (set! font (car name-mag-pair))
142   "")
143
144 (define (font-load-command name-mag command)
145   "")
146
147 (define (beam x y width slope thick)
148   (apply sketch-filled-rectangle
149          (map mul-scale
150               (list width (* slope width) 0 thick x y))))
151
152 (define (comment s)
153   (string-append "# " s))
154
155 (define (bracket arch_angle arch_width arch_height  height arch_thick thick)
156   (string-append
157    (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
158
159 (define (char x y i)
160   (string-append
161    "fp((0,0,0))\n"
162    "le()\n"
163    "lw(0.1)\n"
164    ;; "Fn('" global-font "')\n"
165    ;; "Fn('Times-Roman')\n"
166    "Fn('TeX-feta20')\n"
167    "Fs(20)\n"
168    ;; chars > 128 don't work yet
169    (format #f "txt('\\~o',(" (modulo i 128))
170    ;;       "char(" ,(number->string i)  ",("
171    (sketch-numbers->string (map mul-scale (list x y)))
172    "))\n"))
173
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 ;; TODO: bezier-ending, see ps.scm
234 (define (bezier-bow x y l thick)
235   (bezier-sandwich x y l thick))
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-system 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-system)
257     "G_()\n")
258
259 ;; huh?
260 (define (stop-last-system)
261    (stop-system))
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 (unknown) 
269   "\n unknown\n")
270
271 (define (ez-ball ch letter-col ball-col)
272   (string-append
273    " (" ch ") "
274    (numbers->string (list letter-col ball-col))
275    " /Helvetica-Bold " ;; ugh
276    " draw_ez_ball"))
277
278 (define (define-origin a b c ) "")
279 (define (no-origin) "")
280
281
282