% -*-Fundamental-*-
% parmesan-flags.mf -- implement ancient flags
% 
% source file of LilyPond's pretty-but-neat music font
% 
% (c)  2001--2003 Juergen Reuter <reuter@ipd.uka.de>
% 

fet_begingroup ("flags")

save between_staff_lines, on_staff_line, anywhere;
between_staff_lines = 0;
on_staff_line = 1;
anywhere = 2;

save dir_up, dir_down;
dir_up = 1;
dir_down = -1;


%%%%%%%%
%
%
%
% Mensural Notation
%
%
%

def draw_mensural_outermost_flare (expr staffline_adjustment) =
	define_pixels(stafflinethickness, staff_space)

	pickup pencircle
		xscaled 1.00 stafflinethickness
		yscaled 0.22 staff_space
		rotated -35;

	save za, zb, zc, zd, ze;
	pair za, zb, zc, zd, ze;

	za = (+0.00 staff_space, -0.00 staff_space);
	zb = (+0.15 staff_space, -0.00 staff_space);

	if staffline_adjustment = between_staff_lines:
		zc = (+0.45 staff_space, -0.35 staff_space);
		zd = (+0.45 staff_space, -0.85 staff_space);
		ze = (+0.00 staff_space, -2.00 staff_space);
	elseif staffline_adjustment = on_staff_line:
		zc = (+0.20 staff_space, -0.05 staff_space);
		zd = (+0.20 staff_space, -1.15 staff_space);
		ze = (+0.00 staff_space, -1.40 staff_space);
	else: % staffline_adjustment = anywhere
		zc = (+0.33 staff_space, -0.20 staff_space);
		zd = (+0.33 staff_space, -1.00 staff_space);
		ze = (+0.00 staff_space, -1.70 staff_space);
	fi;

	draw za .. zb -- zc{zc-zb} .. {ze-zd}zd -- ze;
enddef;

def draw_mensural_inner_flare(expr il_shift) =
	define_pixels(stafflinethickness, staff_space)

	pickup pencircle
		xscaled 1.00 stafflinethickness
		yscaled 0.22 staff_space
		rotated -35;

	save zs, za, zb, zc, zd;
	pair zs, za, zb, zc, zd;

	zs = (0, -il_shift * staff_space);
	za = zs + (+0.00 staff_space, -0.10 staff_space);
	zb = zs + (+0.33 staff_space, -0.30 staff_space);
	zc = zs + (+0.33 staff_space, -0.70 staff_space);
	zd = zs + (+0.00 staff_space, -0.90 staff_space);

	draw za{2,1} .. zb .. zc .. {-2,-1}zd;
enddef;

