]> git.donarmstrong.com Git - lilypond.git/blob - scm/sketch.scm
6a7660dbb7cf7a2474dae326f98818a9c9acc473
[lilypond.git] / scm / 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--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9 ;; als in: 
10
11 ;; def dispats (out,x,y,expr):
12 ;;     (symbol, rest) = expr
13 ;;     if symbol == 'placebox':
14 ;;      (dx,dy,expr) = rest
15 ;;      dispats (out, x + dx, y + dy, expr)
16 ;;         # hier wordt (X+DX) dus eerder gedaan dan dispats van EXPR.
17 ;;         # er zijn geen "globale" variabelen.
18 ;;     elif symbol == 'char':
19 ;;         out.write ('moveto( %f %f); char(%d)' % (x,y,rest))
20
21
22 ;; (define (dispatch x y expr)
23 ;;  (let ((keyword (car expr))) 
24 ;;   (cond
25 ;;    ((eq? keyword 'placebox)
26 ;;          (dispatch (+ x (cadr expr)) (+ y (caddr expr) (cadddr expr)))
27
28 ;;      [etc.]
29 ;;    ))
30
31
32
33 (define-module (scm sketch)
34   :export (sketch-output-expression)
35   :no-backtrace)
36
37 (define this-module (current-module))
38
39 (define (sketch-output-expression expr port)
40   (display (dispatch expr) port))
41
42 (use-modules
43  (guile)
44  (guile-user))
45
46 (use-modules (ice-9 format))
47
48
49 (define (dispatch expr)
50   (let ((keyword (car expr))) 
51     (cond
52      ((eq? keyword 'placebox)
53       (dispatch-x-y (cadr expr) (+ 150 (caddr expr)) (cadddr expr)))
54      (else
55       (apply (eval keyword this-module) (cdr expr))))))
56
57 (define (dispatch-x-y x y expr)
58   (apply (eval (car expr) this-module) (append (list x y) (cdr expr))))
59
60
61
62       
63 (define (ascii->string i) (make-string 1 (integer->char i)))
64
65 (define (control->list x y c)
66   (list (+ x (car c)) (+ y (cdr c))))
67
68 (define (control-flip-y c)
69   (cons (car c) (* -1 (cdr c))))
70
71 ;;; urg.
72 (define (sketch-numbers->string l)
73   (string-append
74    (number->string (car l))
75    (if (null? (cdr l))
76        ""
77        (string-append ","  (sketch-numbers->string (cdr l))))))
78
79 (define font "")
80 (define output-scale 1.0)
81 (define (mul-scale x) (* output-scale x))
82
83 (define (sketch-filled-rectangle width dy dx height x y)
84   (string-append
85    "fp((0,0,0))\n"
86    "lw(0.1)\n"
87    "r("
88    (sketch-numbers->string (map mul-scale (list width dy dx height x y)))
89    ")\n"))
90
91 (define (sketch-bezier x y l)
92   (let* ((c0 (car (list-tail l 3)))
93          (c123 (list-head l 3))
94          (start (control->list x y c0))
95          (control (apply append
96                          (map (lambda (c) (control->list x y c)) c123))))
97     (string-append
98      "bs(" (sketch-numbers->string (map mul-scale start)) ",0)\n"
99      "bc(" (sketch-numbers->string (map mul-scale control)) ",2)\n")))
100   
101
102 (define (sketch-beziers x y l thick)
103   (let* ((first (list-tail l 4))
104          (second (list-head l 4)))
105     (string-append
106      "fp((0,0,0))\n"
107      "lw(0.1)\n"
108      "b()\n"
109      (sketch-bezier x y first)
110      (sketch-bezier x y second))))
111          
112
113 ;; alist containing fontname -> fontcommand assoc (both strings)
114 (define font-alist '())
115 (define font-count 0)
116 (define current-font "")
117
118 (define (fontify x y name-mag-pair exp)
119   (string-append (select-font name-mag-pair)
120                  (apply (eval (car exp) this-module)
121                         (append (list x y) (cdr exp)))))
122 ;;               (if (string? exp) exp "")))
123
124 (define (define-fonts x) "")
125
126 (define (font-def x)
127 "")
128
129
130 (define (cached-fontname i)
131   "")
132
133 (define (select-font name-mag-pair)
134   (set! font (car name-mag-pair))
135   "")
136
137 (define (font-load-command name-mag command)
138   "")
139
140 (define (beam x y width slope thick)
141   (apply sketch-filled-rectangle
142          (map mul-scale
143               (list width (* slope width) 0 thick x y))))
144
145 (define (comment s)
146   (string-append "# " s))
147
148 (define (bracket arch_angle arch_width arch_height  height arch_thick thick)
149   (string-append
150    (numbers->string (list arch_angle arch_width arch_height height arch_thick thick)) " draw_bracket" ))
151
152 (define (char x y i)
153   (string-append
154    "fp((0,0,0))\n"
155    "le()\n"
156    "lw(0.1)\n"
157    ;; "Fn('" global-font "')\n"
158    ;; "Fn('Times-Roman')\n"
159    "Fn('TeX-feta20')\n"
160    "Fs(20)\n"
161    ;; chars > 128 don't work yet
162    (format #f "txt('\\~o',(" (modulo i 128))
163 ;;   (format #f "txt('\\~o',(" i)
164 ;;   "txt('" (ascii->string i) "',("
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