%
%   This file is part of MusiXTeX
%
%   MusiXTeX is free software; you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation; either version 2, or (at your option)
%   any later version.
%
%   MusiXTeX is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with MusiXTeX; see the file COPYING.  If not, write to
%   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
%   Boston, MA 02111-1307, USA.
%
\immediate\write10{MusiXGREgorian T.67\space<3 January 1997>}%

\ifx\undefined\gregorianCclef \else \endinput \fi

\edef\catcodeat{\the\catcode`\@}\catcode`\@=11
\catcodesmusic

\font\xgregeleven=xgreg11
\font\xgregthirteen=xgreg13
\font\xgregsixteen=xgreg16
\font\xgregtwenty=xgreg20
\font\xgregtwentyfour=xgreg24
\font\xgregtwentynine=xgreg29

\let\xgregnorfont\xgregtwenty

\def\xgregkeyfont{%
  \ifdim\internote<\p@seven6\Internote \xgregtinyfont
  \else
    \ifdim\internote<.95\Internote \xgregsmallfont
    \else
      \ifdim\internote<1.19\Internote \xgregnorfont
      \else
        \ifdim\internote<1.43\Internote \xgreglargefont
        \else
          \xgregLargefont
        \fi
      \fi
    \fi
  \fi}

\def\xgregchar{\xgregfont\char}
\def\xgregkeychar{\xgregkeyfont\char}


% \[z]carrg=\[z]squ, \[z]carpg=\[z]lsqu, \[z]carqg=\[z]rsqu

\def\gregorianCclef{\xgregkeychar98}
\def\gregorianFclef{\xgregkeychar122}

\def\squ#1{\getn@i#1\relax\let\n@fon\squ \def\n@sym{\xgregchar5}\g@diamg}
\def\r@small@squ#1{\getn@i#1\relax\let\n@fon\r@small@squ
 \def\n@sym{\xgregchar0\llap{\xgregchar12\xgregchar18}}\g@diamg}
\def\punctumauctup#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar9}\g@diamg}
\def\punctumauctdown#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar8}\g@diamg}
\def\punctumdeminutum#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar4}\g@diamg}
\def\shavedsqu#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar17}\g@diamg}
\let\punctum\squ
\def\diapunc#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar1}\g@diamg}
\def\diapuncauctdown#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar2}\g@diamg}
\def\apostropha#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar3}\g@diamg}
\def\apostrophaaucta#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar11}\g@diamg}
\def\oriscus#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar10}\g@diamg}
\def\usqu#1{\getn@i#1\relax\let\n@fon\squ
 \def\n@sym{\xgregchar13}\g@diamg}
\def\lsqu#1{\getn@i#1\relax\let\n@fon\lsqu
 \def\n@sym{\xgregchar6}\g@diamg}
\def\rsqu#1{\getn@i#1\relax\let\n@fon\rsqu
 \def\n@sym{\xgregchar7}\g@diamg}
\let\virga\rsqu
\def\quilisma#1{\getn@i#1\relax\let\n@fon\quilisma
 \def\n@sym{\xgregchar125}\g@diamg}
\def\shavedquilisma#1{\getn@i#1\relax\let\n@fon\shavedquilisma
 \def\n@sym{\xgregchar126}\g@diamg}



\def\zsqu{\advancefalse\squ}
\let\zpunctum\zsqu
\def\zusqu{\advancefalse\usqu}
\def\zlsqu{\advancefalse\lsqu}
\def\zrsqu{\advancefalse\rsqu}
\let\zvirga\zrsqu
\def\zoriscus{\advancefalse\oriscus}
\def\zdiapunc{\advancefalse\diapunc}
\def\zapostropha{\advancefalse\apostropha}
\def\zquilisma{\advancefalse\quilisma} 
\def\zshavedquilisma{\advancefalse\shavedquilisma} 

\def\g@diamg{\y@v.71\qn@width \let\st@m\resetst@m \writ@note}

\def\groff{\roffset{.71}}
\def\dgroff{\roffset{1.42}}