def draw_mensural_flag (expr staffline_adjustment, flares, direction) =
	save char_box_adjust, flare_shift;
	if staffline_adjustment = between_staff_lines:
		flare_shift = 0.5;
	elseif staffline_adjustment = on_staff_line:
		flare_shift = 0.0;
	else: % staffline_adjustment = anywhere
		flare_shift = 0.25;
	fi;
	char_box_adjust = flare_shift+0.5;
	if direction = dir_up:
		set_char_box(0,
			     0.60 staff_space#,
			     (flares+char_box_adjust)*staff_space#,
			     0.10 staff_space#)
	else: % direction = dir_down
		set_char_box(0.60 staff_space#,
			     0,
			     0.10 staff_space#,
			     (flares+char_box_adjust)*staff_space#)
	fi;
	draw_mensural_outermost_flare (staffline_adjustment)
	for flare_count := 2 step 1 until 4:
		if flares >= flare_count:
			draw_mensural_inner_flare(flare_shift+flare_count-0.5)
		fi;
	endfor;
	if direction = dir_down:
		currentpicture := currentpicture xscaled -1 yscaled -1;
	fi;
enddef;

% 8th mensural flag, upwards, between staff lines
fet_beginchar("8th Mensural Flag (up)", "mensuralu03", "menseighthflag")
	draw_mensural_flag (between_staff_lines, 1, dir_up)
fet_endchar;

% 8th mensural flag, upwards, on staff line
fet_beginchar("8th Mensural Flag (up)", "mensuralu13", "mens1eighthflag")
	draw_mensural_flag (on_staff_line, 1, dir_up)
fet_endchar;

% 8th mensural flag, upwards, anywhere
fet_beginchar("8th Mensural Flag (up)", "mensuralu23", "mens1eighthflag")
	draw_mensural_flag (anywhere, 1, dir_up)
fet_endchar;

% 8th mensural flag, downwards, between staff lines
fet_beginchar("8th Mensural Flag (down)", "mensurald03", "mensdeighthflag")
	draw_mensural_flag (between_staff_lines, 1, dir_down)
fet_endchar;

% 8th mensural flag, downwards, on staff line
fet_beginchar("8th Mensural Flag (down)", "mensurald13", "mensd1eighthflag")
	draw_mensural_flag (on_staff_line, 1, dir_down)
fet_endchar;

% 8th mensural flag, downwards, anywhere
fet_beginchar("8th Mensural Flag (down)", "mensurald23", "mensd1eighthflag")
	draw_mensural_flag (anywhere, 1, dir_down)
fet_endchar;

% 16th mensural flag, upwards, between staff lines
fet_beginchar("16th Mensural Flag (up)", "mensuralu04", "menssixteenthflag")
	draw_mensural_flag (between_staff_lines, 2, dir_up)
fet_endchar;

% 16th mensural flag, upwards, on staff line
fet_beginchar("16th Mensural Flag (up)", "mensuralu14", "mens1sixteenthflag")
	draw_mensural_flag (on_staff_line, 2, dir_up)
fet_endchar;

% 16th mensural flag, upwards, anywhere
fet_beginchar("16th Mensural Flag (up)", "mensuralu24", "mens1sixteenthflag")
	draw_mensural_flag (anywhere, 2, dir_up)
fet_endchar;

% 16th mensural flag, downwards, between staff lines
fet_beginchar("16th Mensural Flag (down)", "mensurald04", "mensdsixteenthflag")
	draw_mensural_flag (between_staff_lines, 2, dir_down)
fet_endchar;

% 16th mensural flag, downwards, on staff line
fet_beginchar("16th Mensural Flag (down)", "mensurald14", "mensd1sixteenthflag")
	draw_mensural_flag (on_staff_line, 2, dir_down)
fet_endchar;

% 16th mensural flag, downwards, anywhere
fet_beginchar("16th Mensural Flag (down)", "mensurald24", "mensd1sixteenthflag")
	draw_mensural_flag (anywhere, 2, dir_down)
fet_endchar;

% 32th mensural flag, upwards, between staff lines
fet_beginchar("32th Mensural Flag (up)", "mensuralu05", "mensthirtysecondflag")
	draw_mensural_flag (between_staff_lines, 3, dir_up)
fet_endchar;

% 32th mensural flag, upwards, on staff line
fet_beginchar("32th Mensural Flag (up)", "mensuralu15", "mens1thirtysecondflag")
	draw_mensural_flag (on_staff_line, 3, dir_up)
fet_endchar;

% 32th mensural flag, upwards, anywhere
fet_beginchar("32th Mensural Flag (up)", "mensuralu25", "mens1thirtysecondflag")
	draw_mensural_flag (anywhere, 3, dir_up)
fet_endchar;

% 32th mensural flag, downwards, between staff lines
fet_beginchar("32th Mensural Flag (down)", "mensurald05", "mensdthirtysecondflag")
	draw_mensural_flag (between_staff_lines, 3, dir_down)
fet_endchar;

% 32th mensural flag, downwards, on staff line
fet_beginchar("32th Mensural Flag (down)", "mensurald15", "mensd1thirtysecondflag")
	draw_mensural_flag (on_staff_line, 3, dir_down)
fet_endchar;

% 32th mensural flag, downwards, anywhere
fet_beginchar("32th Mensural Flag (down)", "mensurald25", "mensd1thirtysecondflag")
	draw_mensural_flag (anywhere, 3, dir_down)
fet_endchar;

% 64th mensural flag, upwards, between staff lines
fet_beginchar("64th Mensural Flag (up)", "mensuralu06", "menssixtyfourthflag")
	draw_mensural_flag (between_staff_lines, 4, dir_up)
fet_endchar;

% 64th mensural flag, upwards, on staff line
fet_beginchar("64th Mensural Flag (up)", "mensuralu16", "mens1sixtyfourthflag")
	draw_mensural_flag (on_staff_line, 4, dir_up)
fet_endchar;

% 64th mensural flag, upwards, anywhere
fet_beginchar("64th Mensural Flag (up)", "mensuralu26", "mens1sixtyfourthflag")
	draw_mensural_flag (anywhere, 4, dir_up)
fet_endchar;

% 64th mensural flag, downwards, between staff lines
fet_beginchar("64th Mensural Flag (down)", "mensurald06", "mensdsixtyfourthflag")
	draw_mensural_flag (between_staff_lines, 4, dir_down)
fet_endchar;

% 64th mensural flag, downwards, on staff line
fet_beginchar("64th Mensural Flag (down)", "mensurald16", "mensd1sixtyfourthflag")
	draw_mensural_flag (on_staff_line, 4, dir_down)
fet_endchar;

% 64th mensural flag, downwards, anywhere
fet_beginchar("64th Mensural Flag (down)", "mensurald26", "mensd1sixtyfourthflag")
	draw_mensural_flag (anywhere, 4, dir_down)
fet_endchar;

fet_endgroup ("flags")
