1 % feta-klef.mf -- implement Clefs -*-Fundamental-*-
3 % part of LilyPond's pretty-but-neat music font
5 % source file of the Feta (not the Font-En-Tja) music font
7 % (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 % Jan Nieuwenhuizen <janneke@gnu.org>,
9 % Juergen Reuter <reuter@ipd.uka.de>
12 fet_begingroup("clefs");
16 % [Wanske] says the bulbs should be positioned about 1/4 right of the
20 % TODO: the hair-curve at z6r looks a little awkward.
21 def draw_c_clef (expr reduction) =
22 save hair, norm, reduced_ss, right_edge;
23 reduced_ss#=staff_space#*reduction;
24 norm#:=2/3reduced_ss#;
25 hair#:=0.06 reduced_ss# + 0.5 stafflinethickness# ;
27 right_edge# = 15/4norm#+2hair#;
29 set_char_box (0, right_edge# + 0,
30 2 reduced_ss#, 2 reduced_ss#);
31 define_pixels (hair,norm,reduced_ss, right_edge);
33 draw_block ((0,-d), (3/4norm+1/2hair,h));
34 draw_block ((3/4norm+2hair,-d),
40 z5l = (xoff - 3/4 hair, 0);
44 z1l=(xoff+norm+hair,h);
45 penpos2(norm-3/2hair,180);
48 z3=(((right_edge -xoff)/2)+xoff,2hair);
51 z4=(xoff+1/2norm+1/2hair, reduced_ss - stafflinethickness - .2 hair);
53 penpos6(norm-hair,90);
59 p = z5l..z4l{up}..z4r{down}..z3r{right}..tension t..z2r{up}
61 flare_path(z1l,180,90,hair,norm-1/2hair, -1)
62 ..tension t..z2l{down}
63 ..z3l{left}..z6r..z5r{down};
64 pickup pencircle scaled 1pt#;
65 filldraw p..(reverse p yscaled -1)..cycle;
66 penlabels (1,2,3,4,5,6);
68 % ugh, should be bulb, not flare?
72 fet_beginchar ("C clef", "C", "altoclef")
74 draw_staff (-2,2, 0.0);
79 fet_beginchar ("C clef", "C_change", "caltoclef")
81 draw_staff (-2,2, 0.0);
89 % Insert a brushed piece of the path, and draw a bulb separately
91 % The bulb is circular form. Neat merging of the bulb and brushed path
92 % is done by playing with tension.
96 def new_bulb (expr outer_tangent_point,
97 big_radius, bulb_radius, flare, direction, turning_dir) =
107 center = outer_tangent_point +big_radius* dir(0) + big_radius* dir(-turning_dir * 90)
108 - bulb_radius * dir (- turning_dir * 90);
110 z1 = center + bulb_radius * dir (turning_dir * 180);
111 z2 = center + bulb_radius * dir (turning_dir * 270);
113 z9 = center + bulb_radius * dir (0);
114 z10 = center + bulb_radius * dir (turning_dir *90);
115 z3 = outer_tangent_point + flare * dir (0);
119 % tension is needed to open up the space between return path and the
123 z9 .. z10 .. tension 1.1 .. z1 .. z2 .. cycle;
125 p:= outer_tangent_point{dir (-turning_dir* 90)}
127 .. {dir (turning_dir * 90)}z9 -- z3
141 % There is some variation is shape of bass clefs. Important points
143 % * the size of the swoosh tip: in some clefs, it almost reaches the
144 % bottom staff line, in some it crosses the 2nd line from the bottom
145 % with a small overshoot.
147 % The most popular design is where the X part of the tip is aligned
148 % left bulb boundary, and the Y part ends on the 2nd staffline exactly.
149 % This is what we do.
151 % * The size of the bulb. The diameter of the bulb is the width of the
154 % * The y-alignment of the bulb. The center of the bulb can be on or slightly
155 % above the staff line.
157 % * The position of the dots. They can be symmetrical around the
158 % staffline, centered in the staff space. The Baerenreiter SCS has the
159 % bottom dot raised by approx. 0.1 ss.
161 % * uncarefully set music may have overshoots at the top. We have none.
163 % * It is not exactly clear where the vertical tangent at the right
164 % of the swoosh should be.
168 def draw_bass_clef(expr exact_center, reduction) =
169 save reduced_ss, left_tilt, left_thick, swoosh_width;
170 save right_thickness, tip_protude;
173 reduced_ss# = staff_space# * reduction;
176 2.2 dot_diam = round reduction* (staff_space - stafflinethickness);
177 right_thickness = 0.48;
179 swoosh_width# = 2.1 reduced_ss#;
180 % tip_protude := (-stafflinethickness, -.2 staff_space);
181 tip_protude := (0, 0);
182 bulb_y_offset := 0.15 staff_space;
183 overshoot_top := 0.0;
187 - xpart exact_center,
189 xpart exact_center + swoosh_width# + 7/12 reduced_ss#,
190 - ypart exact_center + 2.5 reduced_ss#,
191 ypart exact_center +reduced_ss#);
193 define_pixels(swoosh_width);
194 define_whole_pixels(reduced_ss);
203 y2l := vround_pixels (reduced_ss# + 0.5 stafflinethickness#);
204 y2l - y2r = (1.0 + overshoot_top) * stafflinethickness;
207 x3l - x1 = swoosh_width;
208 x3l - x3r = right_thickness * reduced_ss;
210 % try to correct: the top dot seems farther away if y3l = 0.
211 y3l = 0.05 staff_space;
213 z4 = - (0, 2.0 reduced_ss) + tip_protude;
215 z5 = (x3l + 1/3 reduced_ss, .5 reduced_ss);
217 penpos3(whatever, 185);
218 penpos4(stafflinethickness, 135);
220 pickup pencircle scaled 1;
223 new_bulb (z1, 0.45 reduced_ss, 0.4 reduced_ss, 2.5 stafflinethickness, 1, 1)
226 .. z2r{right} .. tension 1.0 .. z3r{down} .. {curl 0}
227 simple_serif(z4r, z4l, 90) {curl 0}
228 .. z3l{up} .. tension 0.9 .. z2l{left}
232 labels(range 1 thru 12);
236 pickup pencircle scaled dot_diam;
238 drawdot z5 yscaled -1;
244 fet_beginchar("F clef ", "F", "bassclef")
246 draw_staff(-3,1, 0.0);
248 draw_bass_clef((0, 0), 1.0);
251 fet_beginchar("F clef (reduced)", "F_change", "cbassclef")
252 draw_bass_clef((0, 0),0.8);
258 % Inspired by Baerenreiter
261 % Beste lezers, kijk,
263 % Een bolletje hebben we bij toeval allemaal wel eens getekend, maar begint u
264 % toch eenvoudig. Eerst een eenvoudig kruis of herstellingsteken
265 % en via de dubbelslag naar een voorzichtig vlaggetje, en heb geduld!
266 % Ikzelf heb bijvoorbeeld over mijn eerste gave G-sleutel
267 % 35 kilobyte metafont, 12 patchlevels, 0 vriendinnen en 45 dagen gedaan
269 % -- vrij naar Van Kooten & De Bie
271 def debugfill = fill enddef;
272 def draw_gclef (expr reduction)=
273 save reduced_ss, downstroke_dir, downstroke_angle, center;
274 save breapth_factor, inner_thick_end, thinness, thickness, thinnib;
275 save inner_start_angle, thinness;
276 reduced_ss# = staff_space# * reduction;
277 define_pixels(reduced_ss);
278 pair downstroke_dir, center;
280 thinness = 0.1 staff_space + 0.4 stafflinethickness;
281 downstroke_dir = unitvector (14, -75);
282 downstroke_angle = angle downstroke_dir;
285 breapth_factor = 21.0 /14;
286 inner_thick_end = 45;
287 inner_start_angle = downstroke_angle - 43;
288 thickness = .3 reduced_ss + 1 stafflinethickness;
294 1.71 * breapth_factor* reduced_ss#,
298 center := (1.0 * breapth_factor* reduced_ss, 0);
300 save upward_swoosh_angle;
301 upward_swoosh_angle = 132;
302 penpos7(thickness, upward_swoosh_angle);
303 penpos5(thickness, upward_swoosh_angle);
306 z1 = center + whatever * dir (inner_start_angle);
307 x1 = xpart center -.28 reduced_ss;
309 top z2r = center + (0,reduced_ss + stafflinethickness/2);
311 x4 = xpart center - .1 reduced_ss;
312 bot y4r = -(reduced_ss + .5 stafflinethickness);
314 z3 = (z4 - center) rotated inner_thick_end + center;
315 x5r = - breapth_factor* reduced_ss + xpart center;
316 y5r = .37 reduced_ss + ypart center;
318 z6 = center + whatever * downstroke_dir;
319 y6 = ypart center + 2 reduced_ss;
321 z7l - z6 = whatever * (z5 - z6) ;
322 y7l = 3.5 reduced_ss;
325 top y9l = 5 reduced_ss;
327 y11 = ypart center - 47/28 reduced_ss;
328 y12 = ypart center - 71/28 reduced_ss;
330 x11 - x13r = 1.5 reduced_ss + 0.5 thinnib;
331 x12r = xpart (.45 [z13r , z11] + .75 reduced_ss * downstroke_dir) ;
333 % z10= center + whatever * dir (downstroke_angle - 1.5 );
334 x10 = x6 - 2 thinnib;
335 y10 = ypart center + 3.5 reduced_ss;
336 y10l - y10r = 1.2 thickness;
338 .7 thinnib* dir (downstroke_angle + 90) + whatever * downstroke_dir;
340 z10 = .5 [z10l, z10r];
342 z11 = center + whatever * downstroke_dir + ( .00 reduced_ss, 0);
344 penpos1(thinnib, inner_start_angle);
345 penpos2(thickness, 90);
346 penpos3(thinnib, -90 + inner_thick_end);
347 penpos4(thinnib, -90);
350 penpos9(1.45 thickness, -70);
353 lipje= .5 [z9l, z9r] + .25 ((z9r- z9l) rotated -90);
354 penpos13(thinnib + 0.14 staff_space, 180);
356 pickup pencircle scaled 1;
366 --z9r % {dir (downstroke_angle+ 0)}
368 .. z7r{down} .. z5r{down} .. z4r{right}
369 .. z3r .. z2r{left} ..
371 z1r -- simple_serif(z1r, z1l, 80) -- z1l
372 .. tension 0.85 ..cycle;
374 save p, staffline_time, staff_line_path, down_staff_line_intersection;
375 path p, staff_line_path;
376 pair down_staff_line_intersection;
377 p := z4{left} .. z5{up} .. z7{up} ;
379 staff_line_path := (-reduced_ss, 2 reduced_ss) .. (2 reduced_ss,2 reduced_ss);
384 % we don't do this with a path: variations in thickness
385 % are very easily made and look very ugh.
386 pickup pencircle scaled thinnib;
391 bot_angle = -180; % downstroke_angle- 87;
393 penpos12(thinnib, bot_angle + 90);
398 .. z12{dir(bot_angle)}
401 save down_intersection_t;
402 down_intersection_t := xpart (p intersectiontimes staff_line_path) ;
403 down_staff_line_intersection = point down_intersection_t of p;
404 z14 = down_staff_line_intersection;
405 penpos14(thinnib, angle (direction down_intersection_t of p) + 90);
408 start_angle=angle (direction xpart (p intersectiontimes z11) of p);
409 penpos11 (thinnib, start_angle+ 90);
413 loop_end_dir = direction (xpart (p intersectiontimes staff_line_path)) of p;
416 penpos6(thinnib, angle (loop_end_dir) + 90);
417 pickup pencircle scaled 1;
421 .. z14l{loop_end_dir} -- z14r{-loop_end_dir}
427 pickup pencircle scaled 1;
430 z11r{dir(start_angle)}
431 .. z12r{dir(bot_angle)}
433 ..new_bulb (z13r, 0.45 reduced_ss, 0.38 reduced_ss, thinnib
438 .. z12l{-dir (bot_angle)}
440 .. z11l{-dir(start_angle)}
445 penlabels(range 1 thru 16);
449 fet_beginchar("G clef", "G", "trebleclef")
451 draw_staff(-1,3, 0.0);
455 fet_beginchar("G clef", "G_change", "ctrebleclef")
468 % The perc clef extent is not coincident with its bbox, since
469 % the perc clef needs more space in front than a normal clef.
472 def draw_percussion_clef(expr reduction) =
473 save reduced_ss, razt;
475 reduced_ss# = staff_space# * reduction;
476 define_pixels(reduced_ss);
477 set_char_box(-.67reduced_ss#,2.0reduced_ss#,reduced_ss#,reduced_ss#);
478 razt := 0.45reduced_ss;
479 draw_block((-b,-d),(-b+razt,h));
480 draw_block((w-razt,-d),(w,h));
483 fet_beginchar("percussion clef", "percussion", "percussionclef")
484 draw_percussion_clef(1.0);
487 fet_beginchar("percussion clef (reduced)", "percussion_change", "cpercussionclef")
488 draw_percussion_clef(.8);
491 def draw_tab_T(expr pos, siz, slant) =
495 vx=(xpart siz) * dir 0;
496 vy=(ypart siz) * dir 90;
498 penpos1(.75penh, 100);
499 z1=z2+(1/6*vx-.15*vy);
512 penpos11(.75[penh,penw],170);
515 z12l=(xpart .5[z13,z11],ypart (pos-.025*siz));
516 penpos13(.75penh,60);
519 % penlabels (1,2,3,4,5,10,11,12,13);
521 soft_penstroke (z1e..tension 1.1
523 ..z3e{right}..tension 1.5
526 ) slanted slant shifted (slant*-ypart pos,0);
528 soft_penstroke (z10e..tension 1.5
531 ..z13e{(z13r-z13l) rotated 90}
532 ) slanted slant shifted (slant*-ypart pos,0);
536 def draw_tab_A(expr pos, siz, slant) =
540 vx=(xpart siz) * dir 0;
541 vy=(ypart siz) * dir 90;
543 penpos1(.75penh,-110);
546 z2r=(.5[x1,x3],ypart pos);
547 penpos3(.25[penh,penw],-30);
548 z3=(.45[x2,x4],.15[y2,y4]);
549 penpos4(1[penh,penw],0);
552 penpos5(1[penh,penw],-180);
554 penpos6(.2[penh,penw],-150);
555 z6l=(.8[x5l,x7l],.9[y5l,y7l]);
557 z7r=(.5[x6,x8],ypart pos);
558 penpos8(.75penh,-70);
559 z8r=(xpart(pos+siz),y7r+.075ypart(siz));
563 penpos11(.9penh,-90);
564 z11=.4[z10,z6]-0.05vy;
565 penpos12(.75penh,-75);
566 z12=.3[z11,z6]+0.02vy;
568 % penlabels(1,2,3,4,5,6,7,8,10,11,12);
570 soft_penstroke (z1e {(z1r-z1l) rotated 90}
574 ) slanted slant shifted (slant*-ypart pos,0);
579 ..z8e {(z8r-z8l) rotated 90}
580 ) slanted slant shifted (slant*-ypart pos,0);
585 ) slanted slant shifted (slant*-ypart pos,0);
590 def draw_tab_B(expr pos, siz, slant) =
594 vx=(xpart siz) * dir 0;
595 vy=(ypart siz) * dir 90;
597 penpos1(.75penh, 100);
598 z1=z2+(.15*vx-.1*vy);
602 z3l = pos+.4vx+1.05vy;
603 penpos4(.8[penh,penw],-180);
604 z4=(xpart(pos+.75siz),.5[y3,y5]);
606 z5=(.5[x10,x4],ypart (pos+.55siz));
611 z7l=(xpart(pos+siz),.5[y6,y8]);
613 z8=.5[z12l,z11l]+.15vx-.05vy;
615 penpos10(.75[penh,penw],170);
616 z10=pos+.375vx+.95vy;
617 penpos11(.8[penh,penw],150);
620 z12l=(xpart .5[z13,z11],ypart pos);
621 penpos13(.75penh,60);
624 % penlabels (1,2,3,4,5,6,7,8,10,11,12,13);
626 soft_penstroke (z1e..tension 1.1
631 ) slanted slant shifted (slant*-ypart pos,0);
633 soft_penstroke (z6e{right}
635 ..z8e{(z8r-z8l) rotated 90}
636 ) slanted slant shifted (slant*-ypart pos,0);
638 soft_penstroke (z10e.. tension 1.5
641 ..z13e{(z13r-z13l) rotated 90}
642 ) slanted slant shifted (slant*-ypart pos,0);
646 def draw_tab_clef(expr reduction) =
647 save reduced_ss,vx,vy,letterheight,penw,penh;
648 reduced_ss# = staff_space# * reduction;
649 letterheight# = 1.8*reduced_ss#;
650 define_pixels(reduced_ss,letterheight);
651 set_char_box(-.2*reduced_ss#,2.8*reduced_ss#,1.6*letterheight#,1.6*letterheight#);
653 %draw_staff (-3,2, 0.5);
655 penw = .45reduced_ss;
658 draw_tab_T((-b+.15reduced_ss,h-letterheight),
659 (2.1*reduced_ss,letterheight),0.2);
660 draw_tab_A((-b-.05reduced_ss,-.5letterheight +.15reduced_ss),
661 (2.2*reduced_ss,letterheight),0.4);
662 draw_tab_B((-b+.025reduced_ss,-d),
663 (2.1*reduced_ss,letterheight),0.25);
666 fet_beginchar("tab clef", "tab", "tabclef")
670 fet_beginchar("tab clef (reduced)", "tab_change", "ctabclef")
674 fet_endgroup("clefs");