2 % feta-toevallig.mf -- implement Accidentals
4 % (c) 1997--2006 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);
25 % Accidentals from various sources, notably
27 % Baerenreiter edition of Schuberts `Auf dem Strom' (sharp, natural)
28 % F Hofmeister edition of Muellers `Etueden fuer Horn' (double sharp, flat)
33 % Naming for microtonal
37 % mirroredflat.flat.slashslash
41 % sharp.slashslash.stemstem
42 % 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 y2 - y1 = 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);
143 fet_beginchar ("1/2 Sharp", "sharp.slashslash.stem");
144 save stem, stemwidth;
145 save outer_space, interbeam;
147 stemwidth# := stafflinethickness# + .05 staff_space#;
148 define_whole_blacker_pixels (stemwidth);
150 interbeam := 1.05 staff_space_rounded;
152 set_char_box (0, 0.7 staff_space#,
153 1.5 staff_space#, 1.5 staff_space#);
156 outer_space := hround ((w - stemwidth) / 2);
158 w := 2 outer_space + stemwidth;
159 d := d - feta_space_shift;
161 draw_meta_sharp (w, -.5 interbeam);
162 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
164 pickup pencircle scaled stemwidth;
166 lft x5 = lft x6 = outer_space;
167 top y6 = vround (1.5 staff_space - .5 stem);
168 bot y5 = -top y6 + feta_space_shift;
172 draw_gridline (z5, z6, stemwidth);
174 remember_pic := currentpicture;
176 draw_staff (-2, 2, 0);
181 fet_beginchar ("Sharp (3 beams)", "sharp.slashslashslash.stemstem");
182 save stem, stemx, stemwidth;
183 save outer_space, interbeam;
184 save sharp_beamheight;
186 sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
189 stemwidth# := stafflinethickness# + .05 staff_space#;
190 define_whole_blacker_pixels (stemwidth);
192 interbeam := 1.2 staff_space_rounded;
194 set_char_box (0, 1.1 staff_space#,
195 1.5 staff_space#, 1.5 staff_space#);
198 stemx := hround stem;
199 outer_space := hround ((w - stemx - stemwidth) / 2);
201 w := 2 outer_space + stemx + stemwidth;
202 d := d - feta_space_shift;
204 draw_meta_sharp (.88 w, -.5 interbeam);
205 draw_meta_sharp (w, 0);
206 draw_meta_sharp (.88 w, -.5 interbeam + vround interbeam);
208 pickup pencircle scaled stemwidth;
210 lft x5 = lft x6 = outer_space;
211 lft x7 = lft x8 = outer_space + stemx;
213 top y6 = vround (1.5 staff_space - stem * beamslope);
214 bot y7 = -top y6 + feta_space_shift;
219 draw_gridline (z5, z6, stemwidth);
220 draw_gridline (z7, z8, stemwidth);
222 remember_pic := currentpicture;
224 draw_staff (-2, 2, 0);
229 fet_beginchar ("1/2 Sharp (3 beams)", "sharp.slashslashslash.stem");
230 save stem, stemx, stemwidth;
231 save outer_space, interbeam;
232 save sharp_beamheight;
234 sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
236 stemwidth# := stafflinethickness# + .05 staff_space#;
237 define_whole_blacker_pixels (stemwidth);
239 interbeam := 1.2 staff_space_rounded;
241 set_char_box (0, 0.95 staff_space#,
242 1.3 staff_space#, 1.3 staff_space#);
245 outer_space := hround ((w - stemwidth) / 2);
246 w := 2 outer_space + stemwidth;
247 d := d - feta_space_shift;
249 draw_meta_sharp (.8 w, -.5 interbeam);
250 draw_meta_sharp (w, 0);
251 draw_meta_sharp (.8 w, -.5 interbeam + vround interbeam);
253 pickup pencircle scaled stemwidth;
255 lft x5 = lft x6 = outer_space;
256 top y6 = vround (1.5 staff_space - .5 stem);
257 bot y5 = -top y6 + feta_space_shift;
261 draw_gridline (z5, z6, stemwidth);
264 remember_pic := currentpicture;
266 draw_staff (-2, 2, 0);
272 fet_beginchar ("3/4 Sharp", "sharp.slashslash.stemstemstem");
273 save stem, stemx, stemwidth;
274 save outer_space, interbeam;
276 stemwidth# := stafflinethickness# + .05 staff_space#;
277 define_whole_blacker_pixels (stemwidth);
279 interbeam := 1.05 staff_space_rounded;
281 set_char_box (0, 1.6 staff_space#,
282 1.5 staff_space#, 1.5 staff_space#);
285 stemx := hround stem;
286 outer_space := hround ((w - 2 stemx - stemwidth) / 2);
288 w := 2 outer_space + 2 stemx + stemwidth;
289 d := d - feta_space_shift;
291 draw_meta_sharp (w, -.5 interbeam);
292 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
294 pickup pencircle scaled stemwidth;
296 lft x5 = lft x6 = outer_space;
297 lft x7 = lft x8 = outer_space + stemx;
298 lft x9 = lft x10 = outer_space + 2 stemx;
300 top y6 = vround (1.5 staff_space - 2 stem * beamslope);
301 bot y9 = -top y6 + feta_space_shift;
306 labels (5, 6, 7, 8, 9, 10);
308 draw_gridline (z5, z6, stemwidth);
309 draw_gridline (z7, z8, stemwidth);
310 draw_gridline (z9, z10, stemwidth);
312 remember_pic := currentpicture;
314 draw_staff (-2, 2, 0);
322 % The stems of the natural are brushed (at least, in Barenreiter SCS)
325 fet_beginchar ("Natural", "natural");
326 save stemwidth, top_stem_thick;
327 save ne, pat_top, pat_bottom;
329 path pat_top, pat_bottom;
331 top_stem_thick# = stafflinethickness# + .10 staff_space#;
332 stemwidth# = 0.09 staff_space# + .5 stafflinethickness#;
333 define_whole_blacker_pixels (top_stem_thick, stemwidth);
335 set_char_box (0, 2/3 staff_space#,
336 1.5 staff_space#, 1.5 staff_space#);
338 d := d - feta_space_shift;
340 pickup pencircle scaled stemwidth;
342 penpos1 (top_stem_thick, 0);
343 penpos3 (top_stem_thick, 0);
344 penpos2 (stemwidth, 0);
345 penpos4 (stemwidth, 0);
354 top y2 = vround (staff_space - 3/2 stafflinethickness);
355 y4 = -y2 + feta_space_shift;
357 pat_bottom := z4r{z4r - z1r}
360 fill simple_serif (z1l, z1r, -30)
364 pat_top := z2r{z2r - z3r}
367 fill simple_serif (z3l, z3r, 30)
371 ne = (x2 - x4, stafflinethickness);
373 z11' = z3l + whatever * (z2l - z3l);
374 y11' = vround (.5 (staff_space - stafflinethickness));
375 z11 = z11' + whatever * ne;
377 z12 = directionpoint -ne of pat_top;
378 z13 = z12 + whatever * ne;
380 z14 = z11 + whatever * ne;
383 z21' = z4r + whatever * (z1r - z4r);
384 y21' = -y11' + feta_space_shift;
385 z21 = z21' + whatever * ne;
387 z22 = directionpoint -ne of pat_bottom;
388 z23 = z22 + whatever * ne;
390 z24 = z21 + whatever * ne;
404 penlabels (1, 2, 3, 4);
405 labels (11, 11', 12, 13, 14, 21, 21', 22, 23, 24);
407 remember_pic := currentpicture;
409 draw_staff (-2, 2, 0);
416 % Dedicated to my mom. (3/10/97)
418 % Mamma, ik hou van je; kom je alsjeblieft terug?
422 % TODO: remove crook_fatness
423 % TODO: document, simplify!
426 def draw_meta_flat (expr xcenter, w, crook_fatness) =
428 save bottom_overshoot, bot_crook_dir;
429 save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
430 save top_crook_thinness;
433 pair center, bot_crook_dir;
438 % the stem shouldn't reach the top staff line.
439 %% TODO: should take from height.
441 % TODO: parameterize this
443 if w >= 0.75 staff_space:
444 smaller_hole = 0.35 stafflinethickness;
448 clearing = 1.7 stafflinethickness;
449 crook_thinness = .7 stafflinethickness + .06 staff_space;
450 top_crook_thinness = 1 stafflinethickness + .065 staff_space;
451 bottom_overshoot = stafflinethickness;
453 bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
454 top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
455 define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
457 if odd (top_stem_thick - bottom_stem_thick):
458 top_stem_thick := top_stem_thick - 1;
461 center = (xcenter, 0);
463 x1l = hround (xcenter - .5 top_stem_thick);
464 y1 = vround (2 staff_space - clearing);
465 x2l = hround (xcenter - .5 bottom_stem_thick);
466 y2 = -.5 staff_space - .5 stafflinethickness;
468 penpos1 (top_stem_thick, 0);
469 penpos2 (bottom_stem_thick, 0);
471 y3l = vfloor ((staff_space - stafflinethickness) / 2);
472 z3l = whatever [z2r, z1r];
473 z3r = .3 [z2r, z1r] + (smaller_hole, 0);
476 % we insert z3l to get better conversion with mf2pt1
477 fill simple_serif (z1r, z1l, 30)
483 z10 = whatever [z2r, z1r] + (smaller_hole, 0);
484 y10 = -1/10 staff_space;
487 x11 = xcenter + bottom_overshoot / 3;
488 y11 = -vround (.5 (staff_space + stafflinethickness)
491 penpos4 (whatever, 53);
493 y4l - y4r = top_crook_thinness;
494 y5r = .15 staff_space;
495 x5l = hround (w + xcenter);
496 y4 = staff_space / 2;
497 x4r = .45 [x5r, x3r];
500 penpos5 (crook_fatness, -175);
502 bot_crook_dir = unitvector ((x5l, 0) - z11);
503 z8 = z11 + whatever * bot_crook_dir;
504 y8 = -staff_space / 2;
507 + whatever * bot_crook_dir
508 + crook_thinness * (bot_crook_dir rotated 90);
511 unfill z3r{z3r - z10}
514 .. z7{-bot_crook_dir}
530 % unfortunately, 600dpi is not enough to show the brush of the stem.
533 fet_beginchar ("Flat", "flat");
534 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
535 0.6 staff_space#, 1.9 staff_space#);
537 draw_meta_flat (0, w, 0.31 staff_space);
538 penlabels (range 0 thru 11);
540 remember_pic := currentpicture;
542 draw_staff (-2, 2, 0);
547 fet_beginchar ("Flat (slashed)", "flat.slash");
548 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
549 0.6 staff_space#, 1.9 staff_space#);
551 draw_meta_flat (0, w, 0.31 staff_space);
553 save slope, slash_width;
557 z2 = z1 - (slash_width, slash_width * slope)/2;
558 z3 = z1 + (slash_width, slash_width * slope)/2;
560 pickup pencircle scaled 1.5 stafflinethickness;
563 remember_pic := currentpicture;
565 draw_staff (-2, 2, 0);
568 fet_beginchar ("Flat (slashed twice)", "flat.slashslash");
569 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
570 0.6 staff_space#, 1.9 staff_space#);
572 draw_meta_flat (0, w, 0.31 staff_space);
574 save slope, slash_width;
578 pickup pencircle scaled 1.5 stafflinethickness;
582 draw z1 - (slash_width, slash_width * slope)/2
583 .. z1 + (slash_width, slash_width * slope)/2;
584 draw z2 - (slash_width, slash_width * slope)/2
585 .. z2 + (slash_width, slash_width * slope)/2;
587 remember_pic := currentpicture;
589 draw_staff (-2, 2, 0);
592 fet_beginchar ("Flatflat (mirrored)", "mirroredflat.flat");
593 set_char_box (0, 1.6 staff_space#,
594 0.6 staff_space#, 1.9 staff_space#);
596 draw_meta_flat (0, w/2, 0.31 staff_space);
597 currentpicture := currentpicture xscaled -1;
598 draw_meta_flat (0, w/2, 0.31 staff_space);
600 currentpicture := currentpicture shifted (w/2,0);
601 penlabels (range 0 thru 11);
603 remember_pic := currentpicture;
605 draw_staff (-2, 2, 0);
612 fet_beginchar ("Semi flat", "mirroredflat");
613 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
614 0.6 staff_space#, 1.9 staff_space#);
616 draw_meta_flat (0, w, 0.31 staff_space);
617 currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
621 fet_beginchar ("Double Flat", "flatflat");
622 save left_wid, overlap, right_wid;
628 set_char_box (1.2 stafflinethickness#,
629 (left_wid + right_wid - overlap) * staff_space#,
630 .6 staff_space#, 1.9 staff_space#);
631 draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
632 draw_meta_flat (round ((left_wid - overlap) * staff_space),
633 right_wid * staff_space, 0.33 staff_space);
637 fet_beginchar ("3/4 Flat", "flatflat.slash");
638 save left_wid, overlap, right_wid;
644 set_char_box (1.2 stafflinethickness#,
645 (left_wid + right_wid - overlap) * staff_space#,
646 .6 staff_space#, 1.9 staff_space#);
647 draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
648 draw_meta_flat (round ((left_wid - overlap) * staff_space),
649 right_wid * staff_space, 0.33 staff_space);
651 %% maybe we should clip part of the stems?
652 %% or make the 1st flat smaller?
654 pickup pencircle scaled 2 stafflinethickness;
656 z12 = round (-.25 w - b, .55 staff_space) + feta_offset;
657 z13 = round (.75 w, 1.45 staff_space) + feta_offset;
658 penpos12 (2 stafflinethickness, angle (z13 - z12) - 90);
659 penpos13 (2 stafflinethickness, angle (z13 - z12) - 90);
661 z14 = z12 - stafflinethickness * unitvector (z13 - z12);
662 z15 = z13 + stafflinethickness * unitvector (z13 - z12);
676 remember_pic := currentpicture;
678 draw_staff (-2, 2, 0);
683 fet_beginchar ("Double Sharp", "doublesharp");
684 save klaverblad, klaversteel;
688 klaversteel = 1/15 staff_space;
689 klaverblad = .4 staff_space - .5 stafflinethickness;
691 set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
693 z1 = (klaversteel, 0);
694 z2 = (w / 2 - klaverblad / 10, h - klaverblad);
696 z4 = z2 reflectedabout ((0, 0), (1, 1));
697 z5 = z1 reflectedabout ((0, 0), (1, 1));
699 labels (1, 2, 3, 4, 5);
701 pickup pencircle scaled blot_diameter;
703 x2 := hfloor (rt x2) - blot_diameter / 2;
704 x3 := hfloor (rt x3) - blot_diameter / 2;
705 y3 := vfloor (top y3) - blot_diameter / 2;
706 y4 := vfloor (top y4) - blot_diameter / 2;
715 .. {dir 225}(top z5);
717 -- reverse pat xscaled -1 shifted (-feta_eps, 0);
719 % assure symmetry -- it's more important to center the glyph on the
720 % staff line than centering it between staff lines, so we use
721 % feta_shift, not feta_space_shift.
724 fill pat shifted (0, feta_shift)
725 -- reverse pat yscaled -1 shifted (0, -feta_eps)
729 currentpicture := currentpicture shifted (hround (w / 2), 0);
731 remember_pic := currentpicture;
733 draw_staff (-2, 2, 0);
741 leftindent := .2 staff_space;
743 set_char_box (0, .5 staff_space# + stafflinethickness#,
744 staff_space#, staff_space#);
748 z1 = (leftindent, h);
749 z2 = (w - stafflinethickness, .5 (h - d));
750 z3 = (leftindent, -d);
752 penpos1 (stafflinethickness, 35);
753 penpos2 (.1 staff_space + stafflinethickness, 0);
754 penpos3 (stafflinethickness, -35);
757 .. simple_serif (z3l, z3r, 90)
759 .. simple_serif (z1r, z1l, 90)
765 fet_beginchar ("Right Parenthesis", "rightparen");
769 remember_pic := currentpicture;
771 draw_staff (-2, 2, 0);
777 fet_beginchar ("Left Parenthesis", "leftparen");
780 currentpicture := currentpicture xscaled -1;
782 set_char_box (charwd, charbp, chardp, charht);
785 fet_endgroup ("accidentals");