2 % feta-toevallig.mf -- implement Accidentals
4 % (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 % also show in other configuration wrt staff lines.
11 def draw_shifted_too =
13 fet_beginchar ("shifted too", "");
14 set_char_box (0, 0, 0, 0);
15 currentpicture := remember_pic;
17 draw_staff (-2, 2, 0.5);
24 % Accidentals from various sources, notably
26 % Baerenreiter edition of Schuberts `Auf dem Strom' (sharp, natural)
27 % F Hofmeister edition of Muellers `Etueden fuer Horn' (double sharp, flat)
32 % Naming for accidentals (including microtonal variants):
34 % SHARPBASE[.SLASHES.STEMS]
39 % sharp.slashslash.stem
45 fet_begingroup ("accidentals");
51 save sharp_beamheight;
52 sharp_beamheight# := 0.3 staff_space# + stafflinethickness#;
55 % The beams of most sharps have horizontal endings (as if drawn with
56 % a square pen). [Wanske] does not mention this, so we'll just ignore
60 def draw_meta_sharp (expr width, offset) =
61 save beamwidth, beamslope;
67 define_whole_vertical_blacker_pixels (sharp_beamheight);
71 beamslope = sharp_beamheight / beamwidth;
73 pickup pencircle scaled 2 blot_diameter;
75 rt x2 - lft x1 = beamwidth;
76 z2 = z1 + whatever * (beamwidth, sharp_beamheight);
77 .5 [z1, z3] = (.5 w, offset);
79 top y2 - bot y3 = sharp_beamheight;
81 top y1 - bot y4 = sharp_beamheight;
83 ne = unitvector (z2 - z1);
84 nw_dist = (ne rotated 90) * blot_diameter;
87 ... (z1 + nw_dist){ne}
91 ... (z3 - nw_dist){-ne}
92 -- (z4 - nw_dist){-ne}
100 fet_beginchar ("Sharp", "sharp");
101 save stem, stemx, stemwidth;
102 save outer_space, interbeam;
104 stemwidth# := stafflinethickness# + .05 staff_space#;
105 define_whole_blacker_pixels (stemwidth);
107 interbeam := 1.05 staff_space_rounded;
109 set_char_box (0, 1.1 staff_space#,
110 1.5 staff_space#, 1.5 staff_space#);
113 stemx := hround stem;
114 outer_space := hround ((w - stemx - stemwidth) / 2);
116 w := 2 outer_space + stemx + stemwidth;
117 d := d - feta_space_shift;
119 draw_meta_sharp (w, -.5 interbeam);
120 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
122 pickup pencircle scaled stemwidth;
124 lft x5 = lft x6 = outer_space;
125 lft x7 = lft x8 = outer_space + stemx;
127 top y6 = vround (1.5 staff_space - stem * beamslope);
128 bot y7 = -top y6 + feta_space_shift;
133 draw_gridline (z5, z6, stemwidth);
134 draw_gridline (z7, z8, stemwidth);
136 remember_pic := currentpicture;
138 draw_staff (-2, 2, 0);
145 fet_beginchar ("1/2 Sharp", "sharp.slashslash.stem");
146 save stem, stemwidth;
147 save outer_space, interbeam;
149 stemwidth# := stafflinethickness# + .05 staff_space#;
150 define_whole_blacker_pixels (stemwidth);
152 interbeam := 1.05 staff_space_rounded;
154 set_char_box (0, 0.7 staff_space#,
155 1.5 staff_space#, 1.5 staff_space#);
158 outer_space := hround ((w - stemwidth) / 2);
160 w := 2 outer_space + stemwidth;
161 d := d - feta_space_shift;
163 draw_meta_sharp (w, -.5 interbeam);
164 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
166 pickup pencircle scaled stemwidth;
168 lft x5 = lft x6 = outer_space;
169 top y6 = vround (1.5 staff_space - .5 stem);
170 bot y5 = -top y6 + feta_space_shift;
174 draw_gridline (z5, z6, stemwidth);
176 remember_pic := currentpicture;
178 draw_staff (-2, 2, 0);
185 fet_beginchar ("Sharp (3 beams)", "sharp.slashslashslash.stemstem");
186 save stem, stemx, stemwidth;
187 save outer_space, interbeam;
188 save sharp_beamheight;
190 sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
192 stemwidth# := stafflinethickness# + .05 staff_space#;
193 define_whole_blacker_pixels (stemwidth);
195 interbeam := 1.2 staff_space_rounded;
197 set_char_box (0, 1.1 staff_space#,
198 1.5 staff_space#, 1.5 staff_space#);
201 stemx := hround stem;
202 outer_space := hround ((w - stemx - stemwidth) / 2);
204 w := 2 outer_space + stemx + stemwidth;
205 d := d - feta_space_shift;
207 draw_meta_sharp (.88 w, -.5 interbeam);
208 draw_meta_sharp (.88 w, -.5 interbeam + vround interbeam);
209 sharp_beamheight# := 1/.88 sharp_beamheight#;
210 draw_meta_sharp (w, 0);
212 pickup pencircle scaled stemwidth;
214 lft x5 = lft x6 = outer_space;
215 lft x7 = lft x8 = outer_space + stemx;
217 top y6 = vround (1.5 staff_space - stem * beamslope);
218 bot y7 = -top y6 + feta_space_shift;
223 draw_gridline (z5, z6, stemwidth);
224 draw_gridline (z7, z8, stemwidth);
226 remember_pic := currentpicture;
228 draw_staff (-2, 2, 0);
235 fet_beginchar ("1/2 Sharp (3 beams)", "sharp.slashslashslash.stem");
236 save stem, stemx, stemwidth;
237 save outer_space, interbeam;
238 save sharp_beamheight;
240 sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
242 stemwidth# := stafflinethickness# + .05 staff_space#;
243 define_whole_blacker_pixels (stemwidth);
245 interbeam := 1.2 staff_space_rounded;
247 set_char_box (0, 0.95 staff_space#,
248 1.3 staff_space#, 1.3 staff_space#);
251 outer_space := hround ((w - stemwidth) / 2);
253 w := 2 outer_space + stemwidth;
254 d := d - feta_space_shift;
256 draw_meta_sharp (.8 w, -.5 interbeam);
257 draw_meta_sharp (.8 w, -.5 interbeam + vround interbeam);
258 sharp_beamheight# := 1/.8 sharp_beamheight#;
259 draw_meta_sharp (w, 0);
261 pickup pencircle scaled stemwidth;
263 lft x5 = lft x6 = outer_space;
264 top y6 = vround (1.5 staff_space - .5 stem);
265 bot y5 = -top y6 + feta_space_shift;
268 draw_gridline (z5, z6, stemwidth);
270 remember_pic := currentpicture;
272 draw_staff (-2, 2, 0);
279 fet_beginchar ("3/4 Sharp", "sharp.slashslash.stemstemstem");
280 save stem, stemx, stemwidth;
281 save outer_space, interbeam;
283 stemwidth# := stafflinethickness# + .05 staff_space#;
284 define_whole_blacker_pixels (stemwidth);
286 interbeam := 1.05 staff_space_rounded;
288 set_char_box (0, 1.6 staff_space#,
289 1.5 staff_space#, 1.5 staff_space#);
292 stemx := hround stem;
293 outer_space := hround ((w - 2 stemx - stemwidth) / 2);
295 w := 2 outer_space + 2 stemx + stemwidth;
296 d := d - feta_space_shift;
298 draw_meta_sharp (w, -.5 interbeam);
299 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
301 pickup pencircle scaled stemwidth;
303 lft x5 = lft x6 = outer_space;
304 lft x7 = lft x8 = outer_space + stemx;
305 lft x9 = lft x10 = outer_space + 2 stemx;
307 top y6 = vround (1.5 staff_space - 2 stem * beamslope);
308 bot y9 = -top y6 + feta_space_shift;
313 labels (5, 6, 7, 8, 9, 10);
315 draw_gridline (z5, z6, stemwidth);
316 draw_gridline (z7, z8, stemwidth);
317 draw_gridline (z9, z10, stemwidth);
319 remember_pic := currentpicture;
321 draw_staff (-2, 2, 0);
329 % The stems of the natural are brushed (at least, in Barenreiter SCS)
332 fet_beginchar ("Natural", "natural");
333 save stemwidth, top_stem_thick;
334 save ne, pat_top, pat_bottom;
336 path pat_top, pat_bottom;
338 top_stem_thick# = stafflinethickness# + .10 staff_space#;
339 stemwidth# = 0.09 staff_space# + .5 stafflinethickness#;
340 define_whole_blacker_pixels (top_stem_thick, stemwidth);
342 set_char_box (0, 2/3 staff_space#,
343 1.5 staff_space#, 1.5 staff_space#);
345 d := d - feta_space_shift;
347 pickup pencircle scaled stemwidth;
349 penpos1 (top_stem_thick, 0);
350 penpos3 (top_stem_thick, 0);
351 penpos2 (stemwidth, 0);
352 penpos4 (stemwidth, 0);
361 top y2 = vround (staff_space - 3/2 stafflinethickness);
362 y4 = -y2 + feta_space_shift;
364 pat_bottom := z4r{z4r - z1r}
367 fill simple_serif (z1l, z1r, -30)
371 pat_top := z2r{z2r - z3r}
374 fill simple_serif (z3l, z3r, 30)
378 ne = (x2 - x4, stafflinethickness);
380 z11' = z3l + whatever * (z2l - z3l);
381 y11' = vround (.5 (staff_space - stafflinethickness));
382 z11 = z11' + whatever * ne;
384 z12 = directionpoint -ne of pat_top;
385 z13 = z12 + whatever * ne;
387 z14 = z11 + whatever * ne;
390 z21' = z4r + whatever * (z1r - z4r);
391 y21' = -y11' + feta_space_shift;
392 z21 = z21' + whatever * ne;
394 z22 = directionpoint -ne of pat_bottom;
395 z23 = z22 + whatever * ne;
397 z24 = z21 + whatever * ne;
411 penlabels (1, 2, 3, 4);
412 labels (11, 11', 12, 13, 14, 21, 21', 22, 23, 24);
414 remember_pic := currentpicture;
416 draw_staff (-2, 2, 0);
424 % Dedicated to my mom. (3/10/97)
426 % Mamma, ik hou van je; kom je alsjeblieft terug?
430 % TODO: remove crook_fatness
431 % TODO: document, simplify!
434 def draw_meta_flat (expr xcenter, w, crook_fatness) =
436 save bottom_overshoot, bot_crook_dir;
437 save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
438 save top_crook_thinness;
441 pair center, bot_crook_dir;
446 % the stem shouldn't reach the top staff line.
447 %% TODO: should take from height.
449 % TODO: parameterize this
451 if w >= 0.75 staff_space:
452 smaller_hole = 0.35 stafflinethickness;
456 clearing = 1.7 stafflinethickness;
457 crook_thinness = .7 stafflinethickness + .06 staff_space;
458 top_crook_thinness = 1 stafflinethickness + .065 staff_space;
459 bottom_overshoot = stafflinethickness;
461 bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
462 top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
463 define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
465 if odd (top_stem_thick - bottom_stem_thick):
466 top_stem_thick := top_stem_thick - 1;
469 center = (xcenter, 0);
471 x1l = hround (xcenter - .5 top_stem_thick);
472 y1 = vround (2 staff_space - clearing);
473 x2l = hround (xcenter - .5 bottom_stem_thick);
474 y2 = -.5 staff_space - .5 stafflinethickness;
476 penpos1 (top_stem_thick, 0);
477 penpos2 (bottom_stem_thick, 0);
479 y3l = vfloor ((staff_space - stafflinethickness) / 2);
480 z3l = whatever [z2r, z1r];
481 z3r = .3 [z2r, z1r] + (smaller_hole, 0);
484 % we insert z3l to get better conversion with mf2pt1
485 fill simple_serif (z1r, z1l, 30)
491 z10 = whatever [z2r, z1r] + (smaller_hole, 0);
492 y10 = -1/10 staff_space;
495 x11 = xcenter + bottom_overshoot / 3;
496 y11 = -vround (.5 (staff_space + stafflinethickness)
499 penpos4 (whatever, 53);
501 y4l - y4r = top_crook_thinness;
502 y5r = .15 staff_space;
503 x5l = hround (w + xcenter);
504 y4 = staff_space / 2;
505 x4r = .45 [x5r, x3r];
508 penpos5 (crook_fatness, -175);
510 bot_crook_dir = unitvector ((x5l, 0) - z11);
511 z8 = z11 + whatever * bot_crook_dir;
512 y8 = -staff_space / 2;
515 + whatever * bot_crook_dir
516 + crook_thinness * (bot_crook_dir rotated 90);
519 unfill z3r{z3r - z10}
522 .. z7{-bot_crook_dir}
538 % unfortunately, 600dpi is not enough to show the brush of the stem.
541 fet_beginchar ("Flat", "flat");
542 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
543 0.6 staff_space#, 1.9 staff_space#);
545 draw_meta_flat (0, w, 0.31 staff_space);
546 penlabels (range 0 thru 11);
548 remember_pic := currentpicture;
550 draw_staff (-2, 2, 0);
557 fet_beginchar ("Flat (slashed)", "flat.slash");
558 set_char_box (.4 staff_space#, .8 staff_space#,
559 0.6 staff_space#, 1.9 staff_space#);
561 draw_meta_flat (0, w, 0.31 staff_space);
565 save slope, slash_width;
570 z12 = z11 - (slash_width, slash_width * slope) / 2;
571 z13 = z11 + (slash_width, slash_width * slope) / 2;
572 penpos12 (1.5 stafflinethickness, angle (z13 - z12) - 90);
573 penpos13 (1.5 stafflinethickness, angle (z13 - z12) - 90);
575 z14 = z12 - .75 stafflinethickness * unitvector (z13 - z12);
576 z15 = z13 + .75 stafflinethickness * unitvector (z13 - z12);
590 remember_pic := currentpicture;
592 draw_staff (-2, 2, 0);
596 fet_beginchar ("Flat (slashed twice)", "flat.slashslash");
597 set_char_box (.4 staff_space#, .8 staff_space#,
598 0.6 staff_space#, 1.9 staff_space#);
600 draw_meta_flat (0, w, 0.31 staff_space);
604 save slope, slash_width;
609 z12 = z11 - (slash_width, slash_width * slope) / 2;
610 z13 = z11 + (slash_width, slash_width * slope) / 2;
611 penpos12 (1.5 stafflinethickness, angle (z13 - z12) - 90);
612 penpos13 (1.5 stafflinethickness, angle (z13 - z12) - 90);
614 z14 = z12 - .75 stafflinethickness * unitvector (z13 - z12);
615 z15 = z13 + .75 stafflinethickness * unitvector (z13 - z12);
630 z22 = z21 - (slash_width, slash_width * slope) / 2;
631 z23 = z21 + (slash_width, slash_width * slope) / 2;
632 penpos22 (1.5 stafflinethickness, angle (z23 - z22) - 90);
633 penpos23 (1.5 stafflinethickness, angle (z23 - z22) - 90);
635 z24 = z22 - .75 stafflinethickness * unitvector (z23 - z22);
636 z25 = z23 + .75 stafflinethickness * unitvector (z23 - z22);
650 remember_pic := currentpicture;
652 draw_staff (-2, 2, 0);
656 fet_beginchar ("Flatflat (mirrored)", "mirroredflat.flat");
657 set_char_box (0, 1.6 staff_space#,
658 0.6 staff_space#, 1.9 staff_space#);
660 % This is a modified version of `draw_meta_flat'.
662 save crook_thinness, crook_fatness;
663 save bottom_overshoot, bot_crook_dir;
664 save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
665 save top_crook_thinness;
668 pair center, bot_crook_dir;
677 % the stem shouldn't reach the top staff line.
678 %% TODO: should take from height.
680 % TODO: parameterize this
682 if wid >= 0.75 staff_space:
683 smaller_hole = 0.35 stafflinethickness;
687 clearing = 1.7 stafflinethickness;
688 crook_thinness = .7 stafflinethickness + .06 staff_space;
689 crook_fatness = 0.31 staff_space;
690 top_crook_thinness = 1 stafflinethickness + .065 staff_space;
691 bottom_overshoot = stafflinethickness;
693 bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
694 top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
695 define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
697 if odd (top_stem_thick - bottom_stem_thick):
698 top_stem_thick := top_stem_thick - 1;
703 x1l = hround (-.5 top_stem_thick);
704 y1 = vround (2 staff_space - clearing);
705 x2l = hround (-.5 bottom_stem_thick);
706 y2 = -.5 staff_space - .5 stafflinethickness;
708 penpos1 (top_stem_thick, 0);
709 penpos2 (bottom_stem_thick, 0);
711 y3l = vfloor ((staff_space - stafflinethickness) / 2);
712 z3l = whatever [z2r, z1r];
713 z3r = .3 [z2r, z1r] + (smaller_hole, 0);
716 z10 = whatever [z2r, z1r] + (smaller_hole, 0);
717 y10 = -1/10 staff_space;
720 x11 = bottom_overshoot / 3;
721 y11 = -vround (.5 (staff_space + stafflinethickness)
724 penpos4 (whatever, 53);
726 y4l - y4r = top_crook_thinness;
727 y5r = .15 staff_space;
729 y4 = staff_space / 2;
730 x4r = .45 [x5r, x3r];
733 penpos5 (crook_fatness, -175);
735 bot_crook_dir = unitvector ((x5l, 0) - z11);
736 z8 = z11 + whatever * bot_crook_dir;
737 y8 = -staff_space / 2;
740 + whatever * bot_crook_dir
741 + crook_thinness * (bot_crook_dir rotated 90);
744 pat := z3r{z3r - z10}
747 .. z7{-bot_crook_dir}
752 unfill pat xscaled -1;
760 -- simple_serif (z1r, z1l, 30)
761 -- reverse pat xscaled -1 shifted (-feta_eps, 0)
764 currentpicture := currentpicture shifted (w/2, 0);
766 remember_pic := currentpicture;
768 draw_staff (-2, 2, 0);
775 fet_beginchar ("Semi flat", "mirroredflat");
776 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
777 0.6 staff_space#, 1.9 staff_space#);
779 draw_meta_flat (0, w, 0.31 staff_space);
780 currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
784 fet_beginchar ("Semi flat", "mirroredflat.backslash");
785 set_char_box (.4 staff_space#, .8 staff_space#,
786 0.6 staff_space#, 1.9 staff_space#);
788 draw_meta_flat (0, w, 0.31 staff_space);
792 save slope, slash_width;
797 z12 = z11 - (slash_width, slash_width * slope) / 2;
798 z13 = z11 + (slash_width, slash_width * slope) / 2;
799 penpos12 (1.5 stafflinethickness, angle (z13 - z12) - 90);
800 penpos13 (1.5 stafflinethickness, angle (z13 - z12) - 90);
802 z14 = z12 - .75 stafflinethickness * unitvector (z13 - z12);
803 z15 = z13 + .75 stafflinethickness * unitvector (z13 - z12);
814 currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
820 fet_beginchar ("Double Flat", "flatflat");
821 save left_wid, overlap, right_wid;
827 set_char_box (1.2 stafflinethickness#,
828 (left_wid + right_wid - overlap) * staff_space#,
829 .6 staff_space#, 1.9 staff_space#);
830 draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
831 draw_meta_flat (hround ((left_wid - overlap) * staff_space),
832 right_wid * staff_space, 1/3 staff_space);
836 fet_beginchar ("3/4 Flat", "flatflat.slash");
837 save left_wid, overlap, right_wid;
843 set_char_box (1.2 stafflinethickness#,
844 (left_wid + right_wid - overlap) * staff_space#,
845 .6 staff_space#, 1.9 staff_space#);
846 draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
847 draw_meta_flat (hround ((left_wid - overlap) * staff_space),
848 right_wid * staff_space, 1/3 staff_space);
850 %% maybe we should clip part of the stems?
851 %% or make the 1st flat smaller?
853 pickup pencircle scaled 2 stafflinethickness;
855 z12 = round (-.25 w - b, .55 staff_space) + feta_offset;
856 z13 = round (.75 w, 1.45 staff_space) + feta_offset;
857 penpos12 (2 stafflinethickness, angle (z13 - z12) - 90);
858 penpos13 (2 stafflinethickness, angle (z13 - z12) - 90);
860 z14 = z12 - stafflinethickness * unitvector (z13 - z12);
861 z15 = z13 + stafflinethickness * unitvector (z13 - z12);
875 remember_pic := currentpicture;
877 draw_staff (-2, 2, 0);
884 fet_beginchar ("Double Sharp", "doublesharp");
885 save klaverblad, klaversteel;
889 klaversteel = 1/15 staff_space;
890 klaverblad = .4 staff_space - .5 stafflinethickness;
892 set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
894 z1 = (klaversteel, 0);
895 z2 = (w / 2 - klaverblad / 10, h - klaverblad);
897 z4 = z2 reflectedabout ((0, 0), (1, 1));
898 z5 = z1 reflectedabout ((0, 0), (1, 1));
900 labels (1, 2, 3, 4, 5);
902 pickup pencircle scaled blot_diameter;
904 x2 := hfloor (rt x2) - blot_diameter / 2;
905 x3 := hfloor (rt x3) - blot_diameter / 2;
906 y3 := vfloor (top y3) - blot_diameter / 2;
907 y4 := vfloor (top y4) - blot_diameter / 2;
916 .. {dir 225}(top z5);
918 -- reverse pat xscaled -1 shifted (-feta_eps, 0);
920 % assure symmetry -- it's more important to center the glyph on the
921 % staff line than centering it between staff lines, so we use
922 % feta_shift, not feta_space_shift.
925 fill pat shifted (0, feta_shift)
926 -- reverse pat yscaled -1 shifted (0, -feta_eps)
930 currentpicture := currentpicture shifted (hround (w / 2), 0);
932 remember_pic := currentpicture;
934 draw_staff (-2, 2, 0);
944 leftindent := .2 staff_space;
946 set_char_box (0, .5 staff_space# + stafflinethickness#,
947 staff_space#, staff_space#);
951 z1 = (leftindent, h);
952 z2 = (w - stafflinethickness, .5 (h - d));
953 z3 = (leftindent, -d);
955 penpos1 (stafflinethickness, 35);
956 penpos2 (.1 staff_space + stafflinethickness, 0);
957 penpos3 (stafflinethickness, -35);
960 .. simple_serif (z3l, z3r, 90)
962 .. simple_serif (z1r, z1l, 90)
968 fet_beginchar ("Right Parenthesis", "rightparen");
972 remember_pic := currentpicture;
974 draw_staff (-2, 2, 0);
981 fet_beginchar ("Left Parenthesis", "leftparen");
984 currentpicture := currentpicture xscaled -1;
986 set_char_box (charwd, charbp, chardp, charht);
989 fet_endgroup ("accidentals");