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