% adjustable beam slopes
% #1: beam number, #2: starting pitch, #3: ending pitch, #4: extension (number
%                                                            of \noteskip's)
\edef\catcodeat{\the\catcode`\@}\catcode`\@=11

\def\Ibu#1{\selectpoutre{#1}\I@bu{\i@bu}}%
\def\Ibbu#1{\selectpoutre{#1}\I@bu{\i@bbu}}%
\def\Ibbbu#1{\selectpoutre{#1}\I@bu{\i@bbbu}}%
\def\Ibbbbu#1{\selectpoutre{#1}\I@bu{\i@bbbbu}}%
\def\Ibl#1{\selectpoutre{#1}\I@bl{\i@bl}}%
\def\Ibbl#1{\selectpoutre{#1}\I@bl{\i@bbl}}%
\def\Ibbbl#1{\selectpoutre{#1}\I@bl{\i@bbbl}}%
\def\Ibbbbl#1{\selectpoutre{#1}\I@bl{\i@bbbbl}}%
%
\newcount\s@lopenum
\newcount\the@pitch
\newdimen\b@eamlength
%
% compute altitude difference of tried beam in \y@iv
% and compare with notes altitude difference
%
\def\I@buuchk{\y@iv=0.05\b@eamlength\multiply \y@iv by \s@lopenum\relax
\ifdim \y@iv>\n@ii\internote\relax
  \advance\s@lopenum by -1\relax\I@buuchk
\fi
\ifnum \s@lopenum>9\relax  \advance\n@i by 1\relax
  \advance\n@ii by -1\relax\I@buuchk
\fi}%
%
\def\I@budchk{\y@iv=0.05\b@eamlength\multiply \y@iv by \s@lopenum\relax
\ifdim \y@iv<\n@ii\internote\relax
  \advance\s@lopenum by 1\relax\I@budchk
\fi}%
%
\def\I@bu#1#2#3#4{{\inhgetn@i{#3}\n@ii=\n@i\relax
\inhgetn@i{#2}\advance\n@ii by -\n@i\relax
\b@eamlength=\noteskip
\multiply\b@eamlength by #4\relax
\ifnum\n@ii=0\relax
   \edef\I@boper{\noexpand #1}\I@boper{#2}0\relax
\else\ifnum\n@ii>0\relax\s@lopenum=10\relax \I@buuchk
      \else \s@lopenum=-10\relax \I@budchk
      \fi
   \edef\I@boper{\noexpand #1{\the\n@i}{\the\s@lopenum}\relax}\I@boper
\fi}}%
%
%\check
%
\def\I@bldchk{\y@iv=0.05\b@eamlength\multiply \y@iv by \s@lopenum\relax
\ifdim \y@iv<\n@ii\internote\relax
  \advance\s@lopenum by 1\relax\I@bldchk
\fi
\ifnum \s@lopenum<-9\relax  \advance\n@i by -1\relax
  \advance\n@ii by 1\relax\I@bldchk
\fi}%
%
\def\I@bluchk{\y@iv=0.05\b@eamlength\multiply \y@iv by \s@lopenum\relax
\ifdim \y@iv>\n@ii\internote\relax
  \advance\s@lopenum by -1\relax\I@bluchk
\fi}%
%
\def\I@bl#1#2#3#4{{\inhgetn@i{#3}\n@ii=\n@i\relax
\inhgetn@i{#2}\advance\n@ii by -\n@i\relax
\b@eamlength=\noteskip
\multiply\b@eamlength by #4\relax
\ifnum\n@ii=0\relax
   \edef\I@boper{\noexpand #1}\I@boper{#2}0\relax
\else\ifnum\n@ii>0\relax\s@lopenum=10\relax \I@bluchk
      \else \s@lopenum=-10\relax \I@bldchk
      \fi
   \edef\I@boper{\noexpand #1{\the\n@i}{\the\s@lopenum}\relax}\I@boper
\fi}}%
%
%\check
% sets of double notes with computed slopes
\def\Dqbbl#1#2{\Ibbl0{#1}{#2}1\qb0{#1}\tqb0{#2}}%
\def\Dqbbu#1#2{\Ibbu0{#1}{#2}1\qh0{#1}\tqh0{#2}}%
\def\Dqbl#1#2{\Ibl0{#1}{#2}1\qb0{#1}\tqb0{#2}}%
\def\Dqbu#1#2{\Ibu0{#1}{#2}1\qh0{#1}\tqh0{#2}}%
%\check
% sets of triple notes with computed slopes
\def\Tqbbl#1#2#3{\Ibbl0{#1}{#3}2\qb0{#1}\qb0{#2}\tqb0{#3}}%
\def\Tqbbu#1#2#3{\Ibbu0{#1}{#3}2\qh0{#1}\qh0{#2}\tqh0{#3}}%
\def\Tqbl#1#2#3{\Ibl0{#1}{#3}2\qb0{#1}\qb0{#2}\tqb0{#3}}%
\def\Tqbu#1#2#3{\Ibu0{#1}{#3}2\qh0{#1}\qh0{#2}\tqh0{#3}}%
%\check
% sets of quadruple notes with computed slopes
\def\Qqbbl#1#2#3#4{\Ibbl0{#1}{#4}3\qb0{#1}\qb0{#2}\qb0{#3}\tqb0{#4}}%
\def\Qqbbu#1#2#3#4{\Ibbu0{#1}{#4}3\qh0{#1}\qh0{#2}\qh0{#3}\tqh0{#4}}%
\def\Qqbl#1#2#3#4{\Ibl0{#1}{#4}3\qb0{#1}\qb0{#2}\qb0{#3}\tqb0{#4}}%
\def\Qqbu#1#2#3#4{\Ibu0{#1}{#4}3\qh0{#1}\qh0{#2}\qh0{#3}\tqh0{#4}}%
%\check
\catcode`\@=\catcodeat

