% -*- Fundamental -*-

fet_begingroup("accordion")

accreg_dot_size# := .5staff_space#;
accreg_linethickness# := 1.3stafflinethickness#;

% This dimention is the same on all registersymbols.
% The different symbols should calculate their other
% dimensions from this and accreg_dot_size
accreg_lh# := 1.0staff_space#;

define_pixels(accreg_dot_size, accreg_linethickness, accreg_lh);
pen accreg_pen;
accreg_pen := pencircle xscaled accreg_linethickness yscaled 0.7accreg_linethickness;

fet_beginchar("accDiscant", "accDiscant", "accDiscant")
	save r, sx;
	r# = 3/2accreg_lh#;
	define_pixels(r);
%	set_char_box(r#, r#, 2r#, 0);
	set_char_box(r#, r#, 0r#, 2r#); %% arg3 = under linjen, arg4 = over
	pickup accreg_pen;
	draw fullcircle scaled 2r;
	sx = cosd(19.471221);
	draw (-sx*r, r/3)--(sx*r, r/3);
	draw (-sx*r, -r/3)--(sx*r, -r/3);
	currentpicture := currentpicture shifted (0, r);
fet_endchar;

fet_beginchar("accDot", "accDot", "accDot")
	set_char_box(accreg_dot_size#, accreg_dot_size#, 0, 0);
	pickup pencircle scaled accreg_dot_size;
	draw(0, 0);
fet_endchar;

fet_beginchar("accFreebase", "accFreebase", "accFreebase")
	save r;
	r#= accreg_lh#;
	define_pixels(r);
	set_char_box(r#, r#, 0, 2r#);
	pickup accreg_pen;
	draw fullcircle scaled 2r;
	draw (-r, 0)--(r, 0);
	currentpicture := currentpicture shifted (0, r);
fet_endchar;

fet_beginchar("accStdbase", "accStdbase", "accStdbase")
	save r, sx;
	r# = 2accreg_lh#;
	define_pixels(r);
	sx = cosd 30 ;
	set_char_box(r#, r#, 0, 2r#);
	pickup accreg_pen;
	draw fullcircle scaled 2r;
	draw (-r, 0)--(r, 0);
	draw (-sx*r, r/2)--(sx*r, r/2);
	draw (-sx*r, -r/2)--(sx*r, -r/2);
	currentpicture := currentpicture shifted (0, r);
fet_endchar;

%%% strange turning path.
fet_beginchar("accBayanbase", "accBayanbase", "accBayanbase")
	save lh;
	lh = accreg_lh;
%	set_char_box(accreg_lh#, accreg_lh#, 3accreg_lh#, 0);
	set_char_box(accreg_lh#, accreg_lh#, 0, 3accreg_lh#);
	pickup pencircle scaled accreg_linethickness;
	%draw (0, 0)--(2w, 0)--(2w, 3accreg_lh)--(0, 3accreg_lh)--(0, 0);
	draw (0, 0)--(2w, 0)--(2w, 3accreg_lh)--(0, 3accreg_lh)--cycle;
	draw (0, accreg_lh)--(2w, accreg_lh);
	draw (0, 2accreg_lh)--(2w, 2accreg_lh);
	currentpicture := currentpicture shifted (-w, 0);% -3lh);
fet_endchar;

def def_B(expr w, h) = 
	% huh?
	% pickup pencircle scaled 0.1pt;
	pickup pencircle scaled 0.15linethickness;
	penpos10(thin, -90);
	penpos11(thin, -90);
	penpos12(thick, 0);
	penpos13(thin, 90);
	penpos14(thin, 90);

	penpos15(thick, 180);
	penpos16(thin, -90);
	penpos17(thin, -90);
	penpos18(thick, 0);
	penpos19(thick, 0);
	z10 = (0, 0);
	z11 = (cOne*w, 0);
	z12 = (w, .5mb*h);
	z13 = (cTwo*w, mb*h);
	z14 = (2thick, mb*h);
	z15 = (.94w, h-.5mt*h);
	z16 = z13 + (0, mt*h);
	z17 = (0, h);
	z18 = (1.5thick, 0);
	z19 = (1.5thick, h);
enddef;

def def_S(expr w, h) =
	% huh?
	%pickup pencircle scaled 0.02pt;
	pickup pencircle scaled 0.03linethickness;
	penpos1(thin, 180);
	penpos2(thin, -90);
	penpos3(thick, 0);
	penpos4(.5thick, 90);
	penpos5(thick, 0);
	penpos6(thin, -90);
	penpos7(thin, 180);
	penpos8(thin, 180);
	penpos9(thin, 0);
	z1 = (0, hs);
	z2 = (w/2, 0);
	z3 = (w-.5thick, .5mb*h);
	z4 = (w/2, mb*h);
	z5 = (.5thick, h-.5mt*h);
	z6 = (w/2, h);
	z7 = (w, h-hs);
	z8 = (0, y2r);
	z9 = (w, y6l);
	path bue, bueoverst;
	bue=z2{left}..z1{up};
	numeric t;
	t:=xpart(bue intersectiontimes(z8l--z7l));
	show t;
	bueoverst=z6{right}..z7{down};
enddef;

def def_some_vars =
	save hs, mb, mt, thin, thick, height, width, cOne, cTwo;
	width = .8(4 staff_space);
	height = 2.4staff_space;
	% URG.  smaller sizes should be wider and fatter
	%thin = 0.05staff_space;
	%thick = 0.2staff_space;
	save bx,hx; 4hx+bx=1.15; 10hx+bx=1;
	fatten:=designsize*hx+bx*1.2;
	thick:= 0.2staff_space*fatten;
	% urg: mustn't ever go thinner than blot!
	thin#:= blot_diameter#;
	define_pixels (thin);

	hs = 0.4staff_space;
	mb = .53;
	mt = .47;	
	cOne = 0.65;
	cTwo = 0.60;
enddef;

def print_penpos (suffix $)=
	message "z"&str $ &"l = ("&decimal x.$.l&", "&decimal y.$.l&"); z"&str $ &"r = ("&decimal x.$.r&", "&decimal y.$.r&");";
enddef;


%%% strange turning path.
fet_beginchar("accOldEE", "accOldEE", "accOldEE")
	set_char_box(staff_space#, staff_space#, 0, 2staff_space#);
	show w;
	show h;
	r = staff_space;
	lr = .4 staff_space - linethickness;
	ir = .6 staff_space;

	z1 = (0,0);
	z2 = (0, ir);
	penpos1 (0,0);
	penpos2 ( .05 staff_space + .5 linethickness,0);

	penlabels(1,2,3);

	numeric pp;
	pickup pencircle scaled blot_diameter;
	for pp := 0 step 45 until 360:
		filldraw fullcircle scaled lr shifted (ir*(dir pp));
		filldraw  (z1r--z1l--z2l--z2r--cycle) rotated pp;
	endfor

	pickup accreg_pen;
	draw fullcircle scaled 2r;
	pickup penrazor;

	filldraw fullcircle scaled lr;

	currentpicture := currentpicture shifted (0, r);


fet_endchar;



fet_endgroup("accordion")
