% musixmtab.tex : modern tablature definitions for MusiXTeX
%
% usage: 
%
%    \input musixtex
%    \input musixmtab
%    ...
%
%   musixmtab.tex 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.
%
%   musixmtab.tex 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.
%
%   Copyright 2023  Bob Tennent rdtennent@gmail.com
%

\immediate\write16{musixmtab\space<2023/10/07>}
\ifx\undefined\startpiece\errmessage{Input musixtex.tex before musixmtab.tex}\fi

\makeatletter


% Assumption:  there is at most one beam and it is a lower beam

% like \downst@m but with quarter skip; used in \uq
\def\midst@m{\stem@skip\qd@skip
  \divide\stem@skip by 4
  \advance\st@bot-\stemfactor\interbeam
  \advance\st@bot-\altportee
  \ifx\st@mcut\empty
    \ifdim\st@bot<-\thr@@\internote
      \cutst@l\thr@@\cutst@l\f@ur\cutst@l\fiv@
      \cutst@l\si@\cutst@l\s@v@n\cutst@l\@ight \fi \fi
  \minst@bot\advance\st@bot\altportee
  \C@stem}


% a half note (boxed)
% argument 1 is the string number
% argument 2 is the note number
\def\uh#1#2{%
  \boxitsep=1pt%
  \setbox0=\hbox{\raise-0.25\internote\hbox{\boxit{\tabsmallfnt #2}}}%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \advance\stringraise-1%
  \advancefalse\def\q@u{}\loffset{0.2}{\@nq{\the\stringraise}}%
  \special{ps: 1 setgray}%
  \zchar{\the\stringraise}{\vrule height \ht0 width \wd0 depth \dp0}%
  \special{ps: 0 setgray}%
  \zchar{\the\stringraise}{\box0}%
  \n@i\stringraise%
  \def\q@u{}\let\st@m\downst@m\let\n@sym\q@u%
  \y@v\qn@width\writ@note%
}

% a non-spacing stemless half note
% argument 1 is the string number
% argument 2 is the note number
\def\zuh#1#2{%
  \boxitsep=1pt%
  \setbox0=\hbox{\raise-0.25\internote\hbox{\boxit{\tabsmallfnt #2}}}%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \advance\stringraise-1%
  \advancefalse\def\q@u{}\loffset{0.2}{\@nq{\the\stringraise}}%
  \special{ps: 1 setgray}%
  \zchar{\the\stringraise}{\vrule height \ht0 width \wd0 depth \dp0}%
  \special{ps: 0 setgray}%
  \zchar{\the\stringraise}{\box0}%
}

% a quarter note (with a centered stem)
% argument 1 is the string number
% argument 2 is the note number
\def\uq#1#2{%
  \zltab{#1}{#2}%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \advance\stringraise-1%
  \n@i\stringraise%
  \def\q@u{}\let\st@m\midst@m\let\n@sym\q@u%
  \y@v\qn@width\writ@note%
}

% an eighth note (with a flag)
% argument 1 is the string number
% argument 2 is the note number
\def\uc#1#2{%
  \zltab{#1}{#2}%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \n@i\stringraise%
  \def\q@u{}\n@vii\@xlv\let\st@m\down@flag%
  \let\n@sym\q@u\y@v\qn@width\writ@note%
}

% a sixteenth note (with a double flag)
% argument 1 is the string number
% argument 2 is the note number
\def\ucc#1#2{%
  \zltab{#1}{#2}%
  \stringraise\nblines% 
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \n@i\stringraise%
  \def\q@u{}\n@vii46\let\st@m\down@flag%
  \let\n@sym\q@u\y@v\qn@width\writ@note%
}

% a non-spacing stemless quarter or eighth note 
% argument 1 is the string number
% argument 2 is the note number
\def\zu#1#2{\zltab{#1}{#2}}%

% initiate a beam 
% argument 1 is a string number
% argument 2 is the slope
\def\uib#1#2{%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \ibl0{\the\stringraise}{#2}%
}
  
% initiate a double beam
% argument 1 is a string number
% argument 2 is the slope
\def\uibb#1#2{%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \ibbl0{\the\stringraise}{#2}%
}

% a beam note 
% argument 1 is the string number
% argument 2 is the note number
\def\ub#1#2{%
  \zltab{#1}{#2}%
  \s@l@ctbeam{0}\relax%
  \stringraise\nblines%
  \advance\stringraise by -#1%
  \multiply\stringraise by 2%
  \n@i\stringraise%
  \def\q@u{}\let\st@m\beamst@m%
  \let\n@fon\g@q\let\n@sym\q@u\y@v\qn@width\writ@note%
}

% increase the beam multiplicity to 2
\def\unbb{\nbbl0}

% decrease the beam multiplicity to one after the following note
\def\utbb{\tbbl0}

% terminate the beam after the following note
\def\utb{\tbl0}

% terminate the beam at this note
% argument 1 is the string number
% argument 2 is the note number
\def\utq#1#2{\utb\ub{#1}{#2}}

\makeatother
\endinput
