% 
% feta-sleur.mf --  implement runtime MF slurs
% 
% source file of LilyPond's pretty-but-neat music font
% 
% (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
% & Han-Wen Nienhuys <hanwen@stack.nl>
% 

mode_setup;

% staffsize#=16pt#;

pi:=3.14159;

def atan(expr x) = 
	(angle(1,x)*pi/180)
	enddef;

%breapth, width, depth, height

% urgh
% having mf would be nice if only from a "use the source" point of view.
%
% getslurcontrol:
%        slurhtlimit 90 div /slur_alpha exch def
%        slurratio 60 div slur_alpha div  /slur_beta  exch def
%        slur_beta mul 1 atan slur_alpha mul
%
% draw_slur:
%        slur_b getslurcontrol 
%        slur_dir mul /slur_ht exch def
%        slur_b getslurcontrol /slur_indent exch def       
%

interline#:=staffsize#/4;
stafflinethickness#:=0.1interline#;
sleur_pen#:=stafflinethickness#;
slurheightlimit#:=staffsize#/2;
% staffrulethickness 1.5 mul  /slur_thick exch def
slurthick#:=3/2stafflinethickness#;

define_pixels(staffsize,interline,stafflinethickness);
define_pixels(sleur_pen,slurheightlimit,slurthick);

sluralpha:=slurheightlimit#*pi/2;
% slurratio:=1/3;
slurratio:=0.3333;
slurbeta:=3/4*pi*slurratio/sluralpha;

def drawslur(expr dxs,dys,d) =
	beginchar(0,0,0,0) "Embedded mf";
		dx#:=dxs*1pt#;
		dy#:=dys*1pt#;
		define_pixels(dx,dy);
		b#:=length(dx#,dy#);
%		message "sluralpha: "&decimal (sluralpha);
%		message "slurbeta: "&decimal (slurbeta);
%		message "s*b: "&decimal (slurbeta*b#);
%		indent#:=sluralpha*atan(slurbeta*b#);
		% ugh: huh? 2/5
		indent#:=2/5*sluralpha*atan(slurbeta*b#);
		define_pixels(b,indent);
		height:=indent*d;
		z1=(0,0);
		z2=(b,0);
		z3=(indent,height);
		z4=(b-indent,height);
		z5=z4-(0,d*slurthick);
		z6=z3-(0,d*slurthick);
		path boogje;
		boogje=z1..controls z3 and z4..z2..controls z5 and z6..cycle;
		boogje:=boogje rotated angle(dxs,dys);
		pickup pencircle scaled sleur_pen;
		filldraw boogje;
		show z1;
		show z2;
		show z3;
		show z4;
		show z5;
		show z6;
		endchar;
	enddef;

% draw_slur(10,10,1);
