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