% This file is part of Violon, a violin score engine.
% Copyright (C) 2009-2012  Julien Moutinho
%
% This program 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 any later version.
%
% This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

% Any comment or contribution is welcome
% at julm&autogeree.net.

% Déclaration
	\def\fileversion{1.0}%
	\def\filedate{2009/10/11}%
	\NeedsTeXFormat{LaTeX2e}%
	\ProvidesPackage{violon}[\filedate\space\fileversion\space%
		Violin score library (Julien Moutinho)]%
% Bibliothèques
	\usepackage{ifthen}%
	\usepackage{color}%
	\usepackage{verbatim}%
% Polices
	\gdef\ssssmall{%
		\@setfontsize\sssmall{5pt}{5pt}}%
	\gdef\sssmall{%
		\@setfontsize\sssmall{6pt}{6pt}}%
	\gdef\ssmall{%
		\@setfontsize\ssmall\@viiipt\@ixpt}%
	\gdef\vlnfingerfont{%
		\expandafter\color{colVlnBowFingerCord\vlncurrcord}%
		\fontfamily{pnc}\bfseries\sssmall}%
	\gdef\vlncordfont{%
		\color{colVlnBowCord}%
		\fontfamily{pnc}\bfseries\sssmall}%
	\gdef\vlnnamefont{%
		\expandafter\color{colVlnBowNameOctave\the\vlncurroctave}%
		\fontfamily{pnc}\scshape\ssssmall}%
	\gdef\vlnpartfont{%
		\color{colVlnPart}%
		\fontfamily{pnc}\bfseries\sssmall}%
	\gdef\vlntimefont{%
		\fontfamily{pnc}\bfseries\ssssmall}%
% Algèbre
	\newcount\@calc@mod@cnt%
	\def\modulo#1#2{%
		\@calc@mod@cnt=#1\relax%
		\divide\@calc@mod@cnt by#2\relax%
		\multiply\@calc@mod@cnt by#2\relax%
		\advance#1 by-\@calc@mod@cnt%
	 }%
% Convertisseurs
	\def\romannumeralz#1{%
		\ifnum#1>\z@\romannumeral#1\else\number#1\fi%
	 }%
