2 % feta-bolletjes.mf -- implement noteheads
4 % source file of LilyPond's pretty-but-neat music font
6 % (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 % & Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 % & Juergen Reuter <reuter@ipd.uka.de>
14 % Most beautiful noteheads are pronounced, not circular,
15 % and not even symmetric.
16 % These examples are inspired by [Wanske]; see literature list.
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 save black_notehead_width, noteheight;
25 save slash_thick, slash_slope, overdone_heads;
26 numeric black_notehead_width, noteheight, slash_thick;
29 fet_begingroup("noteheads");
32 % Slope of slash. From scm/grob-description.scm. How to auto-copy?
35 % Thickness of slash lines. Quarter notes get 1.5slt width.
36 slash_thick# := 2/3 * 0.48 staff_space#;
40 % Hand-engraved music often has balls extending above and below
41 % the lines. If you like that, modify overdone heads (unit:
45 noteheight# := staff_space# + (1 + overdone_heads) * stafflinethickness#;
47 define_pixels (slash_thick, noteheight);
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 % SLANT moves both extrema on the long axis (by SLANT * ELLIPTICITY,
53 % so SLANT = -1, puts the extreme on the long axis next to the short
57 def draw_outside_ellipse (expr ellipticity, tilt, superness, slant) =
62 p := superellipse ((ellipticity, 0), (-slant * ellipticity, 1.0),
63 (- ellipticity, 0), (slant * ellipticity, -1.0),
67 save top_point, right_point;
68 pair top_point, right_point;
70 top_point := directionpoint left of p;
71 right_point := directionpoint up of p;
73 save scaling, width, height;
75 scaling# = noteheight# / (2 ypart (top_point));
76 width# := 2 xpart (right_point) * scaling#;
78 define_pixels (width, scaling);
80 set_char_box (0, width#, noteheight# / 2, noteheight# / 2);
83 charwy := ypart (right_point) * scaling#;
86 p := p scaled scaling shifted (width / 2, 0);
88 pickup pencircle scaled 1;
96 def undraw_inside_ellipse (expr ellipticity, tilt, superness, clearance,
102 p := superellipse ((ellipticity, 0), (0, 1.0),
103 (-ellipticity, 0), (0, -1.0),
107 save top_point, right_point;
108 pair top_point, right_point;
110 top_point := directionpoint left of p;
111 right_point := directionpoint up of p;
113 save height, scaling;
115 height# = staff_space# + stafflinethickness# - clearance;
116 scaling# = height# / (2 ypart (top_point));
118 define_pixels (scaling);
119 p := (p scaled scaling) shifted center;
121 if test_outlines = 1:
122 pickup pencircle scaled 1;
132 % dimensions aren't entirely right.
134 fet_beginchar ("Brevis notehead", "s-1");
135 save stemthick, fudge;
136 define_pixels (stemthick);
137 fudge = blot_diameter / 2;
138 stemthick# = 2 stafflinethickness#;
140 draw_outside_ellipse (1.80, 0, 0.707, 0);
141 undraw_inside_ellipse (1.30, 125, 0.68, 2 stafflinethickness#,
144 pickup pencircle scaled stemthick;
156 draw_gridline (z1, z2, stemthick);
157 draw_gridline (z3, z4, stemthick);
161 fet_beginchar ("Whole notehead", "s0")
162 draw_outside_ellipse (1.80 - puff_up_factor / 3.0, 0, 0.707, 0);
163 undraw_inside_ellipse (1.30, 125 - puff_up_factor * 10,
164 0.68, 2 stafflinethickness#, (w / 2, 0));
166 % draw_staff_outline (-2, 2, 0.5);
170 fet_beginchar ("Half notehead", "s1")
171 draw_outside_ellipse (1.53 - puff_up_factor / 3.0, 34, 0.66, 0.17);
172 undraw_inside_ellipse (3.25, 33, 0.81, 2.5 stafflinethickness#,
176 fet_beginchar ("Quart notehead", "s2")
177 % used to have 32. With 31, they are slightly bolder.
178 draw_outside_ellipse (1.49 - puff_up_factor / 3.0, 31, 0.707, 0);
179 black_notehead_width# := charwd;
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 fet_beginchar ("Whole diamondhead", "s0diamond")
187 draw_outside_ellipse (1.80, 0, 0.495, 0);
188 undraw_inside_ellipse (1.30, 125, 0.6,
189 .4 staff_space# + stafflinethickness#,
194 fet_beginchar ("Half diamondhead", "s1diamond")
195 draw_outside_ellipse (1.50, 34, 0.49, 0.17);
196 undraw_inside_ellipse (3.5, 33, 0.80,
197 .3 staff_space# + 1.5 stafflinethickness#,
202 fet_beginchar ("Quart diamondhead", "s2diamond")
203 draw_outside_ellipse (1.80, 35, 0.495, -0.25);
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 vardef penposx@# (expr d) =
220 z@#l = pat intersectionpoint (z@# -- infinity * dir (d + 180));
221 z@#r = pat intersectionpoint (z@# -- infinity * dir (d));
226 def define_triangle_shape (expr stemdir) =
227 save triangle_a, triangle_b, triangle_c;
228 save triangle_out_a, triangle_out_b, triangle_out_c;
229 save triangle_in, triangle_out;
230 save width, depth, height;
231 save origin, left_up_dir;
232 save exact_left_point, exact_right_point, exact_down_point;
234 path triangle_a, triangle_b, triangle_c;
235 path triangle_out_a, triangle_out_b, triangle_out_c;
236 path triangle_in, triangle_out;
237 pair origin, left_up_dir;
238 pair exact_down_point, exact_left_point, exact_right_point;
241 pen_thick# = stafflinethickness# + .1 staff_space#;
242 define_pixels (pen_thick, llap);
244 left_up_dir = llap# * dir (90 + tilt);
246 xpart (left_up_dir) * xs - (pen_thick# * xs) / 2 + xpart origin = 0;
249 exact_left_point := origin + (left_up_dir xscaled xs);
250 exact_down_point := origin + (left_up_dir rotated 120 xscaled xs);
251 exact_right_point := origin + (left_up_dir rotated 240 xscaled xs);
253 height# = ypart (exact_left_point + origin) + pen_thick# / 2;
254 depth# = -ypart (exact_down_point + origin) + pen_thick# / 2;
255 width# = xpart (exact_right_point - exact_left_point)
258 set_char_box (0, width#, depth#, height#);
260 % Formerly, the shape has simply been drawn with an elliptical pen
261 % (`scaled pen_thick xsaled xs'), but the envelope of such a curve
262 % is of 6th degree. For the sake of mf2pt1, we approximate it.
264 pickup pencircle scaled pen_thick xscaled xs;
266 z0 = (hround_pixels (xpart origin), 0);
268 z1 = z1' = z0 + llap * dir (90 + tilt) xscaled xs;
269 z2 = z2' = z0 + llap * dir (90 + tilt + 120) xscaled xs;
270 z3 = z3' = z0 + llap * dir (90 + tilt + 240) xscaled xs;
272 z12 = caveness [.5[z1, z2], z3];
273 z23 = caveness [.5[z2, z3], z1];
274 z31 = caveness [.5[z3, z1], z2];
276 triangle_a = z1 .. z12 .. z2;
277 triangle_b = z2 .. z23 .. z3;
278 triangle_c = z3 .. z31 .. z1;
280 penposx1 (angle (direction 0 of triangle_a) - 90);
281 penposx2 (angle (direction 0 of triangle_b) - 90);
282 penposx3 (angle (direction 0 of triangle_c) - 90);
284 penposx1' (angle (direction infinity of triangle_c) + 90);
285 penposx2' (angle (direction infinity of triangle_a) + 90);
286 penposx3' (angle (direction infinity of triangle_b) + 90);
288 penposx12 (angle (z12 - z0));
289 penposx23 (angle (z23 - z0));
290 penposx31 (angle (z31 - z0));
292 z10 = (z0 -- z1) intersectionpoint (z1l .. z12l .. z2'r);
293 z20 = (z0 -- z2) intersectionpoint (z2l .. z23l .. z3'r);
294 z30 = (z0 -- z3) intersectionpoint (z3l .. z31l .. z1'r);
307 triangle_out_a = z1r .. z12r .. z2'l;
308 triangle_out_b = z2r .. z23r .. z3'l;
309 triangle_out_c = z3r .. z31r .. z1'l;
311 triangle_out = top z1
313 .. z1r{direction 0 of triangle_out_a}
315 & {direction infinity of triangle_out_a}z2'l
318 .. z2r{direction 0 of triangle_out_b}
320 & {direction infinity of triangle_out_b}z3'l
323 .. z3r{direction 0 of triangle_out_c}
325 & {direction infinity of triangle_out_c}z1'l
328 labels (0, 10, 20, 30);
329 penlabels (1, 1', 2, 2', 3, 3', 12, 23, 31);
333 charwy := ypart exact_right_point;
334 charwx := xpart exact_right_point;
336 charwy := -ypart exact_down_point;
337 charwx := (width# - xpart exact_down_point);
342 fet_beginchar ("Whole trianglehead", "s0triangle")
348 llap# = 3/4 noteheight#;
352 define_triangle_shape (1);
358 def draw_small_triangle_head (expr dir) =
364 llap# = 2/3 noteheight#;
367 define_triangle_shape (dir);
373 fet_beginchar ("Half trianglehead", "d1triangle")
374 draw_small_triangle_head (-1);
378 fet_beginchar ("Half trianglehead", "u1triangle")
379 draw_small_triangle_head (1);
383 def draw_closed_triangle_head (expr dir) =
389 llap# = 2/3 noteheight#;
392 define_triangle_shape (dir);
397 fet_beginchar ("Quart trianglehead", "u2triangle")
398 draw_closed_triangle_head (1);
402 fet_beginchar("Quart trianglehead", "d2triangle")
403 draw_closed_triangle_head (-1);
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 % Slash heads are for indicating improvisation. They are
410 % twice as high as normal heads.
412 def draw_slash (expr hwid_hash) =
416 exact_height = staff_space# + stafflinethickness# / 2;
418 set_char_box (0, 2 exact_height / slash_slope + hwid_hash,
419 exact_height, exact_height);
425 pickup pencircle scaled blot_diameter;
430 lft x2 = 2 h / slash_slope;
437 ne_dir := unitvector (z3 - z4);
448 if hwid_hash > 2 slash_thick#:
451 th = slash_thick - blot_diameter;
456 z6 - z5 = whatever * ne_dir;
457 z8 - z7 = whatever * ne_dir;
459 z5 = z1 + whatever * ne_dir + th * (ne_dir rotated -90);
460 z8 = z4 + whatever * ne_dir + th * (ne_dir rotated 90);
468 labels (range 1 thru 10);
472 fet_beginchar ("Whole slashhead", "s0slash")
473 draw_slash (4 slash_thick# + 0.5 staff_space#);
477 fet_beginchar ("Half slashhead", "s1slash")
478 draw_slash (3.0 slash_thick# + 0.15 staff_space#);
482 fet_beginchar ("Quart slashhead", "s2slash")
483 draw_slash (1.5 slash_thick#);
487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 % `thick' is the distance between the NE/SW parallel lines in the cross
490 % (distance between centres of lines) in multiples of stafflinethickness
492 def draw_cross (expr thick) =
494 save horz_dist, vert_dist;
495 save crz_in, crz_out;
497 path crz_in, crz_out;
499 pen_thick# := 1.2 stafflinethickness#;
500 define_pixels (pen_thick);
501 pickup pencircle scaled pen_thick;
504 ne_dir := unitvector ((1, (2 h - pen_thick) / (w - pen_thick)));
507 z4 - z5 = whatever * ne_dir;
509 z6 - z3 = whatever * ne_dir;
510 z3 - z4 = whatever * (ne_dir yscaled -1);
512 z4 - z3 = whatever * (ne_dir)
513 + (ne_dir rotated -90) * thick * stafflinethickness;
515 x1 = charwd / 2 - .5 pen_thick#;
516 z1 = whatever * ne_dir
517 + thick / 2 * stafflinethickness# * (ne_dir rotated -90);
519 labels (1, 2, 3, 4, 5, 6);
521 nw_dir = unitvector (z3 - z4);
523 vert_dist = 0.5 pen_thick / cosd (angle (ne_dir));
524 horz_dist = 0.5 pen_thick / sind (angle (nw_dir));
526 crz_out = (z6 + up * vert_dist)
527 --- (z3 + nw_dir * 0.5 pen_thick)
529 .. (z3 + ne_dir * 0.5 pen_thick)
530 --- (z4 + ne_dir * 0.5 pen_thick)
532 .. (z4 - nw_dir * 0.5 pen_thick)
533 --- (z5 + right * horz_dist);
535 & reverse crz_out yscaled -1;
537 & reverse crz_out xscaled -1
542 crz_in = (bot z6){right}
543 .. (z6 - nw_dir * 0.5 pen_thick)
544 --- (z3 + down * vert_dist)
545 --- (z4 + left * horz_dist)
546 --- (z5 + nw_dir * 0.5 pen_thick)
549 .. reverse crz_in yscaled -1;
551 .. reverse crz_in xscaled -1
557 currentpicture := currentpicture shifted (w / 2, 0);
561 z12 = (charwx * hppp, y1 * vppp);
566 fet_beginchar ("Whole Crossed notehead", "s0cross")
567 wid# := black_notehead_width# + 4 stafflinethickness#;
568 hei# := noteheight# + stafflinethickness#;
570 set_char_box (0, wid#, hei# / 2, hei# / 2);
576 fet_beginchar ("Half Crossed notehead", "s1cross")
577 wid# := black_notehead_width# + 2 stafflinethickness#;
578 hei# := noteheight# + stafflinethickness# / 2;
580 set_char_box (0, wid#, hei# / 2, hei# / 2);
586 fet_beginchar ("Crossed notehead", "s2cross")
587 wid# := black_notehead_width#;
589 set_char_box (0, wid#, hei# / 2, hei# / 2);
595 fet_beginchar ("X-Circled notehead", "s2xcircle")
596 wid# := black_notehead_width# * sqrt (sqrt2);
597 hei# := noteheight# * sqrt (sqrt2);
599 set_char_box (0, wid#, hei# / 2, hei# / 2);
601 cthick := (1.2 + 1/4) * stafflinethickness;
602 cxr := w / 2 - cthick / 2;
603 cyr := h - cthick / 2;
605 pickup pencircle scaled cthick;
607 fill fullcircle xscaled (2 cxr + cthick)
608 yscaled (2 cyr + cthick)
610 unfill fullcircle xscaled (2 cxr - cthick)
611 yscaled (2 cyr - cthick)
617 pickup penrazor scaled cthick rotated (angle (xpos, ypos) + 90);
618 draw (-xpos + w / 2, -ypos) -- (xpos + w / 2, ypos);
620 pickup penrazor scaled cthick rotated (angle (xpos, -ypos) + 90);
621 draw (-xpos + w / 2, ypos) -- (xpos + w / 2, -ypos);
626 z12 = (charwx * hppp, charwy * vppp);
636 save solfa_pen_thick;
637 solfa_pen_thick# = 2 stafflinethickness#;
638 define_pixels (solfa_pen_thick);
641 def draw_do_head (expr width_factor, dir) =
643 save left_dist, right_dist;
645 pair left_dist, right_dist;
647 set_char_box (0, width_factor * noteheight#,
648 0.5 noteheight#, 0.5 noteheight#);
650 pickup pencircle scaled solfa_pen_thick;
659 left_dist = (unitvector (z3 - z1) rotated 90) * 0.5 solfa_pen_thick;
660 right_dist = (unitvector (z2 - z3) rotated 90) * 0.5 solfa_pen_thick;
662 p_in := (((z1 - left_dist) -- (z3 - left_dist)) intersectionpoint
664 -- ((top z1 -- top z2) intersectionpoint
665 ((z2 - right_dist) -- (z3 - right_dist)))
666 -- (((z2 - right_dist) -- (z3 - right_dist)) intersectionpoint
667 ((z1 - left_dist) -- (z3 - left_dist)))
674 --- (z3 + right_dist)
685 charwy := -chardp + 0.5 stafflinethickness#;
692 fet_beginchar ("Whole dohead", "s0do")
693 draw_do_head (1.8, 1);
699 fet_beginchar ("Half dohead", "d1do")
700 draw_do_head (1.5, -1);
706 fet_beginchar ("Half dohead", "s1do")
707 draw_do_head (1.5, 1);
713 fet_beginchar ("Quart dohead", "d2do")
714 draw_do_head (1.55, -1);
719 fet_beginchar ("Quart dohead", "s2do")
720 draw_do_head (1.55, 1);
726 % re - flat top, curved bottom:
727 % (0,h/2) {dir -90} .. (w/2,-h/2) .. {dir 90} (w,h/2) -- cycle;
728 % (broader along the base and with more vertical sides for half and
730 % stem attachment: h/2
733 def draw_re_head (expr width_factor, dir) =
737 set_char_box (0, width_factor * noteheight#,
738 0.5 noteheight#, 0.5 noteheight#);
740 pickup pencircle scaled solfa_pen_thick;
747 y2 = curve_start [y3, y1];
755 labels (range 1 thru 5);
757 p_in := (z1 + 0.5 solfa_pen_thick * (1, -1))
761 --- (z5 + 0.5 solfa_pen_thick * (-1, -1))
774 charwy := curve_start [-chardp, charht];
782 fet_beginchar ("Whole rehead", "s0re")
783 draw_re_head (1.8, 1);
789 fet_beginchar ("Half up rehead", "u1re")
790 draw_re_head (1.5, 1);
796 fet_beginchar ("Half down rehead", "d1re")
797 draw_re_head (1.5, -1);
803 fet_beginchar ("Quart rehead", "u2re")
804 draw_re_head (1.55, 1);
809 fet_beginchar ("Quart rehead", "d2re")
810 draw_re_head (1.55, -1);
815 def draw_mi_head (expr width_factor) =
816 save path_out, path_in;
817 save ne_dist, nw_dist;
818 path path_out, path_in;
819 pair ne_dist, nw_dist;
821 set_char_box (0, width_factor * noteheight#,
822 0.5 noteheight#, 0.5 noteheight#);
824 pickup pencircle scaled solfa_pen_thick;
835 z6 - z5 = whatever * (z2 - z1);
836 z8 - z7 = whatever * (z2 - z1);
837 z8 - z5 = whatever * (z4 - z1);
838 z6 - z7 = whatever * (z4 - z1);
840 ne_dist = (unitvector (z4 - z1) rotated 90) * 0.5 solfa_pen_thick;
841 nw_dist = (unitvector (z1 - z2) rotated 90) * 0.5 solfa_pen_thick;
843 z5 = whatever [z1, z4] - ne_dist;
844 z5 = whatever [z1, z2] - 1.5 nw_dist;
846 z5 - z1 = -(z7 - z3);
848 labels (range 1 thru 8);
872 fet_beginchar ("Whole mihead", "s0mi")
879 fet_beginchar ("Half mihead", "s1mi")
886 fet_beginchar ("Quart mihead", "s2mi")
892 def draw_fa_head (expr width_factor) =
893 set_char_box (0, width_factor * noteheight#,
894 0.5 noteheight#, 0.5 noteheight#);
896 save p_down_in, p_down_out, p_up_in, p_up_out, nw_dist;
897 path p_down_in, p_down_out, p_up_in, p_up_out;
900 pickup pencircle scaled solfa_pen_thick;
913 labels (range 1 thru 4);
915 nw_dist = (unitvector (z1 - z3) rotated 90) * 0.5 solfa_pen_thick;
917 p_up_in := (((z1 - nw_dist) -- (z3 - nw_dist)) intersectionpoint
919 -- (((z1 - nw_dist) -- (z3 - nw_dist)) intersectionpoint
921 -- (z2 + 0.5 solfa_pen_thick * (-1, -1))
934 p_down_in := p_up_in rotated 180 shifted (w, 0);
935 p_down_out := p_up_out rotated 180 shifted (w, 0);
942 fet_beginchar ("Whole fa up head", "d0fa")
949 fet_beginchar ("Whole fa down head", "u0fa")
956 fet_beginchar ("half fa up head", "d1fa")
963 fet_beginchar ("Half fa down head", "u1fa")
970 fet_beginchar ("Quarter fa up head", "u2fa")
976 fet_beginchar ("Quarter fa down head", "d2fa")
982 def draw_la_head (expr width_factor) =
983 set_char_box (0, width_factor * noteheight#,
984 0.5 noteheight#, 0.5 noteheight#);
988 pickup pencircle scaled solfa_pen_thick;
1001 labels (range 1 thru 4);
1003 p_in := (z1 + 0.5 solfa_pen_thick * (1, -1))
1004 -- (z2 + 0.5 solfa_pen_thick * (-1, -1))
1005 -- (z3 + 0.5 solfa_pen_thick * (-1, 1))
1006 -- (z4 + 0.5 solfa_pen_thick * (1, 1))
1021 fet_beginchar ("Whole lahead", "s0la")
1028 fet_beginchar ("Half lahead", "s1la")
1035 fet_beginchar ("Quart lahead", "s2la")
1036 draw_la_head (1.55);
1041 def draw_ti_head (expr width_factor, dir) =
1042 set_char_box (0, width_factor * noteheight#,
1043 0.5 noteheight#, 0.5 noteheight#);
1044 save p_in, p_out, p_top;
1045 save left_dist, right_dist;
1046 path p_in, p_out, p_top;
1047 pair left_dist, right_dist;
1051 pickup pencircle scaled solfa_pen_thick;
1056 y2 = cone_height [y1, y3];
1062 labels (range 1 thru 4);
1064 left_dist = (unitvector (z2 - z1) rotated 90) * 0.5 solfa_pen_thick;
1065 right_dist = (unitvector (z1 - z4) rotated 90) * 0.5 solfa_pen_thick;
1067 p_top := (z2 - right_dist) .. (top z3){right} .. (z4 - left_dist);
1069 p_in := (((z1 - left_dist) -- (z2 - left_dist)) intersectionpoint
1070 ((z1 - right_dist) -- (z4 - right_dist)))
1071 -- (((z1 - left_dist) -- (z2 - left_dist)) intersectionpoint
1072 ((z2 + right_dist) .. {right}(bot z3)))
1074 .. (((bot z3){right} .. (z4 + left_dist)) intersectionpoint
1075 ((z1 - right_dist) -- (z4 - right_dist)))
1080 --- (z2 + left_dist)
1082 .. (z2 - right_dist){direction 0 of p_top}
1084 & {direction infinity of p_top}(z4 - left_dist)
1086 .. (z4 + right_dist)
1087 --- (z1 + right_dist)
1091 charwy := cone_height [-chardp, charht];
1098 fet_beginchar ("Whole up tihead", "s0ti")
1099 draw_ti_head (1.8, 1);
1105 fet_beginchar ("Half up tihead", "u1ti")
1106 draw_ti_head (1.5, 1);
1112 fet_beginchar ("Half down tihead", "d1ti")
1113 draw_ti_head (1.5, -1);
1119 fet_beginchar ("Quart up tihead", "u2ti")
1120 draw_ti_head (1.55, 1);
1125 fet_beginchar ("Quart down tihead", "d2ti")
1126 draw_ti_head (1.55, -1);
1131 fet_endgroup("noteheads");
1135 % we derive black_notehead_width# from the quarter head,
1136 % so we have to define black_notehead_width (pixel qty)
1137 % after the black_notehead_width# itself.
1139 % Let's keep it outside the group as well.
1142 define_pixels (black_notehead_width);