]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-bolletjes.mf
* scm/lily-library.scm (ordered-cons): new function.
[lilypond.git] / mf / feta-bolletjes.mf
1 %  -*-Fundamental-*-
2 % feta-bolletjes.mf --  implement noteheads
3 %
4 % source file of LilyPond's pretty-but-neat music font
5 %
6 % (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 % & Han-Wen Nienhuys <hanwen@xs4all.nl>
8 % & Juergen Reuter <reuter@ipd.uka.de>
9 %
10
11 test_outlines := 0;
12
13
14 save remember_pic;
15 picture remember_pic;
16
17
18 % Most beautiful noteheads are pronounced, not circular,
19 % and not even symmetric.
20 % These examples are inspired by [Wanske]; see literature list.
21
22
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % NOTE HEAD VARIABLES
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 save black_notehead_width, noteheight;
29 save half_notehead_width, whole_notehead_width, slash_thick;
30 save slash_slope, overdone_heads, solfa_noteheight;
31
32 numeric noteheight;
33 numeric slash_thick;
34 numeric black_notehead_width;
35 numeric whole_notehead_width;
36 numeric half_notehead_width;
37
38
39 fet_begingroup ("noteheads");
40
41
42 % Slope of slash.  From scm/grob-description.scm.  How to auto-copy?
43 slash_slope := 1.7;
44
45 % Thickness of slash lines.  Quarter notes get 1.5slt width.
46 slash_thick# := 2/3 * 0.48 staff_space#;
47
48
49 %
50 % Hand-engraved music often has balls extending above and below
51 % the lines.  If you like that, modify overdone heads (unit:
52 % stafflinethickness).
53 %
54 overdone_heads = 0.0;
55 noteheight# := staff_space# + (1 + overdone_heads) * stafflinethickness#;
56
57
58 %
59 % solfa heads should not overlap on chords.
60 %
61 solfa_noteheight# := staff_space# - stafflinethickness#;
62
63 define_pixels (slash_thick);
64 define_whole_vertical_pixels (noteheight);
65
66
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %
69 % SLANT moves both extrema on the long axis (by SLANT * ELLIPTICITY,
70 % so SLANT = -1, puts the extreme on the long axis next to the short
71 % axis one).
72 %
73
74 def draw_outside_ellipse (expr ellipticity, tilt, superness, slant) =
75         save attachment_y;
76         save pat;
77         path pat;
78
79         pat := superellipse ((ellipticity, 0), (-slant * ellipticity, 1.0),
80                              (-ellipticity, 0), (slant * ellipticity, -1.0),
81                              superness);
82         pat := pat rotated tilt;
83
84         save top_point, right_point;
85         pair top_point, right_point;
86
87         top_point := directionpoint left of pat;
88         right_point := directionpoint up of pat;
89
90         save scaling, width;
91
92         scaling# = noteheight# / (2 ypart (top_point));
93         width# := 2 xpart (right_point) * scaling#;
94         define_pixels (scaling, width);
95
96         set_char_box (0, width#, noteheight# / 2, noteheight# / 2);
97
98         d := d - feta_space_shift;
99
100         % attachment Y
101         charwy := ypart (right_point) * scaling#;
102         charwx := width#;
103
104         pat := pat scaled scaling shifted (w / 2, .5 (h - d));
105
106         width := hround width;
107
108         if test_outlines = 1:
109                 draw pat;
110         else:
111                 fill pat;
112         fi;
113 enddef;
114
115
116 def undraw_inside_ellipse (expr ellipticity, tilt, superness, clearance) =
117 begingroup
118         save pat;
119         path pat;
120
121         pat := superellipse ((ellipticity, 0), (0, 1.0),
122                              (-ellipticity, 0), (0, -1.0),
123                              superness);
124         pat := pat rotated tilt;
125
126         save top_point, right_point;
127         pair top_point, right_point;
128
129         top_point := directionpoint left of pat;
130         right_point := directionpoint up of pat;
131
132         save height, scaling;
133
134         height# = staff_space# + stafflinethickness# - clearance;
135         scaling# = height# / (2 ypart (top_point));
136         define_pixels (scaling);
137         pat := pat scaled scaling shifted (w / 2, .5 (h - d));
138
139         if test_outlines = 1:
140                 draw pat;
141         else:
142                 unfill pat;
143         fi
144 endgroup;
145 enddef;
146
147
148 %
149 % dimensions aren't entirely right.
150 %
151 def draw_brevis =
152         save stemthick, fudge;
153
154         stemthick# = 2 stafflinethickness#;
155         define_whole_blacker_pixels (stemthick);
156
157         fudge = hround (blot_diameter / 2);
158
159         draw_outside_ellipse (1.80, 0, 0.707, 0);
160         undraw_inside_ellipse (1.30, 125, 0.68, 2 stafflinethickness#);
161
162         pickup pencircle scaled stemthick;
163
164         bot y1 = -d;
165         top y2 = h;
166         rt x1 - fudge = 0;
167         x1 = x2;
168
169         fudge + lft x3 = w;
170         x4 = x3;
171         y4 = y2;
172         y3 = y1;
173
174         draw_gridline (z1, z2, stemthick);
175         draw_gridline (z3, z4, stemthick);
176 enddef;
177
178
179 fet_beginchar ("Brevis notehead", "s-1");
180         draw_brevis;
181
182         draw_staff (-2, 2, 0);
183 fet_endchar;
184
185
186 if test > 0:
187         fet_beginchar ("Brevis notehead", "s-1");
188                 draw_brevis;
189
190                 draw_staff (-2, 2, 0.5);
191         fet_endchar;
192 fi;
193
194
195 fet_beginchar ("Whole notehead", "s0");
196         draw_outside_ellipse (1.80 - puff_up_factor / 3.0, 0, 0.707, 0);
197         undraw_inside_ellipse (1.30, 125 - puff_up_factor * 10,
198                                0.68, 2 stafflinethickness#);
199
200         whole_notehead_width# := charwd;
201
202         draw_staff (-2, 2, 0);
203 fet_endchar;
204
205
206 if test > 0:
207         fet_beginchar ("Whole notehead", "s0");
208                 draw_outside_ellipse (1.80 - puff_up_factor / 3.0, 0,
209                                       0.707, 0);
210                 undraw_inside_ellipse (1.30, 125 - puff_up_factor * 10,
211                                        0.68, 2 stafflinethickness#);
212
213                 draw_staff (-2, 2, 0.5);
214         fet_endchar;
215 fi;
216
217
218
219
220 fet_beginchar ("Half notehead", "s1");
221         draw_outside_ellipse (1.53 - puff_up_factor / 3.0, 34, 0.66, 0.17);
222         undraw_inside_ellipse (3.25, 33, 0.81, 2.5 stafflinethickness#);
223
224         half_notehead_width# := charwd;
225
226         draw_staff (-2, 2, 0);
227 fet_endchar;
228
229
230 if test > 0:
231         fet_beginchar ("Half notehead", "s1");
232                 draw_outside_ellipse (1.53 - puff_up_factor / 3.0, 34,
233                                       0.66, 0.17);
234                 undraw_inside_ellipse (3.25, 33, 0.81,
235                                        2.5 stafflinethickness#);
236
237                 draw_staff (-2, 2, 0.5);
238         fet_endchar;
239 fi;
240
241
242 fet_beginchar ("Quart notehead", "s2");
243         % used to have 32. With 31, they are slightly bolder.
244         draw_outside_ellipse (1.49 - puff_up_factor / 3.0, 31, 0.707, 0);
245         black_notehead_width# := charwd;
246
247         draw_staff (-2, 2, 0);
248 fet_endchar;
249
250 if test > 0:
251         fet_beginchar ("Quart notehead", "s2");
252                 draw_outside_ellipse (1.49 - puff_up_factor / 3.0, 31,
253                                       0.707, 0);
254
255                 draw_staff (-2, 2, 0.5);
256         fet_endchar;
257 fi;
258
259
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261
262
263 fet_beginchar ("Whole diamondhead", "s0diamond");
264         draw_outside_ellipse (1.80, 0, 0.495, 0);
265         undraw_inside_ellipse (1.30, 125, 0.6,
266                                .4 staff_space# + stafflinethickness#);
267
268         draw_staff (-2, 2, 0);
269 fet_endchar;
270
271
272 if test > 0:
273         fet_beginchar ("Whole diamondhead", "s0diamond");
274                 draw_outside_ellipse (1.80, 0, 0.495, 0);
275                 undraw_inside_ellipse (1.30, 125, 0.6,
276                                        .4 staff_space# + stafflinethickness#);
277
278                 draw_staff (-2, 2, 0.5);
279         fet_endchar;
280 fi;
281
282
283 fet_beginchar ("Half diamondhead", "s1diamond");
284         draw_outside_ellipse (1.50, 34, 0.49, 0.17);
285         undraw_inside_ellipse (3.5, 33, 0.80,
286                                .3 staff_space# + 1.5 stafflinethickness#);
287
288         draw_staff (-2, 2, 0);
289 fet_endchar;
290
291
292 if test > 0:
293         fet_beginchar ("Half diamondhead", "s1diamond");
294                 draw_outside_ellipse (1.50, 34, 0.49, 0.17);
295                 undraw_inside_ellipse (3.5, 33, 0.80,
296                                        .3 staff_space#
297                                        + 1.5 stafflinethickness#);
298
299                 draw_staff (-2, 2, 0.5);
300         fet_endchar;
301 fi;
302
303
304 fet_beginchar ("Quart diamondhead", "s2diamond");
305         draw_outside_ellipse (1.80, 35, 0.495, -0.25);
306
307         draw_staff (-2, 2, 0);
308 fet_endchar;
309
310
311 if test > 0:
312         fet_beginchar ("Quart diamondhead", "s2diamond");
313                 draw_outside_ellipse (1.80, 35, 0.495, -0.25);
314
315                 draw_staff (-2, 2, 0.5);
316         fet_endchar;
317 fi;
318
319
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321
322
323 vardef penposx@# (expr d) = 
324 begingroup;
325         save pat;
326         path pat;
327
328         pat = top z@#
329               .. lft z@#
330               .. bot z@#
331               .. rt z@#
332               .. cycle;
333         z@#l = pat intersectionpoint (z@# -- infinity * dir (d + 180));
334         z@#r = pat intersectionpoint (z@# -- infinity * dir (d));
335 endgroup
336 enddef;
337
338
339 %
340 %
341 % UGH : xs not declared as argument.
342 %
343 def define_triangle_shape (expr stemdir) =
344         save triangle_a, triangle_b, triangle_c;
345         save triangle_out_a, triangle_out_b, triangle_out_c;
346         save triangle_in, triangle_out;
347         save width, depth, height;
348         save origin, left_up_dir;
349         save exact_left_point, exact_right_point, exact_down_point;
350
351         path triangle_a, triangle_b, triangle_c;
352         path triangle_out_a, triangle_out_b, triangle_out_c;
353         path triangle_in, triangle_out;
354         pair origin, left_up_dir;
355         pair exact_down_point, exact_left_point, exact_right_point;
356
357         save pen_thick;
358         pen_thick# = stafflinethickness# + .1 staff_space#;
359         define_pixels (llap);
360         define_blacker_pixels (pen_thick);
361
362         left_up_dir = llap# * dir (90 + tilt);
363
364         xpart (left_up_dir) * xs - (pen_thick# * xs) / 2 + xpart origin = 0;
365         ypart origin = 0;
366
367         exact_left_point := origin + (left_up_dir xscaled xs);
368         exact_down_point := origin + (left_up_dir rotated 120 xscaled xs);
369         exact_right_point := origin + (left_up_dir rotated 240 xscaled xs);
370
371         height# = ypart (exact_left_point + origin) + pen_thick# / 2;
372         depth# = -ypart (exact_down_point + origin) + pen_thick# / 2;
373         width# = xpart (exact_right_point - exact_left_point)
374                  + pen_thick# * xs;
375
376         set_char_box (0, width#, depth#, height#);
377
378         % Formerly, the shape has simply been drawn with an elliptical pen
379         % (`scaled pen_thick xsaled xs'), but the envelope of such a curve
380         % is of 6th degree.  For the sake of mf2pt1, we approximate it.
381
382         pickup pencircle scaled pen_thick xscaled xs;
383
384         z0 = (hround_pixels (xpart origin), 0);
385
386         z1 = z1' = z0 + llap * dir (90 + tilt) xscaled xs;
387         z2 = z2' = z0 + llap * dir (90 + tilt + 120) xscaled xs;
388         z3 = z3' = z0 + llap * dir (90 + tilt + 240) xscaled xs;
389
390         z12 = caveness [.5[z1, z2], z3];
391         z23 = caveness [.5[z2, z3], z1];
392         z31 = caveness [.5[z3, z1], z2];
393
394         triangle_a = z1 .. z12 .. z2;
395         triangle_b = z2 .. z23 .. z3;
396         triangle_c = z3 .. z31 .. z1;
397
398         penposx1 (angle (direction 0 of triangle_a) - 90);
399         penposx2 (angle (direction 0 of triangle_b) - 90);
400         penposx3 (angle (direction 0 of triangle_c) - 90);
401
402         penposx1' (angle (direction infinity of triangle_c) + 90);
403         penposx2' (angle (direction infinity of triangle_a) + 90);
404         penposx3' (angle (direction infinity of triangle_b) + 90);
405
406         penposx12 (angle (z12 - z0));
407         penposx23 (angle (z23 - z0));
408         penposx31 (angle (z31 - z0));
409
410         z10 = (z0 -- z1) intersectionpoint (z1l .. z12l .. z2'r);
411         z20 = (z0 -- z2) intersectionpoint (z2l .. z23l .. z3'r);
412         z30 = (z0 -- z3) intersectionpoint (z3l .. z31l .. z1'r);
413
414         triangle_in = z10
415                       .. z12l
416                       .. z20
417                       & z20
418                       .. z23l
419                       .. z30
420                       & z30
421                       .. z31l
422                       .. z10
423                       & cycle;
424
425         triangle_out_a = z1r .. z12r .. z2'l;
426         triangle_out_b = z2r .. z23r .. z3'l;
427         triangle_out_c = z3r .. z31r .. z1'l;
428
429         triangle_out = top z1
430                        .. lft z1
431                        .. z1r{direction 0 of triangle_out_a}
432                        & triangle_out_a
433                        & {direction infinity of triangle_out_a}z2'l
434                        .. lft z2
435                        .. bot z2
436                        .. z2r{direction 0 of triangle_out_b}
437                        & triangle_out_b
438                        & {direction infinity of triangle_out_b}z3'l
439                        .. rt z3
440                        .. top z3
441                        .. z3r{direction 0 of triangle_out_c}
442                        & triangle_out_c
443                        & {direction infinity of triangle_out_c}z1'l
444                        .. cycle;
445
446         labels (0, 10, 20, 30);
447         penlabels (1, 1', 2, 2', 3, 3', 12, 23, 31);
448
449         % attachment Y
450         if stemdir = 1:
451                 charwy := ypart exact_right_point;
452                 charwx := xpart exact_right_point + .5 pen_thick# * xs;
453         else:
454                 charwy := -ypart exact_down_point;
455                 charwx := (width# - xpart exact_down_point + xs * pen_thick#);
456         fi
457 enddef;
458
459
460 def draw_whole_triangle_head =
461         save hei, xs;
462         save llap;
463         save tilt;
464
465         tilt = 40;
466         llap# = 3/4 noteheight#;
467
468         xs = 1.5;
469         caveness := 0.1;
470         define_triangle_shape (1);
471         fill triangle_out;
472         unfill triangle_in;
473 enddef;
474
475
476 fet_beginchar ("Whole trianglehead", "s0triangle");
477         draw_whole_triangle_head;
478
479         draw_staff (-2, 2, 0);
480 fet_endchar;
481
482
483 if test > 0:
484         fet_beginchar ("Whole trianglehead", "s0triangle");
485                 draw_whole_triangle_head;
486
487                 draw_staff (-2, 2, 0.5);
488         fet_endchar;
489 fi;
490
491
492 def draw_small_triangle_head (expr dir) =
493         save hei, xs;
494         save llap;
495         save tilt;
496
497         tilt = 40;
498         llap# = 2/3 noteheight#;
499         xs = 1.2;
500         caveness := 0.1;
501         define_triangle_shape (dir);
502
503         pickup feta_fillpen;
504
505         filldraw triangle_out;
506         unfilldraw triangle_in;
507 enddef;
508
509
510 fet_beginchar ("Half trianglehead (downstem)", "d1triangle");
511         draw_small_triangle_head (-1);
512
513         draw_staff (-2, 2, 0);
514 fet_endchar;
515
516
517 fet_beginchar ("Half trianglehead (upstem)", "u1triangle");
518         draw_small_triangle_head (1);
519
520         draw_staff (-2, 2, 0.5);
521 fet_endchar;
522
523
524 def draw_closed_triangle_head (expr dir) =
525         save hei, xs;
526         save llap;
527         save tilt;
528
529         tilt = 40;
530         llap# = 2/3 noteheight#;
531         xs = 1.0;
532         caveness := 0.1;
533         define_triangle_shape (dir);
534         fill triangle_out;
535 enddef;
536
537
538 fet_beginchar ("Quart trianglehead (upstem)", "u2triangle");
539         draw_closed_triangle_head (1);
540
541         draw_staff (-2, 2, 0);
542 fet_endchar;
543
544
545 fet_beginchar ("Quart trianglehead (downstem)", "d2triangle");
546         draw_closed_triangle_head (-1);
547
548         draw_staff (-2, 2, 0.5);
549 fet_endchar;
550
551
552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 %
554 % Slash heads are for indicating improvisation.  They are
555 % twice as high as normal heads.
556 %
557 def draw_slash (expr hwid_hash) =
558         save exact_height;
559         save ne, nw_dist;
560         pair ne, nw_dist;
561         exact_height = staff_space# + stafflinethickness# / 2;
562
563         set_char_box (0, 2 exact_height / slash_slope + hwid_hash,
564                       exact_height, exact_height);
565
566         charwx := charwd;
567         charwy := charht;
568
569         clearxy;
570
571         d := d - feta_shift;
572
573         pickup pencircle scaled blot_diameter;
574
575         bot y1 = -d;
576         top y2 = h;
577         lft x1 = 0;
578         lft x2 = 2 h / slash_slope;
579
580         rt x3 = w;
581         y3 = y2;
582         y4 = y1;
583         x3 - x2 = x4 - x1;
584
585         ne = unitvector (z3 - z4);
586         nw_dist = (ne rotated 90) * 0.5 blot_diameter;
587
588         fill bot z1{left}
589              .. (z1 + nw_dist){ne}
590              -- (z2 + nw_dist){ne}
591              .. top z2{right}
592              -- top z3{right}
593              .. (z3 - nw_dist){-ne}
594              -- (z4 - nw_dist){-ne}
595              .. bot z4{left}
596              -- cycle;
597
598         if hwid_hash > 2 slash_thick#:
599                 save th;
600
601                 th = slash_thick - blot_diameter;
602                 y6 = y7;
603                 y5 = y8;
604                 y3 - y7 = th;
605                 y5 - y1 = th;
606                 z6 - z5 = whatever * ne;
607                 z8 - z7 = whatever * ne;
608
609                 z5 = z1 + whatever * ne + th * (ne rotated -90);
610                 z8 = z4 + whatever * ne + th * (ne rotated 90);
611
612                 unfill z5
613                        -- z6
614                        -- z7
615                        -- z8
616                        -- cycle;
617         fi
618         labels (range 1 thru 10);
619 enddef;
620
621
622 fet_beginchar ("Whole slashhead", "s0slash");
623         draw_slash (4 slash_thick# + 0.5 staff_space#);
624
625         draw_staff (-2, 2, 0);
626 fet_endchar;
627
628
629 fet_beginchar ("Half slashhead", "s1slash");
630         draw_slash (3.0 slash_thick# + 0.15 staff_space#);
631
632         draw_staff (-2, 2, 0);
633 fet_endchar;
634
635
636 fet_beginchar ("Quart slashhead", "s2slash");
637         draw_slash (1.5 slash_thick#);
638
639         draw_staff (-2, 2, 0);
640 fet_endchar;
641
642
643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 %
645 % `thick' is the distance between the NE/SW parallel lines in the cross
646 % (distance between centres of lines) in multiples of stafflinethickness
647 %
648 def draw_cross (expr thick) =
649         save ne, nw;
650         save ne_dist, nw_dist, rt_dist, up_dist;
651         save crz_in, crz_out;
652         save thickness;
653         pair ne, nw;
654         pair ne_dist, nw_dist, rt_dist, up_dist;
655         path crz_in, crz_out;
656
657         pen_thick# := 1.2 stafflinethickness#;
658         thickness# := thick * stafflinethickness#;
659         define_pixels (thickness);
660         define_blacker_pixels (pen_thick);
661
662         pickup pencircle scaled pen_thick;
663
664         h := h - feta_shift;
665
666         top y3 = h;
667         ne = unitvector ((1, (2 h - pen_thick) / (w - pen_thick)));
668         rt x4 = w / 2;
669         y5 = 0;
670         z4 - z5 = whatever * ne;
671         x6 = 0;
672         z6 - z3 = whatever * ne;
673         z3 - z4 = whatever * (ne yscaled -1);
674
675         z4 - z3 = whatever * (ne) + (ne rotated -90) * thickness;
676
677
678         x1 = charwd / 2 - .5 pen_thick#;
679         z1 = whatever * ne
680              + thick / 2 * stafflinethickness# * (ne rotated -90);
681
682         % labels (1, 2, 3, 4, 5, 6);
683
684         nw = unitvector (z3 - z4);
685
686         up_dist = up * 0.5 pen_thick / cosd (angle (ne));
687         rt_dist = right * 0.5 pen_thick / sind (angle (ne));
688         nw_dist = (ne rotated 90) * 0.5 pen_thick;
689         ne_dist = (nw rotated -90) * 0.5 pen_thick;
690
691         x4' := x4;
692         x5' := x5;
693         y6' := y6;
694
695         x4 := hround (x4' + .5 pen_thick) - .5 pen_thick;
696         x5 := hfloor (x5' + xpart rt_dist) - xpart rt_dist;
697         y6 := vfloor (y6' + ypart up_dist) - ypart up_dist;
698
699         crz_out = (z6 + up_dist)
700                   -- (z3 + nw_dist){ne}
701                   .. (top z3)
702                   .. (z3 + ne_dist){-nw}
703                   -- (z4 + ne_dist){-nw}
704                   .. (rt z4)
705                   .. (z4 - nw_dist){-ne}
706                   -- (z5 + rt_dist);
707         crz_out := crz_out shifted (0, feta_shift)
708                    -- reverse crz_out yscaled -1 shifted (0, -feta_eps);
709         fill crz_out
710              -- reverse crz_out xscaled -1 shifted (-feta_eps, 0)
711              -- cycle;
712
713         if (thick > 1):
714                 x4 := hround (x4' - xpart rt_dist) + xpart rt_dist;
715                 x5 := hceiling (x5' - .5 pen_thick) + .5 pen_thick;
716                 y6 := vfloor (y6' - .5 pen_thick) + .5 pen_thick;
717
718                 crz_in = (bot z6){right}
719                          .. (z6 - nw_dist){ne}
720                          -- (z3 - up_dist)
721                          -- (z4 - rt_dist)
722                          -- (z5 + nw_dist){-ne}
723                          .. {down}(lft z5);
724                 crz_in := crz_in shifted (0, feta_shift)
725                           -- reverse crz_in yscaled -1 shifted (0, -feta_eps);
726                 unfill crz_in
727                        -- reverse crz_in xscaled -1 shifted (-feta_eps, 0)
728                        -- cycle;
729         fi
730
731         % ugh
732         currentpicture := currentpicture shifted (hround (w / 2), 0);
733
734         charwx := charwd;
735         charwy := y1 + feta_shift;
736
737         z12 = (charwx * hppp, y1 * vppp);
738
739         labels (12);
740 enddef;
741
742
743 fet_beginchar ("Whole Crossed notehead", "s0cross");
744         save wid, hei;
745
746         wid# := black_notehead_width# + 4 stafflinethickness#;
747         hei# := noteheight# + stafflinethickness#;
748
749         set_char_box (0, wid#, hei# / 2, hei# / 2);
750
751         draw_cross (3.75);
752
753         remember_pic := currentpicture;
754
755         draw_staff (-2, 2, 0);
756 fet_endchar;
757
758
759 if test > 0:
760         fet_beginchar ("Whole Crossed notehead", "s0cross");
761                 save wid, hei;
762
763                 wid# := black_notehead_width# + 4 stafflinethickness#;
764                 hei# := noteheight# + stafflinethickness#;
765
766                 set_char_box (0, wid#, hei# / 2, hei# / 2);
767
768                 currentpicture := remember_pic;
769
770                 draw_staff (-2, 2, 0.5);
771         fet_endchar;
772 fi;
773
774
775 fet_beginchar ("Half Crossed notehead", "s1cross");
776         save wid, hei;
777
778         wid# := black_notehead_width# + 2 stafflinethickness#;
779         hei# := noteheight# + stafflinethickness# / 2;
780
781         set_char_box (0, wid#, hei# / 2, hei# / 2);
782
783         draw_cross (3.0);
784
785         remember_pic := currentpicture;
786
787         draw_staff (-2, 2, 0);
788 fet_endchar;
789
790
791 if test > 0:
792         fet_beginchar ("Half Crossed notehead", "s1cross");
793                 save wid, hei;
794
795                 wid# := black_notehead_width# + 2 stafflinethickness#;
796                 hei# := noteheight# + stafflinethickness# / 2;
797
798                 set_char_box (0, wid#, hei# / 2, hei# / 2);
799
800                 currentpicture := remember_pic;
801
802                 draw_staff (-2, 2, 0.5);
803         fet_endchar;
804 fi;
805
806
807 fet_beginchar ("Crossed notehead", "s2cross");
808         wid# := black_notehead_width#;
809         hei# := noteheight#;
810         set_char_box (0, wid#, hei# / 2, hei# / 2);
811
812         draw_cross (1.0);
813
814         remember_pic := currentpicture;
815
816         draw_staff (-2, 2, 0);
817 fet_endchar;
818
819
820 if test > 0:
821         fet_beginchar ("Crossed notehead", "s2cross");
822                 wid# := black_notehead_width#;
823                 hei# := noteheight#;
824                 set_char_box (0, wid#, hei# / 2, hei# / 2);
825
826                 currentpicture := remember_pic;
827
828                 draw_staff (-2, 2, 0.5);
829         fet_endchar;
830 fi;
831
832
833 fet_beginchar ("X-Circled notehead", "s2xcircle");
834         save wid, hei;
835         save cthick, cxd, cyd, dy;
836
837         wid# := black_notehead_width# * sqrt (sqrt2);
838         hei# := noteheight# * sqrt (sqrt2);
839
840         set_char_box (0, wid#, hei# / 2, hei# / 2);
841
842         d := d - feta_space_shift;
843
844         cthick# := (1.2 + 1/4) * stafflinethickness#;
845         define_blacker_pixels (cthick);
846
847         cxd := w - cthick;
848         cyd := h + d - cthick / 2;
849
850         dy = .5 (h - d);
851
852         pickup pencircle scaled cthick;
853
854         fill fullcircle xscaled (cxd + cthick)
855                         yscaled (cyd + cthick)
856                         shifted (w / 2, dy);
857         unfill fullcircle xscaled (cxd - cthick)
858                           yscaled (cyd - cthick)
859                           shifted (w / 2, dy);
860
861         xpos := .5 cxd / sqrt2;
862         ypos := .5 cyd / sqrt2;
863
864         pickup penrazor scaled cthick rotated (angle (xpos, ypos) + 90);
865         draw (-xpos + w / 2, -ypos + dy) -- (xpos + w / 2, ypos + dy);
866
867         pickup penrazor scaled cthick rotated (angle (xpos, -ypos) + 90);
868         draw (-xpos + w / 2, ypos + dy) -- (xpos + w / 2, -ypos + dy);
869
870         charwx := charwd;
871         charwy := 0;
872
873         z12 = (charwx * hppp, charwy * vppp);
874         labels (12);
875
876         remember_pic := currentpicture;
877
878         draw_staff (-2, 2, 0);
879 fet_endchar;
880
881
882 if test > 0:
883         fet_beginchar ("X-Circled notehead", "s2xcircle");
884                 save wid, hei;
885                 save cthick, cxr, cyr;
886
887                 wid# := black_notehead_width# * sqrt (sqrt2);
888                 hei# := noteheight# * sqrt (sqrt2);
889
890                 set_char_box (0, wid#, hei# / 2, hei# / 2);
891
892                 currentpicture := remember_pic;
893
894                 draw_staff (-2, 2, 0.5);
895         fet_endchar;
896 fi;
897
898
899 %%%%%%%%
900 %
901 % SOLFA SHAPED NOTES
902 %
903
904 save solfa_pen_thick;
905 solfa_pen_thick# = 1.75 stafflinethickness#;
906 define_blacker_pixels (solfa_pen_thick);
907
908
909 save solfa_base_notewidth;
910 solfa_base_notewidth# := black_notehead_width#;
911
912 solfa_whole_width := whole_notehead_width# / black_notehead_width#;
913 solfa_half_width := half_notehead_width# / black_notehead_width#;
914 solfa_quarter_width := 1.0;
915
916 def draw_do_head (expr width_factor, dir) =
917         save p_in, p_out;
918         save left_dist, right_dist;
919         path p_in, p_out;
920         pair left_dist, right_dist;
921
922         set_char_box (0, width_factor * solfa_base_notewidth#,
923                       0.5 solfa_noteheight#, 0.5 solfa_noteheight#);
924
925         pickup pencircle scaled solfa_pen_thick;
926
927         bot y1 = -d;
928         y1 = y2;
929         lft x1 = 0;
930         rt x2 = w;
931         top y3 = h;
932         x3 =.5 [x1, x2];
933
934         left_dist = (unitvector (z3 - z1) rotated 90) * 0.5 solfa_pen_thick;
935         right_dist = (unitvector (z2 - z3) rotated 90) * 0.5 solfa_pen_thick;
936
937         p_in := (((z1 - left_dist) -- (z3 - left_dist)) intersectionpoint
938                   (top z1 -- top z2))
939                 -- ((top z1 -- top z2) intersectionpoint
940                     ((z2 - right_dist) -- (z3 - right_dist)))
941                 -- (((z2 - right_dist) -- (z3 - right_dist)) intersectionpoint
942                     ((z1 - left_dist) -- (z3 - left_dist)))
943                 -- cycle;
944
945         p_out := bot z1
946                  -- bot z2{right}
947                  .. rt z2{up}
948                  .. (z2 + right_dist){z3 - z2}
949                  -- (z3 + right_dist){z3 - z2}
950                  .. top z3{left}
951                  .. (z3 + left_dist){z1 - z3}
952                  -- (z1 + left_dist){z1 - z3}
953                  .. lft z1{down}
954                  .. {right}cycle;
955                  
956
957         labels (1, 2, 3);
958
959         charwx := charwd;
960         charwy := -chardp + 0.5 stafflinethickness#;
961         if dir = -1:
962                 charwy := -charwy;
963         fi;
964 enddef;
965
966
967 fet_beginchar ("Whole dohead", "s0do");
968         draw_do_head (solfa_whole_width, 1);
969         fill p_out;
970         unfill p_in;
971 fet_endchar;
972
973
974 fet_beginchar ("Half dohead", "d1do");
975         draw_do_head (solfa_half_width, -1);
976         fill p_out;
977         unfill p_in;
978 fet_endchar;
979
980
981 fet_beginchar ("Half dohead", "u1do");
982         draw_do_head (solfa_half_width, 1);
983         fill p_out;
984         unfill p_in;
985 fet_endchar;
986
987
988 fet_beginchar ("Quart dohead", "d2do");
989         draw_do_head (solfa_quarter_width, -1);
990         fill p_out;
991 fet_endchar;
992
993
994 fet_beginchar ("Quart dohead", "u2do");
995         draw_do_head (solfa_quarter_width, 1);
996         fill p_out;
997 fet_endchar;
998
999
1000 %
1001 % re - flat top, curved bottom:
1002 %                (0,h/2) {dir -90} .. (w/2,-h/2) .. {dir 90} (w,h/2) -- cycle;
1003 % (broader along the base and with more vertical sides for half and
1004 % whole notes)
1005 % stem attachment: h/2
1006 %
1007
1008 def draw_re_head (expr width_factor, dir) =
1009         save p_in, p_out;
1010         path p_in, p_out;
1011
1012         set_char_box (0, width_factor * solfa_noteheight#,
1013                       0.5 solfa_noteheight#, 0.5 solfa_noteheight#);
1014
1015         pickup pencircle scaled solfa_pen_thick;
1016
1017         save curve_start;
1018         curve_start = 0.7;
1019         lft x1 = 0;
1020         y1 = y5;
1021         x1 = x2;
1022         y2 = curve_start [y3, y1];
1023         bot y3 = -d;
1024         x3 = .5 [x2, x4];
1025         rt x4 = w;
1026         y4 = y2;
1027         top y5 = h;
1028         x5 = x4;
1029
1030         labels (range 1 thru 5);
1031
1032         p_in := (z1 + 0.5 solfa_pen_thick * (1, -1))
1033                 -- rt z2{down}
1034                 .. top z3
1035                 .. lft z4{up}
1036                 -- (z5 + 0.5 solfa_pen_thick * (-1, -1))
1037                 -- cycle;
1038
1039         p_out := lft z1
1040                  -- lft z2{down}
1041                  .. bot z3
1042                  .. rt z4{up}
1043                  -- rt z5{up}
1044                  .. top z5{left}
1045                  -- top z1{left}
1046                  .. {down}cycle;
1047
1048         charwx := charwd;
1049         charwy := curve_start [-chardp, charht];
1050
1051         if dir = -1:
1052                 charwy := -charwy;
1053         fi;
1054 enddef;
1055
1056
1057 fet_beginchar ("Whole rehead", "s0re");
1058         draw_re_head (solfa_whole_width, 1);
1059         fill p_out;
1060         unfill p_in;
1061 fet_endchar;
1062
1063
1064 fet_beginchar ("Half up rehead", "u1re");
1065         draw_re_head (solfa_half_width, 1);
1066         fill p_out;
1067         unfill p_in;
1068 fet_endchar;
1069
1070
1071 fet_beginchar ("Half down rehead", "d1re");
1072         draw_re_head (solfa_half_width, -1);
1073         fill p_out;
1074         unfill p_in;
1075 fet_endchar;
1076
1077
1078 fet_beginchar ("Quart rehead", "u2re");
1079         draw_re_head (solfa_quarter_width, 1);
1080         fill p_out;
1081 fet_endchar;
1082
1083
1084 fet_beginchar ("Quart rehead", "d2re");
1085         draw_re_head (solfa_quarter_width, -1);
1086         fill p_out;
1087 fet_endchar;
1088
1089
1090 def draw_mi_head (expr width_factor) =
1091         save path_out, path_in;
1092         save ne_dist, se_dist, ne, se;
1093         path path_out, path_in;
1094         pair ne_dist, se_dist, ne, se;
1095
1096         set_char_box (0, width_factor * solfa_noteheight#,
1097                       0.5 solfa_noteheight#, 0.5 solfa_noteheight#);
1098
1099         pickup pencircle scaled solfa_pen_thick;
1100
1101         lft x1 = 0;
1102         y1 = 0;
1103         bot y2 = -d;
1104         x2 = .5 [x1, x3];
1105         rt x3 = w;
1106         x4 = x2;
1107         y3 = y1;
1108         top y4 = h;
1109
1110         z6 - z5 = whatever * (z2 - z1);
1111         z8 - z7 = whatever * (z2 - z1);
1112         z8 - z5 = whatever * (z4 - z1);
1113         z6 - z7 = whatever * (z4 - z1);
1114
1115         ne = unitvector (z4 - z1);
1116         se = unitvector (z1 - z2);
1117
1118         ne_dist = (ne rotated 90) * 0.5 solfa_pen_thick;
1119         se_dist = (se rotated 90) * 0.5 solfa_pen_thick;
1120
1121         z5 = whatever [z1, z4] - ne_dist;
1122         z5 = whatever [z1, z2] - 1.5 se_dist;
1123
1124         z5 - z1 = -(z7 - z3);
1125
1126         labels (range 1 thru 8);
1127
1128         path_in := z5
1129                    -- z6
1130                    -- z7
1131                    -- z8
1132                    -- cycle;
1133
1134         path_out := lft z1
1135                     .. (z1 + se_dist){-se}
1136                     -- (z2 + se_dist){-se}
1137                     .. bot z2
1138                     .. (z2 - ne_dist){ne}
1139                     -- (z3 - ne_dist){ne}
1140                     .. rt z3
1141                     .. (z3 - se_dist){se}
1142                     -- (z4 - se_dist){se}
1143                     .. top z4
1144                     .. (z4 + ne_dist){-ne}
1145                     -- (z1 + ne_dist){-ne}
1146                     .. cycle;
1147 enddef;
1148
1149
1150 fet_beginchar ("Whole mihead", "s0mi");
1151         draw_mi_head (solfa_whole_width);
1152         fill path_out;
1153         unfill path_in;
1154 fet_endchar;
1155
1156
1157 fet_beginchar ("Half mihead", "s1mi");
1158         draw_mi_head (solfa_quarter_width);
1159         fill path_out;
1160         unfill path_in;
1161 fet_endchar;
1162
1163
1164 fet_beginchar ("Quart mihead", "s2mi");
1165         draw_mi_head (solfa_quarter_width);
1166         fill path_out;
1167 fet_endchar;
1168
1169
1170 def draw_fa_head (expr width_factor) =
1171         set_char_box (0, width_factor * solfa_noteheight#,
1172                       0.5 solfa_noteheight#, 0.5 solfa_noteheight#);
1173
1174         save p_down_in, p_down_out, p_up_in, p_up_out, nw_dist, nw;
1175         path p_down_in, p_down_out, p_up_in, p_up_out;
1176         pair nw_dist, nw;
1177
1178         pickup pencircle scaled solfa_pen_thick;
1179
1180         lft x1 = 0;
1181         top y1 = h;
1182
1183         rt x2 = w;
1184         y2 = y1;
1185         bot y3 = -d;
1186         x3 = x2;
1187
1188         y4 = y3;
1189         x4 = x1;
1190
1191         labels (1, 2, 3, 4);
1192
1193         nw = unitvector (z1 - z3);
1194         nw_dist = (nw rotated 90) * 0.5 solfa_pen_thick;
1195
1196         p_up_in := (((z1 - nw_dist) -- (z3 - nw_dist)) intersectionpoint
1197                      (bot z1 -- bot z2))
1198                    -- (((z1 - nw_dist) -- (z3 - nw_dist)) intersectionpoint
1199                         (lft z3 -- lft z2))
1200                    -- (z2 + 0.5 solfa_pen_thick * (-1, -1))
1201                    -- cycle;
1202
1203         p_up_out := lft z1{down}
1204                     .. (z1 + nw_dist){-nw}
1205                     -- (z3 + nw_dist){-nw}
1206                     .. bot z3{right}
1207                     .. rt z3{up}
1208                     -- rt z2{up}
1209                     .. top z2{left}
1210                     -- top z1{left}
1211                     .. {down}cycle;
1212
1213         p_down_in := p_up_in rotated 180 shifted (w, 0);
1214         p_down_out := p_up_out rotated 180 shifted (w, 0);
1215
1216         charwy := 0.0;
1217         charwx := charwd;
1218 enddef;
1219
1220
1221 fet_beginchar ("Whole fa up head", "u0fa");
1222         draw_fa_head (solfa_whole_width);
1223         fill p_up_out;
1224         unfill p_up_in;
1225 fet_endchar;
1226
1227
1228 fet_beginchar ("Whole fa down head", "d0fa");
1229         draw_fa_head (solfa_whole_width);
1230         fill p_down_out;
1231         unfill p_down_in;
1232 fet_endchar;
1233
1234
1235 fet_beginchar ("half fa up head", "u1fa");
1236         draw_fa_head (solfa_half_width);
1237         fill p_up_out;
1238         unfill p_up_in;
1239 fet_endchar;
1240
1241
1242 fet_beginchar ("Half fa down head", "d1fa");
1243         draw_fa_head (solfa_half_width);
1244         fill p_down_out;
1245         unfill p_down_in;
1246 fet_endchar;
1247
1248
1249 fet_beginchar ("Quarter fa up head", "u2fa");
1250         draw_fa_head (solfa_quarter_width);
1251         fill p_up_out;
1252 fet_endchar;
1253
1254
1255 fet_beginchar ("Quarter fa down head", "d2fa");
1256         draw_fa_head (solfa_quarter_width);
1257         fill p_down_out;
1258 fet_endchar;
1259
1260
1261 def draw_la_head (expr width_factor) =
1262         set_char_box (0, width_factor * solfa_noteheight#,
1263                       0.5 solfa_noteheight#, 0.5 solfa_noteheight#);
1264         save p_in, p_out;
1265         path p_in, p_out;
1266
1267         pickup pencircle scaled solfa_pen_thick;
1268
1269         lft x1 = 0;
1270         top y1 = h;
1271
1272         rt x2 = w;
1273         y2 = y1;
1274         bot y3 = -d;
1275         x3 = x2;
1276
1277         y4 = y3;
1278         x4 = x1;
1279
1280         labels (range 1 thru 4);
1281
1282         p_in := (z1 + 0.5 solfa_pen_thick * (1, -1))
1283                 -- (z2 + 0.5 solfa_pen_thick * (-1, -1))
1284                 -- (z3 + 0.5 solfa_pen_thick * (-1, 1))
1285                 -- (z4 + 0.5 solfa_pen_thick * (1, 1))
1286                 -- cycle;
1287
1288         p_out := top z1
1289                  -- top z2{right}
1290                  .. rt z2{down}
1291                  -- rt z3{down}
1292                  .. bot z3{left}
1293                  -- bot z4{left}
1294                  .. lft z4{up}
1295                  -- lft z1{up}
1296                  .. cycle;
1297 enddef;
1298
1299
1300 fet_beginchar ("Whole lahead", "s0la");
1301         draw_la_head (solfa_whole_width);
1302         fill p_out;
1303         unfill p_in;
1304 fet_endchar;
1305
1306
1307 fet_beginchar ("Half lahead", "s1la");
1308         draw_la_head (solfa_half_width);
1309         fill p_out;
1310         unfill p_in;
1311 fet_endchar;
1312
1313
1314 fet_beginchar ("Quart lahead", "s2la");
1315         draw_la_head (solfa_quarter_width);
1316         fill p_out;
1317 fet_endchar;
1318
1319
1320 def draw_ti_head (expr width_factor, dir) =
1321         set_char_box (0, width_factor * solfa_noteheight#,
1322                       0.5 solfa_noteheight#, 0.5 solfa_noteheight#);
1323         save p_in, p_out, p_top;
1324         save nw_dist, sw_dist, nw, sw;
1325         path p_in, p_out, p_top;
1326         pair nw_dist, sw_dist, nw, sw;
1327         save cone_height;
1328         cone_height = 0.64;
1329
1330         pickup pencircle scaled solfa_pen_thick;
1331
1332         x1 = .5 [x2, x4];
1333         bot y1 = -d;
1334         lft x2 = 0;
1335         y2 = cone_height [y1, y3];
1336         rt x4 = w;
1337         y4 = y2;
1338         x3 = x1;
1339         top y3 = h;
1340
1341         labels (range 1 thru 4);
1342
1343         nw = unitvector (z2 - z1);
1344         sw = unitvector (z1 - z4);
1345
1346         nw_dist = (nw rotated 90) * 0.5 solfa_pen_thick;
1347         sw_dist = (sw rotated 90) * 0.5 solfa_pen_thick;
1348
1349         p_top := (z2 - sw_dist)
1350                  .. (top z3){right}
1351                  .. (z4 - nw_dist);
1352
1353         p_in := (((z1 - nw_dist) -- (z2 - nw_dist)) intersectionpoint
1354                   ((z1 - sw_dist) -- (z4 - sw_dist)))
1355                 -- (((z1 - nw_dist) -- (z2 - nw_dist)) intersectionpoint
1356                      ((z2 + sw_dist) .. {right}(bot z3)))
1357                 .. bot z3
1358                 .. (((bot z3){right} .. (z4 + nw_dist)) intersectionpoint
1359                      ((z1 - sw_dist) -- (z4 - sw_dist)))
1360                 -- cycle;
1361
1362         p_out := bot z1
1363                  .. (z1 + nw_dist)
1364                  -- (z2 + nw_dist)
1365                  .. lft z2
1366                  .. (z2 - sw_dist){direction 0 of p_top}
1367                  & p_top
1368                  & {direction infinity of p_top}(z4 - nw_dist)
1369                  .. rt z4
1370                  .. (z4 + sw_dist)
1371                  -- (z1 + sw_dist)
1372                  .. cycle;
1373
1374         charwx := charwd;
1375         charwy := cone_height [-chardp, charht];
1376         if dir = -1:
1377                 charwy := -charwy;
1378         fi;
1379 enddef;
1380
1381
1382 fet_beginchar ("Whole up tihead", "s0ti");
1383         draw_ti_head (solfa_whole_width, 1);
1384         fill p_out;
1385         unfill p_in;
1386 fet_endchar;
1387
1388
1389 fet_beginchar ("Half up tihead", "u1ti");
1390         draw_ti_head (solfa_half_width, 1);
1391         fill p_out;
1392         unfill p_in;
1393 fet_endchar;
1394
1395
1396 fet_beginchar ("Half down tihead", "d1ti");
1397         draw_ti_head (solfa_half_width, -1);
1398         fill p_out;
1399         unfill p_in;
1400 fet_endchar;
1401
1402
1403 fet_beginchar ("Quart up tihead", "u2ti");
1404         draw_ti_head (solfa_quarter_width, 1);
1405         fill p_out;
1406 fet_endchar;
1407
1408
1409 fet_beginchar ("Quart down tihead", "d2ti");
1410         draw_ti_head (solfa_quarter_width, -1);
1411         fill p_out;
1412 fet_endchar;
1413
1414
1415 fet_endgroup ("noteheads");
1416
1417
1418 %
1419 % we derive black_notehead_width# from the quarter head,
1420 % so we have to define black_notehead_width (pixel qty)
1421 % after the black_notehead_width# itself.
1422 %
1423 % Let's keep it outside the group as well.
1424 %
1425
1426 define_pixels (black_notehead_width);