2 % feta-bolletjes.mf -- implement noteheads
4 % source file of LilyPond's pretty-but-neat music font
6 % (c) 1997--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 % & Han-Wen Nienhuys <hanwen@cs.uu.nl>
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);
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);
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);
58 z2l = (0, -stafflinethickness/2);
59 z3r = z2r + serif_size *(1,-1);
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;
70 addto currentpicture also currentpicture
71 shifted (-x4r,0) xscaled -1 shifted (x4l,0);
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) =
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);
92 fill z7r .. z6r{z6-z7} .. {z7-z6} z6l -- z7l -- cycle;
97 % En wij presenteren U: de opvolgster van Emily
101 fet_beginchar("Maxima notehead", "-3mensural", "mensuralmaximahead");
102 draw_longa (1.3 brevis_wid#)
105 fet_beginchar("Longa notehead", "-2mensural", "mensurallongahead");
106 draw_longa (brevis_wid#)
109 fet_beginchar("Brevis notehead", "-1mensural", "mensuralbrevishead")
110 draw_brevis(brevis_wid#);
113 def draw_mensural_black_head (expr wid) =
116 set_char_box (0, head_width#, noteheight#/2, noteheight#/2);
120 x2 = x4 = (x1 + x3) /2;
121 define_pixels (head_width);
122 pickup pencircle scaled blot_diameter;
128 filldraw z1 -- z2 -- z3 -- z4 -- cycle;
131 def draw_mensural_open_head (expr wid)=
132 draw_mensural_black_head (wid);
134 diamNW = length (z2 - z1) + blot_diameter;
135 diamSW = length (z4 - z1) + blot_diameter;
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;
151 fet_beginchar("Mensural open head","0mensural","mensuralminimhead")
152 draw_mensural_open_head (staff_space#);
155 fet_beginchar("Mensural open head","1mensural","mensuralsemiminimhead")
156 draw_mensural_open_head (staff_space#);
159 fet_beginchar("Mensural black head","2mensural","fusahead")
160 draw_mensural_black_head (staff_space#);
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;
184 filldraw z1 --- z2 --- z3 --- z4 --- cycle ;
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 % TODO: Document these!
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;
204 % setup addititional vars and calc them
206 save a,beta,ai,bi, ht, wd;
213 define_pixels(a,beta);
214 define_pixels(ai,bi);
215 set_char_box(0, wd#, .5 ht#, .5 ht#);
219 % draw the outer and inner ellipse.
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);
226 x1=-x3=a; x2=x4=0; y1=y3=0; y2=-y4=b;
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);
241 def draw_whole_head =
245 err_y_a:=0; % no slant
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
263 whole_notehead_width# := wd#;
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#;
279 pickup pencircle scaled stemthick;
297 fet_beginchar("Whole notehead", "0", "wholehead")
305 fet_beginchar("Half notehead", "1",
308 % a_b:=1.49; % after text
309 a_b:=1.50; % after drawing
313 superness:=0.67; % jcn
321 inner_superness:=0.80;
326 half_notehead_width# := wd#;
334 fet_beginchar("Quart notehead", "2", "quarthead")
336 % a_b:=1.57; % after text
337 a_b:=1.54; % after drawing
346 inner_superness:=0.707;
351 black_notehead_width# := wd#;
358 fet_beginchar("Whole diamondhead", "0diamond", "wholediamondhead")
362 err_y_a:=0; % no slant
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
380 whole_notehead_width# := wd#;
387 fet_beginchar("Half diamondhead", "1diamond",
391 a_b := 1.50; % after drawing
395 superness:=0.49; % jcn
402 inner_superness:=0.80;
408 half_notehead_width# := wd#;
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;
419 save a,beta,ai,bi, ht, wd;
432 define_pixels(a,beta);
434 black := distorted_ellipse(.72 noteheight, .45 noteheight, -.2 noteheight , 0, superness)
436 % beta,a*err_y_a,0,superness);
438 black:=black rotated tilt;
439 black:=black shifted (w/2,0);
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);
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);
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);
466 slw# := staff_space#;
467 slt := 1.25stafflinethickness;
468 slt# := 1.25stafflinethickness#;
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);
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);
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);
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);
498 fet_beginchar("Quart slashhead","2slash","quartslashhead")
500 set_char_box(0,slw#+slxt#-stafflinethickness#,slh#/2,slh#/2);
502 pickup penrazor scaled slxt;
503 draw (b+slxt/2-stafflinethickness/2,-d) -- (b+slxt/2+slw-stafflinethickness/2,h);
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);
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);
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);
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);
541 fet_beginchar("Crossed notehead", "2cross", "crossedhead")
542 wid# := black_notehead_width#;
544 set_char_box(0, wid#,hei#/2,hei#/2);
545 draw_cross(stafflinethickness/4);
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);
554 draw (-pos+h,-pos) -- (pos+h,pos);
555 draw (-pos+h,pos) -- (pos+h,-pos);
558 fet_endgroup("noteheads");
559 define_pixels(black_notehead_width);