+% New bulb routine:
+%
+% Insert a brushed piece of the path, and draw a bulb separately
+%
+% The bulb is circular form. Neat merging of the bulb and brushed path
+% is done by playing with tension.
+%
+%
+
+def new_bulb (expr outer_tangent_point,
+ big_radius, bulb_radius, flare, direction, turning_dir) =
+
+begingroup;
+ save p, oldpen;
+ path p;
+ pen oldpen;
+ save center;
+ pair center;
+ clearxy;
+
+ center = outer_tangent_point +big_radius* dir(0) + big_radius* dir(-turning_dir * 90)
+ - bulb_radius * dir (- turning_dir * 90);
+
+ z1 = center + bulb_radius * dir (turning_dir * 180);
+ z2 = center + bulb_radius * dir (turning_dir * 270);
+
+ z9 = center + bulb_radius * dir (0);
+ z10 = center + bulb_radius * dir (turning_dir *90);
+ z3 = outer_tangent_point + flare * dir (0);
+
+ labels(1,2,3,9,10);
+
+ % tension is needed to open up the space between return path and the
+ % ball.
+ fill
+% draw
+ z9 .. z10 .. tension 1.1 .. z1 .. z2 .. cycle;
+
+ p:= outer_tangent_point{dir (-turning_dir* 90)}
+ .. tension 0.97
+ .. {dir (turning_dir * 90)}z9 -- z3
+ ;
+ if direction = 1:
+ p
+ else:
+ reverse p
+ fi
+ endgroup
+enddef;
+
+
+
+%
+%
+% There is some variation is shape of bass clefs. Important points
+%
+% * the size of the swoosh tip: in some clefs, it almost reaches the
+% bottom staff line, in some it crosses the 2nd line from the bottom
+% with a small overshoot.
+%
+% The most popular design is where the X part of the tip is aligned
+% left bulb boundary, and the Y part ends on the 2nd staffline exactly.
+% This is what we do.
+%
+% * The size of the bulb. The diameter of the bulb is the width of the
+% open space.
+%
+% * The y-alignment of the bulb. The center of the bulb can be on or slightly
+% above the staff line.
+%
+% * The position of the dots. They can be symmetrical around the
+% staffline, centered in the staff space. The Baerenreiter SCS has the
+% bottom dot raised by approx. 0.1 ss.
+%
+% * uncarefully set music may have overshoots at the top. We have none.
+%
+% * It is not exactly clear where the vertical tangent at the right
+% of the swoosh should be.