% -*- Fundamental -*-

accreg_dot_size# := .7interline#;
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.2interline#;

define_pixels(accreg_dot_size, accreg_linethickness, accreg_lh);
pen accreg_pen;
accreg_pen := pencircle xscaled accreg_linethickness yscaled 0.7accreg_linethickness;
def draw_discant_reg(expr A, B, C, D, E, F) = 
	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);

	pickup pencircle scaled accreg_dot_size;
	if A = 1: drawdot (0, 2/3r); fi
	if B = 1: drawdot (r/2, 0); fi
	if C = 1: drawdot (0, 0); fi
	if D = 1: drawdot (-r/2, 0); fi
	if E = 1: drawdot (0, -2/3r); fi
	if F = 1: drawdot (-.25r, -.642r); drawdot (.25r, -.642r); fi
	currentpicture := currentpicture shifted (0, r);
enddef;

def draw_freebass_reg(expr rFour, rEight) =
	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);
	pickup pencircle scaled accreg_dot_size;
	if rFour = 1: draw (0, r/2); fi
	if rEight = 1: draw (0, -r/2); fi
	currentpicture := currentpicture shifted (0, r);
enddef;

def draw_stdbass_reg(expr A, B, C, D, E) =
	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);
	pickup pencircle scaled accreg_dot_size;
	if A = 1: draw (0, -3/4r); fi
	if B = 1: draw (0, -1/4r); fi
	if C = 1: draw (0, 1/4r); fi
	if D = 1: draw (0, 3/4r); fi
	if E = 1: draw (1/2r, 0); fi
	currentpicture := currentpicture shifted (0, r);
enddef;

def draw_bayanbass_reg_sign(expr nTwo, nEight) = 
	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, accreg_lh)--(2w, accreg_lh);
	draw (0, 2accreg_lh)--(2w, 2accreg_lh);

	pickup pencircle scaled accreg_dot_size;
	if nTwo = 1: draw (w, 5/2lh); fi
	if nEight = 1: draw (w, lh/2); fi
	if nEight = 2: draw (5/8w, lh/2); draw (11/8w, lh/2); fi
	currentpicture := currentpicture shifted (-w, 0);% -3lh);
enddef;

fet_beginchar("accDiscant", "accDiscant", "accDiscant")
	draw_discant_reg(0, 0, 0, 0, 0, 0);
fet_endchar;

fet_beginchar("accDiscantF", "accDiscantF", "accDiscantF")
	draw_discant_reg(1, 0, 0, 0, 0, 0);
fet_endchar;

fet_beginchar("accDiscantEh", "accDiscantEh", "accDiscantEh")
	draw_discant_reg(0, 1, 0, 0, 0, 0);
fet_endchar;

fet_beginchar("accDiscantE", "accDiscantE", "accDiscantE")
	draw_discant_reg(0, 0, 1, 0, 0, 0);
fet_endchar;

fet_beginchar("accDiscantFE", "accDiscantFE", "accDiscantFE")
	draw_discant_reg(1, 0, 1, 0, 0, 0);
fet_endchar;	

fet_beginchar("accDiscantFEh", "accDiscantFEh", "accDiscantFEh")
	draw_discant_reg(1, 1, 0, 0, 0, 0);
fet_endchar;	

fet_beginchar("accDiscantEE", "accDiscantEE", "accDiscantEE")
	draw_discant_reg(0, 1, 0, 1, 0, 0);
fet_endchar;

fet_beginchar("accDiscantFEE", "accDiscantFEE", "accDiscantFEE")
	draw_discant_reg(1, 1, 0, 1, 0, 0);
fet_endchar;

fet_beginchar("accDiscantEEE", "accDiscantEEE", "accDiscantEEE")
	draw_discant_reg(0, 1, 1, 1, 0, 0);
fet_endchar;

fet_beginchar("accDiscantFEEE", "accDiscantFEEE", "accDiscantFEEE")
	draw_discant_reg(1, 1, 1, 1, 0, 0);
fet_endchar;

fet_beginchar("accDiscantS", "accDiscantS", "accDiscantS")
	draw_discant_reg(0, 0, 0, 0, 1, 0);
fet_endchar;

fet_beginchar("accDiscantFS", "accDiscantFS", "accDiscantFS")
	draw_discant_reg(1, 0, 0, 0, 1, 0);
fet_endchar;

fet_beginchar("accDiscantES", "accDiscantES", "accDiscantES")
	draw_discant_reg(0, 0, 1, 0, 1, 0);
fet_endchar;

fet_beginchar("accDiscantEhS", "accDiscantEhS", "accDiscantEhS")
	draw_discant_reg(0, 1, 0, 0, 1, 0);
fet_endchar;

fet_beginchar("accDiscantFES", "accDiscantFES", "accDiscantFES")
	draw_discant_reg(1, 0, 1, 0, 1, 0);
