]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-bolletjes.mf
1d6e27ce44416aa4a7be502de927658e2fde4f59
[lilypond.git] / mf / feta-bolletjes.mf
1 %  -*-Fundamental-*-
2 % feta-bolletjes.mf --  implement noteheads
3
4 % source file of LilyPond's pretty-but-neat music font
5
6 % (c)  1997--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 % & Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 % & Juergen Reuter <reuter@ipd.uka.de>
9
10
11
12 % most beautiful noteheads are pronounced, not circular, 
13 % and not even symmetric.
14 % These examples are inspired by [Wanske], see literature list
15
16
17 save black_notehead_width;
18 numeric black_notehead_width;
19
20 fet_begingroup("noteheads");
21
22 noteheight#:=staff_space#+ (1 + overdone_heads) *stafflinethickness#;
23 define_pixels(noteheight);
24
25 %
26
27 %%% TODO: Document these!
28 %
29
30 % setup user vars
31 def setup_notehead_vars =
32         save a_b,err_y_a,tilt,superness;
33         save ai_a,ai_bi,err_y_ai,err_x_bi,inner_tilt,inner_superness;
34         save b_h,a_w;
35         enddef;
36
37 % setup addititional vars and calc them
38 def notehead_calc =
39         save a,beta,ai,bi, ht, wd;
40         ht# =noteheight#;
41         2beta#=ht#*b_h;
42         a# = beta#*a_b;
43         wd# = 2a# / a_w;
44         ai# = a# * ai_a;
45         bi# = ai#/ai_bi;
46         define_pixels(a,beta);
47         define_pixels(ai,bi);
48         set_char_box(0, wd#, .5 ht#, .5 ht#);
49         enddef;
50
51
52 % draw the outer and inner ellipse.
53 def notehead_draw =
54         path black,white;
55         black=distorted_ellipse(a,beta,a*err_y_a,0,superness);
56         white=distorted_ellipse(ai,bi,ai*err_y_ai,bi*err_x_bi,inner_superness);
57 if test>1: %fixme
58                 save x;
59                 x1=-x3=a; x2=x4=0; y1=y3=0; y2=-y4=b;
60                 penlabels(1,2,3,4);
61                 test_grid;
62 else:
63                 black:=black rotated tilt;
64                 black:=black shifted (w/2,0);
65                 white:=white rotated inner_tilt;
66                 white:=white shifted (w/2,0);
67 fi
68
69         if test = 1:
70                 pickup pencircle scaled 1;
71                 draw black;
72                 draw white;
73         else:
74                 fill black;
75                 unfill white;
76         fi      
77
78                 
79         enddef;
80
81 def draw_whole_head =
82         setup_notehead_vars;
83         
84         a_b:=1.80;
85         err_y_a:=0; % no slant
86         tilt:=0;
87         superness:=0.707;
88         ai_a:=0.508;
89         % ai_bi:=1.23;
90         ai_bi:=1.30; % jcn
91         % err_y_ai:=0.0938;
92         % err_x_bi:=0;
93         err_y_ai:=0;
94         err_x_bi:=0.115;
95         % inner_tilt:=135;
96         inner_tilt:=125; % jcn
97         % inner_superness:=0.69;
98         inner_superness:=0.68; % jcn
99         b_h:=1; %no rotate-> no height correction
100         a_w:=1; % no rotate-> no width correction
101
102         notehead_calc;
103         whole_notehead_width# := wd#;
104         notehead_draw;
105 enddef;
106
107
108 %
109 % dimensions aren't entirely right.
110 %
111 fet_beginchar ("Brevis notehead", "-1", "brevishead");
112         save stemthick, fudge;
113         define_pixels (stemthick);
114         fudge = blot_diameter /2;
115         stemthick# = 2 stafflinethickness#;
116
117         draw_whole_head;
118
119         pickup pencircle scaled stemthick;
120
121         bot y1 = -d;
122         top y2 = h;
123         rt x1 - fudge = 0;
124         x1 = x2;
125
126         fudge + lft x3 = w;
127         x4 = x3;
128         y4 = y2;
129         y3 = y1;
130
131         draw_gridline(z1,z2,stemthick);
132         draw_gridline(z3,z4,stemthick);
133 fet_endchar;
134
135 % whole note
136 % Wanske, p.38
137 fet_beginchar("Whole notehead", "0", "wholehead")
138         draw_whole_head;
139 fet_endchar;
140
141
142
143 % half note
144 % Wanske, p.39
145 fet_beginchar("Half notehead", "1", 
146         "halfhead")
147         setup_notehead_vars;
148                 % a_b:=1.49; % after text
149         a_b:=1.50; % after drawing
150         err_y_a:=0.157;
151         tilt:=34;
152         % superness:=0.66;
153         superness:=0.67; % jcn
154         % ai_a:=0.863;
155         % was 0.85
156         % set to 0.83 to avoid stem entering white part.
157         ai_a:=0.830; 
158         % ai_bi:=3.14;
159         ai_bi:=3.25;
160         err_y_ai:=0;
161         err_x_bi:=-0.12;
162         inner_tilt:=tilt;
163         inner_superness:=0.80;
164         b_h:=0.935;
165         a_w:=1.12;
166
167         notehead_calc;
168         half_notehead_width# := wd#;
169         notehead_draw;
170
171         define_pixels (wd);
172         if test = 1:
173                 pickup penrazor scaled stemthickness;
174                 draw (.5 stemthickness, -2 staff_space) ..
175                     (.5 stemthickness, - wd * (ypart dir (inner_tilt - 10)) /2);
176         fi;
177 fet_endchar;
178
179
180
181 % quarter note
182 % Wanske p.38
183 fet_beginchar("Quart notehead", "2", "quarthead")
184         setup_notehead_vars;
185         % a_b:=1.57; % after text
186         a_b:=1.54; % after drawing
187         err_y_a:=0.044;
188         tilt:=32;
189         superness:=0.707;
190         ai_a:=0;
191         ai_bi:=1;
192         err_y_ai:=0;
193         err_x_bi:=0;
194         inner_tilt:=0;
195         inner_superness:=0.707;
196         b_h:=0.85;
197         a_w:=1.09;
198
199         notehead_calc;
200         black_notehead_width# := wd#;
201         notehead_draw;
202 fet_endchar;
203
204
205 % whole note
206 % Wanske, p.38
207 fet_beginchar("Whole diamondhead", "0diamond", "wholediamondhead")
208         setup_notehead_vars;
209         
210         a_b:=1.80;
211         err_y_a:=0; % no slant
212         tilt:=0;
213         superness:=0.495;
214         ai_a:=0.350;
215         % ai_bi:=1.23;
216         ai_bi:=1.30; % jcn
217         % err_y_ai:=0.0938;
218         % err_x_bi:=0;
219         err_y_ai:=0;
220         err_x_bi:=0.115;
221         % inner_tilt:=135;
222         inner_tilt:=125; % jcn
223         % inner_superness:=0.69;
224         inner_superness:=0.6; % jcn
225         b_h:=1; %no rotate-> no height correction
226         a_w:=1; % no rotate-> no width correction
227
228         notehead_calc;
229         whole_notehead_width# := wd#;
230         notehead_draw;
231 fet_endchar;
232
233
234 % half note
235 % Wanske, p.39
236 fet_beginchar("Half diamondhead", "1diamond", 
237         "halfdiamondhead")
238         setup_notehead_vars;
239
240         a_b := 1.50; % after drawing
241         err_y_a:=0.157;
242
243         tilt:=34;
244         superness:=0.49; % jcn
245         ai_a:=0.550; % jcn
246         ai_bi:=3.30; % jcn
247
248         err_y_ai:=0;
249         err_x_bi:=-0.12;
250         inner_tilt:=tilt;
251         inner_superness:=0.80;
252
253         b_h:= 1.03;
254         a_w:= 1.2;
255
256         notehead_calc;
257         half_notehead_width# := wd#;
258         notehead_draw;
259 fet_endchar;
260
261
262 % quarter note
263 % Wanske p.38
264 fet_beginchar("Quart diamondhead", "2diamond", "diamondhead")
265         set_char_box(0, black_notehead_width#, noteheight#/2, noteheight#/2);
266         save a_b,err_y_a,tilt,superness;
267         save b_h,a_w;
268         save a,beta,ai,bi, ht, wd;
269
270         a_b:= 1.8;
271         err_y_a:=-0.044;
272         b_h:=0.90;
273         a_w:=1.1;
274         tilt:=35;
275         superness:=0.495;
276
277         ht# =noteheight#;
278         2beta#=ht#*b_h;
279         a# = beta#*a_b;
280
281         define_pixels(a,beta);
282
283         black := distorted_ellipse(.72 noteheight, .45 noteheight, -.2 noteheight ,   0, superness)
284                                 
285 %                       beta,a*err_y_a,0,superness);
286
287         black:=black rotated tilt;
288         black:=black shifted (w/2,0);
289         fill black;
290 fet_endchar;
291
292
293 save pent;
294 pen_thick# = 2stafflinethickness#;
295 define_pixels(pen_thick);
296
297
298 begingroup;
299
300
301 def def_triangle_old =
302         save triangle,kern; path triangle;
303         kern = 1/3(x2-x1);
304         z2 = z1 rotated 120;
305         z3 = z1 rotated 240;
306         z12 = caveness[.5[z1,z2],z3];
307         z23 = z12 rotated 120;
308         z31 = z12 rotated 240;
309         triangle = z1 .. z12 .. z2 ..
310                     z2 .. z23 .. z3 ..
311                     z3 .. z31 .. z1 ..
312                     cycle;
313         triangle := triangle shifted (-x1+pent/2-kern,0) xscaled xs;
314         pickup pencircle scaled pent xscaled xs;
315         hei = max(y1,-y2)+pent/2; 
316         %set_char_box(-kern*xs*fac, ((x3-x1)*fac+pent#)*xs,hei*fac,hei*fac);
317         set_char_box(0, ((x3-x1-kern)*fac+pent#)*xs,hei*fac,hei*fac);
318 enddef;
319
320
321 def def_triangle =
322         save triangle,kern; path triangle;
323         save left_point, height, width;
324         pair exact_left_point;
325
326         exact_left_point := llap# * dir (90 + tilt);
327         height# = max (ypart exact_left_point,
328                         -ypart  (exact_left_point rotated 120)) + pen_thick#/2;
329
330         kern# = 1/3 xpart (exact_left_point - (exact_left_point rotated 120));
331         width# = xpart (-exact_left_point + (exact_left_point rotated 240));
332         define_pixels (kern);   
333         z1 = (hround_pixels (xpart exact_left_point), vround_pixels  (ypart exact_left_point));
334         z2 = z1 rotated 120;
335         z3 = z1 rotated 240;
336
337         z12 = caveness[.5[z1,z2],z3];
338         z23 = z12 rotated 120;
339         z31 = z12 rotated 240;
340         triangle = z1 .. z12 .. z2 ..
341                     z2 .. z23 .. z3 ..
342                     z3 .. z31 .. z1 ..
343                     cycle;
344         triangle := triangle shifted (-x1+pen_thick/2-kern,0) xscaled xs;
345         pickup pencircle scaled pen_thick xscaled xs;
346 %       labels(1,2,12,23,31,3);
347         set_char_box(0, width# - kern#+ pen_thick#, height#, height#);
348 enddef;
349
350 fet_beginchar("Whole trianglehead", "0triangle", "wholetrianglehead")
351         save hei,xs;
352         save llap;
353         save tilt;
354
355         tilt = 40;
356         llap# = 3/4noteheight#;
357
358         xs = 1.5;
359         caveness:=0.1;
360         def_triangle;
361         draw triangle;
362 fet_endchar;
363
364 fet_beginchar("Half trianglehead", "1triangle", "halftrianglehead")
365         save hei,xs;
366         save llap;
367         save tilt;
368
369         tilt = 40;
370         llap# = 2/3noteheight#;
371         xs = 1.2;
372         caveness:=0.1;
373         def_triangle;
374         draw triangle;
375 fet_endchar;
376
377 fet_beginchar("Quart trianglehead", "2triangle", "trianglehead")
378         save hei,xs;
379         save llap;
380         save tilt;
381         tilt = 40;
382         llap# = 2/3noteheight#;
383         xs = 1.0;
384         caveness:=0.1;
385         def_triangle;
386         filldraw triangle;
387 fet_endchar;
388
389 endgroup;
390
391 %%% Editable values:
392
393 slash_slope := 1.7; % slope of slash. From scm/grob-description.scm. How to auto-copy?
394 slt# := 2/3*0.48staff_space#; % thickness of lines. quarter notes get 1.5slt width.
395 slh# := 2staff_space#; % height of char.
396
397 %%% Calculated values:
398 sxa# := 0; % how much the char exceeds the boundingbox horizontally:
399
400  % Width of hor. pen - with thanks to Pythagoras
401 slxt# := sqrt(slt#*slt#+(slt#/slash_slope)*(slt#/slash_slope));
402 slw# := slh#/slash_slope; % width of sloping part of slash:
403
404 define_pixels(slt,slh,sxa,slxt,slw);
405
406
407 %
408 %
409 % UUGGGH! FIXME -- get rid of those sharp corners. 
410 %
411 %
412 %
413
414
415 def draw_slash(expr hwid_hash) =
416         wid# := slw#+2slxt#+hwid_hash;
417         set_char_box(0,wid#-2sxa#,slh#/2,slh#/2);
418         define_pixels (wid#);
419         pickup penrazor scaled slxt;
420         draw (-b+slxt/2-sxa,-d) -- (-b+slxt/2+slw-sxa,h);
421         draw (w-slxt/2-slw+sxa,-d) -- (w-slxt/2+sxa,h);
422         pickup penrazor scaled slt rotated 90;
423         draw (-b+slxt-sxa,-d+slt/2) -- (w-slw+sxa,-d+slt/2);
424         draw (-b+slw-sxa,h-slt/2) -- (w-slxt+sxa,h-slt/2);
425 enddef;
426
427 fet_beginchar("Whole slashhead","0slash","wholeslashhead")
428         draw_slash(staff_space#);
429 fet_endchar;
430
431 fet_beginchar("Half slashhead","1slash","halfslashhead")
432         draw_slash(0.6staff_space#);
433 fet_endchar;
434
435 fet_beginchar("Quart slashhead","2slash","quartslashhead")
436         draw_slash(-slxt#/2);
437 fet_endchar;
438
439 % thick is the distance between the two parallel lines in the cross (distance between centres of lines)
440 def draw_cross(expr thick) =
441         pent := 1.2stafflinethickness;
442         pickup pencircle scaled pent;
443         % alfa is the slant of the lines (i.e. 1 means 45 degrees)
444         alfa := (2h-pent)/(w-pent);
445         % llen is the length of the little outer lines
446         % llen = thick / sin(2atan(alfa))
447         llen := thick/(ypart(dir(2angle(1,alfa))));
448         xa := llen/sqrt(1+alfa**2);
449         ya := xa*alfa;
450         xl := w/2-xa-pent/2;
451         yl := h-ya-pent/2;
452         save crz; path crz;
453         crz = (xa,0) -- (xa+xl,yl) -- (xl,yl+ya) -- (0,ya);
454         draw crz shifted(w/2,0);
455         draw crz xscaled -1 shifted(w/2,0);
456         draw crz yscaled -1 shifted(w/2,0);
457         draw crz scaled -1 shifted(w/2,0);
458 enddef;
459
460 fet_beginchar("Whole Crossed notehead", "0cross", "wholecrossedhead")
461         wid# := black_notehead_width#+4stafflinethickness#;
462         hei# := noteheight#+stafflinethickness#;
463         set_char_box(0, wid#,hei#/2,hei#/2);
464         draw_cross(3.75stafflinethickness);
465 fet_endchar;
466
467 fet_beginchar("Half Crossed notehead", "1cross", "halfcrossedhead")
468         wid# := black_notehead_width#+2stafflinethickness#;
469         hei# := noteheight#+stafflinethickness#/2;
470         set_char_box(0, wid#,hei#/2,hei#/2);
471         draw_cross(3stafflinethickness);
472 fet_endchar;
473
474 fet_beginchar("Crossed notehead", "2cross", "crossedhead")
475         wid# := black_notehead_width#;
476         hei# := noteheight#;
477         set_char_box(0, wid#,hei#/2,hei#/2);
478         draw_cross(stafflinethickness/4);
479 fet_endchar;
480
481 fet_beginchar("X-Circled notehead", "2xcircle", "xcircledhead")
482         wid# := black_notehead_width#*sqrt(sqrt2);
483         hei# := noteheight#*sqrt(sqrt2);
484         set_char_box(0, wid#,hei#/2,hei#/2);
485         cthick := (1.2+1/4)*stafflinethickness;
486         cxr := w/2-cthick/2;
487         cyr := h-cthick/2;
488         pickup pencircle scaled cthick;
489         draw fullcircle xscaled 2cxr yscaled 2cyr shifted (w/2,0);
490         xpos := cxr/sqrt2;
491         ypos := cyr/sqrt2;
492         draw (-xpos+w/2,-ypos) -- (xpos+w/2,ypos);
493         draw (-xpos+w/2,ypos) -- (xpos+w/2,-ypos);
494 fet_endchar;
495
496
497
498 fet_endgroup("noteheads");
499 define_pixels(black_notehead_width);