%
%   tuplet.tex - conventional tuplet brackets for MusiXTeX.
%   Col. G. L. Sicherman.  Last revised 2003-05-17.
%
%   MusiXTeX is free software, licensed under the GNU General Public
%   License.  This file is also free software.  You may use it and
%   modify it as you please so long as you leave this message intact.
%
%   To use this file with MusiXTeX, refer to it in your source code
%   after MusiXTeX:
%
%       \input musixtex
%       \input tuplet
%
%   This file uses macros defined in musixtex.tex.
%
%   Standard MusiXTeX uses \uptrio and \downtrio to print tuplet brackets.
%   This file defines \uptuplet and \downtuplet, with the same arguments:
%
%       #1 : starting pitch
%       #2 : width of bracket, in (\noteskip)s
%       #3 : slope of bracket, in multiples of 1-1/8 degrees
%
%   The user defines the text to appear in the opening as \tuplettxt.
%   This is to avoid conflicting with the \txt in standard MusiXTeX.
%
%   Examples:
%
%       Draw a triplet bracket over the notes, starting at pitch "p",
%       1.25\noteskip wide, with a slope up of 3-3/8 degrees:
%
%           \uptuplet p{1.25}3
%
%       Draw a sextuplet bracket under the notes, starting at pitch "a",
%       2.5\noteskip wide, with a slope down of 4-1/2 degrees:
%
%           \def\tuplettxt{\smallppff 6\/\/}
%           \downtuplet{a}{2.5}{-4}
%
%   Send comments, complaints, and bouquets to the Colonel at
%   <colonel@monmouth.com>.
%
\makeatletter % Names of internal macros contain atpersats.

% Standard MusiXTeX prints a small "3" (or other number) within
% the bracket.  Here we print the "3" in an opening in the bracket,
% so we need not use a small font.
%
% The double italic correction compensates for centering the number
% on the bracket line.

\def\tuplettxt{\smallppff3\/\/}

%%% The rest is adapted from standard MusixTeX.

\newdimen\y@vii		% x of right end of left part of bracket.
\newdimen\y@viii	% x of left end of right part of bracket.
\newdimen\y@ix
\newbox\tuptxtb@x

% v@rline #1=height[dimen] #2=length[dimen] #3=slope (1\eqiv 1.125degree)
% (comments and ideas from Ian Collier)              (from -20 upto 20 )
% This macro is used by some of the others which follow,
% using it directly it must be set in zero box

\def\v@rline#1#2#3{\n@v#3\y@i#2%
  \setbox\tuptxtb@x\hbox{\hskip1pt\tuplettxt\hskip1pt}%
  \y@vii=\h@lf\y@i\advance\y@vii-\h@lf\wd\tuptxtb@x%
  \n@ii-\tw@nty \min@n@v\n@ii
  \max@n@v\tw@nty \n@iii\n@v
  \ifnum\n@v<\z@ \n@v-\n@v \advance\n@v\tw@nty \fi % offset to lower linechars
  \advance\n@v\@xxix
  \setbox\ch@box\hbox{\mxsps\char\n@v}%
  \ifdim\y@vii<\wd\ch@box \y@vii\wd\ch@box\fi% At least one whole segment!
  \y@viii=\y@i\advance\y@viii-\y@vii%
  \y@iv\wd\ch@box \y@ii\qu@rt\p@ \y@ii\n@iii\y@ii \y@iii\z@
  \raise#1\internote\hbox{\mxsps\char\n@iv
%
% Build bracket with slanted line segments of width 10pt.
% Left part of bracket:
%
    \loop\ifdim\y@iv<\y@vii\raise\y@iii\copy\ch@box
    \advance\y@iv\wd\ch@box \advance\y@iii\y@ii \repeat
%
% last element
%
%  \finalheight=2.5\completewidth
%  \finalheight=\n@iii\finalheight
%  \divide\finalheight by 100
%  \advance\overlapwidth by -\completewidth
%  \stepheight=-2.5\overlapwidth
%  \stepheight=\n@iii\stepheight
%  \divide\stepheight by 100
%  \advance\curheight by \stepheight
%  \kern -\overlapwidth \raise\curheight \box\ch@box
%
  \y@ix=\y@vii\advance\y@ix-\y@iv\hbox to\y@ix{\hss}%
  \y@ix\y@vii\advance\y@ix-\wd\ch@box%
  \y@iii\n@iii\y@ix\y@iii2\h@lf\y@iii\divide\y@iii\@c\raise\y@iii\copy\ch@box%
%
% Text:
%
  \y@v2\h@lf\y@i \y@v\n@iii\y@v \divide\y@v\@c%
  \y@ix=-\y@vii \advance\y@ix\h@lf\y@i \advance\y@ix-\h@lf\wd\tuptxtb@x%
  \hbox to\y@ix{\hss}%
  \y@iii\h@lf\y@v \raise\y@iii\vbox to\z@{%
  \vss{\copy\tuptxtb@x}\vss}
  \y@ix=\y@viii \advance\y@ix-\h@lf\y@i \advance\y@ix-\h@lf\wd\tuptxtb@x
  \hbox to\y@ix{\hss}% To start of right part. No-op unless bracket is short.
%
% Right part of bracket:
%
  \y@iii2\h@lf\y@viii \y@iii\n@iii\y@iii \divide\y@iii\@c%
  \y@iv=\y@viii \advance\y@iv\wd\ch@box%
  \loop\ifdim\y@iv<\y@i\raise\y@iii\copy\ch@box%
  \advance\y@iv\wd\ch@box \advance\y@iii\y@ii \repeat
%
% Finish off the right part:
%
  \y@iii\y@i\advance\y@iii-\wd\ch@box\y@iii2\h@lf\y@iii\y@iii\n@iii\y@iii%
  \y@ix=\y@i\advance\y@ix-\y@iv\hbox to\y@ix{\hss}%
  \divide\y@iii\@c%
  \raise\y@iii\copy\ch@box%
%
  \raise\y@v\hbox{\mxsps\char\n@iv}}}
%
% y@i   =complete length
% y@ii  =height of linechar
% y@iii =current height
% y@iv  =current width
% y@v   =height of ending line
% y@vii =width of left segment of bracket
% y@viii=y@vii + width of opening
% y@ix  =adjustment register
%
% n@iii=slope
% n@iv =(number of char for hooks)
% n@v  =slope (number of linechar)

\def\X@bkt#1#2#3{\y@v#2\noteskip \advance\y@v\wn@width
  \inhgetn@i#1\relax \rlap{\kernm\p@ne\qn@width\v@rline\n@i\y@v{#3}}}

\def\uptuplet{\n@iv22\X@bkt}
\def\downtuplet{\n@iv21\X@bkt}

\makeatother
\endinput