fet_endchar;

fet_beginchar("accDiscantFEhS", "accDiscantFEhS", "accDiscantFEhS")
	draw_discant_reg(1, 1, 0, 0, 1, 0);
fet_endchar;

fet_beginchar("accDiscantEES", "accDiscantEES", "accDiscantEES")
	draw_discant_reg(0, 1, 0, 1, 1, 0);
fet_endchar;

fet_beginchar("accDiscantFEES", "accDiscantFEES", "accDiscantFEES")
	draw_discant_reg(1, 1, 0, 1, 1, 0);
fet_endchar;

fet_beginchar("accDiscantEEES", "accDiscantEEES", "accDiscantEEES")
	draw_discant_reg(0, 1, 1, 1, 1, 0);
fet_endchar;

fet_beginchar("accDiscantFEEES", "accDiscantFEEES", "accDiscantFEEES")
	draw_discant_reg(1, 1, 1, 1, 1, 0);
fet_endchar;

fet_beginchar("accDiscantSS", "accDiscantSS", "accDiscantSS")
	draw_discant_reg(0, 0, 0, 0, 0, 1);
fet_endchar;

fet_beginchar("accDiscantESS", "accDiscantESS", "accDiscantESS")
	draw_discant_reg(0, 0, 1, 0, 0, 1);
fet_endchar;

fet_beginchar("accDiscantEESS", "accDiscantEESS", "accDiscantEESS")
	draw_discant_reg(0, 1, 0, 1, 0, 1);
fet_endchar;

fet_beginchar("accDiscantEEESS", "accDiscantEEESS", "accDiscantEEESS")
	draw_discant_reg(0, 1, 1, 1, 0, 1);
fet_endchar;

fet_beginchar("accFreebass", "accFreebass", "accFreebass")
	draw_freebass_reg(0, 0);
fet_endchar;

fet_beginchar("accFreebassF", "accFreebassF", "accFreebassF")
	draw_freebass_reg(1, 0);
fet_endchar;

fet_beginchar("accFreebassE", "accFreebassE", "accFreebassE")
	draw_freebass_reg(0, 1);
fet_endchar;

fet_beginchar("accFreebassFE", "accFreebassFE", "accFreebassFE")
	draw_freebass_reg(1, 1);
fet_endchar;

fet_beginchar("accStdbass", "accStdbass", "accStdbass")
	draw_stdbass_reg(0, 0, 0, 0, 0);
fet_endchar;

fet_beginchar("accStdbassM", "accStdbassM", "accStdbassM")
	draw_stdbass_reg(1, 1, 1, 1, 1);
fet_endchar;

fet_beginchar("accStdbassBp", "accStdbassBp", "accStdbassBp")
	draw_stdbass_reg(1, 1, 0, 0, 1);
fet_endchar;

fet_beginchar("accStdbassT", "accStdbassT", "accStdbassT")
	draw_stdbass_reg(0, 1, 1, 1, 0);
fet_endchar;

fet_beginchar("accStdbassTp", "accStdbassTp", "accStdbassTp")
	draw_stdbass_reg(0, 1, 1, 0, 0);
fet_endchar;

fet_beginchar("accBayanbass", "accBayanbass", "accBayanbass")
	draw_bayanbass_reg_sign(1, 0);
fet_endchar;

fet_beginchar("accBayanbassT", "accBayanbassT", "accBayanbassT")
	draw_bayanbass_reg_sign(1, 0);
fet_endchar;

fet_beginchar("accBayanbassE", "accBayanbassE", "accBayanbassE")
	draw_bayanbass_reg_sign(0, 1);
fet_endchar;

fet_beginchar("accBayanbassTE", "accBayanbassTE", "accBayanbassTE")
	draw_bayanbass_reg_sign(1, 1);
fet_endchar;

fet_beginchar("accBayanbassEE", "accBayanbassEE", "accBayanbassEE")
	draw_bayanbass_reg_sign(0, 2);
fet_endchar;

fet_beginchar("accBayanbassTEE", "accBayanbassTEE", "accBayanbassTEE")
	draw_bayanbass_reg_sign(1, 2);
fet_endchar;

def def_B(expr w, h) = 
	pickup pencircle scaled 0.1pt;
	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) =
	pickup pencircle scaled 0.02pt;
	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 = .8staffsize;
	height = 2.4interline;
	thin = 0.05interline;
	thick = 0.2interline;
	hs = 0.4interline;
	mb = .53;
	mt = .47;	
	cOne = 0.65;
	cTwo = 0.60;
enddef;