% Moteur
	% Constantes
		% Couleurs
			%\definecolor{colVlnBowU}{rgb}{0.24,0.92,0.24}%
			%\definecolor{colVlnBowD}{rgb}{0.80,0,0}%
			%\definecolor{colVlnBowU}{rgb}{0.30,0.75,0.75}%
			\definecolor{colVlnBowU}{gray}{0.50}%
			\definecolor{colVlnBowD}{gray}{0}%
			\definecolor{colVlnBowN}{gray}{1}%
			\definecolor{colVlnBowCord}{rgb}{0,1,0}%
			\definecolor{colVlnBowFinger}{rgb}{0,0,0}%
			\definecolor{colVlnBowFingerCord0}{rgb}{0,0,0}%
			\definecolor{colVlnBowFingerCord1}{rgb}{0,0.66,0}%
			\definecolor{colVlnBowFingerCord2}{rgb}{0,0,1}%
			\definecolor{colVlnBowFingerCord3}{rgb}{1,0,0}%
			\definecolor{colVlnBowName}{rgb}{1,0,0}%
			\definecolor{colVlnBowNameOctave0}{rgb}{0,0,0}%
			\definecolor{colVlnBowNameOctave1}{rgb}{0,0.66,0}%
			\definecolor{colVlnBowNameOctave2}{rgb}{0,0,1}%
			\definecolor{colVlnBowNameOctave3}{rgb}{1,0,0}%
			\definecolor{colVlnBowNameOctave4}{rgb}{1,1,0}%
			\definecolor{colVlnLineHalfToneEven}{gray}{0.98}%
			\definecolor{colVlnLineHalfToneOdd}{gray}{1}%
			\definecolor{colVlnLineHalfToneFifth}{gray}{0.92}%
			\definecolor{colVlnPart}{gray}{0}%
			\definecolor{colVlnBar}{gray}{.85}%
			\definecolor{colVlnCrescD}{rgb}{0,0.66,0}%
			\definecolor{colVlnCrescU}{rgb}{1,0,0}%
	% Portée
		% Déclarations
			\newdimen\vlnstaffhalftonelinevdim%
			\newskip\vlnstaffvdim%
			\def\vlnstaffvdimpre{0pt}%
			\newskip\vlnstaffintervskip%
			\newskip\vlnstaffvskip%
		% Initialisations
			\def\vlnstaffhsize{\hsize}%
			\def\vlnstaffmaxvsize{\textheight}%
			\vlnstaffhalftonelinevdim=3pt%
			\vlnstaffvdim=0pt\relax%
			\vlnstaffvskip=0pt\relax%
			\vlnstaffintervskip=\vlnstaffhalftonelinevdim\relax%
			\multiply\vlnstaffintervskip by 2\relax%
		\def\vlnstaffhalftoneline#1{%
			{\color{colVlnLineHalfTone#1}\hrule depth 0pt height \vlnstaffhalftonelinevdim width \vlnstaffhsize }}%
		\def\vlnstafftoneskip{%
			\advance\vlnstaffvdim by\vlnstaffhalftonelinevdim%
			\nobreak%
		 }%
		\def\vlnstafffivehalftonelines{%
			\vlnstaffhalftoneline{Odd}\vlnstafftoneskip%
			\vlnstaffhalftoneline{Even}\vlnstafftoneskip%
			\vlnstaffhalftoneline{Odd}\vlnstafftoneskip%
			\vlnstaffhalftoneline{Even}\vlnstafftoneskip%
			\vlnstaffhalftoneline{Fifth}\vlnstafftoneskip%
		 }%
		\def\vlnstaffallhalftonelines{%
			\vlnstaffhalftoneline{Fifth}\vlnstafftoneskip%
			\vlnstafffivehalftonelines%
			\vlnstafffivehalftonelines%
			\vlnstafffivehalftonelines%
			\vlnstafffivehalftonelines%
			\vlnstafffivehalftonelines%
		 }%
		\def\vlnstaff{%
			\nobreak\vskip\vlnstaffvdimpre%
			\nobreak\vskip\vlnstaffvdim%
			\advance\vlnstaffvskip by\vlnstaffvdim\relax%
			\count@\vlnstaffvskip\relax%
			\advance\count@ by\vlnstaffvdim\relax%
			\ifnum\count@>\vlnstaffmaxvsize%
				\vlnstaffvskip=0pt\relax%
				\break%
			 \else%
				\advance\vlnstaffvskip by\vlnstaffintervskip\relax%
				\nobreak\vskip\vlnstaffintervskip%
			 \fi%
			\vlnnotehskip=0pt\relax%
			\vlnstaffvdim=0pt\relax%
			\vlnstaffallhalftonelines%
			\advance\vlnstaffvdim by\vlnstaffhalftonelinevdim%
			\nobreak\vskip-\vlnstaffvdim%
		 }%
	% Notes
		% Déclarations
			% Variables
				\newskip\vlnnotevskip%
				\newskip\vlnnotehskip%
				\newdimen\dimen@%
				\newdimen\dimen@@%
				\newdimen\vlnnotevdim%
				\newdimen\vlnnotevdimmore%
				\newdimen\vlnnotehdim%
				\newdimen\vlnnotehdimbase%
				\newcount\vlncurrfinger%
				\newcount\vlncurrposbase%
				\newcount\vlncurrposunit%
				\newcount\vlncurroctave%
				\def\vlncurrletter{}%
				\def\vlncurrshift{}%
				\newcount\vlnnotepos%
				\newcount\vlncurrpos%
				\newcount\vlncurrpitch%
				\newcount\vlnlastpitch%
				\newcount\vlnnote%
				\newcount\vlnbow%
				\gdef\vlncrescleft{}%
				\gdef\vlncrescright{}%
		% Initialisations
			\vlnnotevskip=0pt\relax%
			\vlnnotehskip=0pt\relax%
			\vlnnotevdim=\vlnstaffhalftonelinevdim%
			\vlnnotevdimmore=1pt\relax%
			\vlnnotehdimbase=2cm\relax%
			%\advance\vlnnotevdim by\vlnnotevdimmore%
			%\advance\vlnnotevdim by\vlnnotevdimmore%
			\def\vlncurrbow{}%
			\def\vlncurrrealbow{}%
			\def\vlncurrcord{}%
			\def\vlncurrtimenum{}%
			\def\vlncurrtimeden{}%
			\def\vlncurrbowwithnext{no}%
			\def\vlnnotehdimmodetim{yes}%
			\def\vlnnotehdimmodetxt{}%
			\parindent=0pt\relax%
			\parskip=0pt\relax%
			\parfillskip=0pt\relax%
		\def\vlncurrposfinger{%
			\csname vlncurrposfinger\romannumeralz\vlncurrfinger\endcsname%
		 }%
		\def\vlncurrfingerpos{%
			\csname vlncurrfingerpos\romannumeralz\vlncurrpos\endcsname%
		 }%
		%\def\vlncurrposname{%
		%	\csname vlncurrposname\romannumeralz\vlncurrpos\endcsname%
		% }%
		\def\vlntimefrac#1/#2{%
			\leavevmode%
			\hbox{#1}%
			\kern-.4ex\lower.3ex\hbox{\bfseries\tiny /}%
			\kern-.3ex\lower.6ex\hbox{#2}%
		 }%
		% Graveur
			\def\vlndoatnote#1#2#3#4{%
				\nointerlineskip%
				\vlnnotevskip=0pt\relax%
				\advance\vlnnotevskip by\vlnstaffhalftonelinevdim\relax%
				\multiply\vlnnotevskip by#1\relax%
				\advance\vlnnotevskip by\vlnstaffhalftonelinevdim\relax%
				%\advance\vlnnotevskip by-\vlnnotevdimmore\relax%
				\nobreak\vskip\vlnnotevskip\relax%
				\vrule depth 0pt height 0pt width \vlnnotehskip\relax%
				\setbox0=#3%
				\advance\vlnnotevskip by \ht0\relax%
				#2%
				\box0%
				#4%
				\nobreak\vskip-\vlnnotevskip\relax%
				\nointerlineskip%
			 }%
			\def\vlnnotedraw{%
				% Durée
					\vlnnotehdim\vlnnotehdimbase%
					\ifthenelse{\equal{\vlnnotehdimmodetim}{yes}}%
					 {\multiply\vlnnotehdim by\vlncurrtimenum\relax%
						\divide\vlnnotehdim by\vlncurrtimeden\relax%
					 }%
					 {}%
					% Automatic staff break
						\count@\vlnnotehskip\relax%
						\advance\count@ by\vlnnotehdim\relax%
						\ifnum\count@>\vlnstaffhsize\vlnstaff\fi%
					% Explicite
						\def\vlnnotehdimmodetxtdo{%
							\vbox to0pt{%
								\setbox0=\hbox{%
									\ifthenelse{\equal{\vlncurrtimeden}{1}}%
									 {{\vlntimefont{\vlncurrtimenum}}}%
									 {\vlntimefrac{\vlntimefont{\vlncurrtimenum}}/{\vlntimefont{\vlncurrtimeden}}}%
								 }%
								\nobreak\vskip\vlnnotevdim\relax%
								\nobreak\vskip0.2mm\relax%
								\nobreak\hskip\vlnnotehdim\relax%
								\nobreak\hskip-\wd0\relax%
								\dp0=0pt\relax%
								\box0%
							 }%
						 }%
						\ifthenelse{\equal{}{\vlnnotehdimmodetxt}}%
						 {\null}%
						 {\vlndoatnote{\vlncurrpos}%
							 {}%
							 {\vlnnotehdimmodetxtdo}%
							 {}%
						 }%
				% Archet
					\vlndoatnote{\vlncurrpos}%
					 {\begingroup\expandafter\color{colVlnBow\vlncurrbow}}%
					 {%
						\hbox{%
							\ifthenelse{\equal{\vlncurrbow}{N}}
							 {}%
							 {%
								\vrule depth 0pt height \vlnnotevdim width \vlnnotehdim\relax%
								\nobreak\hskip-\vlnnotehdim\relax%
								\dimen@\vlnnotevdim%
								\divide\dimen@ by3\relax%
								\dimen@@\vlnnotehdim%
								\divide\dimen@@ by2\relax%
								\ifthenelse{\equal{\vlncrescleft}{}}%
								 {%
									\ifthenelse{\equal{\vlncrescright}{}}%
									 {%
									 }%
									 {%
										\vrule depth 0pt height 0pt width \dimen@@\relax%
										\color{colVlnCresc\vlncrescright}%
										\vrule depth 0pt height \dimen@ width \dimen@@\relax%
									 }%
								 }%
								 {%
									\ifthenelse{\equal{\vlncrescright}{}}%
									 {%
										\color{colVlnCresc\vlncrescleft}%
										\vrule depth 0pt height \dimen@ width \dimen@@\relax%
									 }%
									 {%
										\color{colVlnCresc\vlncrescleft}%
										\vrule depth 0pt height \dimen@ width \dimen@@\relax%
										\color{colVlnCresc\vlncrescright}%
										\vrule depth 0pt height \dimen@ width \dimen@@\relax%
									 }%
								 }%
								\global\let\vlncrescleft\vlncrescright%
							 }%
						 }%
					 }%
					 {\endgroup}%
				% Cordes
				% Doigts
					\ifthenelse{\equal{\vlncurrbow}{N}%
					%	\OR\equal{\the\vlncurrfinger}{\vlncurrfingerpos}%
					%	\AND\equal{\the\vlncurrpos}{\vlncurrposfinger}%
					%	\AND\equal{\the\vlncurrcord}{\thevlncurrlastcord}%
					 }%
					 {}%
					 {%
						\expandafter\edef\csname vlncurrfingerpos\romannumeralz\vlncurrpos\endcsname{\the\vlncurrfinger}%
						\expandafter\edef\csname vlncurrposfinger\romannumeralz\vlncurrfinger\endcsname{\the\vlncurrpos}%
						\vlndoatnote{\vlncurrpos}%
						 {}%
						 {\vbox to0pt{%
							\setbox0=\hbox{{\vlnfingerfont{\the\vlncurrfinger}}}%
							\nobreak\vskip\vlnnotevdim\relax%
							\nobreak\vskip0.2mm\relax%
							\dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
							\box0}}%
						 {}%
					 }%
				% Nom
					%\expandafter\edef\csname vlncurrposname\romannumeralz\vlncurrpos\endcsname{#5}%
					\ifthenelse{\equal{\vlncurrbow}{N}}%
					 {}%
					 {%
						\vlndoatnote{\vlncurrpos}%
						 {}%
						 {\vbox to0pt{%
							\setbox0=\hbox{{\vlnnamefont{\vlncurrname}}}%
							\nobreak\vskip-0.275mm\relax%
							\nobreak\vskip-\ht0\relax%
							%\vskip-\dp0\relax%
							\dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
							\box0}}%
						 {}%
					 }%
				% Accord
					\ifthenelse{\equal{\vlncurrbowwithnext}{yes}}%
					 {%
					 }%
					 {
						\advance\vlnnotehskip by\vlnnotehdim\relax%
					 }%
				\nointerlineskip%
			 }%
		% Cordes
			\def\vlncordposi{0}%    G
			\def\vlncordposii{7}%   D
			\def\vlncordposiii{14}% A
			\def\vlncordposiv{21}%  E
		% Demi-tons alphabétiques sans modification
			\expandafter\def\csname vlnnotetoneofnameG=\endcsname{0}%
			\expandafter\def\csname vlnnotetoneofnameG+\endcsname{1}%
			\expandafter\def\csname vlnnotetoneofnameA-\endcsname{1}%
			\expandafter\def\csname vlnnotetoneofnameA=\endcsname{2}%
			\expandafter\def\csname vlnnotetoneofnameA+\endcsname{3}%
			\expandafter\def\csname vlnnotetoneofnameB-\endcsname{3}%
			\expandafter\def\csname vlnnotetoneofnameB=\endcsname{4}%
			\expandafter\def\csname vlnnotetoneofnameB+\endcsname{5}%
			\expandafter\def\csname vlnnotetoneofnameC-\endcsname{4}%
			\expandafter\def\csname vlnnotetoneofnameC=\endcsname{5}%
			\expandafter\def\csname vlnnotetoneofnameC+\endcsname{6}%
			\expandafter\def\csname vlnnotetoneofnameD-\endcsname{6}%
			\expandafter\def\csname vlnnotetoneofnameD=\endcsname{7}%
			\expandafter\def\csname vlnnotetoneofnameD+\endcsname{8}%
			\expandafter\def\csname vlnnotetoneofnameE-\endcsname{8}%
			\expandafter\def\csname vlnnotetoneofnameE=\endcsname{9}%
			\expandafter\def\csname vlnnotetoneofnameE+\endcsname{10}%
			\expandafter\def\csname vlnnotetoneofnameF-\endcsname{9}%
			\expandafter\def\csname vlnnotetoneofnameF=\endcsname{10}%
			\expandafter\def\csname vlnnotetoneofnameF+\endcsname{11}%
			\expandafter\def\csname vlnnotetoneofnameG-\endcsname{11}%
		% Modifications
			\expandafter\def\csname vlnshiftsymbol-\endcsname{\kern-0.7pt$\flat$}%
			\expandafter\def\csname vlnshiftsymbol=\endcsname{}%
			\expandafter\def\csname vlnshiftsymbol+\endcsname{\kern-0.7pt$\sharp$}%
		\def\vlnnotedrawtonebyname#1#2#3#4#5#6#7#8{%
			% Octave
				\ifthenelse{\equal{#1}{.}}%
				 {}%
				 {\vlncurroctave#1\relax}%
			% Ton dans l'octave
				\ifthenelse{\equal{#2}{.}}%
				 {}%
				 {\def\vlncurrletter{#2}}%
				\ifthenelse{\equal{#3}{.}}%
				 {}%
				 {\def\vlncurrshift{#3}}%
				\edef\vlncurrname{%
					\vlncurrletter\csname vlnshiftsymbol\vlncurrshift\endcsname%
				 }%
			% Position
				\edef\vlncurroctavepitch{\csname vlnnotetoneofname\vlncurrletter\vlncurrshift\endcsname}%
				\vlnlastpitch\vlncurrpitch%
				\vlncurrpitch\vlncurroctavepitch%
				\count@\vlncurroctave\relax%
				\multiply\count@ by12\relax%
				\advance\vlncurrpitch by\count@%
			% Corde
				\ifthenelse{\equal{#4}{.}}%
				 {}%
				 {\def\vlncurrcord{#4}%
				 }%
				\count@\vlncurrcord%
				\advance\count@ by1\relax%
				\vlncurrpos\vlncurrpitch%
				\advance\vlncurrpos by-\csname vlncordpos\romannumeralz\count@\endcsname%
			% Doigt
				\ifthenelse{\equal{#5}{.}}%
				 {}%
				 {\vlncurrfinger#5\relax}%
			% Archet
				\let\vlnlastlastrealbow\vlnlastrealbow%
				\let\vlnlastrealbow\vlncurrrealbow%
				\ifthenelse{\equal{#6}{C}}%
				 {\ifthenelse{\equal{U}{\vlncurrrealbow}}%
					 {\def\vlncurrbow{D}}%
					 {\def\vlncurrbow{U}}}%
				 {\ifthenelse{\equal{#6}{.}}%
					{\def\vlncurrbow{\vlncurrrealbow}}%
					{\def\vlncurrbow{#6}}}%
				\ifthenelse{\equal{\vlncurrbow}{N}}%
				 {}%
				 {\edef\vlncurrrealbow{\vlncurrbow}}%
			% Durée
				\ifthenelse{\equal{#7}{.}}%
				 {}%
				 {\def\vlncurrtimenum{#7}}%
				\ifthenelse{\equal{#8}{.}}%
				 {}%
				 {\def\vlncurrtimeden{#8}}%
			\let\vlncurrbowwithlast\vlncurrbowwithnext%
			\@ifnextchar&{%
				\def\next&{%
					\def\vlncurrbowwithnext{yes}%
					\vlnnotelily%
					\vlnnotedraw%
					\advance\vlnnote by1\relax%
				 }%
				\next%
			 }{%
				\def\vlncurrbowwithnext{no}%
				\advance\vlnbow by1\relax%
				\vlnnotelily%
				\vlnnotedraw%
				\advance\vlnnote by1\relax%
			 }%
		 }%
		\def\vlnpart#1{%
			\vlndoatnote{0}%
			 {}%
			 {\vbox to0pt{%
				\setbox0=\hbox{{\vlnpartfont{#1}}}%
				\nobreak\vskip-0.3mm\relax%
				\nobreak\vskip-\ht0\relax%
				\dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
				\box0}}%
			 {}%
		 }%
		\def\vlnpartup#1{%
			\vlndoatnote{0}%
			 {}%
			 {\vbox to0pt{%
				\setbox0=\hbox{{\vlnpartfont{#1}}}%
				\nobreak\vskip-0.3mm\relax%
				\nobreak\vskip-\ht0\relax%
				\nobreak\vskip-\ht0\relax%
				\dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
				\box0}}%
			 {}%
		 }%
		\def\vlnbar{%
			\vlndoatnote{0}%
			 {}%
			 {\vbox to0pt{%
				\dimen@\vlnstaffvdim%
				\advance\dimen@ by -\vlnnotevdim\relax%
				\advance\dimen@ by -\vlnnotevdim\relax%
				\setbox0=\hbox{{\color{colVlnBar}\vrule depth 0pt height \dimen@ width 0.1pt\relax}}%
				\nobreak\vskip\vlnnotevdim\relax%
				\dp0=0pt\relax%
				\box0}}%
			 {}%
		 }%
		\def\vlncresc#1{%
			\global\let\vlncrescleft\vlncrescright%
			\xdef\vlncrescright{#1}%
		 }%
		% Lylipond
			\def\lily{}%
			% input octave -> Lilypond octave
				\expandafter\def\csname vlnnotelilyofoctave0\endcsname{}%
				\expandafter\def\csname vlnnotelilyofoctave1\endcsname{'}%
				\expandafter\def\csname vlnnotelilyofoctave2\endcsname{''}%
				\expandafter\def\csname vlnnotelilyofoctave3\endcsname{'''}%
			% input name -> Lilypond name
				\expandafter\def\csname vlnnotelilyofnameG=\endcsname{g}%
				\expandafter\def\csname vlnnotelilyofnameG+\endcsname{gis}%
				\expandafter\def\csname vlnnotelilyofnameA-\endcsname{aes}%
				\expandafter\def\csname vlnnotelilyofnameA=\endcsname{a}%
				\expandafter\def\csname vlnnotelilyofnameA+\endcsname{ais}%
				\expandafter\def\csname vlnnotelilyofnameB-\endcsname{bes}%
				\expandafter\def\csname vlnnotelilyofnameB=\endcsname{b}%
				\expandafter\def\csname vlnnotelilyofnameB+\endcsname{bis}%
				\expandafter\def\csname vlnnotelilyofnameC-\endcsname{ces}%
				\expandafter\def\csname vlnnotelilyofnameC=\endcsname{c}%
				\expandafter\def\csname vlnnotelilyofnameC+\endcsname{cis}%
				\expandafter\def\csname vlnnotelilyofnameD-\endcsname{des}%
				\expandafter\def\csname vlnnotelilyofnameD=\endcsname{d}%
				\expandafter\def\csname vlnnotelilyofnameD+\endcsname{dis}%
				\expandafter\def\csname vlnnotelilyofnameE-\endcsname{ees}%
				\expandafter\def\csname vlnnotelilyofnameE=\endcsname{e}%
				\expandafter\def\csname vlnnotelilyofnameE+\endcsname{eis}%
				\expandafter\def\csname vlnnotelilyofnameF-\endcsname{fes}%
				\expandafter\def\csname vlnnotelilyofnameF=\endcsname{f}%
				\expandafter\def\csname vlnnotelilyofnameF+\endcsname{fis}%
				\expandafter\def\csname vlnnotelilyofnameG-\endcsname{ges}%
			\def\lilywrite{%
				\newwrite\lilyfile%
				\immediate\openout\lilyfile=out.ly%
				\immediate\write\lilyfile{\lily}%
				\immediate\closeout\lilyfile%
			 }%
			\def\vlnlilyaddnote#1{%
				\expandafter\xdef\csname lilynote\the\vlnnote\endcsname{#1}%
			 }
			\def\vlnlilyflush{%
				\count@0%
				\ifthenelse{\equal{\the\vlnlilyslurbegin}{0}}%
				 {%
				 }%
				 {%
					\advance\vlnlilyslurbegin by-1\relax%
					\expandafter\xdef\csname lilynote\the\vlnlilyslurbegin\endcsname{\csname lilynote\the\vlnlilyslurbegin\endcsname(}%
					\advance\vlnnote by-1\relax%
					\expandafter\xdef\csname lilynote\the\vlnnote\endcsname{)\csname lilynote\the\vlnnote\endcsname}%
					\advance\vlnnote by1\relax%
					\vlnlilyslurbegin=0%
				 }%
				\whiledo{\count@<\vlnnote}{%
					\edef\lily{\lily\csname lilynote\the\count@\endcsname^^J}%
					\advance\count@ by1\relax%
				 }%
			 }%
			\def\vlnlilywriteverbatim{%
				\@bsphack%
				\let\do\@makeother\dospecials%
				\catcode`\^^M\active \catcode`\^^I=12%
				\def\verbatim@processline{%
					\xdef\lily{\lily\the\verbatim@line^^J}%
				 }%
				\verbatim@start%
			 }%
			\def\endvlnlilywriteverbatim{%
				\@esphack%
			 }%
			\newcount\vlnlilyslurbegin%
			\vlnlilyslurbegin=0%
			\def\vlnlilyslurend{}%
			\def\vlnnotelily{%
				\count@=\vlncurrpitch\relax%
				\advance\count@ by8%
				\divide\count@ by12%
				\edef\vlnlilyoctave{\csname vlnnotelilyofoctave\the\count@\endcsname}%
				\ifthenelse{\equal{\vlncurrbow}{N}}%
					{%
						\edef\vlnlilyname{r}%
					}%
					{%
						\edef\vlnlilyname{\csname vlnnotelilyofname\vlncurrletter\vlncurrshift\endcsname}%
					}%
				% Phrasé
					\def\vlnlilytie{}%yes
					\def\vlnlilyslurend{}%
					\ifthenelse{\equal{\vlncurrrealbow}{\vlnlastrealbow}}%
					 {%
						\ifthenelse{\equal{\vlncurrbowwithlast}{yes}}%
						 {%
						 }%
						 {%
							\ifthenelse{\equal{\the\vlnlilyslurbegin}{0}}%
							 {%
								\vlnlilyslurbegin\vlnnote%
							 }%
							 {%
							 }%
						 }%
					 }%
					 {%
						\ifthenelse{\equal{\the\vlnlilyslurbegin}{0}}%
						 {%
						 }%
						 {%
							\advance\vlnlilyslurbegin by-1\relax%
							\expandafter\xdef\csname lilynote\the\vlnlilyslurbegin\endcsname{\csname lilynote\the\vlnlilyslurbegin\endcsname(}%
							\vlnlilyslurbegin=0%
							\def\vlnlilyslurend{)}%
						 }%
					 }%
					%\ifthenelse{\equal{\the\vlncurrpitch}{\the\vlnlastpitch}}%
					%\edef\vlnlilytie{\string~ }%
					%\edef\vlnlilytie{}
					%\csname lilynote\the\vlnlilyslurbegin\endcsname%
					%\expandafter\def\csname lilynote\the\vlnlilyslurbegin\endcsname{#1}%
					%\ifthenelse{\equal{\vlnlilyslurbegin}{}}%
					% {\edef\vlnlilyslurend{}}%
					% {\edef\vlnlilyslurend{)}}%
					%\edef\vlnlilyslurbegin{}
				% Accord
					\ifthenelse{\equal{\vlncurrbowwithnext}{yes}}%
					 {%
						\ifthenelse{\equal{\vlncurrbowwithlast}{yes}}%
						 {%
							\vlnlilyaddnote{%
								\space%
								\vlnlilyname%
								\vlnlilyoctave%
							 }%
						 }%
						 {%
							\vlnlilyaddnote{%
								\vlnlilytie%
								\vlnlilyslurend%
								<\vlnlilyname%
								\vlnlilyoctave%
							 }%
						 }%
					 }%
					 {%
						\ifthenelse{\equal{\vlncurrbowwithlast}{yes}}%
						 {%
							\vlnlilyaddnote{%
								\space%
								\vlnlilyname%
								\vlnlilyoctave%
								>%
							 }%
								%\vlncurrtimeden*\vlncurrtimenum%
						 }%
						 {%
							\vlnlilyaddnote{%
								\vlnlilyslurend%
								\vlnlilyname%
								\vlnlilyoctave%
							 }%
								%\vlncurrtimeden*\vlncurrtimenum%
						 }%
					 }%
			 }%
