% eindelijk.mf
% LilyPond's own rest(s)

% todo breve/longa rests


fet_begingroup("rests");

begingroup

thick#:=1/16designsize;
define_blacker_pixels(thick);

rthin:=1/8*interline;
% rthick:=2rthin;
rthick:=2thick+rthin;

def shift_pic (expr pone, ptwo) =
  currentpicture:=currentpicture shifted (round(pone),round(ptwo))
enddef;

% stuff for     8th,16th etc rests
%
save stem, ball_crook_stem, ball_crook_balldiam, flare;

% stem#:=1/8*interline#;
stem# = 1/5interline#;
% flare# = 2/3interline#;
flare# = 2/3interline# - 1/8stafflinethickness#;

define_pixels(stem,flare);

ball_crook_stem = stem;
ball_crook_balldiam =flare;


save block_rest_y, block_rest_x;

block_rest_y# = 5/8 interline#;
block_rest_x# = 3/2 interline#;

define_pixels(block_rest_y, block_rest_x);

def block_rest =
	draw_block ((0,0), (block_rest_x, block_rest_y));
	enddef;

fet_beginchar( "whole rest", "0", "wholerest");
	set_char_box(0, block_rest_x#,
		block_rest_y#,  0);
	block_rest;
	currentpicture := currentpicture shifted (0,- block_rest_y);
fet_endchar;

fet_beginchar("half rest", "1", "halfrest");
	set_char_box(0, block_rest_x#, 0, block_rest_y#);
	block_rest;
fet_endchar;


%
% should use ledgerline thickness?
%
fet_beginchar( "whole rest (outside staff)", "0o", "outsidewholerest");
	set_char_box(block_rest_y#, block_rest_x# + block_rest_y#, 
		block_rest_y#, ledgerlinethickness#/2);
	block_rest;
	currentpicture := currentpicture shifted (0, - block_rest_y);
	pickup pencircle scaled ledgerlinethickness;

	y5 = y6 = 0;
	lft x5 = - b; 
	rt x6 = w;
	draw z5 .. z6;
fet_endchar;

fet_beginchar("half rest (outside staff)", "1o", "outsidehalfrest");
	set_char_box(block_rest_y#, block_rest_x#+ block_rest_y#, 
		ledgerlinethickness#/2, block_rest_y#);
	block_rest;
	pickup pencircle scaled ledgerlinethickness;
	y5 = y6 = 0;
	lft x5 = - b; 
	rt x6 = w;
	draw z5 .. z6;
fet_endchar;

fet_beginchar("Quarter rest","2","quartrest");
	save alpha;
	alpha:=-50;
	save ne,nw,se,sw; pair ne,nw,se,sw;
	se=dir alpha; nw=dir (alpha+180);
	ne=dir (alpha+90); sw=dir (alpha-90);
	penpos1(rthin,alpha+90);
	penpos2(5/4rthick,alpha);
	penpos4(5/4rthick,alpha);
	penpos5(rthin,alpha+90);
	penpos3(3/4rthick,alpha);
%	penpos6(5/8rthick,alpha);
	penpos6(2/3rthick,alpha);
	penpos7(1/2rthin,alpha+90);

	z10=z2l+1/2rthin*sw;
%	z11=z4l+1/2rthin*sw;
	z11=z4l+1/2rthin*sw+1/2rthin*se;
	z12=z4r+1/2rthin*ne;
%	z13=z2r+1/2rthin*ne;
	z13=z2r+1/2rthin*ne+1/2rthin*nw;

	y1l=7/2interline; x1l=1/3interline;
	z2r=z1+interline*se;
	z3=1/2[z2,z4];
	x4=3/8interline; y4=2interline;
	z5=z4l+1.3interline*se;
	x6l=x4l; y6l=y4r;
	x7=2/5interline; y7=3/4interline;
	fill z1l{se}..{se}z10..z3l..z11{se}..{se}z5l..z5r{nw}..{nw}z12..z3r..z13{nw}..{nw}z1r.. cycle;
	fill z5r{nw}..tension1.4..z6l..tension1.4..{se}z7l..z7r{nw}..tension1.4..z6r..tension1.4..{se}z5l..cycle;
	penlabels(1,2,3,4,5,6,7);
	penlabels(10,11,12,13);
	set_char_box(0, 27/25interline#, -3/4 interline#, 18/5interline#);
	fet_endchar;

def rest_crook(expr a, w) =
	balled_crook(a, w, ball_crook_balldiam, ball_crook_stem)
enddef;

fet_beginchar("8th rest","3","eighthrest");
	set_char_box(0, 4/3interline#,-interline#, 8/3interline#+7/4stafflinethickness#);
	save x,y, ht;
	ht = h + d;
	x1=w-stem/6; y1=ht-flare/4;
	rest_crook (z1,w-stem/6);
	z2-z1=whatever*dir70;
	y2=stem/2;
	brush(z1,2/3stem,z2,stem);
	% ugh
	currentpicture:=currentpicture shifted (0,interline);
	fet_endchar;

fet_beginchar("16th rest","4","sixteenthrest");
	save alpha,cw,h,w;
	alpha=74;
	cw#=7/6interline#;
%	h#=5/3interline#+interline#+2stafflinethickness#;
	h#=5/3interline#+interline#+7/4stafflinethickness#;
	w#=cw#+(h#-3/2interline#)/tand(alpha);
	set_char_box(0,w#,0,h#);
	define_pixels(cw);
	save x,y;
	x1=w-stem/6; y1=h-flare/4;
	z2-z1=whatever*dir alpha;
	y2=stem/2;
	brush(z1,2/3stem,z2,stem);
	rest_crook (z1,cw);
	z3-z1=whatever*dir alpha;
	y3=y1-interline;
	rest_crook (z3,cw);
	penlabels(1,2);
	fet_endchar;

fet_beginchar("32th rest","5","thirtysecondrest");
	save alpha,cw,h,w;
	alpha=76;
	cw#=7/6interline#;
	h#=5/3interline#+2interline#+7/4stafflinethickness#;
	w#=cw#+(h#-3/2interline#)/tand(alpha);
	set_char_box(0,w#,0,h#);
	define_pixels(cw);
	save x,y;
	x1=w-stem/6; y1=h-flare/4;
	z2-z1=whatever*dir alpha;
	y2=stem/2;
	brush(z1,2/3stem,z2,stem);
	rest_crook (z1,cw);
	z3-z1=whatever*dir alpha;
	y3=y1-interline;
	rest_crook (z3,cw);
	z4-z1=whatever*dir alpha;
	y4=y1-2interline;
	rest_crook (z4,cw);
	fet_endchar;

fet_beginchar("64th rest","6","sixtyfourthrest");
	save alpha,cw,h,w;
	alpha=78;
	cw#=7/6interline#;
	h#=5/3interline#+3interline#+7/4stafflinethickness#;
	w#=cw#+(h#-3/2interline#)/tand(alpha);
	set_char_box(0,w#,0,h#);
	define_pixels(cw);
	save x,y;
	x1=w-stem/6; y1=h-flare/4;
	z2-z1=whatever*dir alpha;
	y2=stem/2;
	brush (z1,2/3stem,z2,stem);
	rest_crook (z1,cw);
	z3-z1=whatever*dir alpha;
	y3=y1-interline;
	rest_crook (z3,cw);
	z4-z1=whatever*dir alpha;
	y4=y1-2interline;
	rest_crook (z4,cw);
	z5-z1=whatever*dir alpha;
	y5=y1-3interline;
	rest_crook (z5,cw);
	% ugh
	currentpicture:=currentpicture shifted (0,-interline);
	fet_endchar;

fet_beginchar("128th rest","7","hundredtwentyeighthrest"); 
	save alpha,cw,h,w;
	alpha=78;
	cw#=7/6interline#;
	h#=5/3interline#+4interline#+7/4stafflinethickness#;
	w#=cw#+(h#-3/2interline#)/tand(alpha);
	set_char_box(0,w#,0,h#);
	define_pixels(cw);
	save x,y;
	x1=w-stem/6; y1=h-flare/4;
	z2-z1=whatever*dir alpha;
	y2=stem/2;
	brush (z1,2/3stem,z2,stem);
	rest_crook (z1,cw);
	z3-z1=whatever*dir alpha;
	y3=y1-interline;
	rest_crook (z3,cw);
	z4-z1=whatever*dir alpha;
	y4=y1-2interline;
	rest_crook (z4,cw);
	z5-z1=whatever*dir alpha;
	y5=y1-3interline;
	rest_crook (z5,cw);
	z6-z1=whatever*dir alpha;
	y6=y1-4interline;
	rest_crook (z6,cw);
	% ugh
	currentpicture:=currentpicture shifted (0,-interline);
	fet_endchar;

endgroup;
fet_endgroup("rests");

