\ProvidesPackage{keisennote}[2025/09/17, v1.0.3]

\RequirePackage[dvipsnames, svgnames, x11names]{xcolor}
\RequirePackage{luatex85, zref, zref-savepos, fp, url, expl3, xkeyval}
\RequirePackage{tikz}\RequirePackage{graphicx}
\usetikzlibrary{shapes, positioning, shadows, shadows.blur, patterns, decorations.text, decorations.pathmorphing, arrows.meta, calc, snakes, intersections}
\RequirePackage{xparse, calc, ifthen}

\newdimen\VoD@mag
\VoD@mag=.5pt 
\newdimen\noteLineWidth
\newdimen\dotsRadius
\newdimen\noteLineDistance
\noteLineWidth.5truept\relax%    <- 罫線の太さ
\dotsRadius.8truept\relax%       <- ドットの半径
\noteLineDistance=6truemm\relax% <- 罫線間隔（A罫 : 7truemm，B罫 : 6truemm） 

%%%必要な内部レジスタの用意
\newdimen\VDNT@currentXPos
\newdimen\VDNT@currentYPos
\newdimen\VDNT@Xinterval
\newdimen\VDNT@Yinterval
\newdimen\VDNT@notegoal


%%% \notefillで用いる座標管理用カウンタの準備
\def\VDNT@pkgname{vodnote}
\global\newcount\VDNT@uniqe


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% \notefill の定義
\NewDocumentCommand{\notefill}{ O{.5pt} O{white!70!black} }{\par\bgroup
  \VoD@mag=#1
  \parindent\z@
  %%罫線間隔の算出
  \@tempcnta\linewidth
  \@tempcntb\noteLineDistance
  \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
  \VDNT@Xinterval\dimexpr(\linewidth)/\VDNT@dotsNum\relax
  \VDNT@Yinterval\VDNT@Xinterval
  %%上端の座標取得
  \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}%
  %%下端の座標取得
  \leavevmode\vfill\leavevmode
  \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}%
  %%ノート罫線描画幅の決定
  \VDNT@notegoal=\dimexpr
    \zposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}sp
    -\zposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}sp
  \relax
  %%ノート罫線描画
  \noindent\smash{%
    \begin{tikzpicture}[xscale=0.996]
      \VDNT@currentYPos\z@
      \fill[#2] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos+\VoD@mag*4pt) -- ++(\VoD@mag*3pt,-\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle;
      \@whiledim\VDNT@currentYPos<\VDNT@notegoal\do{
        \VDNT@currentXPos\z@
        \draw[#2,line width=\noteLineWidth] (0,\VDNT@currentYPos) -- (\linewidth,\VDNT@currentYPos);
        \foreach \k in{0,1,...,\VDNT@dotsNum}{%
          \VDNT@currentXPos=\dimexpr\VDNT@Xinterval*\k\relax
          \fill[#2] (\VDNT@currentXPos,\VDNT@currentYPos) circle [radius=\dotsRadius];
        }
        \advance\VDNT@currentYPos\VDNT@Yinterval\relax
      }
      \fill[#2] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos-\VDNT@Yinterval-\VoD@mag*4pt) -- ++(\VoD@mag*3pt,\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle;
    \end{tikzpicture}%
  }%
  \egroup
  %%座標管理用カウンタのインクリメント
  \global\advance\VDNT@uniqe\@ne
  \par
}


%%% \note の定義（２以上の整数を引数に）
\NewDocumentCommand{\note}{ m O{.5pt} O{white!70!black} }{\par\bgroup
  %%三角形の大きさ
  \VoD@mag=#2
  %%罫線間隔の算出
  \@tempcnta\linewidth
  \@tempcntb\noteLineDistance
  \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
  \VDNT@Xinterval\dimexpr\linewidth/\VDNT@dotsNum\relax
  \VDNT@Yinterval\VDNT@Xinterval
  %%ノート罫線描画
  \noindent
    \begin{tikzpicture}[xscale=0.996]
      \VDNT@currentYPos\z@
      \fill[#3] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos+\VDNT@Yinterval+\VoD@mag*4pt) -- ++(\VoD@mag*3pt,-\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle; %上の三角形
      \foreach \i in{1,2,...,#1}{ 
        \VDNT@currentXPos\z@
        \global\VDNT@currentYPos=\dimexpr\VDNT@Yinterval*\i\relax
        \draw[#3,line width=\noteLineWidth] (0,\VDNT@currentYPos) -- (\linewidth,\VDNT@currentYPos);
        \foreach \k in{0,1,...,\VDNT@dotsNum}{
          \VDNT@currentXPos=\dimexpr\VDNT@Xinterval*\k\relax
          \fill[#3] (\VDNT@currentXPos,\VDNT@currentYPos) circle [radius=\dotsRadius];
        }
      }
      \fill[#3] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos-\VoD@mag*4pt) -- ++(\VoD@mag*3pt,\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle; %下の三角形
    \end{tikzpicture}%
  \egroup
  \par
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand{\masumefill}{ O{.5pt} O{white!70!black} }{\par\bgroup
  \VoD@mag=#1
  \parindent\z@
  %%罫線間隔の算出
  \@tempcnta\linewidth
  \@tempcntb\noteLineDistance
  \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
  \VDNT@Xinterval\dimexpr(\linewidth)/\VDNT@dotsNum\relax
  \VDNT@Yinterval\VDNT@Xinterval
  %%上端の座標取得
  \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}%
  %%下端の座標取得
  \leavevmode\vfill\leavevmode
  \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}%
  %%ノート罫線描画幅の決定
  \VDNT@notegoal=\dimexpr
    \zposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}sp
    -\zposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}sp
  \relax
  %%ノート罫線描画
  \noindent\smash{%
    \begin{tikzpicture}[xscale=0.996]
      \VDNT@currentYPos\z@
      \fill[#2] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos+\VoD@mag*4pt) -- ++(\VoD@mag*3pt,-\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle;
      \@whiledim\VDNT@currentYPos<\VDNT@notegoal\do{
        \VDNT@currentXPos\z@
        \draw[#2,line width=\noteLineWidth] (0,\VDNT@currentYPos) -- (\linewidth,\VDNT@currentYPos);
        \foreach \k in{0,1,...,\VDNT@dotsNum}{%
          \VDNT@currentXPos=\dimexpr\VDNT@Xinterval*\k\relax
          \draw[#2,line width=\noteLineWidth]
          (\VDNT@currentXPos,0) -- (\VDNT@currentXPos,\VDNT@notegoal-.5\VDNT@Yinterval);
          \fill[#2] (\VDNT@currentXPos,\VDNT@currentYPos) circle [radius=\dotsRadius];
        }
        \advance\VDNT@currentYPos\VDNT@Yinterval\relax
      }
      \fill[#2] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos-\VDNT@Yinterval-\VoD@mag*4pt) -- ++(\VoD@mag*3pt,\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle;
    \end{tikzpicture}%
  }%
  \egroup
  %%座標管理用カウンタのインクリメント
  \global\advance\VDNT@uniqe\@ne
  \par
}


\NewDocumentCommand{\masume}{ m O{.5pt} O{white!70!black} }{\par\bgroup
  %%三角形の大きさ
  \VoD@mag=#2
  %%罫線間隔の算出
  \@tempcnta\linewidth
  \@tempcntb\noteLineDistance
  \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
  \VDNT@Xinterval\dimexpr\linewidth/\VDNT@dotsNum\relax
  \VDNT@Yinterval\VDNT@Xinterval
  %%ノート罫線描画
  \noindent
    \begin{tikzpicture}[xscale=0.996]
      \VDNT@currentYPos\z@
      \fill[#3] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos+\VDNT@Yinterval+\VoD@mag*4pt) -- ++(\VoD@mag*3pt,-\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle; %上の三角形
      \foreach \i in{1,2,...,#1}{ 
        \VDNT@currentXPos\z@
        \global\VDNT@currentYPos=\dimexpr\VDNT@Yinterval*\i\relax
        \draw[#3,line width=\noteLineWidth] (0,\VDNT@currentYPos) -- (\linewidth,\VDNT@currentYPos);
        \foreach \k in{0,1,...,\VDNT@dotsNum}{
          \VDNT@currentXPos=\dimexpr\VDNT@Xinterval*\k\relax
          \draw[#3,line width=\noteLineWidth] (\VDNT@currentXPos,\VDNT@Yinterval) -- (\VDNT@currentXPos,\VDNT@Yinterval*#1);
          \fill[#3] (\VDNT@currentXPos,\VDNT@currentYPos) circle [radius=\dotsRadius];
        }
      }
      \fill[#3] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos-\VoD@mag*4pt) -- ++(\VoD@mag*3pt,\VoD@mag*4pt) -- ++(-\VoD@mag*6pt,0) -- cycle; %下の三角形
    \end{tikzpicture}%
  \egroup
  \par
}

\endinput