%GregorioTeX file.
%
% Copyright (C) 2014-2025 The Gregorio Project (see CONTRIBUTORS.md)
%
% This file is part of Gregorio.
%
% Gregorio 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 3 of the License, or
% (at your option) any later version.
%
% Gregorio 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 Gregorio.  If not, see <http://www.gnu.org/licenses/>.

% this file contains macros for St. Gall ancient neume support

\gre@declarefileversion{gregoriotex-nabc.tex}{6.1.0}% GREGORIO_VERSION


\xdef\gre@nabcfontname{gregall}%
\xdef\gre@nabcfontsize{8}%

\def\gresetnabcfont#1#2{%
	\xdef\gre@nabcfontname{#1}%
	\xdef\gre@nabcfontsize{#2}%
	\global\font\gre@font@nabc={name:#1} at #2 pt\relax %
	{%
		\gre@font@nabc %
		\directlua{gregoriotex.init_nabc_font("\luatexluaescapestring{#1}")}%
	}%
	\gre@nabcfontloadedtrue%
}

\def\gre@nabccharno#1#2#3{%
	\gre@trace{gre@nabccharno{#1}{#2}{#3}}%
	{\directlua{gregoriotex.print_nabc(gregoriotex.parse_nabc("#1", "\luatexluaescapestring{#2}", #3))}}%
	\gre@trace@end%
}

\def\GreNABCChar#1{{%
	%\catcode`\~=12{}%
	%\catcode`\@=11{}%
	\gre@font@nabc %
	\gre@style@nabc %
	\gre@nabccharno{#1}{\gre@nabcfontname}{1}%
	\endgre@style@nabc%
}}

\newif\ifgre@nabcvoice@i@visible
\gre@nabcvoice@i@visibletrue
% define more of these when more voices are supported

\def\gresetnabc#1#2{%
	\IfStrEqCase{#2}{%
		{visible}%
			{\csname gre@nabcvoice@\romannumeral#1@visibletrue\endcsname}%
		{invisible}%
			{\csname gre@nabcvoice@\romannumeral#1@visiblefalse\endcsname}%
		}[% all other cases
			\gre@error{Unrecognized option "#2" for \protect\gresetnabc\MessageBreak Possible options are: 'visible' and 'invisible'}%
		]%
}

\def\GreNABCNeumes#1#2#3#4{%
	\csname ifgre@nabcvoice@\romannumeral#1@visible\endcsname %
		\GreSetNabcAboveLines{\GreNABCChar{#2}}%
	\fi %
}

\newif\ifgre@nabcfontloaded%
\gre@nabcfontloadedfalse%

\def\GreScoreNABCLines#1{%
	\ifgre@nabcfontloaded\else%
		\gresetnabcfont{\gre@nabcfontname}{\gre@nabcfontsize}%
	\fi %
}