\def\getthen@one@two#1#2{\getn@i{#1}\relax\edef\then@one{\the\n@i}%
  \getn@i{#2}\relax\edef\then@two{\the\n@i}%
  \n@ii=\then@one\relax
  \advance\n@i -\n@ii\relax
  \edef\the@two@minus@one{\the\n@i}%
  \n@i=-\n@i
  \edef\the@one@minus@two{\the\n@i}%
}%
\def\getthen@one@three#1#2#3{\getthen@one@two{#1}{#2}\relax
  \getn@i{#3}\relax\edef\then@three{\the\n@i}%
  \n@ii=\then@two\relax
  \advance\n@i -\n@ii\relax
  \edef\the@three@minus@two{\the\n@i}%
  \n@i=-\n@i
  \edef\the@two@minus@three{\the\n@i}%
}%

\def\bivirga#1#2{\zrsqu{#1}\roff{\rsqu{#2}}}

\def\trivirga#1#2#3{\zrsqu{#1}\roff{\zrsqu{#2}}\roffset2{\rsqu{#3}}}

\def\bistropha#1#2{\zsqu{#1}\roff{\squ{#2}}}

\def\tristropha#1#2#3{\zsqu{#1}\roff{\zsqu{#2}}\roffset2{\squ{#3}}}

\def\trigonus#1#2#3{\zdiapunc{#1}\groff{\zdiapunc{#2}}\dgroff{\diapunc{#3}}}

