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