1 % Feta (not the Font-En-Tja) music font -- implement Clefs -*-Fundamental-*-
2 % This file is part of LilyPond, the GNU music typesetter.
4 % Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>,
5 % Jan Nieuwenhuizen <janneke@gnu.org>,
6 % Juergen Reuter <reuter@ipd.uka.de>
8 % LilyPond is free software: you can redistribute it and/or modify
9 % it under the terms of the GNU General Public License as published by
10 % the Free Software Foundation, either version 3 of the License, or
11 % (at your option) any later version.
13 % LilyPond is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU General Public License for more details.
18 % You should have received a copy of the GNU General Public License
19 % along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 fet_begingroup ("clefs");
25 % [Wanske] says the bulbs should be positioned about 1/4 right of the
28 % TODO: The hair-curve at z6r looks a little awkward.
31 def draw_c_clef (expr reduction) =
32 save hair, norm, reduced_ss, right_edge;
35 reduced_ss# = staff_space# * reduction;
36 norm# := 2/3 reduced_ss#;
37 hair# := 0.06 reduced_ss# + 0.5 linethickness#;
38 right_edge# = 15/4 norm# + 2 hair#;
39 define_pixels (norm, reduced_ss, right_edge);
40 define_whole_vertical_blacker_pixels (hair);
42 set_char_box (0, right_edge#, 2 reduced_ss#, 2 reduced_ss#);
44 % make unreduced glyph fit exactly into five staff lines
46 h := d := 2 staff_space_rounded;
49 % assure that the gap between the left and right stem
50 % has the same number of pixels as the thickness of the right
52 draw_block ((0, -d + feta_shift),
53 (3/4 norm + 1/2 hair, h));
54 draw_block ((3/4 norm + 1/2 hair + hround (3/2 hair), -d + feta_shift),
55 (3/4 norm + 1/2 hair + 2 hround (3/2 hair), h));
62 xoff = 3/4 norm + 1/2 hair + 2 hround (3/2 hair);
63 z5l = (xoff - 3/4 hair, 0);
66 penpos1 (hair - pen_top - pen_bot, -90);
67 top z1l = (xoff + norm + hair, h);
69 penpos2 (hround (norm - 3/2 hair) - pen_lft - pen_rt, 180);
72 penpos3 (hair - pen_top - pen_bot, 90);
73 bot z3l = ((right_edge - xoff) / 2 + xoff,
74 vround (.5 norm - 1.5 hair));
76 penpos4 (hair - pen_lft - pen_rt, 0);
77 top z4 = (xoff + 1/2 norm + 1/2 hair,
78 vfloor (reduced_ss - linethickness - .2 hair));
80 bot z6 = (xoff + 3/4 norm, vround (.5 norm - .5 hair));
93 ..tension t.. flare_path (top z1l, 180, 90,
94 hair, hfloor (norm - 1/2 hair), -1)
95 ..tension t.. z2l{down}
100 filldraw pat shifted (0, feta_shift)
101 -- reverse pat yscaled -1 shifted (0, -feta_eps)
104 penlabels (1, 2, 3, 4, 5, 6);
106 % ugh, should be bulb, not flare?
108 draw_staff (-2, 2, 0);
112 fet_beginchar ("C clef", "C");
117 fet_beginchar ("C clef", "C_change");
125 % Insert a brushed piece of the path, and draw the rest of the bulb
128 % The bulb has circular form. Neat merging of the bulb and brushed path
129 % is done by playing with tension.
132 def new_bulb (expr start_point, start_angle,
134 end_point, end_angle,
135 big_radius, bulb_radius, flare,
136 direction, turning_dir) =
138 save pat, before, after;
141 path pat, before, after;
146 center = outer_tangent_point
147 + big_radius * dir (0);
148 % + (big_radius - bulb_radius) * dir (-turning_dir * 90)
150 z1' = center + bulb_radius * dir (turning_dir * 180);
151 z2' = outer_tangent_point + flare * dir (0);
152 z3' = center + bulb_radius * dir (0);
153 z4' = center + bulb_radius * dir (turning_dir * 90);
154 z5' = center - 0.5 [big_radius, bulb_radius] * dir (turning_dir * 90);
156 labels (1', 2', 3', 4', 5');
158 before := z3'{dir (turning_dir * 90)}
160 ..tension 1.1.. z1'{-dir (turning_dir* 90)};
161 after := z2'{dir (turning_dir * 90)}
162 .. end_point{dir (end_angle)};
163 (u, v) = before intersectiontimes after;
165 pat := start_point{dir (start_angle)}
166 .. outer_tangent_point{dir (-turning_dir * 90)}
167 ..tension 1.02.. z5'{dir (0)}
168 .. subpath (0, u) of before
169 .. subpath (v, infinity) of after;
181 % There is some variation in the shape of bass clefs.
183 % * In some clefs the size of the swoosh tip almost reaches the
184 % bottom staff line; in some it crosses the 2nd line from the bottom
185 % with a small overshoot.
187 % The most popular design is where the X part of the tip is aligned
188 % with the left bulb boundary, and the Y part ends on the 2nd
189 % staffline exactly. This is what we do.
191 % * The diameter of the bulb is the width of the open space.
193 % * The vertical center of the bulb can be on or slightly above the
196 % * The vertical position of the dots can be symmetrical around the
197 % staffline, centered in the staff space. The Baerenreiter SCS has
198 % the bottom dot raised by approximately 0.1 staff space.
200 % * Uncarefully set music may have overshoots at the top. We have none.
202 % * It is not exactly clear where the vertical tangent at the right
203 % of the swoosh should be.
206 def draw_bass_clef (expr exact_center, reduction) =
207 save reduced_ss, swoosh_width;
208 save right_thickness, right_offset, tip_protrude;
209 save dot_diam, bulb_y_offset, bulb_flare;
212 reduced_ss# = staff_space# * reduction;
213 2.2 dot_diam# = reduction * (staff_space# - stafflinethickness#);
214 right_thickness# = 0.37 staff_space# + 1.2 linethickness#;
215 swoosh_width# = 2.1 reduced_ss#;
216 define_pixels (swoosh_width);
217 define_whole_pixels (reduced_ss);
218 define_whole_blacker_pixels (dot_diam, right_thickness);
220 right_offset = 0.05 staff_space;
221 bulb_y_offset := 0.075 staff_space;
222 bulb_flare := 2.5 linethickness;
223 % tip_protrude := (-linethickness, -.2 staff_space);
224 tip_protrude := (0, 0);
226 set_char_box (-xpart exact_center,
227 xpart exact_center + swoosh_width# + 7/12 reduced_ss#,
228 -ypart exact_center + 2.5 reduced_ss#,
229 ypart exact_center + reduced_ss#);
237 y2l := vround_pixels (reduced_ss# + 0.5 linethickness#);
238 y2l - y2r = linethickness;
240 x3l - x1 = swoosh_width;
241 x3l - x3r = right_thickness;
243 % optical correction: the top dot seems farther away if y3l = 0.
246 z4 = -(0, 2.0 reduced_ss) + tip_protrude;
248 penpos3 (whatever, 185);
249 penpos4 (linethickness, 135);
251 fill new_bulb (z2l, 180, z1, z2r, 0,
252 0.45 reduced_ss, 0.4 reduced_ss,
255 .. {curl 0}simple_serif (z4r, z4l, 90){curl 0}
257 ..tension 0.9.. cycle;
259 pickup pencircle scaled dot_diam;
261 lft x5 = hround (x3l + 1/3 reduced_ss - dot_diam / 2);
262 bot y5 = vfloor (.5 reduced_ss - dot_diam / 2);
266 y5 := y5 + feta_shift;
271 penlabels (1, 2, 3, 4, 5, 6);
273 draw_staff (-3, 1, 0);
277 fet_beginchar ("F clef ", "F");
278 draw_bass_clef ((0, 0), 1.0);
282 fet_beginchar ("F clef (reduced)", "F_change");
283 draw_bass_clef ((0, 0), 0.8);
289 % Inspired by Baerenreiter
292 % Beste lezers, kijk,
294 % Een bolletje hebben we bij toeval allemaal wel eens getekend, maar begint u
295 % toch eenvoudig. Eerst een eenvoudig kruis of herstellingsteken
296 % en via de dubbelslag naar een voorzichtig vlaggetje, en heb geduld!
297 % Ikzelf heb bijvoorbeeld over mijn eerste gave G-sleutel
298 % 35 kilobyte metafont, 12 patchlevels, 0 vriendinnen en 45 dagen gedaan
300 % -- vrij naar Van Kooten & De Bie
303 def debugfill = fill enddef;
305 def draw_gclef (expr reduction) =
306 save reduced_ss, downstroke_dir, downstroke_angle, center;
307 save breapth_factor, inner_thick_end, thinness, thickness, thinnib;
308 save start_angle, inner_start_angle;
309 save upward_swoosh_angle, bot_angle;
311 save corr_angle, corr, left_, right_, up_, down_, bot_angle_;
313 pair downstroke_dir, center;
315 pair left_, right_, up_, down_;
317 reduced_ss# = staff_space# * reduction;
318 define_pixels (reduced_ss);
320 % G clef has now a smaller upper loop than it used to have.
321 % Too small loop in reduced clef (G_change) interacts badly
322 % with stafflines, so we make reduced clef's loop a bit bigger.
323 reduced_loop_correction := min (max (0.94, (0.6 + 0.46 * reduction)), 1);
325 thinness = 0.095 staff_space + 0.75 linethickness;
326 downstroke_dir = unitvector (14, -75);
327 downstroke_angle = angle downstroke_dir;
328 bot_angle = -180; % downstroke_angle - 87
330 upward_swoosh_angle = 132;
333 breapth_factor = 21/14;
334 inner_thick_end = 45;
335 inner_start_angle = downstroke_angle - 43;
336 thickness = .33 reduced_ss + 1.1 linethickness;
340 set_char_box (0, 1.71 * breapth_factor * reduced_ss#,
341 2.55 * reduced_ss#, 4.8 * reduced_ss# / reduced_loop_correction);
343 center := (breapth_factor * reduced_ss, 0);
345 z1 = center + whatever * dir (inner_start_angle);
346 x1 = xpart center - .28 reduced_ss;
347 penpos1 (thinnib, inner_start_angle);
350 y2r = vround_pixels (reduced_ss# + .5 stafflinethickness#);
351 penpos2 (thickness, 90);
353 z3 = (z4 - center) rotated inner_thick_end + center;
354 penpos3 (thinnib, -90 + inner_thick_end);
356 x4 = xpart center - .1 reduced_ss;
357 y4r = -y2r + feta_shift;
358 penpos4 (thinnib, -90);
360 x5r = -breapth_factor * reduced_ss + xpart center;
361 y5r = .37 reduced_ss + ypart center;
362 penpos5 (thickness, upward_swoosh_angle);
364 z6 = center + whatever * downstroke_dir + (-0.02, 0) * reduced_ss;
365 y6 = ypart center + 1.95 reduced_ss / reduced_loop_correction;
366 % penpos6 is computed later
368 z7l - z6 = whatever * (z5 - z6);
369 y7l = 3.38 reduced_ss / reduced_loop_correction;
370 penpos7 (thickness, upward_swoosh_angle);
373 top y9l = 4.78 reduced_ss / reduced_loop_correction;
374 penpos9 (1.45 thickness, -70);
376 x11 - x13r = 1.44 * reduced_ss + 0.5 thinnib;
377 y11 = ypart center - 45/28 reduced_ss;
378 y12 = ypart center - 69/28 reduced_ss;
379 y13 = .48 [y12, y4r];
380 x12r = xpart (.45 [z13r, z11] + .75 reduced_ss * downstroke_dir);
382 % z10 = center + whatever * dir (downstroke_angle - 1.5);
383 x10 = x6 - 1.85 thinnib * reduction / reduced_loop_correction;
384 y10 = ypart center + 3.32 reduced_ss / reduced_loop_correction;
385 y10l - y10r = 1.0 thickness;
386 z10r - z10l = .7 thinnib * dir (downstroke_angle + 90)
387 + whatever * downstroke_dir;
388 z10 = .5 [z10l, z10r];
389 z11 = center + whatever * downstroke_dir + (0.03 reduced_ss, 0);
391 penpos11 (thinnib, start_angle + 90);
392 penpos12 (thinnib, bot_angle + 90);
393 penpos13 (thinnib + 0.14 staff_space, 180);
395 % this auxiliary point ensures good contour overlapping
396 z8 = .5 [z9l, z9r] + .25 ((z9r - z9l) rotated -90);
398 z20 = z9l - (0, .25 blot_diameter);
399 penpos20 (blot_diameter, 0);
403 ..tension 1.1.. z11{dir (start_angle)};
405 penpos6 (thinnib, angle (direction 1 of pat) + 90);
407 % two auxiliary points to simulate `draw' with `penstroke'
408 z10' = point 0.3 of pat;
409 penpos10' (1.3 thinnib, angle (direction 0.3 of pat) + 50);
411 z11' = point 1.5 of pat + (0.033, -0.5) * reduced_ss;
412 penpos11' (thinnib, angle (direction 1.5 of pat) + 90);
417 % after computing all points, we want to rotate the clef
418 % rotating the whole picture won't work due to the complexity
419 % of the path and metafont's memory limitations, so we transform
420 % each point and draw the clef thereafter
422 corr := identity rotatedabout (center, -corr_angle);
424 bot_angle_ := bot_angle + corr_angle;
426 left_ := left rotated corr_angle;
427 right_ := right rotated corr_angle;
428 up_ := up rotated corr_angle;
429 down_ := down rotated corr_angle;
431 % transform points; we transform every point and save it
432 % to a shifted index range: z1 -> z101, z2 -> z102, etc.
434 forsuffixes e := l,,r:
435 z[n+100]e = z[n]e transformed corr;
439 % transform helper points
441 forsuffixes e := l,,r:
442 z[n+100]'e = z[n]'e transformed corr;
453 ..tension 1.07.. z105l{up_}% inside curve
455 ..tension 1.2.. z120r{curl 1}
456 .. {direction 0 of pat}z120l
458 -- z109r % {dir (downstroke_angle + 0)}
459 ..tension 0.8.. z107r{down_}
464 ..tension .95.. z101r
465 -- simple_serif (z101r, z101l, 80)
467 ..tension 0.85.. cycle;
474 .. z111e{dir (-95 + corr_angle)}
475 .. z112e{dir (bot_angle_)};
477 fill new_bulb (z112r, bot_angle_, z113r, z112l, bot_angle_ + 180,
478 0.45 reduced_ss, 0.38 reduced_ss,
479 thinnib + .05 staff_space, 1, -1)
482 penlabels (range 101 thru 121);
483 penlabels (110', 111');
485 draw_staff (-1, 3, 0);
489 fet_beginchar ("G clef", "G");
494 fet_beginchar ("G clef", "G_change");
505 % The percussion clef extent is not coincident with its bbox, since
506 % the percussion clef needs more space in front than a normal clef.
509 def draw_percussion_clef (expr reduction) =
510 save reduced_ss, razt;
512 reduced_ss# = staff_space# * reduction;
513 define_pixels (reduced_ss);
515 set_char_box (-.67 reduced_ss#, 2.0 reduced_ss#,
516 reduced_ss#, reduced_ss#);
518 razt := hround (0.45 reduced_ss);
522 draw_block ((-b, -d), (-b + razt, h));
523 draw_block ((w - razt, -d), (w, h));
525 draw_staff (-3, 1, 1);
529 fet_beginchar ("percussion clef", "percussion");
530 draw_percussion_clef (1.0);
534 fet_beginchar ("percussion clef (reduced)", "percussion_change");
535 draw_percussion_clef (.8);
539 def draw_tab_T (expr pos, siz, slant) =
546 vx = (xpart siz) * dir 0;
547 vy = (ypart siz) * dir 90;
549 penpos1 (.75 penh, 100);
550 z1 = z2 + (1/6 * vx - .15 * vy);
551 penpos2 (hround (.9 penw), 0);
552 x2l = hround xpart (pos + .75 vy);
553 y2l = ypart (pos + .75 vy);
554 penpos3 (penh, -100);
555 z3l = pos + .4 vx + vy;
557 z4 = -.1 vy + .5 [z3, z5];
558 penpos5 (.8 penh, -30);
559 x5r = xpart (pos + siz);
560 y5l = ypart (pos + siz);
562 penpos10 (penw, 170);
563 z10 = pos + .55 vx + .9 vy;
564 penpos11 (.75 [penh, penw], 170);
565 z11 = z10 - .5 vy + .025 vx;
566 penpos12 (penh, 100);
567 z12l = (xpart .5 [z13, z11], ypart (pos - .025 * siz));
568 penpos13 (.75 penh, 60);
569 z13 = pos + .2 vx + .15 vy;
571 % penlabels (range 1 thru 13);
578 slanted slant shifted (slant * -ypart pos, 0);
580 soft_end_penstroke (z10e
583 ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
584 slanted slant shifted (slant * -ypart pos, 0);
589 def draw_tab_A (expr pos, siz, slant) =
597 vx = (xpart siz) * dir 0;
598 vy = (ypart siz) * dir 90;
600 penpos1 (.75 penh, -110);
603 z2r = (.5 [x1, x3], ypart pos);
604 penpos3 (.25 [penh, penw], -30);
605 z3 = (.45 [x2, x4], .15 [y2, y4]);
606 penpos4 (1 [penh, penw], 0);
607 z4 = pos + .5 vx + .975 vy;
609 penpos5 (1 [penh, penw], -180);
611 penpos6 (.2 [penh, penw], -150);
612 z6l = (.8 [x5l, x7l], .9 [y5l, y7l]);
614 z7r = (.5 [x6, x8], ypart pos);
615 penpos8 (.75 penh, -70);
616 z8r = (xpart (pos + siz), y7r + .075 ypart (siz));
622 penpos10 (penh, angle (direction 1.2 of pat) - 180);
623 z10 = point 1.2 of pat;
624 penpos11 (.9 penh, -90);
625 z11 = .4 [z10, z6] - 0.05 vy;
626 penpos12 (.75 penh, -75);
627 z12 = .3 [z11, z6] + 0.02 vy;
629 % penlabels (range 1 thru 12);
631 soft_penstroke (z1e{(z1r - z1l) rotated 90}
635 slanted slant shifted (slant * -ypart pos, 0);
637 soft_end_penstroke (z5e
640 .. z8e{(z8r - z8l) rotated 90})
641 slanted slant shifted (slant * -ypart pos, 0);
643 soft_end_penstroke (z10e
646 slanted slant shifted (slant * -ypart pos, 0);
651 def draw_tab_B (expr pos, siz, slant) =
658 vx = (xpart siz) * dir 0;
659 vy = (ypart siz) * dir 90;
661 penpos1 (.75 penh, 100);
662 z1 = z2 + (.15 * vx - .1 * vy);
663 penpos2 (hround (.9 penw), 0);
664 x2l = hround xpart (pos + .75 vy);
665 y2l = ypart (pos + .75 vy);
666 penpos3 (penh, -100);
667 z3l = pos + .4 vx + 1.05 vy;
668 penpos4 (.8 [penh, penw], -180);
669 z4 = (xpart (pos + .75 siz), .5 [y3, y5]);
670 penpos5 (.8 penh, 90);
671 z5 = (.5 [x10, x4], ypart (pos + .55 siz));
673 penpos6 (.8 penh, 270);
676 z7l = (xpart (pos + siz), .5 [y6, y8]);
677 penpos8 (.8 penh, 45);
678 z8 = .5 [z12l, z11l] + .15 vx - .05 vy;
680 penpos10 (.75 [penh, penw], 170);
681 z10 = pos + .375 vx + vy;
682 penpos11 (.8 [penh, penw], 150);
683 z11 = z10 - .5 vy + .04 vx;
684 penpos12 (penh, 100);
685 z12l = (xpart .5 [z13, z11], ypart pos);
686 penpos13 (.75 penh, 60);
687 z13 = pos + .1 vx + .15 vy;
689 % penlabels (range 1 thru 13);
696 slanted slant shifted (slant * -ypart pos, 0);
698 soft_end_penstroke (z6e{right}
700 .. z8e{(z8r - z8l) rotated 90})
701 slanted slant shifted (slant * -ypart pos, 0);
703 soft_end_penstroke (z10e
706 ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
707 slanted slant shifted (slant * -ypart pos, 0);
712 def draw_tab_clef (expr reduction) =
713 save reduced_ss, letterheight, penw, penh;
715 reduced_ss# = staff_space# * reduction;
716 letterheight# = 1.8 reduced_ss#;
717 define_pixels (reduced_ss, letterheight);
719 set_char_box (-.2 reduced_ss#, 2.8 reduced_ss#,
720 1.6 letterheight#, 1.6 letterheight#);
722 penw = .45 reduced_ss;
723 penh = .2 reduced_ss;
725 draw_tab_T ((-b + .15 reduced_ss, h - letterheight),
726 (2.1 reduced_ss, letterheight), 0.2);
727 draw_tab_A ((-b - .05 reduced_ss, -.5 letterheight +.15 reduced_ss),
728 (2.2 reduced_ss, letterheight), 0.4);
729 draw_tab_B ((-b + .025 reduced_ss, -d),
730 (2.1 reduced_ss, letterheight), 0.25);
732 draw_staff (-3, 2, 0.5);
736 fet_beginchar ("tab clef", "tab");
741 fet_beginchar ("tab clef (reduced)", "tab_change");
745 fet_endgroup ("clefs");