% solfa.mf - implements solfa shaped notes
%
% (c)  2001--2003 Glen Prideaux <glenprideaux@iname.com>

% We can use the regular distorted-elliptical head in the feta font
% for the sol head, but we can't use the triangle or diamond heads for
% the do or me because they're too narrow and their lines too thin.

fet_begingroup("solfa");

noteheight#:=staff_space#+ (overdone_heads) *stafflinethickness#;
define_pixels(noteheight);

%%%%%%%%
%
%
% SOLFA SHAPED NOTES
%
%
save pent;
pent# = stafflinethickness#;
define_pixels(pent);

def generic_drawnoteshape =
  save a,beta,black,white;
  path black, white;

  pickup pencircle scaled pent;
  2 beta# = noteheight#;
  a# = a_b*beta#;
  wid# := 2a#+pent#;
  hei# := noteheight#+pent#;
  set_char_box(0, wid#,0.5 hei#, 0.5 hei#);

  define_pixels(a,beta);

  black = noteshape xscaled a yscaled beta shifted (a+pent/2,0);
  filldraw black;

  if (solid=false):
    white = noteishape xscaled (a*ai_a) yscaled (beta*bi_b)
                       shifted ((dx+1)*(a+pent/2),dy*(beta+pent/2));
    unfill white;
  fi;
enddef;  

def drawnoteshape =
  save solid; boolean solid;
  solid=false;
  generic_drawnoteshape;
enddef;
def drawquarternoteshape =
  save solid; boolean solid;
  solid=true;
  generic_drawnoteshape;
enddef;

% do - equilateral triangle: (0,-h/2) -- (w/2,h/2) -- (w,-h/2) -- cycle;
% stem attachment: -h/2

save triangle; path triangle;
triangle := (-1,-1) -- (0,1) -- (1,-1) -- cycle;

def drawdoshape =
  save noteshape, noteishape, dx, dy, ai_a, bi_b;
  path noteshape, noteishape;
  noteshape = noteishape = triangle;
  (dx,dy)=(0,0.05);
  (ai_a,bi_b)=(i_o,i_o);
  drawnoteshape;
enddef;

fet_beginchar("Whole dohead", "0do", "wholedohead")
  pickup pencircle scaled blot_diameter;
  save a_b, i_o;
  a_b = 1.8;
  i_o = 0.6;

  drawdoshape;
fet_endchar;
  
fet_beginchar("Half dohead", "1do", "halfdohead")
  save a_b, i_o;
  a_b = 1.5;
  i_o = 0.6;

  drawdoshape;
fet_endchar;
  
fet_beginchar("Quart dohead", "2do", "dohead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = triangle;
  drawquarternoteshape;

fet_endchar;
  
% re - flat top, curved bottom:
%                (0,h/2) {dir -90} .. (w/2,-h/2) .. {dir 90} (w,h/2) -- cycle;
% (broader along the base and with more vertical sides for half and
% whole notes)
% stem attachment: h/2

save reshape; path reshape;
reshape = (-1,1)--(-1,0.2){down} ... (0,-1) ... {up}(1,0.2)--(1,1)--cycle;

fet_beginchar("Whole rehead", "0re", "wholerehead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = reshape;
  noteishape = reshape;
  a_b = 1.8;
  bi_b = 0.65;
  ai_a = 0.8;
  (dx,dy)=(0,-0.1);
  drawnoteshape;
fet_endchar;

fet_beginchar("Half rehead", "1re", "halfrehead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = reshape;
  noteishape = reshape;
  a_b = 1.5;
  bi_b = 0.65;
  ai_a = 0.8;
  (dx,dy)=(0,-0.1);
  drawnoteshape;
fet_endchar;

fet_beginchar("Quart rehead", "2ro", "rehead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = reshape;
  drawquarternoteshape;
fet_endchar;
  
% me - diamond: (0,0) -- (w/2,h/2) -- (w,0) -- (w/2,-h/2) -- cycle;
% similar to existing diamond shaped head, but not quite the same
% stem attachment: 0

save meshape; path meshape;
meshape = (-1,0)--(0,1)--(1,0)--(0,-1)--cycle;

fet_beginchar("Whole mehead", "0me", "wholemehead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = meshape;
  noteishape = (meshape slanted -0.35) rotated -10.5;
  a_b = 1.8;
  bi_b = 0.65;
  ai_a = 0.7;
  (dx,dy)=(0,0);
  drawnoteshape;
fet_endchar;

fet_beginchar("Half mehead", "1me", "halfmehead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = meshape;
  noteishape =  (meshape slanted -0.35) rotated -10.5;
  a_b = 1.5;
  bi_b = 0.65;
  ai_a = 0.7;
  (dx,dy)=(0,0);
  drawnoteshape;
fet_endchar;

fet_beginchar("Quart mehead", "2me", "mehead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = meshape;
  drawquarternoteshape;
fet_endchar;


% fa - scalene triangle:
%         for stem up: (0,h/2) -- (w,h/2) -- (w,-h/2) -- cycle;
%       for stem down: (w,-h/2) -- (0,1h/2) -- (0,h/2) -- cycle;
%       (one is a 180 degree rotation of the other)
% stem attachment: (doesn't much matter)

save fashape; path fashape;
fashape = (-1,1)--(1,1)--(1,-1)--cycle;

fet_beginchar("Whole fahead", "0fa", "wholefahead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = fashape;
  noteishape = fashape;
  a_b = 1.8;
  bi_b = 0.6;
  ai_a = 0.6;
  (dx,dy)=(0.2,.05);
  drawnoteshape;
fet_endchar;

fet_beginchar("Half stemup fahead", "1fau", "halffauhead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = fashape;
  noteishape =  fashape;
  a_b = 1.5;
  bi_b = 0.6;
  ai_a = 0.6;
  (dx,dy)=(0.2,.05);
  drawnoteshape;
fet_endchar;

fet_beginchar("Quart stemup fahead", "2fau", "fauhead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = fashape;
  drawquarternoteshape;
fet_endchar;

fet_beginchar("Half stemdn fahead", "1fad", "halffadhead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = fashape rotated 180;
  noteishape =  fashape rotated 180;
  a_b = 1.5;
  bi_b = 0.6;
  ai_a = 0.6;
  (dx,dy)=(-0.2,-.05);
  drawnoteshape;
fet_endchar;

fet_beginchar("Quart stemdn fahead", "2fad", "fadhead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = fashape rotated 180;
  drawquarternoteshape;
fet_endchar;


% sol - oval ... the standard "round" note

% la - rectangle: (0,h/2)--(w,h.2)--(w,-h/2)--(0,-h/2)--cycle;
% stem attachment: (doesn't much matter)
save lashape; path lashape;
lashape = (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle;

fet_beginchar("Whole lahead", "0la", "wholelahead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = lashape;
  noteishape = lashape;
  a_b = 1.8;
  bi_b = 0.6;
  ai_a = 0.85;
  (dx,dy)=(0,0);
  drawnoteshape;
fet_endchar;

fet_beginchar("Half lahead", "1la", "halflahead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = lashape;
  noteishape =  lashape;
  a_b = 1.5;
  bi_b = 0.6;
  ai_a = 0.85;
  (dx,dy)=(0,0);
  drawnoteshape;
fet_endchar;

fet_beginchar("Quart lahead", "2la", "lahead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = lashape;
  drawquarternoteshape;
fet_endchar;


% te - an "icecream cone" with about 2/3 of
% the height in the cone and only 1/3 in the curved top:
%      (0,h/6)--(w/2,-h/2)--(w,h/6)..(w/2,h/2)..cycle;
% stem attachment: h/6
save teshape; path teshape;
teshape = (0,-1)--(-1,0.3)..(0,1)..(1,0.3)--cycle;

fet_beginchar("Whole tehead", "0te", "wholetehead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = teshape;
  noteishape = teshape;
  a_b = 1.8;
  bi_b = 0.75;
  ai_a = 0.75;
  (dx,dy)=(0,-.02);
  drawnoteshape;
fet_endchar;

fet_beginchar("Half tehead", "1te", "halftehead")
  save a_b, ai_a, bi_b, dx, dy, noteshape, noteishape;
  path noteshape, noteishape;
  noteshape = teshape;
  noteishape =  teshape;
  a_b = 1.5;
  bi_b = 0.75;
  ai_a = 0.75;
  (dx,dy)=(0,-.02);
  drawnoteshape;
fet_endchar;

fet_beginchar("Quart tehead", "2te", "tehead")
  save a_b, noteshape;
  path noteshape;
  a_b = 1.54;
  
  noteshape = teshape;
  drawquarternoteshape;
fet_endchar;

fet_endgroup("solfa")
