]> git.donarmstrong.com Git - lilypond.git/blob - scm/sketch.scm
release: 1.5.24
[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 ;; (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-public (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 (ly-eval keyword this-module) (cdr expr))))))
56
57 (define (dispatch-x-y x y expr)
58   (apply (ly-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 (ly-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    ;;       "char(" ,(number->string i)  ",("
164    (sketch-numbers->string (map mul-scale (list x y)))
165    "))\n"))
166
167 (define (hairpin x y thick width starth endh )
168   (string-append
169    "#"
170    (numbers->string (list width starth endh thick))
171    " draw_hairpin"))
172
173 ;; what the heck is this interface ?
174 (define (dashed-slur thick dash l)
175   (string-append 
176    (apply string-append (map control->string l)) 
177    (ly-number->string thick) 
178    " [ "
179    (ly-number->string dash)
180    " "
181    (ly-number->string (* 10 thick))     ;UGH.  10 ?
182    " ] 0 draw_dashed_slur"))
183
184 (define (dashed-line thick on off dx dy)
185   (string-append 
186    (ly-number->string dx)
187    " "
188    (ly-number->string dy)
189    " "
190    (ly-number->string thick) 
191    " [ "
192    (ly-number->string on)
193    " "
194    (ly-number->string off)
195    " ] 0 draw_dashed_line"))
196
197 (define (repeat-slash wid slope thick)
198  (string-append (numbers->string (list wid slope thick))
199   " draw_repeat_slash"))
200
201 (define (end-output)
202   "guidelayer('Guide Lines',1,0,0,1,(0,0,1))
203 grid((0,0,20,20),0,(0,0,1),'Grid')\n")
204
205 (define (experimental-on) "")
206
207 (define (font-switch i)
208   "")
209
210 (define (header-end)
211   "")
212
213 (define (lily-def key val)
214   (if (equal? key "lilypondpaperoutputscale")
215       ;; ugr
216       (set! output-scale (string->number val)))
217   "")
218
219
220 (define (header creator generate)
221   (string-append
222    "##Sketch 1 2
223 document()
224 layout('A4',0)
225 layer('Layer 1',1,1,0,0,(0,0,0))
226 "))
227
228 (define (invoke-char s i)
229   "")
230
231 (define (invoke-dim1 s d) 
232   (string-append
233    (ly-number->string (* d  (/ 72.27 72))) " " s ))
234
235 (define (bezier-sandwich x y l thick)
236   (apply
237    sketch-beziers (list x y (primitive-eval l) thick)))
238
239 ; TODO: use HEIGHT argument
240 (define (start-line height)
241    "G()\n"
242    )
243
244 ;;  r((520.305,0,0,98.0075,51.8863,10.089))
245 ;;  width, 0, 0, height, x, y
246 (define (filledbox x y breapth width depth height)
247   (apply sketch-filled-rectangle
248          (list
249           (+ breapth width) 0 0 (+ depth height) (- x breapth) (- y depth))))
250
251 (define (stem x y z w) (filledbox x y z w))
252
253
254 (define (stop-line)
255     "G_()\n")
256
257 ;; huh?
258 (define (stop-last-line)
259    (stop-line))
260
261 (define (text x y s)
262   (string-append "txt('" s "',(" (sketch-numbers->string
263                                   (map mul-scale (list x y))) "))\n"))
264
265
266 (define (volta x y h w thick vert_start vert_end)
267   (string-append "#"
268    (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
269    " draw_volta"))
270
271 (define (tuplet x y ht gap dx dy thick dir)
272   (string-append "#"
273    (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
274    " draw_tuplet"))
275
276
277 (define (unknown) 
278   "\n unknown\n")
279
280 (define (ez-ball ch letter-col ball-col)
281   (string-append
282    " (" ch ") "
283    (numbers->string (list letter-col ball-col))
284    " /Helvetica-Bold " ;; ugh
285    " draw_ez_ball"))
286
287 (define (define-origin a b c ) "")
288 (define (no-origin) "")
289
290
291