fet_beginchar("accSB", "accSB", "accSB")
	set_char_box(.4staffsize#, .4staffsize#, 0, 2.4interline#);
	def_some_vars;
	def_B(.35width, .7height);
	penstroke z10e--z11e{right}..z12e{up}..z13e{left}--z14e;
	penstroke z13e{right}..z15e{up}..z16e{left}--z17e;
	penstroke z18e--z19e;
	pickup pencircle scaled .5thick;
	drawdot (.37width, .10thick);
	currentpicture := currentpicture shifted(.40width, 0);

	def_S(.35width, .7height);
%	penlabels(1, 2, 3, 4, 5, 6, 7, 8, 9);
	filldraw z1r--z8r--z8l--subpath(t, 1) of bue--cycle;
	filldraw subpath(t, 1) of bueoverst--z7l--z9r--z9l--cycle;
	penstroke z1e{down}..z2e{right}..z3e
		..z4e
		..z5e..z6e{right}...z7e{down};
	pickup pencircle scaled .5thick;
	drawdot (.37width, .10thick);
	currentpicture := currentpicture shifted (-.40width, -.85height);
	draw (-.5width, 0)--(.5width, 0)--(.5width, -height)
		--(-.5width, -height)--(-.5width, 0);
	currentpicture := currentpicture shifted (0, 2.4interline);
fet_endchar;

fet_beginchar("accBB", "accBB", "accBB")
	set_char_box(.4staffsize#, .4staffsize#, 0, 2.4interline#);
	def_some_vars;
	def_B(.35width, .7height);
	penstroke z10e--z11e{right}..z12e{up}..z13e{left}--z14e;
	penstroke z13e{right}..z15e{up}..z16e{left}--z17e;
	penstroke z18e--z19e;
	pickup pencircle scaled .5thick;
	drawdot(.37width, .10thick);
	currentpicture := currentpicture shifted (.40width, 0);
	penstroke z10e--z11e{right}..z12e{up}..z13e{left}--z14e;
	penstroke z13e{right}..z15e{up}..z16e{left}--z17e;
	penstroke z18e--z19e;
	drawdot(.37width, .10thick);
	currentpicture := currentpicture shifted(-.40width, -.85height);
	draw (-.5width, 0)--(.5width, 0)--(.5width, -height)
		--(-.5width, -height)--(-.5width, 0);
	currentpicture := currentpicture shifted (0, 2.4interline);
fet_endchar;


fet_beginchar("accOldEE", "accOldEE", "accOldEE")
	set_char_box(interline#, interline#, 0, 2interline#);
	show w;
	show h;
	r = interline;
	lr = .3interline;
	ir = .6interline;
	pickup accreg_pen;
	draw fullcircle scaled 2r;
	pickup penrazor;
	filldraw fullcircle scaled lr;
	z1 = (ir, 0);
	z2 = (0, 0) + ir*(dir 45);
	z3 = (0, ir);
	numeric pp;
	for pp := 0 step 45 until 360:
		filldraw fullcircle scaled lr shifted (ir*(dir pp));
	endfor;
	for pp := 0 step 45 until 360:
		filldraw ((0, 0)--(.2lr, ir)--(-.2lr, ir)--cycle) rotated pp;
	endfor
	currentpicture := currentpicture shifted (0, r);
fet_endchar;

fet_beginchar("accOldEES", "accOldEES", "accOldEES")
	set_char_box(interline#, interline#, 0, 2interline#);
	save r, shy;
	r = interline;
	shy = .3;
	pickup accreg_pen;
	draw fullcircle scaled 2r;
	currentpicture := currentpicture shifted (w/2, shy*h);
	save thin, thick, sw, ch, cw, mb, mt;
	ch = .6h;
	cw = .8w;
	thin = .05cw;
	thick = .17w;
	mb = .53; mt = .47;
	sw = .8thick;
	z1 = (0, ch-.5thin); penpos1 (thin, -90);
	z2 = (.7cw, y1); penpos2 (thin, -90);
	z3 = (cw, (mb+.5mt)*ch); penpos3(thick, -180);
	z4 = (.65cw, mb*ch); penpos4(thin, 90);
	z5 = (sw+thick, mb*ch); penpos5(thin, 90);
	z6 = (.9cw, .5mb*ch); penpos6(thick, 0);
	z7 = (1.2cw, 0); penpos7(thin, 90);
	z8 = (1.3cw, .2mb*ch); penpos8(thin, 180);
	penlabels(1, 2, 3, 4, 5, 6, 7, 8);
	pickup pencircle scaled 0.001pt;
	filldraw (0, 0)--(0, thin)--(sw, thin)--(sw, ch-thin)
		--(sw+thick, ch-thin)--(sw+thick, thin)
		--(2sw+thick, thin)--(2sw+thick, 0)--cycle;
	penstroke z1e--z2e{right}..z3e..z4e{left}--z5e;
	penstroke z4e{right}..z6e{down}..z7e{right}..z8e{up};
	currentpicture := currentpicture shifted (-w/2, -shy*h);
	currentpicture := currentpicture shifted (0, r);
fet_endchar;
