]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-klef.mf
''
[lilypond.git] / mf / feta-klef.mf
1 % feta-klef.mf --  implement Clefs -*-Fundamental-*-
2
3 % part of LilyPond's pretty-but-neat music font
4 %
5 % source file of the Feta (not the Font-En-Tja) music font
6
7 % (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 % Jan Nieuwenhuizen <janneke@gnu.org>,
9 % Juergen Reuter <reuter@ipd.uka.de>
10
11
12 fet_begingroup("clefs");
13
14 %
15 % [Ross] says that clefs take 1 staff_space space on the left and right
16 %
17 % this is now handled in the lilypond spacing engine. 
18 %
19
20 def set_horizontal_spacing =
21         save left_space ,right_space;
22         left_space# = 0;
23         right_space# = 0;
24 enddef;
25
26
27 % [Wanske] says the bulbs should be positioned about 1/4 right of the
28 % "arrow"
29
30 %
31 % TODO: the hair-curve at z6r looks a little awkward.
32 def draw_c_clef (expr reduction) = 
33         save hair, norm, reduced_ss, right_edge;
34         reduced_ss#=staff_space#*reduction;
35         norm#:=2/3reduced_ss#;
36         hair#:=1/6norm#;
37
38         set_horizontal_spacing;
39         right_edge# = 15/4norm#+2hair#;
40
41         set_char_box (left_space#, right_edge# + right_space#, 
42                 2 reduced_ss#, 2 reduced_ss#);
43         define_pixels (hair,norm,reduced_ss, right_edge);
44
45         draw_block ((0,-d), (3/4norm+1/2hair,h));
46         draw_block ((3/4norm+2hair,-d), 
47                 (3/4norm+7/2hair,h));
48         
49         save xoff;
50         xoff=3/4norm+7/2hair;
51         penpos1(hair,-90);
52         z1l=(xoff+norm+hair,h);
53         penpos2(norm-3/2hair,180);
54         z2l=(right_edge,h/2);
55         penpos3(hair,90);
56         z3=(((right_edge -xoff)/2)+xoff,2hair);
57
58         penpos4(hair,0);
59         z4=(xoff+1/2norm+1/2hair,reduced_ss-hair);
60         
61         penpos5(4hair,0);
62         z5=(xoff+5/4hair,0);
63
64         penpos6(norm-hair,90);
65         z6=(xoff+3/4norm,0);
66
67
68         save t; t=0.833;
69         save p; path p;
70         p = z5l..z4l{up}..z4r{down}..z3r{right}..tension t..z2r{up}
71                 ..tension t..
72                 flare_path(z1l,180,90,hair,norm-1/2hair, -1)
73                 ..tension t..z2l{down}
74                 ..z3l{left}..z6r..z5r{down};
75         pickup pencircle scaled 1pt#;
76         filldraw p..(reverse p yscaled -1)..cycle;
77         penlabels (1,2,3,4,5,6);
78
79         % ugh, should be bulb, not flare?
80
81         enddef;
82
83 fet_beginchar ("C clef", "C", "altoclef")
84         if test = 1:
85                 draw_staff (-2,2, 0.0);
86         fi;
87         draw_c_clef (1.0);
88 fet_endchar;
89
90 fet_beginchar ("C clef", "C_change", "caltoclef")
91         if test = 1:
92                 draw_staff (-2,2, 0.0);
93         fi;
94         draw_c_clef (.8);
95 fet_endchar;
96
97 %
98 % New bulb routine:
99 %
100 % Insert a brushed piece of the path, and draw a bulb separately
101 %
102 % The bulb is  circular form. Neat merging of the bulb and brushed path
103 % is done by playing with tension.
104 %
105 %
106
107 def new_bulb (expr outer_tangent_point, 
108     big_radius, bulb_radius, flare, direction) =
109   begingroup;
110     save p, oldpen;
111     path p;
112     pen oldpen;
113     save center;
114     pair center;
115     clearxy;
116     
117     center = outer_tangent_point +big_radius* dir(0) + big_radius* dir(-90)
118       - bulb_radius * dir (-90);
119
120     z1 = center + bulb_radius * dir 180;
121     z2 = center + bulb_radius * dir 270;
122
123     z9 = center + bulb_radius * dir (0);
124     z10 = center + bulb_radius * dir (90);
125     z3 = outer_tangent_point + flare * dir (0);
126
127     labels(1,2,3,9,10);
128
129     % tension is needed to open up the space between return path and the
130     % ball.
131     fill
132       z9 .. z10 .. tension 1.1  .. z1 .. z2 .. cycle;
133     
134     p:=    outer_tangent_point{down}
135        .. tension 0.97
136        .. {up}z9 -- z3
137      ;
138     if direction = 1:
139       p
140     else:
141       reverse p
142     fi
143   endgroup
144 enddef;
145
146
147
148 %
149 %
150 % There is  some variation is shape of bass clefs. Important points
151 %
152 % * the size of the swoosh tip: in some clefs, it almost reaches the
153 % bottom staff line, in some it crosses the 2nd line from the bottom
154 % with a small overshoot.
155 %
156 % The most popular design is where the X part of the tip is aligned 
157 % left bulb boundary, and the Y part ends on the 2nd staffline exactly. 
158 % This is what we do.
159 %
160 % * The size of the bulb. The diameter of the bulb is the width of the 
161 % open space.
162 %
163 % * The y-alignment of the bulb. The center of the bulb can be on or slightly 
164 % above the staff line.
165 %
166 % * The position of the dots. They can be symmetrical around the
167 % staffline, centered in the staff space. The Baerenreiter SCS has the
168 % bottom dot raised by approx. 0.1 ss.
169 %
170 % * uncarefully set music may have overshoots at the top. We have none. 
171 %
172 % * It is not exactly clear where the vertical tangent at the right
173 % of the swoosh should be.
174 %
175 %
176
177 def draw_bass_clef(expr exact_center, reduction) = 
178         save reduced_ss, left_tilt, left_thick, swoosh_width;
179         save right_thickness, tip_protude;
180         pair tip_protude;
181         save dot_diam;
182         reduced_ss# = staff_space# * reduction;
183
184
185         2.2 dot_diam = round reduction* (staff_space - stafflinethickness);
186         right_thickness = 0.48;
187         left_thick = .25;
188         swoosh_width# = 2.1 reduced_ss#;
189 %       tip_protude := (-stafflinethickness, -.2 staff_space);
190         tip_protude := (0, 0);  
191         set_horizontal_spacing;
192         bulb_y_offset := 0.15 staff_space;
193         overshoot_top := 0.0;
194         %% 
195
196         set_char_box(left_space# +
197                 - xpart exact_center,
198                 right_space# +
199                 xpart exact_center + swoosh_width# + 7/12 reduced_ss#, 
200                 - ypart exact_center + 2.5 reduced_ss#, 
201                 ypart exact_center +reduced_ss#);
202
203         define_pixels(swoosh_width);
204         define_whole_pixels(reduced_ss); 
205         left_tilt = 5;
206
207         y1 = bulb_y_offset;
208         x1 = 0;
209
210         x2 = .5 [x1,x3];
211         x2l = x2r = x2;
212
213         y2l := vround_pixels (reduced_ss#  + 0.5 stafflinethickness#);
214         y2l - y2r = (1.0 + overshoot_top) * stafflinethickness;
215         y2 = .5 [y2l, y2r];
216
217         x3l - x1 =  swoosh_width;
218         x3l - x3r = right_thickness * reduced_ss;
219
220         % try to correct: the top dot seems farther away if y3l = 0.
221         y3l = 0.05 staff_space;
222         
223         z4 =  - (0, 2.0 reduced_ss) + tip_protude;
224
225         z5 = (x3l +  1/3 reduced_ss, .5 reduced_ss);
226
227         penpos3(whatever,  185);
228         penpos4(stafflinethickness, 135);
229
230         pickup pencircle scaled 1; 
231 %       draw
232         fill
233            new_bulb (z1, 0.45 reduced_ss, 0.4 reduced_ss, 2.5 stafflinethickness,  1)
234
235 {dir (90)}
236                 .. z2r{right} .. tension 1.0 .. z3r{down}  .. {curl 0} 
237                 simple_serif(z4r, z4l, 90) {curl 0}
238                 .. z3l{up} .. tension 0.9 .. z2l{left} 
239                  .. cycle
240                 ;
241         labels(2,4);
242         labels(range 1 thru 12);
243
244         penlabels(2,3,4);
245
246         pickup pencircle scaled dot_diam;
247         drawdot z5;
248         drawdot z5 yscaled -1;
249 enddef;
250
251
252
253
254 fet_beginchar("F clef ", "F", "bassclef")
255         if test = 1:
256                 draw_staff(-3,1, 0.0);
257         fi;
258         draw_bass_clef((0, 0), 1.0);
259 fet_endchar;
260
261 fet_beginchar("F clef (reduced)", "F_change", "cbassclef")
262         draw_bass_clef((0, 0),0.8);
263 fet_endchar;
264
265
266
267 %
268 % Inspired by Baerenreiter
269
270 % FIXME bulb should curve (see bass clef)
271 % FIXME start (inside) should be little thinner
272 % FIXME parametrise.
273 %
274
275 % Beste lezers, kijk,
276 %
277 % Een bolletje  hebben we bij toeval allemaal wel eens getekend, maar begint u
278 % toch eenvoudig.   Eerst een eenvoudig kruis of herstellingsteken
279 % en via de dubbelslag naar een voorzichtig vlaggetje, en heb geduld!
280 % Ikzelf heb bijvoorbeeld over mijn eerste gave G-sleutel
281 % 35 kilobyte metafont, 12 patchlevels, 0 vriendinnen en 45 dagen gedaan
282 %
283 %  -- vrij naar Van Kooten & De Bie
284 %
285
286 def draw_gclef (expr exact_center, reduction)=
287         save reduced_ss, downstroke_dir, downstroke_angle, hair, center;
288         save breapth_factor, inner_thick_end, thinness, thickness, thinnib;
289         save inner_start_angle, thinness, thinpen;
290         reduced_ss# = staff_space# * reduction;
291         define_pixels(reduced_ss);
292         pair downstroke_dir, center;
293
294         center := (hround_pixels(xpart exact_center), 
295                 vround_pixels(ypart exact_center));
296
297         hair =  .3 stafflinethickness;
298 %       hair = blot_diameter; 
299         thinness = 1.3 stafflinethickness;
300         downstroke_dir = (14, -75);
301         breapth_factor = 11/7;
302         inner_thick_end = 45;
303         inner_start_angle = downstroke_angle - 43;
304         thickness = .4 reduced_ss - hair;
305
306         thinnib = thinness - hair;
307         thinpen = thinness;
308         set_horizontal_spacing;
309         
310         set_char_box(
311                 left_space# +
312                 -xpart exact_center + 1.0 * breapth_factor* reduced_ss#, 
313                 right_space# +
314                 xpart exact_center + .66 breapth_factor* reduced_ss#,
315                 -ypart exact_center + 3 * reduced_ss#,
316                 ypart exact_center + 5 * reduced_ss#);
317         
318         pickup pencircle scaled hair;
319         downstroke_angle = angle downstroke_dir;
320
321         z1 = center + whatever * dir (inner_start_angle);
322         x1 = xpart center -.28 reduced_ss;
323         
324         top z2r = center + (0,reduced_ss + stafflinethickness/2);
325         
326         x4 = xpart center - .1 reduced_ss;
327         bot y4r = -(reduced_ss + .5 stafflinethickness);
328
329         z3 = (z4 - center) rotated inner_thick_end + center;
330         
331         z5r = (- breapth_factor, .37)* reduced_ss + center;
332         penpos5(thickness, 135);
333
334         z6 = center + whatever * downstroke_dir;
335         y6 = ypart center + 2 reduced_ss;
336
337         z7l - z6 = whatever *(z5- z6) ;
338         y7l = 3.5 reduced_ss;
339         z8r = .4 [z9r, z7r] + 1.5 stafflinethickness * dir 52;
340
341         x9 = .7 [x10, x7r];
342         top y9l = 5 reduced_ss;
343
344         y10 = 3. reduced_ss;
345         y11 = -11/7 reduced_ss;
346
347         y12 = ypart center - 18.5/7 reduced_ss;
348         x12 = x11 - 5 /7 reduced_ss;    
349
350         z13 = z12 + .6 reduced_ss*(-1,1);
351
352         (z10r - z10l) dotprod (unitvector downstroke_dir rotated 90) = 
353                 thinnib;
354
355         center - z10= whatever * downstroke_dir;
356         center - z11 =  whatever * downstroke_dir;
357         center - z14 = .8 (center - z11);
358         penpos1(thinnib, inner_start_angle);
359         penpos2(thickness, 90);
360         penpos3(thinnib, -90 + inner_thick_end);
361         penpos4(thinnib, -90);
362
363
364         penpos7(thickness, 135);
365         penpos8(1.5 thinnib, - 70 + angle downstroke_dir);
366         penpos9(1.4 thickness, -80);  % ugh
367         penpos10(whatever, downstroke_angle + 10);
368         penpos11(thinnib, downstroke_angle + 90);
369         penpos14(thinnib, downstroke_angle + 90);
370         penpos12(thinnib, -90);
371         penpos13(3 thinnib, 180);
372
373         filldraw z2l{right}   .. z3l.. z4l{left} .. z5l{up}  .. z7l{up} 
374                 %.. z8l 
375                 .. tension 1.2 
376                 .. z9l & z9l ..
377                 {downstroke_dir}z10l --- z11l -- z11r --- z10r{- downstroke_dir} 
378                 .. tension .8 
379                 .. z9r & z9r{dir (downstroke_angle+ 40)} % ugh
380                 %.. z8r
381                 .. z7r{down} .. z5r{down} .. z4r{right}
382                 .. z3r .. z2r{left} .. 
383                 tension .95 .. 
384                 z1r -- z1l 
385                 .. tension 0.85 ..cycle;
386
387         filldraw simple_serif(z1r, z1l, 80)  -- cycle;
388
389         filldraw z12r{left} .. z13r{up} -- z13l{down} .. z12l{right} .. cycle;
390
391         draw_bulb(-1,  z13l, lft z13r, 6/14 reduced_ss, 1.0);
392
393         pickup pencircle scaled (thinpen);
394         draw z10 --- z14 .. z11  .. tension 0.85 ..  z12{left};
395
396         penlabels(range 1 thru 15);
397 enddef;
398
399
400 fet_beginchar("G clef", "G", "trebleclef")
401         if test = 1:
402                 draw_staff(-1,3, 0.0);
403         fi;
404         draw_gclef((1.7 staff_space#,0), 1.0);
405 fet_endchar;
406 fet_beginchar("G clef", "G_change", "ctrebleclef")
407         draw_gclef((1.3 staff_space#,0), .8);
408 fet_endchar;
409
410 %%%%
411 % PERCUSSION
412 %
413 %
414
415
416 def draw_percussion_clef(expr reduction) =
417         save reduced_ss;
418         reduced_ss# = staff_space# * reduction;
419         define_pixels(reduced_ss);
420         set_char_box(-.67reduced_ss#,2.0reduced_ss#,reduced_ss#,reduced_ss#);
421         razt := 0.45reduced_ss;
422         draw_block((-b,-d),(-b+razt,h));
423         draw_block((w-razt,-d),(w,h));
424 enddef;
425
426 fet_beginchar("percussion clef", "percussion", "percussionclef")
427         draw_percussion_clef(1.0);
428 fet_endchar;
429
430 fet_beginchar("percussion clef (reduced)", "percussion_change", "cpercussionclef")
431         draw_percussion_clef(.8);
432 fet_endchar;
433
434 def draw_tab_T(expr pos, siz, slant) =
435         begingroup;
436         clearxy;
437         pair vx,vy;
438         vx=(xpart siz) * dir 0;
439         vy=(ypart siz) * dir 90;
440
441         penpos1(.75penh, 100);
442         z1=z2+(1/6*vx-.15*vy);
443         penpos2(.9penw, 0);
444         z2l = pos+.75vy;
445         penpos3(penh,-100);
446         z3l = pos+.4vx+vy;
447         penpos4(penh,-90);
448         z4=-.1vy+.5[z3,z5];
449         penpos5(.8penh,-30);
450         x5r=xpart (pos+siz);
451         y5l=ypart (pos+siz);
452
453         penpos10(penw,170);
454         z10=pos+.55vx+.85vy;
455         penpos11(.75[penh,penw],170);
456         z11=z10-.5vy+.025vx;
457         penpos12(penh,100);
458         z12l=(xpart .5[z13,z11],ypart (pos-.025*siz));
459         penpos13(.75penh,60);
460         z13=pos +.2vx+.15vy;
461         
462         % penlabels (1,2,3,4,5,10,11,12,13);
463
464         soft_penstroke (z1e..tension 1.1
465                 ..z2e
466                 ..z3e{right}..tension 1.5
467                 ..z4e
468                 ..z5e
469                 ) slanted slant shifted (slant*-ypart pos,0);
470
471         soft_penstroke (z10e..tension 1.5
472                 ..z11e
473                 ..z12e..tension 1.1
474                 ..z13e{(z13r-z13l) rotated 90}
475                 ) slanted slant shifted (slant*-ypart pos,0);
476         endgroup;
477 enddef;
478            
479 def draw_tab_A(expr pos, siz, slant) =
480         begingroup;
481         clearxy;
482         pair vx,vy;
483         vx=(xpart siz) * dir 0;
484         vy=(ypart siz) * dir 90;
485         
486         penpos1(.75penh,-110);
487         z1r=pos+.07vy;
488         penpos2(penh,-75);
489         z2r=(.5[x1,x3],ypart pos);
490         penpos3(.25[penh,penw],-30);
491         z3=(.45[x2,x4],.15[y2,y4]);
492         penpos4(1[penh,penw],0);
493         z4=pos+.5vx+.975vy;
494
495         penpos5(1[penh,penw],-180);
496         z5=z4;
497         penpos6(.2[penh,penw],-150);
498         z6l=(.8[x5l,x7l],.9[y5l,y7l]);
499         penpos7(penh,-90);
500         z7r=(.5[x6,x8],ypart pos);
501         penpos8(.75penh,-70);
502         z8r=(xpart(pos+siz),y7r+.075ypart(siz));
503
504         penpos10(penh,-105);
505         z10=.2[z3,z4];
506         penpos11(.9penh,-90);
507         z11=.4[z10,z6]-0.05vy;
508         penpos12(.75penh,-75);
509         z12=.3[z11,z6]+0.02vy;
510
511         % penlabels(1,2,3,4,5,6,7,8,10,11,12);
512
513         soft_penstroke (z1e {(z1r-z1l) rotated 90}
514                 ..z2e 
515                 ..z3e
516                 ..z4e
517                 ) slanted slant shifted (slant*-ypart pos,0);
518
519         soft_penstroke (z5e
520                 ..z6e 
521                 ..z7e
522                 ..z8e {(z8r-z8l) rotated 90}
523                 ) slanted slant shifted (slant*-ypart pos,0);
524
525         soft_penstroke (z10e
526                 ..z11e
527                 ..z12e
528                 ) slanted slant shifted (slant*-ypart pos,0);
529
530         endgroup;
531 enddef;
532
533 def draw_tab_B(expr pos, siz, slant) =
534         begingroup;
535         clearxy;
536         pair vx,vy;
537         vx=(xpart siz) * dir 0;
538         vy=(ypart siz) * dir 90;
539
540         penpos1(.75penh, 100);
541         z1=z2+(.15*vx-.1*vy);
542         penpos2(.9penw, 0);
543         z2l = pos+.75vy;
544         penpos3(penh,-100);
545         z3l = pos+.4vx+1.05vy;
546         penpos4(.8[penh,penw],-180);
547         z4=(xpart(pos+.75siz),.5[y3,y5]);
548         penpos5(.8penh,90);
549         z5=(.5[x10,x4],ypart (pos+.55siz));
550
551         penpos6(.8penh,270);
552         z6=z5;
553         penpos7(penw,180);
554         z7l=(xpart(pos+siz),.5[y6,y8]);
555         penpos8(.8penh,45);
556         z8=.5[z12l,z11l]+.15vx-.05vy;
557
558         penpos10(.75[penh,penw],170);
559         z10=pos+.375vx+.95vy;
560         penpos11(.8[penh,penw],150);
561         z11=z10-.5vy+.04vx;
562         penpos12(penh,100);
563         z12l=(xpart .5[z13,z11],ypart pos);
564         penpos13(.75penh,60);
565         z13=pos+.1vx+.15vy;
566         
567         % penlabels (1,2,3,4,5,6,7,8,10,11,12,13);
568
569         soft_penstroke (z1e..tension 1.1
570                 ..z2e
571                 ..z3e
572                 ..z4e
573                 ..z5e{left}
574                 ) slanted slant shifted (slant*-ypart pos,0);
575
576         soft_penstroke (z6e{right}
577                 ..z7e
578                 ..z8e{(z8r-z8l) rotated 90}
579                 ) slanted slant shifted (slant*-ypart pos,0);
580
581         soft_penstroke (z10e.. tension 1.5
582                 ..z11e
583                 ..z12e..tension 1.1
584                 ..z13e{(z13r-z13l) rotated 90}
585                 ) slanted slant shifted (slant*-ypart pos,0);
586         endgroup;
587 enddef;
588
589 def draw_tab_clef(expr reduction) =
590         save reduced_ss,vx,vy,letterheight,penw,penh;
591         reduced_ss# = staff_space# * reduction;
592         letterheight# = 1.8*reduced_ss#;
593         define_pixels(reduced_ss,letterheight);
594         set_char_box(-.2*reduced_ss#,2.8*reduced_ss#,1.6*letterheight#,1.6*letterheight#);
595
596                 %draw_staff (-3,2, 0.5);
597
598         penw = .45reduced_ss;
599         penh = .2reduced_ss;
600
601         draw_tab_T((-b+.15reduced_ss,h-letterheight),
602           (2.1*reduced_ss,letterheight),0.2);
603         draw_tab_A((-b-.05reduced_ss,-.5letterheight +.15reduced_ss),
604           (2.2*reduced_ss,letterheight),0.4);
605         draw_tab_B((-b+.025reduced_ss,-d),
606           (2.1*reduced_ss,letterheight),0.25);
607 enddef;
608
609 fet_beginchar("tab clef", "tab", "tabclef")
610         draw_tab_clef(1.0);
611 fet_endchar;
612
613 fet_beginchar("tab clef (reduced)", "tab_change", "ctabclef")
614         draw_tab_clef(.8);
615 fet_endchar;
616
617 fet_endgroup("clefs");