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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 % Jan Nieuwenhuizen <janneke@gnu.org>,
9 % Juergen Reuter <reuter@ipd.uka.de>
12 fet_begingroup("clefs");
15 % [Ross] says that clefs take 1 staff_space space on the left and right
17 % this is now handled in the lilypond spacing engine.
20 def set_horizontal_spacing =
21 save left_space ,right_space;
27 % [Wanske] says the bulbs should be positioned about 1/4 right of the
29 def draw_c_clef (expr reduction) =
30 save hair, norm, reduced_ss, right_edge;
31 reduced_ss#=staff_space#*reduction;
32 norm#:=2/3reduced_ss#;
35 set_horizontal_spacing;
36 right_edge# = 15/4norm#+2hair#;
38 set_char_box (left_space#, right_edge# + right_space#,
39 2 reduced_ss#, 2 reduced_ss#);
40 define_pixels (hair,norm,reduced_ss, right_edge);
42 draw_block ((0,-d), (3/4norm+1/2hair,h));
43 draw_block ((3/4norm+2hair,-d),
49 z1l=(xoff+norm+hair,h);
50 penpos2(norm-3/2hair,180);
53 z3=(((right_edge -xoff)/2)+xoff,2hair);
56 z4=(xoff+1/2norm+1/2hair,reduced_ss-hair);
61 penpos6(norm-hair,90);
67 p = z5l..z4l{up}..z4r{down}..z3r{right}..tension t..z2r{up}
69 flare_path(z1l,180,90,hair,norm-1/2hair, -1)
70 ..tension t..z2l{down}
71 ..z3l{left}..z6r..z5r{down};
72 pickup pencircle scaled 1pt#;
73 filldraw p..(reverse p yscaled -1)..cycle;
74 penlabels (1,2,3,4,5,6);
76 % ugh, should be bulb, not flare?
80 fet_beginchar ("C clef", "C", "altoclef")
82 draw_staff (-2,2, 0.0);
87 fet_beginchar ("C clef", "C_change", "caltoclef")
89 draw_staff (-2,2, 0.0);
97 % Insert a brushed piece of the path, and draw a bulb separately
99 % The bulb is circular form. Neat merging of the bulb and brushed path
100 % is done by playing with tension.
104 def new_bulb (expr outer_tangent_point,
105 big_radius, bulb_radius, flare, direction) =
114 center = outer_tangent_point +big_radius* dir(0) + big_radius* dir(-90)
115 - bulb_radius * dir (-90);
117 z1 = center + bulb_radius * dir 180;
118 z2 = center + bulb_radius * dir 270;
120 z9 = center + bulb_radius * dir (0);
121 z10 = center + bulb_radius * dir (90);
122 z3 = outer_tangent_point + flare * dir (0);
126 % tension is needed to open up the space between return path and the
129 z9 .. z10 .. tension 1.1 .. z1 .. z2 .. cycle;
131 p:= outer_tangent_point{down}
147 % There is some variation is shape of bass clefs. Important points
149 % * the size of the swoosh tip: in some clefs, it almost reaches the
150 % bottom staff line, in some it crosses the 2nd line from the bottom
151 % with a small overshoot.
153 % The most popular design is where the X part of the tip is aligned
154 % left bulb boundary, and the Y part ends on the 2nd staffline exactly.
155 % This is what we do.
157 % * The size of the bulb. The diameter of the bulb is the width of the
160 % * The y-alignment of the bulb. The center of the bulb can be on or slightly
161 % above the staff line.
163 % * The position of the dots. They can be symmetrical around the
164 % staffline, centered in the staff space. The Baerenreiter SCS has the
165 % bottom dot raised by approx. 0.1 ss.
167 % * uncarefully set music may have overshoots at the top. We have none.
169 % * It is not exactly clear where the vertical tangent at the right
170 % of the swoosh should be.
174 def draw_bass_clef(expr exact_center, reduction) =
175 save reduced_ss, left_tilt, left_thick, swoosh_width;
176 save right_thickness, tip_protude;
179 reduced_ss# = staff_space# * reduction;
182 2.2 dot_diam = round reduction* (staff_space - stafflinethickness);
183 right_thickness = 0.48;
185 swoosh_width# = 2.1 reduced_ss#;
186 % tip_protude := (-stafflinethickness, -.2 staff_space);
187 tip_protude := (0, 0);
188 set_horizontal_spacing;
189 bulb_y_offset := 0.15 staff_space;
190 overshoot_top := 0.0;
193 set_char_box(left_space# +
194 - xpart exact_center,
196 xpart exact_center + swoosh_width# + 7/12 reduced_ss#,
197 - ypart exact_center + 2.5 reduced_ss#,
198 ypart exact_center +reduced_ss#);
200 define_pixels(swoosh_width);
201 define_whole_pixels(reduced_ss);
210 y2l := vround_pixels (reduced_ss# + 0.5 stafflinethickness#);
211 y2l - y2r = (1.0 + overshoot_top) * stafflinethickness;
214 x3l - x1 = swoosh_width;
215 x3l - x3r = right_thickness * reduced_ss;
217 % try to correct: the top dot seems farther away if y3l = 0.
218 y3l = 0.05 staff_space;
220 z4 = - (0, 2.0 reduced_ss) + tip_protude;
222 z5 = (x3l + 1/3 reduced_ss, .5 reduced_ss);
224 penpos3(whatever, 185);
225 penpos4(stafflinethickness, 135);
227 pickup pencircle scaled 1;
230 new_bulb (z1, 0.4 reduced_ss, 0.35 reduced_ss, 2 stafflinethickness, 1)
233 .. z2r{right} .. tension 1.0 .. z3r{down} .. {curl 0}
234 simple_serif(z4r, z4l, 90) {curl 0}
235 .. z3l{up} .. tension 0.9 .. z2l{left}
239 labels(range 1 thru 12);
243 pickup pencircle scaled dot_diam;
245 drawdot z5 yscaled -1;
251 fet_beginchar("F clef ", "F", "bassclef")
253 draw_staff(-3,1, 0.0);
255 draw_bass_clef((0, 0), 1.0);
258 fet_beginchar("F clef (reduced)", "F_change", "cbassclef")
259 draw_bass_clef((0, 0),0.8);
265 % Inspired by Baerenreiter
267 % FIXME bulb should curve (see bass clef)
268 % FIXME start (inside) should be little thinner
272 % Beste lezers, kijk,
274 % Een bolletje hebben we bij toeval allemaal wel eens getekend, maar begint u
275 % toch eenvoudig. Eerst een eenvoudig kruis of herstellingsteken
276 % en via de dubbelslag naar een voorzichtig vlaggetje, en heb geduld!
277 % Ikzelf heb bijvoorbeeld over mijn eerste gave G-sleutel
278 % 35 kilobyte metafont, 12 patchlevels, 0 vriendinnen en 45 dagen gedaan
280 % -- vrij naar Van Kooten & De Bie
283 def draw_gclef (expr exact_center, reduction)=
284 save reduced_ss, downstroke_dir, downstroke_angle, hair, center;
285 save breapth_factor, inner_thick_end, thinness, thickness, thinnib;
286 save inner_start_angle, thinness, thinpen;
287 reduced_ss# = staff_space# * reduction;
288 define_pixels(reduced_ss);
289 pair downstroke_dir, center;
291 center := (hround_pixels(xpart exact_center),
292 vround_pixels(ypart exact_center));
294 hair = .3 stafflinethickness;
295 % hair = blot_diameter;
296 thinness = 1.3 stafflinethickness;
297 downstroke_dir = (14, -75);
298 breapth_factor = 11/7;
299 inner_thick_end = 45;
300 inner_start_angle = downstroke_angle - 43;
301 thickness = .4 reduced_ss - hair;
303 thinnib = thinness - hair;
305 set_horizontal_spacing;
309 -xpart exact_center + 1.0 * breapth_factor* reduced_ss#,
311 xpart exact_center + .66 breapth_factor* reduced_ss#,
312 -ypart exact_center + 3 * reduced_ss#,
313 ypart exact_center + 5 * reduced_ss#);
315 pickup pencircle scaled hair;
316 downstroke_angle = angle downstroke_dir;
318 z1 = center + whatever * dir (inner_start_angle);
319 x1 = xpart center -.28 reduced_ss;
321 top z2r = center + (0,reduced_ss + stafflinethickness/2);
323 x4 = xpart center - .1 reduced_ss;
324 bot y4r = -(reduced_ss + .5 stafflinethickness);
326 z3 = (z4 - center) rotated inner_thick_end + center;
328 z5r = (- breapth_factor, .37)* reduced_ss + center;
329 penpos5(thickness, 135);
331 z6 = center + whatever * downstroke_dir;
332 y6 = ypart center + 2 reduced_ss;
334 z7l - z6 = whatever *(z5- z6) ;
335 y7l = 3.5 reduced_ss;
336 z8r = .4 [z9r, z7r] + 1.5 stafflinethickness * dir 52;
339 top y9l = 5 reduced_ss;
342 y11 = -11/7 reduced_ss;
344 y12 = ypart center - 18.5/7 reduced_ss;
345 x12 = x11 - 5 /7 reduced_ss;
347 z13 = z12 + .6 reduced_ss*(-1,1);
349 (z10r - z10l) dotprod (unitvector downstroke_dir rotated 90) =
352 center - z10= whatever * downstroke_dir;
353 center - z11 = whatever * downstroke_dir;
354 center - z14 = .8 (center - z11);
355 penpos1(thinnib, inner_start_angle);
356 penpos2(thickness, 90);
357 penpos3(thinnib, -90 + inner_thick_end);
358 penpos4(thinnib, -90);
361 penpos7(thickness, 135);
362 penpos8(1.5 thinnib, - 70 + angle downstroke_dir);
363 penpos9(1.4 thickness, -80); % ugh
364 penpos10(whatever, downstroke_angle + 10);
365 penpos11(thinnib, downstroke_angle + 90);
366 penpos14(thinnib, downstroke_angle + 90);
367 penpos12(thinnib, -90);
368 penpos13(3 thinnib, 180);
370 filldraw z2l{right} .. z3l.. z4l{left} .. z5l{up} .. z7l{up}
374 {downstroke_dir}z10l --- z11l -- z11r --- z10r{- downstroke_dir}
376 .. z9r & z9r{dir (downstroke_angle+ 40)} % ugh
378 .. z7r{down} .. z5r{down} .. z4r{right}
379 .. z3r .. z2r{left} ..
382 .. tension 0.85 ..cycle;
384 filldraw simple_serif(z1r, z1l, 80) -- cycle;
386 filldraw z12r{left} .. z13r{up} -- z13l{down} .. z12l{right} .. cycle;
388 draw_bulb(-1, z13l, lft z13r, 6/14 reduced_ss, 1.0);
390 pickup pencircle scaled (thinpen);
391 draw z10 --- z14 .. z11 .. tension 0.85 .. z12{left};
393 penlabels(range 1 thru 15);
397 fet_beginchar("G clef", "G", "trebleclef")
399 draw_staff(-1,3, 0.0);
401 draw_gclef((1.7 staff_space#,0), 1.0);
403 fet_beginchar("G clef", "G_change", "ctrebleclef")
404 draw_gclef((1.3 staff_space#,0), .8);
413 def draw_percussion_clef(expr reduction) =
415 reduced_ss# = staff_space# * reduction;
416 define_pixels(reduced_ss);
417 set_char_box(-.67reduced_ss#,2.0reduced_ss#,reduced_ss#,reduced_ss#);
418 razt := 0.45reduced_ss;
419 draw_block((-b,-d),(-b+razt,h));
420 draw_block((w-razt,-d),(w,h));
423 fet_beginchar("percussion clef", "percussion", "percussionclef")
424 draw_percussion_clef(1.0);
427 fet_beginchar("percussion clef (reduced)", "percussion_change", "cpercussionclef")
428 draw_percussion_clef(.8);
431 def draw_tab_T(expr pos, siz, slant) =
435 vx=(xpart siz) * dir 0;
436 vy=(ypart siz) * dir 90;
438 penpos1(.75penh, 100);
439 z1=z2+(1/6*vx-.15*vy);
452 penpos11(.75[penh,penw],170);
455 z12l=(xpart .5[z13,z11],ypart (pos-.025*siz));
456 penpos13(.75penh,60);
459 % penlabels (1,2,3,4,5,10,11,12,13);
461 soft_penstroke (z1e..tension 1.1
463 ..z3e{right}..tension 1.5
466 ) slanted slant shifted (slant*-ypart pos,0);
468 soft_penstroke (z10e..tension 1.5
471 ..z13e{(z13r-z13l) rotated 90}
472 ) slanted slant shifted (slant*-ypart pos,0);
476 def draw_tab_A(expr pos, siz, slant) =
480 vx=(xpart siz) * dir 0;
481 vy=(ypart siz) * dir 90;
483 penpos1(.75penh,-110);
486 z2r=(.5[x1,x3],ypart pos);
487 penpos3(.25[penh,penw],-30);
488 z3=(.45[x2,x4],.15[y2,y4]);
489 penpos4(1[penh,penw],0);
492 penpos5(1[penh,penw],-180);
494 penpos6(.2[penh,penw],-150);
495 z6l=(.8[x5l,x7l],.9[y5l,y7l]);
497 z7r=(.5[x6,x8],ypart pos);
498 penpos8(.75penh,-70);
499 z8r=(xpart(pos+siz),y7r+.075ypart(siz));
503 penpos11(.9penh,-90);
504 z11=.4[z10,z6]-0.05vy;
505 penpos12(.75penh,-75);
506 z12=.3[z11,z6]+0.02vy;
508 % penlabels(1,2,3,4,5,6,7,8,10,11,12);
510 soft_penstroke (z1e {(z1r-z1l) rotated 90}
514 ) slanted slant shifted (slant*-ypart pos,0);
519 ..z8e {(z8r-z8l) rotated 90}
520 ) slanted slant shifted (slant*-ypart pos,0);
525 ) slanted slant shifted (slant*-ypart pos,0);
530 def draw_tab_B(expr pos, siz, slant) =
534 vx=(xpart siz) * dir 0;
535 vy=(ypart siz) * dir 90;
537 penpos1(.75penh, 100);
538 z1=z2+(.15*vx-.1*vy);
542 z3l = pos+.4vx+1.05vy;
543 penpos4(.8[penh,penw],-180);
544 z4=(xpart(pos+.75siz),.5[y3,y5]);
546 z5=(.5[x10,x4],ypart (pos+.55siz));
551 z7l=(xpart(pos+siz),.5[y6,y8]);
553 z8=.5[z12l,z11l]+.15vx-.05vy;
555 penpos10(.75[penh,penw],170);
556 z10=pos+.375vx+.95vy;
557 penpos11(.8[penh,penw],150);
560 z12l=(xpart .5[z13,z11],ypart pos);
561 penpos13(.75penh,60);
564 % penlabels (1,2,3,4,5,6,7,8,10,11,12,13);
566 soft_penstroke (z1e..tension 1.1
571 ) slanted slant shifted (slant*-ypart pos,0);
573 soft_penstroke (z6e{right}
575 ..z8e{(z8r-z8l) rotated 90}
576 ) slanted slant shifted (slant*-ypart pos,0);
578 soft_penstroke (z10e.. tension 1.5
581 ..z13e{(z13r-z13l) rotated 90}
582 ) slanted slant shifted (slant*-ypart pos,0);
586 def draw_tab_clef(expr reduction) =
587 save reduced_ss,vx,vy,letterheight,penw,penh;
588 reduced_ss# = staff_space# * reduction;
589 letterheight# = 1.8*reduced_ss#;
590 define_pixels(reduced_ss,letterheight);
591 set_char_box(-.2*reduced_ss#,2.8*reduced_ss#,1.6*letterheight#,1.6*letterheight#);
593 %draw_staff (-3,2, 0.5);
595 penw = .45reduced_ss;
598 draw_tab_T((-b+.15reduced_ss,h-letterheight),
599 (2.1*reduced_ss,letterheight),0.2);
600 draw_tab_A((-b-.05reduced_ss,-.5letterheight +.15reduced_ss),
601 (2.2*reduced_ss,letterheight),0.4);
602 draw_tab_B((-b+.025reduced_ss,-d),
603 (2.1*reduced_ss,letterheight),0.25);
606 fet_beginchar("tab clef", "tab", "tabclef")
610 fet_beginchar("tab clef (reduced)", "tab_change", "ctabclef")
614 fet_endgroup("clefs");