% fetdefs.tex
% encapsulating tex backend for auto-generated font-en-tja definitions

\def\fetsixteendefs{
        \font\fontentja=feta16
        \font\vetfont=feta-beams16
        \font\fetanummer=feta-nummer8
        \font\dynfont=feta-din10 scaled \magstep1
}
\def\fettwentydefs{
        \font\fontentja=feta20
        \font\vetfont=feta-beams20
        \font\fetanummer=feta-nummer10
        \font\dynfont=feta-din10 scaled \magstep2
}
\def\fetdef#1#2{\def#1{%
        % what the fuck is this?
        %\lower.3884\staffrulethickness
        \hbox{\fetchar{#2}}}}

\def\fetchar#1{\fontentja\char#1}

%\input feta16
\input feta20

\def\beamslope#1#2{{\count0=#2\advance\count0 by#1
        \advance\count0by128
        {\vetfont\char\count0}}}

% stacked numbers; overrules def in lilyponddefs
% oeps: \meter 12/8;
\def\generalmeter#1#2{%
        \vbox to 0pt{\vss%
        \hbox to0.42\balkheight{\hss\fetanummer #1\hss}%
        \nointerlineskip%
        \hbox to0.42\balkheight{\hss\fetanummer #2\hss}%
        \vss}}

\newcount\embedcount\embedcount=0
\newwrite\checkexists
\newwrite\embedfile
\def\inputifexists#1{%
        \openin\checkexists #1
        \ifeof\checkexists
                 \closein\checkexists
        \else
                \closein\checkexists
                \input #1
        \fi
}
\def\embedcountid{feta-embed}
\inputifexists{\embedcountid.aux}
%
% let's not overwrite -- and be sure to create new
\def\storeembedcount{%
        \immediate\openout\embedfile=\embedcountid.aux
        \immediate\write\embedfile{\embedcount=\the\embedcount}
        \immediate\closeout\embedfile
}
\def\turnOnExperimentalFeatures{

% draw a slur in embedded postscript
\special{ps:
/xbow 1 3 div def
/ybow 1 4 div def
/thin 0.2 def
/thick thin 5 mul def
/draw_slur { 
        % up or down?
        /dir exch def
%       
%       for mo*tex shift
%       exch
%       1 copy /dx exch def
%       exch
%
        % calc angle alpha
        2 copy exch atan /alpha exch def
        % calc len(gth)
        2 exp exch 2 exp add sqrt /len exch def
%
        % add and calc z2, z3
        len xbow mul
        len ybow mul dir mul
        1 xbow sub len mul
        len ybow mul dir mul
%       
        % add z4, z1
        len 0 
        0 0
%
        % add and calc z5..z8 
        8 copy
        thin dir mul sub
        8 2 roll
        thin dir mul sub
        8 2 roll
        thick dir mul sub
        8 2 roll
        thick dir mul sub
%
        % reverse order, must be cycle
        8 6 roll
        6 2 roll
        4 2 roll
        8 6 roll
%       
        % set z1..z4
        16 8 roll
%
        alpha rotate
%       silly mo*tex convention
%       dx 2 div -1 mul 0 translate
        % draw z1..z4
        moveto curveto
        % draw z5..z8
        lineto curveto
        % cycle
        0 0 lineto
        fill
} def }
}

\def\embeddedtex#1{#1}
\def\embeddedps#1{
        \special{ps: @beginspecial @setspecial #1 @endspecial}       
}
\def\embeddedmf#1{
        \edef\embedid{feta-sleur-\number\embedcount}
        \immediate\openout\embedfile=\embedid.mf
        \global\advance\embedcount by 1
        \immediate\write\embedfile{#1}
        \immediate\closeout\embedfile
        \font\expandafter\embedid\expandafter=\embedid
        \embedid\char0
}

\def\notex{\def\embeddedtex##1{}}
\def\nopostscript{\def\embeddedps##1{}}
\def\nometafont{\def\embeddedmf##1{}}

% dat heb je handig gedaan, lieverd!
%\nometafont
\nopostscript
\notex

\def\EndLilyPondOutput{
        \storeembedcount
        \csname bye\endcsname
}


