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