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