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);
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):
38 % mirroredflat.flat.slashslash
39 % sharp.slashslash.stemstem (the standard sharp sign)
43 fet_begingroup ("accidentals");
49 save sharp_beamheight;
50 sharp_beamheight# := 0.3 staff_space# + stafflinethickness#;
53 % The beams of most sharps have horizontal endings (as if drawn with
54 % a square pen). [Wanske] does not mention this, so we'll just ignore
58 def draw_meta_sharp (expr width, offset) =
59 save beamwidth, beamslope;
65 define_whole_vertical_blacker_pixels (sharp_beamheight);
69 beamslope = sharp_beamheight / beamwidth;
71 pickup pencircle scaled 2 blot_diameter;
73 rt x2 - lft x1 = beamwidth;
74 y2 - y1 = sharp_beamheight;
75 .5 [z1, z3] = (.5 w, offset);
77 top y2 - bot y3 = sharp_beamheight;
79 top y1 - bot y4 = sharp_beamheight;
81 ne = unitvector (z2 - z1);
82 nw_dist = (ne rotated 90) * blot_diameter;
85 ... (z1 + nw_dist){ne}
89 ... (z3 - nw_dist){-ne}
90 -- (z4 - nw_dist){-ne}
98 fet_beginchar ("Sharp", "sharp");
99 save stem, stemx, stemwidth;
100 save outer_space, interbeam;
102 stemwidth# := stafflinethickness# + .05 staff_space#;
103 define_whole_blacker_pixels (stemwidth);
105 interbeam := 1.05 staff_space_rounded;
107 set_char_box (0, 1.1 staff_space#,
108 1.5 staff_space#, 1.5 staff_space#);
111 stemx := hround stem;
112 outer_space := hround ((w - stemx - stemwidth) / 2);
114 w := 2 outer_space + stemx + stemwidth;
115 d := d - feta_space_shift;
117 draw_meta_sharp (w, -.5 interbeam);
118 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
120 pickup pencircle scaled stemwidth;
122 lft x5 = lft x6 = outer_space;
123 lft x7 = lft x8 = outer_space + stemx;
125 top y6 = vround (1.5 staff_space - stem * beamslope);
126 bot y7 = -top y6 + feta_space_shift;
131 draw_gridline (z5, z6, stemwidth);
132 draw_gridline (z7, z8, stemwidth);
134 remember_pic := currentpicture;
136 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);
183 fet_beginchar ("Sharp (3 beams)", "sharp.slashslashslash.stemstem");
184 save stem, stemx, stemwidth;
185 save outer_space, interbeam;
186 save sharp_beamheight;
188 sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
191 stemwidth# := stafflinethickness# + .05 staff_space#;
192 define_whole_blacker_pixels (stemwidth);
194 interbeam := 1.2 staff_space_rounded;
196 set_char_box (0, 1.1 staff_space#,
197 1.5 staff_space#, 1.5 staff_space#);
200 stemx := hround stem;
201 outer_space := hround ((w - stemx - stemwidth) / 2);
203 w := 2 outer_space + stemx + stemwidth;
204 d := d - feta_space_shift;
206 draw_meta_sharp (.88 w, -.5 interbeam);
207 draw_meta_sharp (w, 0);
208 draw_meta_sharp (.88 w, -.5 interbeam + vround interbeam);
210 pickup pencircle scaled stemwidth;
212 lft x5 = lft x6 = outer_space;
213 lft x7 = lft x8 = outer_space + stemx;
215 top y6 = vround (1.5 staff_space - stem * beamslope);
216 bot y7 = -top y6 + feta_space_shift;
221 draw_gridline (z5, z6, stemwidth);
222 draw_gridline (z7, z8, stemwidth);
224 remember_pic := currentpicture;
226 draw_staff (-2, 2, 0);
233 fet_beginchar ("1/2 Sharp (3 beams)", "sharp.slashslashslash.stem");
234 save stem, stemx, stemwidth;
235 save outer_space, interbeam;
236 save sharp_beamheight;
238 sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
240 stemwidth# := stafflinethickness# + .05 staff_space#;
241 define_whole_blacker_pixels (stemwidth);
243 interbeam := 1.2 staff_space_rounded;
245 set_char_box (0, 0.95 staff_space#,
246 1.3 staff_space#, 1.3 staff_space#);
249 outer_space := hround ((w - stemwidth) / 2);
251 w := 2 outer_space + stemwidth;
252 d := d - feta_space_shift;
254 draw_meta_sharp (.8 w, -.5 interbeam);
255 draw_meta_sharp (w, 0);
256 draw_meta_sharp (.8 w, -.5 interbeam + vround interbeam);
258 pickup pencircle scaled stemwidth;
260 lft x5 = lft x6 = outer_space;
261 top y6 = vround (1.5 staff_space - .5 stem);
262 bot y5 = -top y6 + feta_space_shift;
265 draw_gridline (z5, z6, stemwidth);
267 remember_pic := currentpicture;
269 draw_staff (-2, 2, 0);
276 fet_beginchar ("3/4 Sharp", "sharp.slashslash.stemstemstem");
277 save stem, stemx, stemwidth;
278 save outer_space, interbeam;
280 stemwidth# := stafflinethickness# + .05 staff_space#;
281 define_whole_blacker_pixels (stemwidth);
283 interbeam := 1.05 staff_space_rounded;
285 set_char_box (0, 1.6 staff_space#,
286 1.5 staff_space#, 1.5 staff_space#);
289 stemx := hround stem;
290 outer_space := hround ((w - 2 stemx - stemwidth) / 2);
292 w := 2 outer_space + 2 stemx + stemwidth;
293 d := d - feta_space_shift;
295 draw_meta_sharp (w, -.5 interbeam);
296 draw_meta_sharp (w, -.5 interbeam + vround interbeam);
298 pickup pencircle scaled stemwidth;
300 lft x5 = lft x6 = outer_space;
301 lft x7 = lft x8 = outer_space + stemx;
302 lft x9 = lft x10 = outer_space + 2 stemx;
304 top y6 = vround (1.5 staff_space - 2 stem * beamslope);
305 bot y9 = -top y6 + feta_space_shift;
310 labels (5, 6, 7, 8, 9, 10);
312 draw_gridline (z5, z6, stemwidth);
313 draw_gridline (z7, z8, stemwidth);
314 draw_gridline (z9, z10, stemwidth);
316 remember_pic := currentpicture;
318 draw_staff (-2, 2, 0);
326 % The stems of the natural are brushed (at least, in Barenreiter SCS)
329 fet_beginchar ("Natural", "natural");
330 save stemwidth, top_stem_thick;
331 save ne, pat_top, pat_bottom;
333 path pat_top, pat_bottom;
335 top_stem_thick# = stafflinethickness# + .10 staff_space#;
336 stemwidth# = 0.09 staff_space# + .5 stafflinethickness#;
337 define_whole_blacker_pixels (top_stem_thick, stemwidth);
339 set_char_box (0, 2/3 staff_space#,
340 1.5 staff_space#, 1.5 staff_space#);
342 d := d - feta_space_shift;
344 pickup pencircle scaled stemwidth;
346 penpos1 (top_stem_thick, 0);
347 penpos3 (top_stem_thick, 0);
348 penpos2 (stemwidth, 0);
349 penpos4 (stemwidth, 0);
358 top y2 = vround (staff_space - 3/2 stafflinethickness);
359 y4 = -y2 + feta_space_shift;
361 pat_bottom := z4r{z4r - z1r}
364 fill simple_serif (z1l, z1r, -30)
368 pat_top := z2r{z2r - z3r}
371 fill simple_serif (z3l, z3r, 30)
375 ne = (x2 - x4, stafflinethickness);
377 z11' = z3l + whatever * (z2l - z3l);
378 y11' = vround (.5 (staff_space - stafflinethickness));
379 z11 = z11' + whatever * ne;
381 z12 = directionpoint -ne of pat_top;
382 z13 = z12 + whatever * ne;
384 z14 = z11 + whatever * ne;
387 z21' = z4r + whatever * (z1r - z4r);
388 y21' = -y11' + feta_space_shift;
389 z21 = z21' + whatever * ne;
391 z22 = directionpoint -ne of pat_bottom;
392 z23 = z22 + whatever * ne;
394 z24 = z21 + whatever * ne;
408 penlabels (1, 2, 3, 4);
409 labels (11, 11', 12, 13, 14, 21, 21', 22, 23, 24);
411 remember_pic := currentpicture;
413 draw_staff (-2, 2, 0);
421 % Dedicated to my mom. (3/10/97)
423 % Mamma, ik hou van je; kom je alsjeblieft terug?
427 % TODO: remove crook_fatness
428 % TODO: document, simplify!
431 def draw_meta_flat (expr xcenter, w, crook_fatness) =
433 save bottom_overshoot, bot_crook_dir;
434 save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
435 save top_crook_thinness;
438 pair center, bot_crook_dir;
443 % the stem shouldn't reach the top staff line.
444 %% TODO: should take from height.
446 % TODO: parameterize this
448 if w >= 0.75 staff_space:
449 smaller_hole = 0.35 stafflinethickness;
453 clearing = 1.7 stafflinethickness;
454 crook_thinness = .7 stafflinethickness + .06 staff_space;
455 top_crook_thinness = 1 stafflinethickness + .065 staff_space;
456 bottom_overshoot = stafflinethickness;
458 bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
459 top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
460 define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
462 if odd (top_stem_thick - bottom_stem_thick):
463 top_stem_thick := top_stem_thick - 1;
466 center = (xcenter, 0);
468 x1l = hround (xcenter - .5 top_stem_thick);
469 y1 = vround (2 staff_space - clearing);
470 x2l = hround (xcenter - .5 bottom_stem_thick);
471 y2 = -.5 staff_space - .5 stafflinethickness;
473 penpos1 (top_stem_thick, 0);
474 penpos2 (bottom_stem_thick, 0);
476 y3l = vfloor ((staff_space - stafflinethickness) / 2);
477 z3l = whatever [z2r, z1r];
478 z3r = .3 [z2r, z1r] + (smaller_hole, 0);
481 % we insert z3l to get better conversion with mf2pt1
482 fill simple_serif (z1r, z1l, 30)
488 z10 = whatever [z2r, z1r] + (smaller_hole, 0);
489 y10 = -1/10 staff_space;
492 x11 = xcenter + bottom_overshoot / 3;
493 y11 = -vround (.5 (staff_space + stafflinethickness)
496 penpos4 (whatever, 53);
498 y4l - y4r = top_crook_thinness;
499 y5r = .15 staff_space;
500 x5l = hround (w + xcenter);
501 y4 = staff_space / 2;
502 x4r = .45 [x5r, x3r];
505 penpos5 (crook_fatness, -175);
507 bot_crook_dir = unitvector ((x5l, 0) - z11);
508 z8 = z11 + whatever * bot_crook_dir;
509 y8 = -staff_space / 2;
512 + whatever * bot_crook_dir
513 + crook_thinness * (bot_crook_dir rotated 90);
516 unfill z3r{z3r - z10}
519 .. z7{-bot_crook_dir}
535 % unfortunately, 600dpi is not enough to show the brush of the stem.
538 fet_beginchar ("Flat", "flat");
539 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
540 0.6 staff_space#, 1.9 staff_space#);
542 draw_meta_flat (0, w, 0.31 staff_space);
543 penlabels (range 0 thru 11);
545 remember_pic := currentpicture;
547 draw_staff (-2, 2, 0);
554 fet_beginchar ("Flat (slashed)", "flat.slash");
555 set_char_box (.4 staff_space#, .8 staff_space#,
556 0.6 staff_space#, 1.9 staff_space#);
558 draw_meta_flat (0, w, 0.31 staff_space);
562 save slope, slash_width;
567 z2 = z1 - (slash_width, slash_width * slope) / 2;
568 z3 = z1 + (slash_width, slash_width * slope) / 2;
570 pickup pencircle scaled 1.5 stafflinethickness;
573 remember_pic := currentpicture;
575 draw_staff (-2, 2, 0);
579 fet_beginchar ("Flat (slashed twice)", "flat.slashslash");
580 set_char_box (.4 staff_space#, .8 staff_space#,
581 0.6 staff_space#, 1.9 staff_space#);
583 draw_meta_flat (0, w, 0.31 staff_space);
587 save slope, slash_width;
594 pickup pencircle scaled 1.5 stafflinethickness;
595 draw z1 - (slash_width, slash_width * slope) / 2
596 .. z1 + (slash_width, slash_width * slope) / 2;
597 draw z2 - (slash_width, slash_width * slope) / 2
598 .. z2 + (slash_width, slash_width * slope) / 2;
600 remember_pic := currentpicture;
602 draw_staff (-2, 2, 0);
606 fet_beginchar ("Flatflat (mirrored)", "mirroredflat.flat");
607 set_char_box (0, 1.6 staff_space#,
608 0.6 staff_space#, 1.9 staff_space#);
610 draw_meta_flat (0, w/2, 0.31 staff_space);
611 currentpicture := currentpicture xscaled -1;
612 draw_meta_flat (0, w/2, 0.31 staff_space);
614 currentpicture := currentpicture shifted (w/2, 0);
615 penlabels (range 0 thru 11);
617 remember_pic := currentpicture;
619 draw_staff (-2, 2, 0);
626 fet_beginchar ("Semi flat", "mirroredflat");
627 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
628 0.6 staff_space#, 1.9 staff_space#);
630 draw_meta_flat (0, w, 0.31 staff_space);
631 currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
635 fet_beginchar ("Semi flat", "mirroredflat.backslash");
636 set_char_box (.4 staff_space#, .8 staff_space#,
637 0.6 staff_space#, 1.9 staff_space#);
639 draw_meta_flat (0, w, 0.31 staff_space);
643 save slope, slash_width;
648 z2 = z1 - (slash_width, slash_width * slope) / 2;
649 z3 = z1 + (slash_width, slash_width * slope) / 2;
651 pickup pencircle scaled 1.5 stafflinethickness;
654 currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
660 fet_beginchar ("Double Flat", "flatflat");
661 save left_wid, overlap, right_wid;
667 set_char_box (1.2 stafflinethickness#,
668 (left_wid + right_wid - overlap) * staff_space#,
669 .6 staff_space#, 1.9 staff_space#);
670 draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
671 draw_meta_flat (round ((left_wid - overlap) * staff_space),
672 right_wid * staff_space, 0.33 staff_space);
676 fet_beginchar ("3/4 Flat", "flatflat.slash");
677 save left_wid, overlap, right_wid;
683 set_char_box (1.2 stafflinethickness#,
684 (left_wid + right_wid - overlap) * staff_space#,
685 .6 staff_space#, 1.9 staff_space#);
686 draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
687 draw_meta_flat (round ((left_wid - overlap) * staff_space),
688 right_wid * staff_space, 0.33 staff_space);
690 %% maybe we should clip part of the stems?
691 %% or make the 1st flat smaller?
693 pickup pencircle scaled 2 stafflinethickness;
695 z12 = round (-.25 w - b, .55 staff_space) + feta_offset;
696 z13 = round (.75 w, 1.45 staff_space) + feta_offset;
697 penpos12 (2 stafflinethickness, angle (z13 - z12) - 90);
698 penpos13 (2 stafflinethickness, angle (z13 - z12) - 90);
700 z14 = z12 - stafflinethickness * unitvector (z13 - z12);
701 z15 = z13 + stafflinethickness * unitvector (z13 - z12);
715 remember_pic := currentpicture;
717 draw_staff (-2, 2, 0);
724 fet_beginchar ("Double Sharp", "doublesharp");
725 save klaverblad, klaversteel;
729 klaversteel = 1/15 staff_space;
730 klaverblad = .4 staff_space - .5 stafflinethickness;
732 set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
734 z1 = (klaversteel, 0);
735 z2 = (w / 2 - klaverblad / 10, h - klaverblad);
737 z4 = z2 reflectedabout ((0, 0), (1, 1));
738 z5 = z1 reflectedabout ((0, 0), (1, 1));
740 labels (1, 2, 3, 4, 5);
742 pickup pencircle scaled blot_diameter;
744 x2 := hfloor (rt x2) - blot_diameter / 2;
745 x3 := hfloor (rt x3) - blot_diameter / 2;
746 y3 := vfloor (top y3) - blot_diameter / 2;
747 y4 := vfloor (top y4) - blot_diameter / 2;
756 .. {dir 225}(top z5);
758 -- reverse pat xscaled -1 shifted (-feta_eps, 0);
760 % assure symmetry -- it's more important to center the glyph on the
761 % staff line than centering it between staff lines, so we use
762 % feta_shift, not feta_space_shift.
765 fill pat shifted (0, feta_shift)
766 -- reverse pat yscaled -1 shifted (0, -feta_eps)
770 currentpicture := currentpicture shifted (hround (w / 2), 0);
772 remember_pic := currentpicture;
774 draw_staff (-2, 2, 0);
784 leftindent := .2 staff_space;
786 set_char_box (0, .5 staff_space# + stafflinethickness#,
787 staff_space#, staff_space#);
791 z1 = (leftindent, h);
792 z2 = (w - stafflinethickness, .5 (h - d));
793 z3 = (leftindent, -d);
795 penpos1 (stafflinethickness, 35);
796 penpos2 (.1 staff_space + stafflinethickness, 0);
797 penpos3 (stafflinethickness, -35);
800 .. simple_serif (z3l, z3r, 90)
802 .. simple_serif (z1r, z1l, 90)
808 fet_beginchar ("Right Parenthesis", "rightparen");
812 remember_pic := currentpicture;
814 draw_staff (-2, 2, 0);
821 fet_beginchar ("Left Parenthesis", "leftparen");
824 currentpicture := currentpicture xscaled -1;
826 set_char_box (charwd, charbp, chardp, charht);
829 fet_endgroup ("accidentals");