\def\clivis#1#2{\getthen@one@two{#1}{#2}\relax
\zlsqu{#1}{\xgregchar0}\zcharnote{#2}{\vrule\@depth\z@ \@height \the@one@minus@two\internote}\squ{#2}}

\def\clivisdeminut#1#2{\getthen@one@two{#1}{#2}\relax
\zlsqu{#1}\zcharnote{#2}{\xgregchar0\vrule\@depth\z@ \@height
\the@one@minus@two\internote}\r@small@squ{#2}}

\def\clivisauctup#1#2{\getthen@one@two{#1}{#2}\relax
\zlsqu{#1}{\xgregchar0}\zcharnote{#2}{\vrule\@depth\z@ \@height \the@one@minus@two\internote}\punctumauctup{#2}}

\def\clivisauctdown#1#2{\getthen@one@two{#1}{#2}\relax
\zlsqu{#1}{\xgregchar0}\zcharnote{#2}{\vrule\@depth\z@ \@height \the@one@minus@two\internote}\punctumauctdown{#2}}

\def\lclivis#1#2{\zsqu{#1}\groff{\lsqu{#2}}}

\def\podatus#1#2{\getthen@one@two{#1}{#2}\relax
  \zcharnote{#1}{\ifnum\the@two@minus@one<2\relax
                    \xgregchar16%
                 \else
                    \xgregchar15%
                 \fi
  \vrule\@depth\z@ \@height\the@two@minus@one\internote}%
\ifnum\the@two@minus@one<2\relax
                    \shavedsqu{#2}%
                 \else
                    \squ{#2}%
                 \fi
}

\def\podatusdeminut#1#2{\getthen@one@two{#1}{#2}\relax
  \zcharnote{#1}{\ifnum\the@two@minus@one<2\relax
                    \xgregchar16%
                 \else
                    \xgregchar15%
                 \fi
  \vrule\@depth\z@ \@height\the@two@minus@one\internote}%
                    \r@small@squ{#2}%
}

\def\lpodatus#1#2{\zusqu{#1}\groff{\rsqu{#2}}}

\def\podatusinitiodebilis#1#2{\getthen@one@two{#1}{#2}\relax
  \zcharnote{#1}{\xgregchar12\xgregchar18%
     \vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  {\xgregchar18}\squ{#2}%
}

\def\podatusauctup#1#2{\getthen@one@two{#1}{#2}\relax
  \zcharnote{#1}{\xgregchar5\xgregchar0%
     \vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  {\xgregchar0}\punctumauctup{#2}%
}

\def\podatusauctdown#1#2{\getthen@one@two{#1}{#2}\relax
  \zcharnote{#1}{\xgregchar5\xgregchar0%
     \vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  {\xgregchar0}\punctumauctdown{#2}%
}

\def\scandicus#1#2#3{\getthen@one@three{#1}{#2}{#3}\relax
  \advancefalse\podatus{#1}{#2}{\xgregchar0}%
%  \zcharnote{#2}{\vrule\@depth\z@ \@height\the@three@minus@two\internote}%
  \rsqu{#3}}

\def\scandicusdeminut#1#2#3{\getthen@one@two{#1}{#2}%
  \zsqu{#1}{\xgregchar0}%
%  \zcharnote{#1}{\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  \podatusdeminut{#2}{#3}}

\def\scandicusauctdown#1#2#3{\getthen@one@three{#1}{#2}{#3}\relax
  \zsqu{#1}{\xgregchar0}%
  \zcharnote{#1}{\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  \zsqu{#2}{\xgregchar0}%
  \zcharnote{#2}{\vrule\@depth\z@ \@height\the@three@minus@two\internote}%
  \punctumauctdown{#3}}

\def\torculus#1#2#3{\getthen@one@three{#1}{#2}{#3}\zsqu{#1}{\xgregchar0}%
  \zcharnote{#1}{\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  \zsqu{#2}{\xgregchar0}%
  \zcharnote{#3}{\vrule\@depth\z@ \@height\the@two@minus@three\internote}%
  \squ{#3}}

\def\torculusdeminut#1#2#3{\getthen@one@three{#1}{#2}{#3}\zsqu{#1}{\xgregchar0}%
  \zcharnote{#1}{\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  \zsqu{#2}%
  \zcharnote{#3}{\xgregchar0\vrule\@depth\z@ \@height\the@two@minus@three\internote}%
  \r@small@squ{#3}}
                
\def\torculusauctdown#1#2#3{\getthen@one@three{#1}{#2}{#3}\zsqu{#1}{\xgregchar0}%
  \zcharnote{#1}{\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  \zsqu{#2}{\xgregchar0}%
  \zcharnote{#3}{\vrule\@depth\z@ \@height\the@two@minus@three\internote}%
  \punctumauctdown{#3}}
                
\def\torculusinitiodebilis#1#2#3{\getthen@one@three{#1}{#2}{#3}%
  \zcharnote{#1}{\xgregchar12\xgregchar18\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  {\xgregchar18}\zsqu{#2}{\xgregchar0}%
  \zcharnote{#3}{\vrule\@depth\z@ \@height\the@two@minus@three\internote}%
  \squ{#3}}
                
\def\torculusdebilis#1#2#3{\getthen@one@three{#1}{#2}{#3}%
  \zcharnote{#1}{\xgregchar12\xgregchar18\vrule\@depth\z@ \@height\the@two@minus@one\internote}%
  {\xgregchar18}\zsqu{#2}%
  \zcharnote{#3}{\xgregchar0\vrule\@depth\z@ \@height\the@two@minus@three\internote}%
  \r@small@squ{#3}}
                
\def\climacus#1#2#3{\zrsqu{#1}\groff{\zdiapunc{#2}{\xgregchar0}\diapunc{#3}}}

\def\climacusresupinus#1#2#3#4{\zrsqu{#1}\groff{\zdiapunc{#2}{\xgregchar0}\zdiapunc{#3}{\xgregchar0}\squ{#4}}}

\def\climacusdeminut#1#2#3{\zrsqu{#1}\groff{\zdiapunc{#2}{\xgregchar0}\punctumdeminutum{#3}}}

\def\climacusauctdown#1#2#3{\zrsqu{#1}\groff{\zdiapunc{#2}{\xgregchar0}\diapuncauctdown{#3}}}

\def\lclimacus#1#2#3{\zlsqu{#1}\groff{\zdiapunc{#2}{\xgregchar0}\diapunc{#3}}}

\def\pesquassus#1#2{\getthen@one@two{#1}{#2}\relax
 \zoriscus{#1}{\xgregchar0}\zcharnote{#1}{\vrule\@depth\z@ \@height \the@two@minus@one\internote}\rsqu{#2}}

\def\pesquassusauctdown#1#2{\getthen@one@two{#1}{#2}\relax
 \zoriscus{#1}{\xgregchar0}\zcharnote{#1}{\vrule\@depth\z@ \@height \the@two@minus@one\internote}\punctumauctdown{#2}}

\def\quilismapes#1#2{\getthen@one@two{#1}{#2}\relax
 \ifnum\the@two@minus@one<2\relax
    \zshavedquilisma{#1}% \message{ zshavedqui OK}%
 \else
    \zquilisma{#1}% \message{ zquilisma OK}%
 \fi %\message{zqui OK}%
 \zcharnote{#1}{\xgregchar0\vrule\@depth\z@ \@height \the@two@minus@one\internote}%
 \ifnum\the@two@minus@one<2\relax
    \shavedsqu{#2}%
 \else
    \squ{#2}%
 \fi
}
\def\quilismapesauctdown#1#2{\getthen@one@two{#1}{#2}\relax
 \zquilisma{#1}% \message{ zquilisma OK}%
 \zcharnote{#1}{\xgregchar0\vrule\@depth\z@ \@height \the@two@minus@one\internote}%
 {\xgregchar0}\punctumauctdown{#2}%
}

 %\check
\def\hporrectus#1{\errmessage{\noexpand\hporrectus\space does not exist
anymore, use \bporrectus with two args}}
 
\def\porrectus#1#2{\errmessage{\noexpand\porrectus does not exist anymore, use
  \noexpand\Porrectus}}

\def\porrectusflexus#1#2{\errmessage{\noexpand\porrectusflexus does not exist anymore, use
  \noexpand\Porrectusflexus}}

 %\check
\def\bporrectus#1#2{\getthen@one@two{#1}{#2}\relax
 \ifnum\the@one@minus@two=1\relax
       \def\n@sym{\xgregchar121}\relax
 \else\ifnum\the@one@minus@two=2\relax
            \def\n@sym{\xgregchar120}\relax
      \else\ifnum\the@one@minus@two=3\relax
                 \def\n@sym{\xgregchar119}\relax
           \else\ifnum\the@one@minus@two=4\relax
                      \def\n@sym{\xgregchar118}\relax
                \else\errmessage{Porrectus 2nd arg must be 1st minus 1 to 4}\relax
                \fi
           \fi
      \fi
 \fi
 \getn@i#1\relax\let\n@fon\squ \g@diamg
}

%\check

\def\Porrectusflexus#1#2#3#4{%
   \advancefalse\bporrectus{#1}{#2}{\xgregchar0\xgregchar0\xgregchar0}%
   \getthen@one@three{#2}{#3}{#4}%
   \zcharnote{#2}{\vrule \@height\the@two@minus@one\internote\@depth\z@}%
   \zsqu{#3}%
   {\xgregchar0}\zcharnote{#4}{\vrule\@depth\z@ \@height \the@two@minus@three\internote}\squ{#4}}

%\check
 
\def\Porrectus#1#2#3{\getthen@one@three{#1}{#2}{#3}\relax
  \advancefalse\bporrectus{#1}{#2}{\xgregchar0\xgregchar0}%
  \zcharnote{#2}{\xgregchar0\vrule\@height\the@three@minus@two\internote\@depth\z@}%
  \ifnum\the@three@minus@two<2\relax
                    \shavedsqu{#3}%
                 \else
                    \squ{#3}%
                 \fi
}

\def\Porrectusdeminut#1#2#3{\getthen@one@three{#1}{#2}{#3}\relax
  \advancefalse\bporrectus{#1}{#2}{\xgregchar0\xgregchar0}%
  \zcharnote{#2}{\xgregchar0\vrule\@height\the@three@minus@two\internote\@depth\z@}\r@small@squ{#3}%
}

\def\Porrectusauctdown#1#2#3{\getthen@one@three{#1}{#2}{#3}\relax
  \advancefalse\bporrectus{#1}{#2}{\xgregchar0\xgregchar0\xgregchar0}%
  \zcharnote{#2}{\vrule\@height\the@three@minus@two\internote\@depth\z@}\punctumauctdown{#3}%
}

\def\salicus#1#2#3{\zsqu{#1}\groff{\pesquassus{#2}{#3}}}
%\check

\def\salicusflexus#1#2#3#4{\zsqu{#1}{\xgregchar0}\torculus{#2}{#3}{#4}}

\def\salicusauctdown#1#2#3{\zsqu{#1}\groff{\pesquassusauctdown{#2}{#3}}}
%\check

\let\xgregfont\xgregnorfont

\endcatcodesmusic
\catcode`\@=\catcodeat
\endinput
