]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-klef.mf
release: 1.5.39
[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 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#;
33         hair#:=1/6norm#;
34
35         set_horizontal_spacing;
36         right_edge# = 15/4norm#+2hair#;
37
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);
41
42         draw_block ((0,-d), (3/4norm+1/2hair,h));
43         draw_block ((3/4norm+2hair,-d), 
44                 (3/4norm+7/2hair,h));
45         
46         save xoff;
47         xoff=3/4norm+7/2hair;
48         penpos1(hair,-90);
49         z1l=(xoff+norm+hair,h);
50         penpos2(norm-3/2hair,180);
51         z2l=(right_edge,h/2);
52         penpos3(hair,90);
53         z3=(((right_edge -xoff)/2)+xoff,2hair);
54
55         penpos4(hair,0);
56         z4=(xoff+1/2norm+1/2hair,reduced_ss-hair);
57         
58         penpos5(4hair,0);
59         z5=(xoff+5/4hair,0);
60
61         penpos6(norm-hair,90);
62         z6=(xoff+3/4norm,0);
63
64
65         save t; t=0.833;
66         save p; path p;
67         p = z5l..z4l{up}..z4r{down}..z3r{right}..tension t..z2r{up}
68                 ..tension t..
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);
75
76         % ugh, should be bulb, not flare?
77
78         enddef;
79
80 fet_beginchar ("C clef", "C", "altoclef")
81         if test = 1:
82                 draw_staff (-2,2, 0.0);
83         fi;
84         draw_c_clef (1.0);
85 fet_endchar;
86
87 fet_beginchar ("C clef", "C_change", "caltoclef")
88         if test = 1:
89                 draw_staff (-2,2, 0.0);
90         fi;
91         draw_c_clef (.8);
92 fet_endchar;
93
94 %
95 % New bulb routine:
96 %
97 % Insert a brushed piece of the path, and draw a bulb separately
98 %
99 % The bulb is  circular form. Neat merging of the bulb and brushed path
100 % is done by playing with tension.
101 %
102 %
103
104 def new_bulb (expr outer_tangent_point, 
105     big_radius, bulb_radius, flare, direction) =
106   begingroup;
107     save p, oldpen;
108     path p;
109     pen oldpen;
110     save center;
111     pair center;
112     clearxy;
113     
114     center = outer_tangent_point +big_radius* dir(0) + big_radius* dir(-90)
115       - bulb_radius * dir (-90);
116
117     z1 = center + bulb_radius * dir 180;
118     z2 = center + bulb_radius * dir 270;
119
120     z9 = center + bulb_radius * dir (0);
121     z10 = center + bulb_radius * dir (90);
122     z3 = outer_tangent_point + flare * dir (0);
123
124     labels(1,2,3,9,10);
125
126     % tension is needed to open up the space between return path and the
127     % ball.
128     fill
129       z9 .. z10 .. tension 1.1  .. z1 .. z2 .. cycle;
130     
131     p:=    outer_tangent_point{down}
132        .. tension 0.97
133        .. {up}z9 -- z3
134      ;
135     if direction = 1:
136       p
137     else:
138       reverse p
139     fi
140   endgroup
141 enddef;
142
143
144
145 %
146 %
147 % There is  some variation is shape of bass clefs. Important points
148 %
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.
152 %
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.
156 %
157 % * The size of the bulb. The diameter of the bulb is the width of the 
158 % open space.
159 %
160 % * The y-alignment of the bulb. The center of the bulb can be on or slightly 
161 % above the staff line.
162 %
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.
166 %
167 % * uncarefully set music may have overshoots at the top. We have none. 
168 %
169 % * It is not exactly clear where the vertical tangent at the right
170 % of the swoosh should be.
171 %
172 %
173
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;
177         pair tip_protude;
178         save dot_diam;
179         reduced_ss# = staff_space# * reduction;
180
181
182         2.2 dot_diam = round reduction* (staff_space - stafflinethickness);
183         right_thickness = 0.48;
184         left_thick = .25;
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;
191         %% 
192
193         set_char_box(left_space# +
194                 - xpart exact_center,
195                 right_space# +
196                 xpart exact_center + swoosh_width# + 7/12 reduced_ss#, 
197                 - ypart exact_center + 2.5 reduced_ss#, 
198                 ypart exact_center +reduced_ss#);
199
200         define_pixels(swoosh_width);
201         define_whole_pixels(reduced_ss); 
202         left_tilt = 5;
203
204         y1 = bulb_y_offset;
205         x1 = 0;
206
207         x2 = .5 [x1,x3];
208         x2l = x2r = x2;
209
210         y2l := vround_pixels (reduced_ss#  + 0.5 stafflinethickness#);
211         y2l - y2r = (1.0 + overshoot_top) * stafflinethickness;
212         y2 = .5 [y2l, y2r];
213
214         x3l - x1 =  swoosh_width;
215         x3l - x3r = right_thickness * reduced_ss;
216
217         % try to correct: the top dot seems farther away if y3l = 0.
218         y3l = 0.05 staff_space;
219         
220         z4 =  - (0, 2.0 reduced_ss) + tip_protude;
221
222         z5 = (x3l +  1/3 reduced_ss, .5 reduced_ss);
223
224         penpos3(whatever,  185);
225         penpos4(stafflinethickness, 135);
226
227         pickup pencircle scaled 1; 
228 %       draw
229         fill
230            new_bulb (z1, 0.45 reduced_ss, 0.4 reduced_ss, 2.5 stafflinethickness,  1)
231
232 {dir (90)}
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} 
236                  .. cycle
237                 ;
238         labels(2,4);
239         labels(range 1 thru 12);
240
241         penlabels(2,3,4);
242
243         pickup pencircle scaled dot_diam;
244         drawdot z5;
245         drawdot z5 yscaled -1;
246 enddef;
247
248
249
250
251 fet_beginchar("F clef ", "F", "bassclef")
252         if test = 1:
253                 draw_staff(-3,1, 0.0);
254         fi;
255         draw_bass_clef((0, 0), 1.0);
256 fet_endchar;
257
258 fet_beginchar("F clef (reduced)", "F_change", "cbassclef")
259         draw_bass_clef((0, 0),0.8);
260 fet_endchar;
261
262
263
264 %
265 % Inspired by Baerenreiter
266
267 % FIXME bulb should curve (see bass clef)
268 % FIXME start (inside) should be little thinner
269 % FIXME parametrise.
270 %
271
272 % Beste lezers, kijk,
273 %
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
279 %
280 %  -- vrij naar Van Kooten & De Bie
281 %
282
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;
290
291         center := (hround_pixels(xpart exact_center), 
292                 vround_pixels(ypart exact_center));
293
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;
302
303         thinnib = thinness - hair;
304         thinpen = thinness;
305         set_horizontal_spacing;
306         
307         set_char_box(
308                 left_space# +
309                 -xpart exact_center + 1.0 * breapth_factor* reduced_ss#, 
310                 right_space# +
311                 xpart exact_center + .66 breapth_factor* reduced_ss#,
312                 -ypart exact_center + 3 * reduced_ss#,
313                 ypart exact_center + 5 * reduced_ss#);
314         
315         pickup pencircle scaled hair;
316         downstroke_angle = angle downstroke_dir;
317
318         z1 = center + whatever * dir (inner_start_angle);
319         x1 = xpart center -.28 reduced_ss;
320         
321         top z2r = center + (0,reduced_ss + stafflinethickness/2);
322         
323         x4 = xpart center - .1 reduced_ss;
324         bot y4r = -(reduced_ss + .5 stafflinethickness);
325
326         z3 = (z4 - center) rotated inner_thick_end + center;
327         
328         z5r = (- breapth_factor, .37)* reduced_ss + center;
329         penpos5(thickness, 135);
330
331         z6 = center + whatever * downstroke_dir;
332         y6 = ypart center + 2 reduced_ss;
333
334         z7l - z6 = whatever *(z5- z6) ;
335         y7l = 3.5 reduced_ss;
336         z8r = .4 [z9r, z7r] + 1.5 stafflinethickness * dir 52;
337
338         x9 = .7 [x10, x7r];
339         top y9l = 5 reduced_ss;
340
341         y10 = 3. reduced_ss;
342         y11 = -11/7 reduced_ss;
343
344         y12 = ypart center - 18.5/7 reduced_ss;
345         x12 = x11 - 5 /7 reduced_ss;    
346
347         z13 = z12 + .6 reduced_ss*(-1,1);
348
349         (z10r - z10l) dotprod (unitvector downstroke_dir rotated 90) = 
350                 thinnib;
351
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);
359
360
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);
369
370         filldraw z2l{right}   .. z3l.. z4l{left} .. z5l{up}  .. z7l{up} 
371                 %.. z8l 
372                 .. tension 1.2 
373                 .. z9l & z9l ..
374                 {downstroke_dir}z10l --- z11l -- z11r --- z10r{- downstroke_dir} 
375                 .. tension .8 
376                 .. z9r & z9r{dir (downstroke_angle+ 40)} % ugh
377                 %.. z8r
378                 .. z7r{down} .. z5r{down} .. z4r{right}
379                 .. z3r .. z2r{left} .. 
380                 tension .95 .. 
381                 z1r -- z1l 
382                 .. tension 0.85 ..cycle;
383
384         filldraw simple_serif(z1r, z1l, 80)  -- cycle;
385
386         filldraw z12r{left} .. z13r{up} -- z13l{down} .. z12l{right} .. cycle;
387
388         draw_bulb(-1,  z13l, lft z13r, 6/14 reduced_ss, 1.0);
389
390         pickup pencircle scaled (thinpen);
391         draw z10 --- z14 .. z11  .. tension 0.85 ..  z12{left};
392
393         penlabels(range 1 thru 15);
394 enddef;
395
396
397 fet_beginchar("G clef", "G", "trebleclef")
398         if test = 1:
399                 draw_staff(-1,3, 0.0);
400         fi;
401         draw_gclef((1.7 staff_space#,0), 1.0);
402 fet_endchar;
403 fet_beginchar("G clef", "G_change", "ctrebleclef")
404         draw_gclef((1.3 staff_space#,0), .8);
405 fet_endchar;
406
407 %%%%
408 % PERCUSSION
409 %
410 %
411
412
413 def draw_percussion_clef(expr reduction) =
414         save reduced_ss;
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));
421 enddef;
422
423 fet_beginchar("percussion clef", "percussion", "percussionclef")
424         draw_percussion_clef(1.0);
425 fet_endchar;
426
427 fet_beginchar("percussion clef (reduced)", "percussion_change", "cpercussionclef")
428         draw_percussion_clef(.8);
429 fet_endchar;
430
431 def draw_tab_T(expr pos, siz, slant) =
432         begingroup;
433         clearxy;
434         pair vx,vy;
435         vx=(xpart siz) * dir 0;
436         vy=(ypart siz) * dir 90;
437
438         penpos1(.75penh, 100);
439         z1=z2+(1/6*vx-.15*vy);
440         penpos2(.9penw, 0);
441         z2l = pos+.75vy;
442         penpos3(penh,-100);
443         z3l = pos+.4vx+vy;
444         penpos4(penh,-90);
445         z4=-.1vy+.5[z3,z5];
446         penpos5(.8penh,-30);
447         x5r=xpart (pos+siz);
448         y5l=ypart (pos+siz);
449
450         penpos10(penw,170);
451         z10=pos+.55vx+.85vy;
452         penpos11(.75[penh,penw],170);
453         z11=z10-.5vy+.025vx;
454         penpos12(penh,100);
455         z12l=(xpart .5[z13,z11],ypart (pos-.025*siz));
456         penpos13(.75penh,60);
457         z13=pos +.2vx+.15vy;
458         
459         % penlabels (1,2,3,4,5,10,11,12,13);
460
461         soft_penstroke (z1e..tension 1.1
462                 ..z2e
463                 ..z3e{right}..tension 1.5
464                 ..z4e
465                 ..z5e
466                 ) slanted slant shifted (slant*-ypart pos,0);
467
468         soft_penstroke (z10e..tension 1.5
469                 ..z11e
470                 ..z12e..tension 1.1
471                 ..z13e{(z13r-z13l) rotated 90}
472                 ) slanted slant shifted (slant*-ypart pos,0);
473         endgroup;
474 enddef;
475            
476 def draw_tab_A(expr pos, siz, slant) =
477         begingroup;
478         clearxy;
479         pair vx,vy;
480         vx=(xpart siz) * dir 0;
481         vy=(ypart siz) * dir 90;
482         
483         penpos1(.75penh,-110);
484         z1r=pos+.07vy;
485         penpos2(penh,-75);
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);
490         z4=pos+.5vx+.975vy;
491
492         penpos5(1[penh,penw],-180);
493         z5=z4;
494         penpos6(.2[penh,penw],-150);
495         z6l=(.8[x5l,x7l],.9[y5l,y7l]);
496         penpos7(penh,-90);
497         z7r=(.5[x6,x8],ypart pos);
498         penpos8(.75penh,-70);
499         z8r=(xpart(pos+siz),y7r+.075ypart(siz));
500
501         penpos10(penh,-105);
502         z10=.2[z3,z4];
503         penpos11(.9penh,-90);
504         z11=.4[z10,z6]-0.05vy;
505         penpos12(.75penh,-75);
506         z12=.3[z11,z6]+0.02vy;
507
508         % penlabels(1,2,3,4,5,6,7,8,10,11,12);
509
510         soft_penstroke (z1e {(z1r-z1l) rotated 90}
511                 ..z2e 
512                 ..z3e
513                 ..z4e
514                 ) slanted slant shifted (slant*-ypart pos,0);
515
516         soft_penstroke (z5e
517                 ..z6e 
518                 ..z7e
519                 ..z8e {(z8r-z8l) rotated 90}
520                 ) slanted slant shifted (slant*-ypart pos,0);
521
522         soft_penstroke (z10e
523                 ..z11e
524                 ..z12e
525                 ) slanted slant shifted (slant*-ypart pos,0);
526
527         endgroup;
528 enddef;
529
530 def draw_tab_B(expr pos, siz, slant) =
531         begingroup;
532         clearxy;
533         pair vx,vy;
534         vx=(xpart siz) * dir 0;
535         vy=(ypart siz) * dir 90;
536
537         penpos1(.75penh, 100);
538         z1=z2+(.15*vx-.1*vy);
539         penpos2(.9penw, 0);
540         z2l = pos+.75vy;
541         penpos3(penh,-100);
542         z3l = pos+.4vx+1.05vy;
543         penpos4(.8[penh,penw],-180);
544         z4=(xpart(pos+.75siz),.5[y3,y5]);
545         penpos5(.8penh,90);
546         z5=(.5[x10,x4],ypart (pos+.55siz));
547
548         penpos6(.8penh,270);
549         z6=z5;
550         penpos7(penw,180);
551         z7l=(xpart(pos+siz),.5[y6,y8]);
552         penpos8(.8penh,45);
553         z8=.5[z12l,z11l]+.15vx-.05vy;
554
555         penpos10(.75[penh,penw],170);
556         z10=pos+.375vx+.95vy;
557         penpos11(.8[penh,penw],150);
558         z11=z10-.5vy+.04vx;
559         penpos12(penh,100);
560         z12l=(xpart .5[z13,z11],ypart pos);
561         penpos13(.75penh,60);
562         z13=pos+.1vx+.15vy;
563         
564         % penlabels (1,2,3,4,5,6,7,8,10,11,12,13);
565
566         soft_penstroke (z1e..tension 1.1
567                 ..z2e
568                 ..z3e
569                 ..z4e
570                 ..z5e{left}
571                 ) slanted slant shifted (slant*-ypart pos,0);
572
573         soft_penstroke (z6e{right}
574                 ..z7e
575                 ..z8e{(z8r-z8l) rotated 90}
576                 ) slanted slant shifted (slant*-ypart pos,0);
577
578         soft_penstroke (z10e.. tension 1.5
579                 ..z11e
580                 ..z12e..tension 1.1
581                 ..z13e{(z13r-z13l) rotated 90}
582                 ) slanted slant shifted (slant*-ypart pos,0);
583         endgroup;
584 enddef;
585
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#);
592
593                 %draw_staff (-3,2, 0.5);
594
595         penw = .45reduced_ss;
596         penh = .2reduced_ss;
597
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);
604 enddef;
605
606 fet_beginchar("tab clef", "tab", "tabclef")
607         draw_tab_clef(1.0);
608 fet_endchar;
609
610 fet_beginchar("tab clef (reduced)", "tab_change", "ctabclef")
611         draw_tab_clef(.8);
612 fet_endchar;
613
614 fet_endgroup("clefs");