]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-toevallig.mf
Add arrowed flat signs
[lilypond.git] / mf / feta-toevallig.mf
1 %
2 % feta-toevallig.mf -- implement Accidentals
3 %
4 % (c) 1997--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 %
6
7
8 %
9 % also show in other configuration wrt staff lines.
10 %
11 def draw_shifted_too =
12 if test > 0:
13         fet_beginchar ("shifted too", "");
14                 set_char_box (0, 0, 0, 0);
15                 currentpicture := remember_pic;
16
17                 draw_staff (-2, 2, 0.5);
18         fet_endchar;
19 fi;
20 enddef;
21
22
23 %
24 % Accidentals from various sources, notably
25 %
26 %   Baerenreiter edition of Schuberts `Auf dem Strom' (sharp, natural)
27 %   F Hofmeister edition of Muellers `Etueden fuer Horn' (double sharp, flat)
28 %
29
30
31 %
32 % Naming for accidentals (including microtonal variants):
33 %
34 %   SHARPBASE[.SLASHES.STEMS]
35 %   FLATBASE[.MODIFIER]
36 %  
37 % Examples:
38 %
39 %   sharp.slashslash.stem
40 %   mirroredflat.flat
41 %
42 %
43
44
45 fet_begingroup ("accidentals");
46
47 %
48 % Draw an arrow
49 %
50 % * "stemslant" gives the direction of the stem's left boundary
51 %   (needed for brushed stems, equals "up" for straight stems)
52 % * "extend" is used to make the stem longer or shorter (if negative);
53 %   different kinds of accidentals need different values here
54 %
55 def draw_arrow (expr attach, stemwidth, stemslant, extend, pointingdown) =
56 begingroup;
57         save htip;  % tip height
58         save wwing; % wing "radius"
59         save angle_wing_bot, angle_wing_top, angle_tip;
60         save upshift;
61         clearxy;
62
63         wwing:=0.26 stemwidth;
64         htip:=staff_space*0.85 + stafflinethickness - wwing;
65
66         % "flip" is used to reflect the arrow vertically if arrow points downward
67         transform flip;
68         if pointingdown:
69                 flip=identity reflectedabout (origin, right);
70         else:
71                 flip=identity;
72         fi;
73
74         z1=attach shifted ((-stemwidth/2),0);
75         upshift:=max(0, wwing + 0.1 staff_space + extend);
76         z2=z1 shifted (((unitvector stemslant) scaled upshift) transformed flip);
77
78         z7=attach shifted ((stemwidth/2),0);
79         z6=z7 shifted (((unitvector (-xpart stemslant, ypart stemslant))
80                         scaled upshift) transformed flip);
81         (z2-z3)= (0.38 staff_space, 0.05 htip) transformed flip;
82         (z6-z5)=(-0.38 staff_space, 0.05 htip) transformed flip;
83
84         z4 =attach shifted ((-0.2 stemwidth, upshift+htip) transformed flip);
85         z4'=attach shifted (( 0.2 stemwidth, upshift+htip) transformed flip);
86
87         % angle_wing_bot is the angle at which the arc from z2 to z3a enters z3a
88         % angle_wing_top is the angle at which the arc from z3b to z4 leaves z3b
89         % angle_tip is the angle at which the arc from z4 to z4' leaves z4
90         angle_wing_bot=30;
91         angle_wing_top=55;
92         angle_tip=68;
93
94         z3a=z3 shifted ((((dir angle_wing_bot) rotated (-90))
95                          scaled wwing) transformed flip);
96         z3b=z3 shifted ((((dir angle_wing_top) rotated 90)
97                          scaled wwing) transformed flip);
98
99         z5a=z5 shifted ((((dir (180-angle_wing_bot)) rotated 90)
100                          scaled wwing) transformed flip);
101         z5b=z5 shifted ((((dir (180-angle_wing_top)) rotated (-90))
102                          scaled wwing) transformed flip);
103
104         % Draw the arrow
105         pickup pencircle scaled 1;
106         fill z1
107              -- z2{stemslant transformed flip}
108              .. {(-dir angle_wing_bot) transformed flip}z3a
109              .. z3b{(dir angle_wing_top) transformed flip}
110              .. z4{(dir angle_tip) transformed flip}
111              .. z4'{(dir (-angle_tip)) transformed flip}
112              ..{(dir (-angle_wing_top)) transformed flip}z5b
113              ..z5a{(-dir (-angle_wing_bot)) transformed flip}
114              ..z6{((-stemslant) reflectedabout (origin, up)) transformed flip}
115              -- z7
116              --cycle;
117
118         labels(range 0 thru 7,4',3a,3b,5a,5b);
119 endgroup;
120 enddef;
121
122 save remember_pic;
123 picture remember_pic;
124
125 save sharp_beamheight;
126 sharp_beamheight# := 0.3 staff_space# + stafflinethickness#;
127
128 %
129 % The beams of most sharps have horizontal endings (as if drawn with
130 % a square pen).  [Wanske] does not mention this, so we'll just ignore
131 % this fact.
132 %
133
134 def draw_meta_sharp (expr width, offset) =
135         save beamwidth, beamslope;
136         save ne, nw_dist;
137         pair ne, nw_dist;
138
139         beamwidth := width;
140
141         define_whole_vertical_blacker_pixels (sharp_beamheight);
142
143         clearxy;
144
145         beamslope = sharp_beamheight / beamwidth;
146
147         pickup pencircle scaled 2 blot_diameter;
148
149         rt x2 - lft x1 = beamwidth;
150         z2 = z1 + whatever * (beamwidth, sharp_beamheight);
151         .5 [z1, z3] = (.5 w, offset);
152         x3 = x2;
153         top y2 - bot y3 = sharp_beamheight;
154         x4 = x1;
155         top y1 - bot y4 = sharp_beamheight;
156
157         ne = unitvector (z2 - z1);
158         nw_dist = (ne rotated 90) * blot_diameter;
159
160         fill lft z1{up}
161              ... (z1 + nw_dist){ne}
162              -- (z2 + nw_dist){ne}
163              ... rt z2{down}
164              -- rt z3{down}
165              ... (z3 - nw_dist){-ne}
166              -- (z4 - nw_dist){-ne}
167              ... lft z4{up}
168              -- cycle;
169
170         labels (1, 2, 3, 4);
171 enddef;
172
173
174 def draw_sharp(expr arrowup, arrowdown) =
175         save stem, stemx, stemwidth;
176         save outer_space, interbeam;
177         save stemlength, extendleft, extendright, height, depth;
178
179         stemwidth# := stafflinethickness# + .05 staff_space#;
180         define_whole_blacker_pixels (stemwidth);
181
182         interbeam := 1.05 staff_space_rounded;
183
184         stemlength# := 1.5 staff_space#;
185         define_pixels (stemlength);
186
187         height# = stemlength#;
188         depth#  = stemlength#;
189         extendright# = 0;
190         extendleft# = 0;
191         if arrowup:
192                 height# := height# + 1.2 staff_space#;
193                 extendright# := extendright# + 1.5 stafflinethickness#;
194         fi;
195         if arrowdown:
196                 depth# := depth# + 1.2 staff_space#;
197                 extendleft# := extendleft# + 1.5 stafflinethickness#;
198         fi;
199         define_pixels(extendleft, extendright);
200         set_char_box (extendleft#, 1.1 staff_space#, depth#, height#);
201
202         stem := 7 / 16 * w;
203         stemx := hround stem;
204         outer_space := hround ((w - stemx - stemwidth) / 2);
205
206         w := 2 outer_space + stemx + stemwidth;
207         d := d - feta_space_shift;
208
209         draw_meta_sharp (w, -.5 interbeam);
210         draw_meta_sharp (w, -.5 interbeam + vround interbeam);
211
212         % expand the charbox so that it encloses the whole arrow; this mustn't
213         % happen earlier because some commands above still rely on the old width
214         w := w + extendright;
215
216         pickup pencircle scaled stemwidth;
217
218         lft x5 = lft x6 = outer_space;
219         lft x7 = lft x8 = outer_space + stemx;
220         bot y5 = -stemlength;
221         top y6 = vround (1.5 staff_space - stem * beamslope);
222         bot y7 = -top y6 + feta_space_shift;
223         top y8 = stemlength;
224
225         labels (5, 6, 7, 8);
226
227         draw_gridline (z5, z6, stemwidth);
228         draw_gridline (z7, z8, stemwidth);
229
230         if arrowup:
231                 draw_arrow (z8, stemwidth, up,
232                             +(stafflinethickness/2 + stemwidth/2), false);
233         fi;
234         if arrowdown:
235                 draw_arrow (z5, stemwidth, up,
236                             +(stafflinethickness/2 + stemwidth/2), true);
237         fi;
238
239         remember_pic := currentpicture;
240
241         draw_staff (-2, 2, 0);
242 enddef;
243
244
245 fet_beginchar ("Sharp", "sharp");
246         draw_sharp (false, false);
247 fet_endchar;
248
249
250 draw_shifted_too;
251
252
253 fet_beginchar ("Arrowed Sharp (arrow up)", "sharp.arrowup");
254         draw_sharp (true, false);
255 fet_endchar;
256
257
258 draw_shifted_too;
259
260
261 fet_beginchar ("Arrowed Sharp (arrow down)", "sharp.arrowdown");
262         draw_sharp (false, true);
263 fet_endchar;
264
265
266 draw_shifted_too;
267
268
269 fet_beginchar ("1/2 Sharp", "sharp.slashslash.stem");
270         save stem, stemwidth;
271         save outer_space, interbeam;
272
273         stemwidth# := stafflinethickness# + .05 staff_space#;
274         define_whole_blacker_pixels (stemwidth);
275
276         interbeam := 1.05 staff_space_rounded;
277
278         set_char_box (0, 0.7 staff_space#,
279                       1.5 staff_space#, 1.5 staff_space#);
280
281         stem := 7 / 16 * w;
282         outer_space := hround ((w - stemwidth) / 2);
283
284         w := 2 outer_space + stemwidth;
285         d := d - feta_space_shift;
286
287         draw_meta_sharp (w, -.5 interbeam);
288         draw_meta_sharp (w, -.5 interbeam + vround interbeam);
289
290         pickup pencircle scaled stemwidth;
291
292         lft x5 = lft x6 = outer_space;
293         top y6 = vround (1.5 staff_space - .5 stem);
294         bot y5 = -top y6 + feta_space_shift;
295
296         labels (5, 6);
297
298         draw_gridline (z5, z6, stemwidth);
299
300         remember_pic := currentpicture;
301
302         draw_staff (-2, 2, 0);
303 fet_endchar;
304
305
306 draw_shifted_too;
307
308
309 fet_beginchar ("Sharp (3 beams)", "sharp.slashslashslash.stemstem");
310         save stem, stemx, stemwidth;
311         save outer_space, interbeam;
312         save sharp_beamheight;
313
314         sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
315
316         stemwidth# := stafflinethickness# + .05 staff_space#;
317         define_whole_blacker_pixels (stemwidth);
318
319         interbeam := 1.2 staff_space_rounded;
320
321         set_char_box (0, 1.1 staff_space#,
322                       1.5 staff_space#, 1.5 staff_space#);
323
324         stem := 7 / 16 * w;
325         stemx := hround stem;
326         outer_space := hround ((w - stemx - stemwidth) / 2);
327
328         w := 2 outer_space + stemx + stemwidth;
329         d := d - feta_space_shift;
330
331         draw_meta_sharp (.88 w, -.5 interbeam);
332         draw_meta_sharp (.88 w, -.5 interbeam + vround interbeam);
333         sharp_beamheight# := 1/.88 sharp_beamheight#;
334         draw_meta_sharp (w, 0);
335
336         pickup pencircle scaled stemwidth;
337
338         lft x5 = lft x6 = outer_space;
339         lft x7 = lft x8 = outer_space + stemx;
340         bot y5 = -d;
341         top y6 = vround (1.5 staff_space - stem * beamslope);
342         bot y7 = -top y6 + feta_space_shift;
343         top y8 = h;
344
345         labels (5, 6, 7, 8);    
346
347         draw_gridline (z5, z6, stemwidth);
348         draw_gridline (z7, z8, stemwidth);
349
350         remember_pic := currentpicture;
351
352         draw_staff (-2, 2, 0);
353 fet_endchar;
354
355
356 draw_shifted_too;
357
358
359 fet_beginchar ("1/2 Sharp (3 beams)", "sharp.slashslashslash.stem");
360         save stem, stemx, stemwidth;
361         save outer_space, interbeam;
362         save sharp_beamheight;
363
364         sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
365
366         stemwidth# := stafflinethickness# + .05 staff_space#;
367         define_whole_blacker_pixels (stemwidth);
368
369         interbeam := 1.2 staff_space_rounded;
370
371         set_char_box (0, 0.95 staff_space#,
372                       1.3 staff_space#, 1.3 staff_space#);
373
374         stem := 7 / 16 * w;
375         outer_space := hround ((w - stemwidth) / 2);
376
377         w := 2 outer_space + stemwidth;
378         d := d - feta_space_shift;
379
380         draw_meta_sharp (.8 w, -.5 interbeam);
381         draw_meta_sharp (.8 w, -.5 interbeam + vround interbeam);
382         sharp_beamheight# := 1/.8 sharp_beamheight#;
383         draw_meta_sharp (w, 0);
384
385         pickup pencircle scaled stemwidth;
386
387         lft x5 = lft x6 = outer_space;
388         top y6 = vround (1.5 staff_space - .5 stem);
389         bot y5 = -top y6 + feta_space_shift;
390         labels (5, 6);
391
392         draw_gridline (z5, z6, stemwidth);
393
394         remember_pic := currentpicture;
395
396         draw_staff (-2, 2, 0);
397 fet_endchar;
398
399
400 draw_shifted_too;
401
402
403 fet_beginchar ("3/4 Sharp", "sharp.slashslash.stemstemstem");
404         save stem, stemx, stemwidth;
405         save outer_space, interbeam;
406
407         stemwidth# := stafflinethickness# + .05 staff_space#;
408         define_whole_blacker_pixels (stemwidth);
409
410         interbeam := 1.05 staff_space_rounded;
411
412         set_char_box (0, 1.6 staff_space#,
413                       1.5 staff_space#, 1.5 staff_space#);
414
415         stem := 9 / 32 * w;
416         stemx := hround stem;
417         outer_space := hround ((w - 2 stemx - stemwidth) / 2);
418
419         w := 2 outer_space + 2 stemx + stemwidth;
420         d := d - feta_space_shift;
421
422         draw_meta_sharp (w, -.5 interbeam);
423         draw_meta_sharp (w, -.5 interbeam + vround interbeam);
424
425         pickup pencircle scaled stemwidth;
426
427         lft x5 = lft x6 = outer_space;
428         lft x7 = lft x8 = outer_space + stemx;
429         lft x9 = lft x10 = outer_space + 2 stemx;
430         bot y5 = -d;
431         top y6 = vround (1.5 staff_space - 2 stem * beamslope);
432         bot y9 = -top y6 + feta_space_shift;
433         top y10 = h;
434         y7 = .5 [y5, y9];
435         y8 = .5 [y6, y10];
436
437         labels (5, 6, 7, 8, 9, 10);
438
439         draw_gridline (z5, z6, stemwidth);
440         draw_gridline (z7, z8, stemwidth);
441         draw_gridline (z9, z10, stemwidth);
442
443         remember_pic := currentpicture;
444
445         draw_staff (-2, 2, 0);
446 fet_endchar;
447
448
449 draw_shifted_too;
450
451
452 %
453 % The stems of the natural are brushed (at least, in Barenreiter SCS)
454 %
455
456 fet_beginchar ("Natural", "natural");
457         save stemwidth, top_stem_thick;
458         save ne, pat_top, pat_bottom;
459         pair ne;
460         path pat_top, pat_bottom;
461
462         top_stem_thick# = stafflinethickness# + .10 staff_space#;
463         stemwidth# = 0.09 staff_space# + .5 stafflinethickness#;
464         define_whole_blacker_pixels (top_stem_thick, stemwidth);
465
466         set_char_box (0, 2/3 staff_space#,
467                       1.5 staff_space#, 1.5 staff_space#);
468
469         d := d - feta_space_shift;
470
471         pickup pencircle scaled stemwidth;
472
473         penpos1 (top_stem_thick, 0);
474         penpos3 (top_stem_thick, 0);
475         penpos2 (stemwidth, 0);
476         penpos4 (stemwidth, 0);
477
478         x2r = w;
479         x4l = 0;
480         x3 = x2;
481         x1 = x4;
482
483         y1 = h;
484         y3 = -d;
485         top y2 = vround (staff_space - 3/2 stafflinethickness);
486         y4 = -y2 + feta_space_shift;
487
488         pat_bottom := z4r{z4r - z1r}
489                       .. bot z4
490                       .. z4l{z1l - z4l};
491         fill simple_serif (z1l, z1r, -30)
492              -- pat_bottom
493              -- cycle;
494
495         pat_top := z2r{z2r - z3r}
496                    .. top z2
497                    .. z2l{z3l - z2l};
498         fill simple_serif (z3l, z3r, 30)
499              -- pat_top
500              -- cycle;
501
502         ne = (x2 - x4, stafflinethickness);
503
504         z11' = z3l + whatever * (z2l - z3l);
505         y11' = vround (.5 (staff_space - stafflinethickness));
506         z11 = z11' + whatever * ne;
507         x11 = x12;
508         z12 = directionpoint -ne of pat_top;
509         z13 = z12 + whatever * ne;
510         x13 = x1;
511         z14 = z11 + whatever * ne;
512         x14 = x1;
513
514         z21' = z4r + whatever * (z1r - z4r);
515         y21' = -y11' + feta_space_shift;
516         z21 = z21' + whatever * ne;
517         x21 = x22;
518         z22 = directionpoint -ne of pat_bottom;
519         z23 = z22 + whatever * ne;
520         x23 = x3;
521         z24 = z21 + whatever * ne;
522         x24 = x3;
523
524         fill z11
525              -- z12
526              -- z13
527              -- z14
528              -- cycle;
529         fill z21
530              -- z22
531              -- z23
532              -- z24
533              -- cycle;
534
535         penlabels (1, 2, 3, 4);
536         labels (11, 11', 12, 13, 14, 21, 21', 22, 23, 24);
537
538         remember_pic := currentpicture;
539
540         draw_staff (-2, 2, 0);
541 fet_endchar;
542
543
544 draw_shifted_too;
545
546
547 %
548 % Dedicated to my mom.    (3/10/97)
549 %
550 % Mamma, ik hou van je; kom je alsjeblieft terug?
551 %    -- HW
552 %
553 %
554 % TODO: remove crook_fatness
555 % TODO: document, simplify!
556 %
557
558 def draw_meta_flat (expr xcenter, w, crook_fatness, arrowup, arrowdown) =
559         save crook_thinness;
560         save bottom_overshoot, bot_crook_dir;
561         save top_stem_thick, top_stem_thick_orig, bottom_stem_thick, hair, smaller_hole;
562         save top_crook_thinness;
563         save zwiep;
564         save center;
565         pair center, bot_crook_dir;
566         save clearing, clearing_orig;
567
568         clearxy;
569
570         % the stem shouldn't reach the top staff line.
571         %% TODO: should take from height.
572         %
573         % TODO: parameterize this
574         %
575         if w >= 0.75 staff_space:
576                 smaller_hole = 0.35 stafflinethickness;
577         else:
578                 smaller_hole = 0;
579         fi;
580         crook_thinness = .7 stafflinethickness + .06 staff_space;
581         top_crook_thinness = 1 stafflinethickness + .065 staff_space;
582         clearing = 1.7 stafflinethickness;
583         clearing_orig = clearing;
584         if arrowup:
585                 clearing := 0.5 staff_space;
586         fi;
587         bottom_overshoot = stafflinethickness;
588
589         bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
590         top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
591         top_stem_thick_orig# = top_stem_thick#;
592         if arrowup:
593                 % to look nice, arrowed stems should be less brushed
594                 top_stem_thick# := top_stem_thick#*0.80;
595         fi;
596         define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick,
597                                      top_stem_thick_orig);
598
599         if odd (top_stem_thick - bottom_stem_thick):
600                 top_stem_thick := top_stem_thick - 1;
601         fi;
602         if odd (top_stem_thick_orig - bottom_stem_thick):
603                 top_stem_thick_orig := top_stem_thick_orig - 1;
604         fi;
605
606         center = (xcenter, 0);
607
608         x1l = hround (xcenter - .5 top_stem_thick);
609         y1 = vround (2 staff_space - clearing);
610         x2l = hround (xcenter - .5 bottom_stem_thick);
611         y2 = -.5 staff_space - .5 stafflinethickness;
612         % z16 and the _orig variables are needed for arrowed accidentals because
613         % their inner part should be unchanged from plain ones but the points z3l,
614         % z3r and z10 depend on values that are different for arrowed accidentals
615         x16l = hround (xcenter - .5 top_stem_thick_orig);
616         y16 = vround (2 staff_space - clearing_orig);
617
618         penpos1 (top_stem_thick, 0);
619         penpos16 (top_stem_thick_orig, 0);
620         penpos2 (bottom_stem_thick, 0);
621
622         y3l = vfloor ((staff_space - stafflinethickness) / 2);
623         z3l = whatever [z2r, z1r];
624         z3r = .3 [z2r, (z16r shifted (0, clearing_orig - 1.7 stafflinethickness))]
625               + (smaller_hole, 0);
626         x3r := hceiling x3r;
627
628         % we insert z3l to get better conversion with mf2pt1
629         fill simple_serif (z1r, z1l, 30)
630              -- z2l
631              -- z2r
632              -- z3l
633              -- cycle;
634
635         z10 = whatever [z2r, z16r] + (smaller_hole, 0);
636         y10 = -1/10 staff_space;
637         x10 := hceiling x10;
638
639         x11 = xcenter + bottom_overshoot / 3;
640         y11 = -vround (.5 (staff_space + stafflinethickness)
641                        + bottom_overshoot);
642
643         x2a = 0.2[x2r,x7];
644         y2a = 1.5[y2,y11];
645
646         penpos4 (whatever, 53);
647
648         y4l - y4r = top_crook_thinness;
649         y5r = .15 staff_space;
650         x5l = hround (w + xcenter);
651         y4 = staff_space / 2;
652         x4r = .45 [x5r, x3r];
653         y4l := vround y4l;
654
655         penpos5 (crook_fatness, -175);
656
657         bot_crook_dir = unitvector ((x5l, 0) - z11);
658         z8 = z11 + whatever * bot_crook_dir;
659         y8 = -staff_space / 2;
660
661         z7 = z8
662              + whatever * bot_crook_dir
663              + crook_thinness * (bot_crook_dir rotated 90);
664         x7 = .1 [x3r, x8];
665
666         unfill z3r{z3r - z10}
667                .. z4r{right}
668                .. z5r{down}
669                .. z7{-bot_crook_dir}
670                & z7
671                .. z10{z3r - z10}
672                -- cycle;
673
674         if arrowdown:
675                 fill z2l{down}
676                      .. z2a{up}
677                      .. z8{bot_crook_dir}
678                      .. z5l{up}
679                      .. z4l{left}
680                      .. z3l
681                      -- cycle;
682         else:
683                 fill z2l{down}
684                      .. z11{right}
685                      .. z8{bot_crook_dir}
686                      .. z5l{up}
687                      .. z4l{left}
688                      .. z3l
689                      -- cycle;
690         fi;
691
692         if arrowup:
693                 draw_arrow (z1, top_stem_thick, z1l-z2l,
694                             0.5stafflinethickness, false);
695         fi;
696         if arrowdown:
697                 draw_arrow ((0.5[x2l,x2a],y2), x2a-x2l, up,
698                             staff_space/2, true);
699         fi;
700 enddef;
701
702
703 def draw_arrowed_meta_flat (expr xcenter, width, crook_fatness, arrowup, arrowdown) =
704         save depth, height, extendleft;
705
706         depth# = 0.6 staff_space#;
707         height# = 1.9 staff_space#;
708         extendleft# := 1.2 stafflinethickness#;
709         if arrowup:
710                 extendleft# := 3.45 stafflinethickness#;
711                 height# := height# + 0.8 staff_space#;
712         fi;
713         if arrowdown:
714                 extendleft# := 3.45 stafflinethickness#;
715                 depth# := depth# + 1.6 staff_space#;
716         fi;
717
718         set_char_box (extendleft#, width, depth#, height#);
719         draw_meta_flat(xcenter, w, crook_fatness, arrowup, arrowdown);
720 enddef;
721
722 %
723 % unfortunately, 600dpi is not enough to show the brush of the stem.
724 %
725
726 fet_beginchar ("Flat", "flat");
727         draw_arrowed_meta_flat(0, 0.8 staff_space#, 0.31 staff_space, false, false);
728         penlabels (range 0 thru 11);
729
730         remember_pic := currentpicture;
731
732         draw_staff (-2, 2, 0);
733 fet_endchar;
734
735
736 draw_shifted_too;
737
738
739 fet_beginchar ("Arrowed Flat (up-arrow)", "flat.arrowup");
740         draw_arrowed_meta_flat(0, 0.8 staff_space#, 0.31 staff_space, true, false);
741         penlabels (range 0 thru 23);
742
743         remember_pic := currentpicture;
744
745         draw_staff (-2, 2, 0.0);
746 fet_endchar;
747
748
749 draw_shifted_too;
750
751
752 fet_beginchar ("Arrowed Flat (down-arrow)", "flat.arrowdown");
753         draw_arrowed_meta_flat(0, 0.8 staff_space#, 0.31 staff_space, false, true);
754         penlabels (range 0 thru 23);
755
756         remember_pic := currentpicture;
757
758         draw_staff (-2, 2, 0.0);
759 fet_endchar;
760
761
762 draw_shifted_too;
763
764
765 fet_beginchar ("Flat (slashed)", "flat.slash");
766         set_char_box (.4 staff_space#, .8 staff_space#,
767                       0.6 staff_space#, 1.9 staff_space#);
768
769         draw_meta_flat (0, w, 0.31 staff_space, false, false);
770
771         clearxy;
772
773         save slope, slash_width;
774         slope = 0.5;
775         slash_width = w;
776
777         z11 = (0, h / 2);
778         z12 = z11 - (slash_width, slash_width * slope) / 2;
779         z13 = z11 + (slash_width, slash_width * slope) / 2;
780         penpos12 (1.5 stafflinethickness, angle (z13 - z12) - 90);
781         penpos13 (1.5 stafflinethickness, angle (z13 - z12) - 90);
782
783         z14 = z12 - .75 stafflinethickness * unitvector (z13 - z12);
784         z15 = z13 + .75 stafflinethickness * unitvector (z13 - z12);
785
786         fill z13r
787              .. z15
788              .. z13l
789              -- z12l
790              .. z14
791              .. z12r
792              -- z13r
793              .. cycle;
794
795         penlabels (12, 13);
796         labels (14, 15);
797
798         remember_pic := currentpicture;
799
800         draw_staff (-2, 2, 0);
801 fet_endchar;
802
803
804 fet_beginchar ("Flat (slashed twice)", "flat.slashslash");
805         set_char_box (.4 staff_space#, .8 staff_space#,
806                       0.6 staff_space#, 1.9 staff_space#);
807
808         draw_meta_flat (0, w, 0.31 staff_space, false, false);
809
810         clearxy;
811
812         save slope, slash_width;
813         slope = 0.5;
814         slash_width = w;
815
816         z11 = (0, 5/12 h);
817         z12 = z11 - (slash_width, slash_width * slope) / 2;
818         z13 = z11 + (slash_width, slash_width * slope) / 2;
819         penpos12 (1.5 stafflinethickness, angle (z13 - z12) - 90);
820         penpos13 (1.5 stafflinethickness, angle (z13 - z12) - 90);
821
822         z14 = z12 - .75 stafflinethickness * unitvector (z13 - z12);
823         z15 = z13 + .75 stafflinethickness * unitvector (z13 - z12);
824
825         fill z13r
826              .. z15
827              .. z13l
828              -- z12l
829              .. z14
830              .. z12r
831              -- z13r
832              .. cycle;
833
834         penlabels (12, 13);
835         labels (14, 15);
836
837         z21 = (0, 2/3 h);
838         z22 = z21 - (slash_width, slash_width * slope) / 2;
839         z23 = z21 + (slash_width, slash_width * slope) / 2;
840         penpos22 (1.5 stafflinethickness, angle (z23 - z22) - 90);
841         penpos23 (1.5 stafflinethickness, angle (z23 - z22) - 90);
842
843         z24 = z22 - .75 stafflinethickness * unitvector (z23 - z22);
844         z25 = z23 + .75 stafflinethickness * unitvector (z23 - z22);
845
846         fill z23r
847              .. z25
848              .. z23l
849              -- z22l
850              .. z24
851              .. z22r
852              -- z23r
853              .. cycle;
854
855         penlabels (22, 23);
856         labels (24, 25);
857
858         remember_pic := currentpicture;
859
860         draw_staff (-2, 2, 0);
861 fet_endchar;
862
863
864 fet_beginchar ("Flatflat (mirrored)", "mirroredflat.flat");
865         set_char_box (0, 1.6 staff_space#, 
866                       0.6 staff_space#, 1.9 staff_space#);
867
868         % This is a modified version of `draw_meta_flat'.
869
870         save crook_thinness, crook_fatness;
871         save bottom_overshoot, bot_crook_dir;
872         save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
873         save top_crook_thinness;
874         save zwiep;
875         save center;
876         pair center, bot_crook_dir;
877         save clearing, wid;
878         save pat;
879         path pat;
880
881         clearxy;
882
883         wid = w / 2;
884
885         % the stem shouldn't reach the top staff line.
886         %% TODO: should take from height.
887         %
888         % TODO: parameterize this
889         %
890         if wid >= 0.75 staff_space:
891                 smaller_hole = 0.35 stafflinethickness;
892         else:
893                 smaller_hole = 0;
894         fi;
895         clearing = 1.7 stafflinethickness;
896         crook_thinness = .7 stafflinethickness + .06 staff_space;
897         crook_fatness = 0.31 staff_space;
898         top_crook_thinness = 1 stafflinethickness + .065 staff_space;
899         bottom_overshoot = stafflinethickness;
900
901         bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
902         top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
903         define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
904
905         if odd (top_stem_thick - bottom_stem_thick):
906                 top_stem_thick := top_stem_thick - 1;
907         fi;
908
909         center = (0, 0);
910
911         x1l = hround (-.5 top_stem_thick);
912         y1 = vround (2 staff_space - clearing);
913         x2l = hround (-.5 bottom_stem_thick);
914         y2 = -.5 staff_space - .5 stafflinethickness;
915
916         penpos1 (top_stem_thick, 0);
917         penpos2 (bottom_stem_thick, 0);
918
919         y3l = vfloor ((staff_space - stafflinethickness) / 2);
920         z3l = whatever [z2r, z1r];
921         z3r = .3 [z2r, z1r] + (smaller_hole, 0);
922         x3r := hceiling x3r;
923
924         z10 = whatever [z2r, z1r] + (smaller_hole, 0);
925         y10 = -1/10 staff_space;
926         x10 := hceiling x10;
927
928         x11 = bottom_overshoot / 3;
929         y11 = -vround (.5 (staff_space + stafflinethickness)
930                        + bottom_overshoot);
931
932         penpos4 (whatever, 53);
933
934         y4l - y4r = top_crook_thinness;
935         y5r = .15 staff_space;
936         x5l = hround (wid);
937         y4 = staff_space / 2;
938         x4r = .45 [x5r, x3r];
939         y4l := vround y4l;
940
941         penpos5 (crook_fatness, -175);
942
943         bot_crook_dir = unitvector ((x5l, 0) - z11);
944         z8 = z11 + whatever * bot_crook_dir;
945         y8 = -staff_space / 2;
946
947         z7 = z8
948              + whatever * bot_crook_dir
949              + crook_thinness * (bot_crook_dir rotated 90);
950         x7 = .1 [x3r, x8];
951
952         pat := z3r{z3r - z10}
953                .. z4r{right}
954                .. z5r{down}
955                .. z7{-bot_crook_dir}
956                & z7
957                .. z10{z3r - z10}
958                -- cycle;
959         unfill pat;
960         unfill pat xscaled -1;
961
962         pat := z11{right}
963                .. z8{bot_crook_dir}
964                .. z5l{up}
965                .. z4l{left}
966                .. z3l;
967         fill pat
968              -- simple_serif (z1r, z1l, 30)
969              -- reverse pat xscaled -1 shifted (-feta_eps, 0)
970              -- cycle;
971
972         currentpicture := currentpicture shifted (w/2, 0);
973
974         remember_pic := currentpicture;
975
976         draw_staff (-2, 2, 0);
977 fet_endchar;
978
979
980 draw_shifted_too;
981
982
983 fet_beginchar ("Semi flat", "mirroredflat");
984         set_char_box (1.2 stafflinethickness#, .8 staff_space#,
985                       0.6 staff_space#, 1.9 staff_space#);
986
987         draw_meta_flat (0, w, 0.31 staff_space, false, false);
988         currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
989 fet_endchar;
990
991
992 fet_beginchar ("Semi flat", "mirroredflat.backslash");
993         set_char_box (.4 staff_space#, .8 staff_space#,
994                       0.6 staff_space#, 1.9 staff_space#);
995
996         draw_meta_flat (0, w, 0.31 staff_space, false, false);
997
998         clearxy;
999
1000         save slope, slash_width;
1001         slope = 0.5;
1002         slash_width = w;
1003
1004         z11 = (0, h / 2);
1005         z12 = z11 - (slash_width, slash_width * slope) / 2;
1006         z13 = z11 + (slash_width, slash_width * slope) / 2;
1007         penpos12 (1.5 stafflinethickness, angle (z13 - z12) - 90);
1008         penpos13 (1.5 stafflinethickness, angle (z13 - z12) - 90);
1009
1010         z14 = z12 - .75 stafflinethickness * unitvector (z13 - z12);
1011         z15 = z13 + .75 stafflinethickness * unitvector (z13 - z12);
1012
1013         fill z13r
1014              .. z15
1015              .. z13l
1016              -- z12l
1017              .. z14
1018              .. z12r
1019              -- z13r
1020              .. cycle;
1021
1022         currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
1023
1024         labels (1, 2, 3);
1025 fet_endchar;
1026
1027
1028 fet_beginchar ("Double Flat", "flatflat");
1029         save left_wid, overlap, right_wid;
1030
1031         left_wid = .7;
1032         right_wid = .8;
1033         overlap = .05;
1034
1035         set_char_box (1.2 stafflinethickness#,
1036                       (left_wid + right_wid - overlap) * staff_space#,
1037                       .6 staff_space#, 1.9 staff_space#);
1038         draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space, false, false);
1039         draw_meta_flat (hround ((left_wid - overlap) * staff_space),
1040                         right_wid * staff_space, 1/3 staff_space, false, false);
1041 fet_endchar;
1042
1043
1044 fet_beginchar ("3/4 Flat", "flatflat.slash");
1045         save left_wid, overlap, right_wid;
1046
1047         left_wid = .7;
1048         right_wid = .8;
1049         overlap = .05;
1050
1051         set_char_box (1.2 stafflinethickness#,
1052                       (left_wid + right_wid - overlap) * staff_space#,
1053                       .6 staff_space#, 1.9 staff_space#);
1054         draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space, false, false);
1055         draw_meta_flat (hround ((left_wid - overlap) * staff_space),
1056                         right_wid * staff_space, 1/3 staff_space, false, false);
1057
1058         %% maybe we should clip part of the stems?
1059         %% or make the 1st flat smaller?
1060         %% or reverse it?
1061         pickup pencircle scaled 2 stafflinethickness;
1062
1063         z12 = round (-.25 w - b, .55 staff_space) + feta_offset;
1064         z13 = round (.75 w, 1.45 staff_space) + feta_offset;
1065         penpos12 (2 stafflinethickness, angle (z13 - z12) - 90);
1066         penpos13 (2 stafflinethickness, angle (z13 - z12) - 90);
1067
1068         z14 = z12 - stafflinethickness * unitvector (z13 - z12);
1069         z15 = z13 + stafflinethickness * unitvector (z13 - z12);
1070
1071         fill z13r
1072              .. z15
1073              .. z13l
1074              -- z12l
1075              .. z14
1076              .. z12r
1077              -- z13r
1078              .. cycle;
1079
1080         penlabels (12, 13);
1081         labels (14, 15);
1082
1083         remember_pic := currentpicture;
1084
1085         draw_staff (-2, 2, 0);
1086 fet_endchar;
1087
1088
1089 draw_shifted_too;
1090
1091
1092 fet_beginchar ("Double Sharp", "doublesharp");
1093         save klaverblad, klaversteel;
1094         save pat;
1095         path pat;
1096
1097         klaversteel = 1/15 staff_space;
1098         klaverblad = .4 staff_space - .5 stafflinethickness;
1099
1100         set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
1101
1102         z1 = (klaversteel, 0);
1103         z2 = (w / 2 - klaverblad / 10, h - klaverblad);
1104         z3 = (w / 2, h);
1105         z4 = z2 reflectedabout ((0, 0), (1, 1));
1106         z5 = z1 reflectedabout ((0, 0), (1, 1));
1107
1108         labels (1, 2, 3, 4, 5);
1109
1110         pickup pencircle scaled blot_diameter;
1111
1112         x2 := hfloor (rt x2) - blot_diameter / 2;
1113         x3 := hfloor (rt x3) - blot_diameter / 2;
1114         y3 := vfloor (top y3) - blot_diameter / 2;
1115         y4 := vfloor (top y4) - blot_diameter / 2;
1116
1117         pat = (rt z1){dir45}
1118               .. {right}(bot z2)
1119               .. rt z2
1120               -- rt z3{z3 - z2}
1121               .. top z3{z4 - z3}
1122               -- top z4{z4 - z3}
1123               .. (lft z4){down}
1124               .. {dir 225}(top z5);
1125         pat := pat
1126                -- reverse pat xscaled -1 shifted (-feta_eps, 0);
1127
1128         % assure symmetry -- it's more important to center the glyph on the
1129         % staff line than centering it between staff lines, so we use
1130         % feta_shift, not feta_space_shift.
1131         h := h + feta_shift;
1132
1133         fill pat shifted (0, feta_shift)
1134              -- reverse pat yscaled -1 shifted (0, -feta_eps)
1135              -- cycle;
1136
1137         % ugh
1138         currentpicture := currentpicture shifted (hround (w / 2), 0);
1139
1140         remember_pic := currentpicture;
1141
1142         draw_staff (-2, 2, 0);
1143 fet_endchar;
1144
1145
1146 draw_shifted_too;
1147
1148
1149 def draw_paren =
1150         save leftindent;
1151
1152         leftindent := .2 staff_space;
1153
1154         set_char_box (0, .5 staff_space# + stafflinethickness#,
1155                       staff_space#, staff_space#);
1156
1157         d := d - feta_shift;
1158
1159         z1 = (leftindent, h);
1160         z2 = (w - stafflinethickness, .5 (h - d));
1161         z3 = (leftindent, -d);
1162
1163         penpos1 (stafflinethickness, 35);
1164         penpos2 (.1 staff_space + stafflinethickness, 0);
1165         penpos3 (stafflinethickness, -35);
1166
1167         fill z2l{down}
1168              .. simple_serif (z3l, z3r, 90)
1169              .. z2r{up}
1170              .. simple_serif (z1r, z1l, 90)
1171              .. z2l{down}
1172              -- cycle;
1173 enddef;
1174
1175
1176 fet_beginchar ("Right Parenthesis", "rightparen");
1177         draw_paren;
1178         penlabels (1, 2, 3);
1179
1180         remember_pic := currentpicture;
1181
1182         draw_staff (-2, 2, 0);
1183 fet_endchar;
1184
1185
1186 draw_shifted_too;
1187
1188
1189 fet_beginchar ("Left Parenthesis", "leftparen");
1190         draw_paren;
1191
1192         currentpicture := currentpicture xscaled -1;
1193
1194         set_char_box (charwd, charbp, chardp, charht);
1195 fet_endchar;
1196
1197 fet_endgroup ("accidentals");