lilypond-1.3.139
[lilypond.git] / mf / feta-bolletjes.mf
blob9b0b1150c8ec5b339d1eb2cd8886e12bf9da9e45
1 %  -*-Fundamental-*-
2 % feta-bolletjes.mf --  implement noteheads
3
4 % source file of LilyPond's pretty-but-neat music font
5
6 % (c) 1997--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 % & Han-Wen Nienhuys <hanwen@cs.uu.nl>
8
11 % most beautiful noteheads are pronounced, not circular, 
12 % and not even symmetric.
13 % These examples are inspired by [Wanske], see literature list
16 save black_notehead_width;
17 numeric black_notehead_width;
19 fet_begingroup("noteheads");
21 noteheight#:=staff_space#+ (1 + overdone_heads) *stafflinethickness#;
22 define_pixels(noteheight);
25 %%%%%%%%
29 % MENSURAL NOTATION
33 brevis_wid# := 2 staff_space#;
35 def draw_brevis(expr brevwid) =
36         save beamheight, head_width;
37         save holeheight, stem_width;
38         save serif_size, serif_protrude;
40         head_width# = brevwid;
41         holeheight = 3 stafflinethickness;
42         stem_width = 1.4 stafflinethickness;
45         define_pixels(head_width);
46         set_char_box(0, head_width#, noteheight#/2, noteheight#/2);
47         
48         2 beamheight + holeheight = noteheight;
49         serif_size = (holeheight - stafflinethickness)/2;
50         serif_protrude = 1.5 serif_size;
51         penpos1(stem_width, 0);
52         penpos2(stem_width, 0);
53         penpos3(beamheight, 90);
54         penpos4(beamheight, 90);
55         penpos5(stem_width, 180);
57         z1l = (0, 0);
58         z2l = (0, -stafflinethickness/2);
59         z3r = z2r + serif_size *(1,-1);
60         y4r = y3r;
61         x4r = head_width/2;
62         z5l = z3l + (-serif_size, -serif_protrude);
64         penlabels(1,2,3,4, 5);
65         fill z1r -- z1l -- z5r{down} .. z5l{up} .. z3l{right}
66                 -- z4l -- z4r -- z3r{left} .. z2r{up} -- cycle;
68         addto currentpicture also currentpicture yscaled -1;
69         show z4r; show z4l;
70         addto currentpicture also currentpicture 
71                 shifted (-x4r,0) xscaled -1 shifted (x4l,0);
73 enddef;
77 % Some sources (eg Musix/OpusTeX think that the appendage should be on
78 % the left, some say right. Right wins democratically.
80 def draw_longa (expr wid) =
81         draw_brevis(wid);
82         save theta;
84         x7r = head_width;
85         y7 = y5;
86 %       z7 = z5;
87         z6 - z7 = (stem_width/2, -staff_space);
88         theta = angle(z6-z7)+ 90;
89         penpos7(stem_width, theta);
90         penpos6(1.2 stem_width, theta);
91         
92         fill z7r .. z6r{z6-z7} .. {z7-z6} z6l -- z7l -- cycle;
93         penlabels(6,7);
94 enddef;
97 % En wij presenteren U: de opvolgster van Emily
99 % (ze is wel breed)
101 fet_beginchar("Maxima notehead", "-3mensural", "mensuralmaximahead");
102         draw_longa (1.3 brevis_wid#)
103 fet_endchar;
105 fet_beginchar("Longa notehead", "-2mensural", "mensurallongahead");
106         draw_longa (brevis_wid#)
107 fet_endchar;
109 fet_beginchar("Brevis notehead", "-1mensural", "mensuralbrevishead")
110         draw_brevis(brevis_wid#);
111 fet_endchar;
113 def draw_mensural_black_head (expr wid) =
114         save head_width;
115         head_width# = wid;
116         set_char_box (0, head_width#, noteheight#/2, noteheight#/2);
119         y3 = y1 =0;
120         x2 = x4 = (x1 + x3) /2;
121         define_pixels (head_width);
122         pickup pencircle scaled blot_diameter;
123         top y2 = h;
124         bot y4 = -d;
125         lft x1 = 0;
126         rt x3 = w;
128         filldraw z1 -- z2 -- z3 -- z4 -- cycle;
129 enddef;
131 def draw_mensural_open_head (expr wid)=
132         draw_mensural_black_head (wid);
133         save diamNW, diamSW;
134         diamNW = length (z2 - z1) + blot_diameter;
135         diamSW = length (z4 - z1) + blot_diameter;
136         
137         save hole_widthNW, hole_widthSW;
138         hole_widthNW = 0.34 diamNW ;
139         hole_widthSW + 2.6 stafflinethickness = diamSW;
141         (z7 + z5)/2 = (w/2, 0);
142         (z8 + z6)/2 = (w/2, 0);
143         (z6 - z5) = hole_widthNW * unitvector (z2 - z1);
144         (z7 - z6) = hole_widthSW * unitvector (z4 - z1);
146         labels (1,2,3,4,5,6,7,8);
148         unfill z5 -- z6 -- z7 -- z8 --cycle;
149 enddef;
151 fet_beginchar("Mensural open head","0mensural","mensuralminimhead")
152         draw_mensural_open_head (staff_space#);
153 fet_endchar;
155 fet_beginchar("Mensural open head","1mensural","mensuralsemiminimhead")
156         draw_mensural_open_head (staff_space#);
157 fet_endchar;
159 fet_beginchar("Mensural black head","2mensural","fusahead")
160         draw_mensural_black_head (staff_space#);
161 fet_endchar;
164 %%%%%%%%%%%%
167 % ledger (leger) lines
169 fet_beginchar("Ledger ending", "ledgerending", "ledgerending")
170 set_char_box (5/2 ledgerlinethickness#, 5/2 ledgerlinethickness#,
171                 ledgerlinethickness#/2,ledgerlinethickness#/2);
172         pickup pencircle scaled 1.3 blot_diameter;
174         rt x2 = w;
175         lft x1 = -b;
176         x3 = x2;
177         bot y1 = -d;
178         y2 = y1;
180         top y3 = h;
181         y4 = y3;
182         x4 = x1;
184         filldraw z1 --- z2 --- z3 --- z4 --- cycle ;
185 fet_endchar;
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 % TODO: Document these!
197 % setup user vars
198 def setup_notehead_vars =
199         save a_b,err_y_a,tilt,superness;
200         save ai_a,ai_bi,err_y_ai,err_x_bi,inner_tilt,inner_superness;
201         save b_h,a_w;
202         enddef;
204 % setup addititional vars and calc them
205 def notehead_calc =
206         save a,beta,ai,bi, ht, wd;
207         ht# =noteheight#;
208         2beta#=ht#*b_h;
209         a# = beta#*a_b;
210         wd# = 2a# / a_w;
211         ai# = a# * ai_a;
212         bi# = ai#/ai_bi;
213         define_pixels(a,beta);
214         define_pixels(ai,bi);
215         set_char_box(0, wd#, .5 ht#, .5 ht#);
216         enddef;
219 % draw the outer and inner ellipse.
220 def notehead_draw =
221         path black,white;
222         black=distorted_ellipse(a,beta,a*err_y_a,0,superness);
223         white=distorted_ellipse(ai,bi,ai*err_y_ai,bi*err_x_bi,inner_superness);
224 if test>1: %fixme
225                 save x;
226                 x1=-x3=a; x2=x4=0; y1=y3=0; y2=-y4=b;
227                 penlabels(1,2,3,4);
228                 test_grid;
229 else:
230                 black:=black rotated tilt;
231                 black:=black shifted (w/2,0);
232                 white:=white rotated inner_tilt;
233                 white:=white shifted (w/2,0);
235                 fill black;
236                 unfill white;
238                 
239         enddef;
241 def draw_whole_head =
242         setup_notehead_vars;
243         
244         a_b:=1.80;
245         err_y_a:=0; % no slant
246         tilt:=0;
247         superness:=0.707;
248         ai_a:=0.508;
249         % ai_bi:=1.23;
250         ai_bi:=1.30; % jcn
251         % err_y_ai:=0.0938;
252         % err_x_bi:=0;
253         err_y_ai:=0;
254         err_x_bi:=0.115;
255         % inner_tilt:=135;
256         inner_tilt:=125; % jcn
257         % inner_superness:=0.69;
258         inner_superness:=0.68; % jcn
259         b_h:=1; %no rotate-> no height correction
260         a_w:=1; % no rotate-> no width correction
262         notehead_calc;
263         whole_notehead_width# := wd#;
264         notehead_draw;
265 enddef;
269 % dimensions aren't entirely right.
271 fet_beginchar ("Brevis notehead", "-1", "brevishead");
272         save stemthick, fudge;
273         define_pixels (stemthick);
274         fudge = blot_diameter /2;
275         stemthick# = 2 stafflinethickness#;
277         draw_whole_head;
279         pickup pencircle scaled stemthick;
281         bot y1 = -d;
282         top y2 = h;
283         rt x1 - fudge = 0;
284         x1 = x2;
286         fudge + lft x3 = w;
287         x4 = x3;
288         y4 = y2;
289         y3 = y1;
291         draw z1 -- z2;
292         draw z3 -- z4;
293 fet_endchar;
295 % whole note
296 % Wanske, p.38
297 fet_beginchar("Whole notehead", "0", "wholehead")
298         draw_whole_head;
299 fet_endchar;
303 % half note
304 % Wanske, p.39
305 fet_beginchar("Half notehead", "1", 
306         "halfhead")
307         setup_notehead_vars;
308                 % a_b:=1.49; % after text
309         a_b:=1.50; % after drawing
310         err_y_a:=0.157;
311         tilt:=34;
312         % superness:=0.66;
313         superness:=0.67; % jcn
314         % ai_a:=0.863;
315         ai_a:=0.850; % jcn
316         % ai_bi:=3.14;
317         ai_bi:=3.30; % jcn
318         err_y_ai:=0;
319         err_x_bi:=-0.12;
320         inner_tilt:=tilt;
321         inner_superness:=0.80;
322         b_h:=0.935;
323         a_w:=1.12;
325         notehead_calc;
326         half_notehead_width# := wd#;
327         notehead_draw;
328 fet_endchar;
332 % quarter note
333 % Wanske p.38
334 fet_beginchar("Quart notehead", "2", "quarthead")
335         setup_notehead_vars;
336         % a_b:=1.57; % after text
337         a_b:=1.54; % after drawing
338         err_y_a:=0.044;
339         tilt:=32;
340         superness:=0.707;
341         ai_a:=0;
342         ai_bi:=1;
343         err_y_ai:=0;
344         err_x_bi:=0;
345         inner_tilt:=0;
346         inner_superness:=0.707;
347         b_h:=0.85;
348         a_w:=1.09;
350         notehead_calc;
351         black_notehead_width# := wd#;
352         notehead_draw;
353 fet_endchar;
356 % whole note
357 % Wanske, p.38
358 fet_beginchar("Whole diamondhead", "0diamond", "wholediamondhead")
359         setup_notehead_vars;
360         
361         a_b:=1.80;
362         err_y_a:=0; % no slant
363         tilt:=0;
364         superness:=0.495;
365         ai_a:=0.350;
366         % ai_bi:=1.23;
367         ai_bi:=1.30; % jcn
368         % err_y_ai:=0.0938;
369         % err_x_bi:=0;
370         err_y_ai:=0;
371         err_x_bi:=0.115;
372         % inner_tilt:=135;
373         inner_tilt:=125; % jcn
374         % inner_superness:=0.69;
375         inner_superness:=0.6; % jcn
376         b_h:=1; %no rotate-> no height correction
377         a_w:=1; % no rotate-> no width correction
379         notehead_calc;
380         whole_notehead_width# := wd#;
381         notehead_draw;
382 fet_endchar;
385 % half note
386 % Wanske, p.39
387 fet_beginchar("Half diamondhead", "1diamond", 
388         "halfdiamondhead")
389         setup_notehead_vars;
391         a_b := 1.50; % after drawing
392         err_y_a:=0.157;
394         tilt:=34;
395         superness:=0.49; % jcn
396         ai_a:=0.550; % jcn
397         ai_bi:=3.30; % jcn
399         err_y_ai:=0;
400         err_x_bi:=-0.12;
401         inner_tilt:=tilt;
402         inner_superness:=0.80;
404         b_h:= 1.03;
405         a_w:= 1.2;
407         notehead_calc;
408         half_notehead_width# := wd#;
409         notehead_draw;
410 fet_endchar;
413 % quarter note
414 % Wanske p.38
415 fet_beginchar("Quart diamondhead", "2diamond", "diamondhead")
416         set_char_box(0, black_notehead_width#, noteheight#/2, noteheight#/2);
417         save a_b,err_y_a,tilt,superness;
418         save b_h,a_w;
419         save a,beta,ai,bi, ht, wd;
421         a_b:= 1.8;
422         err_y_a:=-0.044;
423         b_h:=0.90;
424         a_w:=1.1;
425         tilt:=35;
426         superness:=0.495;
428         ht# =noteheight#;
429         2beta#=ht#*b_h;
430         a# = beta#*a_b;
432         define_pixels(a,beta);
434         black := distorted_ellipse(.72 noteheight, .45 noteheight, -.2 noteheight ,   0, superness)
435                                 
436 %                       beta,a*err_y_a,0,superness);
438         black:=black rotated tilt;
439         black:=black shifted (w/2,0);
440         fill black;
441 fet_endchar;
443 save triangle; path triangle;
444 triangle = (-sqrt3/4,-1/2) -- (0,1) -- (sqrt3/4,-1/2) -- cycle;
446 fet_beginchar("Whole trianglehead", "0triangle", "wholetrianglehead")
447         set_char_box(0, 2(noteheight#+stafflinethickness#)/sqrt3*7/8,
448           (noteheight#+stafflinethickness#)/2,(noteheight#+stafflinethickness#)/2);
449         fill triangle scaled (7h/6) shifted (w/2,-h/6);
450         unfill triangle scaled 0.72h shifted (w/2,-h/6);
451 fet_endchar;
452 fet_beginchar("Half trianglehead", "1triangle", "halftrianglehead")
453         thick := 1.2stafflinethickness;
454         set_char_box(0, 2noteheight#/sqrt3*7/8,noteheight#/2,noteheight#/2);
455         fill triangle scaled (7h/6) shifted (w/2,-h/6);
456         unfill triangle scaled 0.7h shifted (w/2,-h/6);
457 fet_endchar;
458 fet_beginchar("Quart trianglehead", "2triangle", "trianglehead")
459         thick := 1.2stafflinethickness;
460         set_char_box(0, 2noteheight#/sqrt3*7/8,noteheight#/2,noteheight#/2);
461         fill triangle scaled (7h/6) shifted (w/2,-h/6);
462 fet_endchar;
465 slw := staff_space;
466 slw# := staff_space#;
467 slt := 1.25stafflinethickness;
468 slt# := 1.25stafflinethickness#;
469 slxt = 1.5slt;
470 slxt# := 1.5slt#;
471 slh := 1.5staff_space;
472 slh# := 1.5staff_space#;
474 fet_beginchar("Whole slashhead","0slash","wholeslashhead")
475         wid := slw#+2slxt#+staff_space#;
476         set_char_box(0,wid-stafflinethickness#,slh#/2,slh#/2);
477         define_pixels (wid);
478         pickup penrazor scaled slxt;
479         draw (-b+slxt/2-stafflinethickness/2,-d) -- (-b+slxt/2+slw-stafflinethickness/2,h);
480         draw (w-slxt/2-slw+stafflinethickness/2,-d) -- (w-slxt/2+stafflinethickness/2,h);
481         pickup penrazor scaled slt rotated 90;
482         draw (-b+slxt-stafflinethickness/2,-d+slt/2) -- (w-slw+stafflinethickness/2,-d+slt/2);
483         draw (-b+slw-stafflinethickness/2,h-slt/2) -- (w-slxt+stafflinethickness/2,h-slt/2);
484 fet_endchar;
486 fet_beginchar("Half slashhead","1slash","halfslashhead")
487         wid := slw#+2slxt#+0.6staff_space#;
488         set_char_box(0,wid-stafflinethickness#,slh#/2,slh#/2);
489         define_pixels (wid);
490         pickup penrazor scaled slxt;
491         draw (b+slxt/2-stafflinethickness/2,-d) -- (b+slxt/2+slw-stafflinethickness/2,h);
492         draw (w-slxt/2-slw+stafflinethickness/2,-d) -- (w-slxt/2+stafflinethickness/2,h);
493         pickup penrazor scaled slt rotated 90;
494         draw (b+slxt-stafflinethickness/2,-d+slt/2) -- (w-slw+stafflinethickness/2,-d+slt/2);
495         draw (b+slw-stafflinethickness/2,h-slt/2) -- (w-slxt+stafflinethickness/2,h-slt/2);
496 fet_endchar;
498 fet_beginchar("Quart slashhead","2slash","quartslashhead")
499         wid := slw#+slxt#;
500         set_char_box(0,slw#+slxt#-stafflinethickness#,slh#/2,slh#/2);
501         define_pixels (wid);
502         pickup penrazor scaled slxt;
503         draw (b+slxt/2-stafflinethickness/2,-d) -- (b+slxt/2+slw-stafflinethickness/2,h);
504 fet_endchar;
506 % thick is the distance between the two parallel lines in the cross (distance between centres of lines)
507 def draw_cross(expr thick) =
508         pent := 1.2stafflinethickness;
509         pickup pencircle scaled pent;
510         % alfa is the slant of the lines (i.e. 1 means 45 degrees)
511         alfa := (2h-pent)/(w-pent);
512         % llen is the length of the little outer lines
513         % llen = thick / sin(2atan(alfa))
514         llen := thick/(ypart(dir(2angle(1,alfa))));
515         xa := llen/sqrt(1+alfa**2);
516         ya := xa*alfa;
517         xl := w/2-xa-pent/2;
518         yl := h-ya-pent/2;
519         save crz; path crz;
520         crz = (xa,0) -- (xa+xl,yl) -- (xl,yl+ya) -- (0,ya);
521         draw crz shifted(w/2,0);
522         draw crz xscaled -1 shifted(w/2,0);
523         draw crz yscaled -1 shifted(w/2,0);
524         draw crz scaled -1 shifted(w/2,0);
525 enddef;
527 fet_beginchar("Whole Crossed notehead", "0cross", "wholecrossedhead")
528         wid# := black_notehead_width#+4stafflinethickness#;
529         hei# := noteheight#+stafflinethickness#;
530         set_char_box(0, wid#,hei#/2,hei#/2);
531         draw_cross(3.75stafflinethickness);
532 fet_endchar;
534 fet_beginchar("Half Crossed notehead", "1cross", "halfcrossedhead")
535         wid# := black_notehead_width#+2stafflinethickness#;
536         hei# := noteheight#+stafflinethickness#/2;
537         set_char_box(0, wid#,hei#/2,hei#/2);
538         draw_cross(3stafflinethickness);
539 fet_endchar;
541 fet_beginchar("Crossed notehead", "2cross", "crossedhead")
542         wid# := black_notehead_width#;
543         hei# := noteheight#;
544         set_char_box(0, wid#,hei#/2,hei#/2);
545         draw_cross(stafflinethickness/4);
546 fet_endchar;
548 fet_beginchar("X-Circled notehead", "2xcircle", "xcircledhead")
549         set_char_box(0, noteheight#+stafflinethickness#,
550           noteheight#/2+stafflinethickness#/2,noteheight#/2+stafflinethickness#/2);
551         pickup pencircle scaled 1.2stafflinethickness;
552         draw fullcircle scaled 2h shifted (h,0);
553         pos := h/sqrt2;
554         draw (-pos+h,-pos) -- (pos+h,pos);
555         draw (-pos+h,pos) -- (pos+h,-pos);
556 fet_endchar;
558 fet_endgroup("noteheads");
559 define_pixels(black_notehead_width);