]> Git — Sourcephile - julm/violon-tex.git/blob - violon.sty
Modification : affichage du doigt et de la corde au début de la note; et la durée...
[julm/violon-tex.git] / violon.sty
1 % This file is part of Violon, a violin score engine.
2 % Copyright (C) 2009 Julien Moutinho
3 %
4 % This program is free software: you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published
6 % by the Free Software Foundation, either version 3 of the License,
7 % or any later version.
8 %
9 % This program is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty
11 % of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 % See the GNU General Public License for more details.
13 %
14 % You should have received a copy of the GNU General Public License
15 % along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 % Any comment or contribution is welcome
18 % at julm arobase julm dot meeee dot eu.
19
20 % Déclaration
21 \def\fileversion{1.0}%
22 \def\filedate{2009/10/11}%
23 \NeedsTeXFormat{LaTeX2e}%
24 \ProvidesPackage{violon}[\filedate\space\fileversion\space%
25 Violin score library (Julien Moutinho)]%
26 % Bibliothèques
27 \usepackage{ifthen}%
28 \usepackage{color}%
29 % Polices
30 \gdef\ssssmall{%
31 \@setfontsize\sssmall{5pt}{5pt}}%
32 \gdef\sssmall{%
33 \@setfontsize\sssmall{6pt}{6pt}}%
34 \gdef\ssmall{%
35 \@setfontsize\ssmall\@viiipt\@ixpt}%
36 \gdef\vlnfingerfont{%
37 \fontfamily{pnc}\bfseries\sssmall}%
38 \gdef\vlncordfont{%
39 \fontfamily{pnc}\scshape\ssssmall}%
40 \gdef\vlntimefont{%
41 \fontfamily{pnc}\bfseries\ssssmall}%
42 % Algèbre
43 \newcount\@calc@mod@cnt%
44 \def\modulo#1#2{%
45 \@calc@mod@cnt=#1\relax%
46 \divide\@calc@mod@cnt by#2\relax%
47 \multiply\@calc@mod@cnt by#2\relax%
48 \advance#1 by-\@calc@mod@cnt%
49 }%
50 % Convertisseurs
51 \let\romannumeral@old\romannumeral%
52 \def\romannumeral#1{%
53 \ifnum#1>\z@\romannumeral@old#1\else\number#1\fi%
54 }%
55 % Moteur
56 % Constantes
57 % Couleurs
58 \definecolor{colVlnBowUp}{rgb}{0.24,0.92,0.24}%
59 \definecolor{colVlnBowDn}{rgb}{1,0,0}%
60 \definecolor{colVlnBowU}{rgb}{0.24,0.92,0.24}%
61 \definecolor{colVlnBowD}{rgb}{1,0,0}%
62 \definecolor{colVlnLineHalfTone}{gray}{0.90}%
63 \definecolor{colVlnLineHalfToneBase}{gray}{0.50}%
64 % Portée
65 % Déclarations
66 \newdimen\vlnhalftonelinevdim
67 \newskip\vlnhalftonelineskip%
68 \newskip\vlntonesskip%
69 % Initialisations
70 \vlnhalftonelinevdim=0.5pt%
71 \vlntonesskip=0pt\relax%
72 \vlnhalftonelineskip=4pt\relax%
73 \advance\vlnhalftonelineskip by -\vlnhalftonelinevdim%
74 \def\vlnhalftoneline{%
75 {\color{colVlnLineHalfTone}\hrule depth 0pt height \vlnhalftonelinevdim width \hsize }}%
76 \def\vlnbasehalftoneline{%
77 {\color{colVlnLineHalfToneBase}\hrule depth 0pt height \vlnhalftonelinevdim width \hsize }}%
78 \def\toneskip{%
79 \advance\vlntonesskip by\vlnhalftonelineskip%
80 \advance\vlntonesskip by\vlnhalftonelinevdim%
81 \vskip\vlnhalftonelineskip%
82 }%
83 \def\vlnfivehalftonelines{%
84 \toneskip\vlnhalftoneline%
85 \toneskip\vlnhalftoneline%
86 \toneskip\vlnhalftoneline%
87 \toneskip\vlnhalftoneline%
88 \toneskip\vlnbasehalftoneline%
89 }%
90 \def\allhalftonelines{%
91 \vlnfivehalftonelines%
92 \vlnfivehalftonelines%
93 \vlnfivehalftonelines%
94 \vlnfivehalftonelines%
95 }%
96 \gdef\vlnlines{%
97 \vlnbasehalftoneline%
98 \allhalftonelines%
99 \advance\vlntonesskip by\vlnhalftonelinevdim%
100 \vskip-\vlntonesskip%
101 }%
102 % Notes
103 % Déclarations
104 % Variables
105 \newskip\vlnnotevskip%
106 \newskip\vlnnotevskipbase%
107 \newskip\vlnnotehskip%
108 \newskip\vlnnotehskipbase%
109 \newdimen\vlnnotevdim%
110 \newdimen\vlnnotevdimmore%
111 \newdimen\vlnnotehdim%
112 \newdimen\vlnnotehdimbase%
113 \newcount\vlnlastfinger%
114 \newcount\vlnlastposbase%
115 \newcount\vlnlastposunit%
116 \newcount\vlnnotepos%
117 \newcount\vlnlastpos%
118 % Initialisations
119 \vlnnotevskip=0pt\relax%
120 \vlnnotevskipbase=0pt\relax%
121 \vlnnotehskip=0pt\relax%
122 \vlnnotehskipbase=0pt\relax%
123 \vlnnotevdim=\vlnhalftonelinevdim%
124 \vlnnotevdimmore=1pt\relax%
125 \vlnnotehdimbase=2cm\relax%
126 \advance\vlnnotevdim by \vlnnotevdimmore%
127 \advance\vlnnotevdim by \vlnnotevdimmore%
128 \def\vlnlastbow{}%
129 \def\vlnlastcord{}%
130 \def\vlnlasttimenum{}%
131 \def\vlnlasttimeden{}%
132 \def\vlnnotehdimmodetim{1}%
133 \def\vlnnotehdimmodetxt{}%
134 \parindent=0pt\relax%
135 \parskip=0pt\relax%
136 \parfillskip=0pt\relax%
137 \def\vlnlastposfinger{%
138 \csname vlnlastposfinger\romannumeral\vlnlastfinger\endcsname%
139 }%
140 \def\vlnlastfingerpos{%
141 \csname vlnlastfingerpos\romannumeral\vlnlastpos\endcsname%
142 }%
143 \def\vlntimefrac#1/#2{%
144 \leavevmode%
145 \hbox{#1}%
146 \kern-.4ex\lower.3ex\hbox{\bfseries\tiny /}%
147 \kern-.3ex\lower.6ex\hbox{#2}%
148 }%
149 \def\vlndoatnote#1#2#3#4{%
150 \nointerlineskip%
151 \vlnnotevskip\vlnhalftonelineskip%
152 \advance\vlnnotevskip by\vlnhalftonelinevdim\relax%
153 \multiply\vlnnotevskip by#1\relax%
154 \advance\vlnnotevskip by-\vlnnotevdimmore\relax%
155 \vskip\vlnnotevskip\relax%
156 \vskip-\vlnnotevskip\relax%
157 \vskip\vlnnotevskip\relax%
158 \vrule depth 0pt height 0pt width \vlnnotehskip\relax%
159 \setbox0=#3%
160 \advance\vlnnotevskip by \ht0\relax%
161 #2%
162 \box0%
163 #4%
164 \vskip-\vlnnotevskip\relax%
165 \nointerlineskip%
166 }%
167 \def\vlnnextnote{%
168 \advance\vlnnotehskip by\vlnnotehdim\relax%
169 }%
170 \def\vlnnotedraw crd#1pos#2fgr#3bow#4tim#5#6{%
171 % Position
172 \ifthenelse{\equal{#2}{.}}%
173 {}%
174 {\vlnlastpos#2\relax}%
175 % Durée
176 \ifthenelse{\equal{#5/#6}{\vlnlasttimenum/\vlnlasttimeden}}%
177 {}%
178 {\ifthenelse{\equal{#5/#6}{./.}}%
179 {}%
180 {\vlndoatnote{\vlnlastpos}%
181 {}%
182 {\ifthenelse{\equal{#5}{.}}%
183 {}%
184 {\def\vlnlasttimenum{#5}}%
185 \ifthenelse{\equal{#6}{.}}%
186 {}%
187 {\def\vlnlasttimeden{#6}}%
188 \vlnnotehdim\vlnnotehdimbase%
189 \ifthenelse{\equal{}{\vlnnotehdimmodetim}}%
190 {}%
191 {\multiply\vlnnotehdim by\vlnlasttimenum\relax%
192 \divide\vlnnotehdim by\vlnlasttimeden\relax%
193 }%
194 \ifthenelse{\equal{}{\vlnnotehdimmodetxt}}%
195 {}%
196 {\vbox to0pt{%
197 \setbox0=\hbox{%
198 \ifthenelse{\equal{\vlnlasttimeden}{1}}%
199 {{\vlntimefont{\vlnlasttimenum}}}%
200 {\vlntimefrac{\vlntimefont{\vlnlasttimenum}}/{\vlntimefont{\vlnlasttimeden}}}%
201 }%
202 \vskip\vlnnotevdim\relax%
203 \vskip0.2mm\relax%
204 \hskip\vlnnotehdim\relax%
205 \hskip-\wd0\relax%
206 \dp0=0pt\relax%
207 \box0}%
208 }%
209 }%
210 {}%
211 }%
212 }%
213 % Archet
214 \ifthenelse{\equal{#4}{C}}%
215 {\ifthenelse{\equal{U}{\vlnlastbow}}%
216 {\def\vlnlastbow{D}}%
217 {\def\vlnlastbow{U}}}%
218 {\ifthenelse{\equal{#4}{.}}%
219 {}%
220 {\def\vlnlastbow{#4}}}%
221 \vlndoatnote{\vlnlastpos}%
222 {\begingroup\expandafter\color{colVlnBow\vlnlastbow}}%
223 {%
224 \hbox{%
225 \vrule depth 0pt height \vlnnotevdim width \vlnnotehdim\relax%
226 }%
227 }%
228 {\endgroup}%
229 % Doigts
230 \ifthenelse{\equal{#3}{.}}%
231 {}%
232 {\vlnlastfinger#3\relax}%
233 \ifthenelse{\equal{\the\vlnlastfinger}{\vlnlastfingerpos}\AND\equal{\the\vlnlastpos}{\vlnlastposfinger}}%
234 {}%
235 {%
236 \expandafter\edef\csname vlnlastfingerpos\romannumeral\vlnlastpos\endcsname{\the\vlnlastfinger}\relax%
237 \expandafter\edef\csname vlnlastposfinger\romannumeral\vlnlastfinger\endcsname{\the\vlnlastpos}\relax%
238 \vlndoatnote{\vlnlastpos}%
239 {}%
240 {\vbox to0pt{%
241 \setbox0=\hbox{{\vlnfingerfont{\the\vlnlastfinger}}}%
242 \vskip-0.2mm\relax%
243 \vskip-\ht0\relax%
244 %\vskip-\dp0\relax%
245 \dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
246 \box0}}%
247 {}%
248 }%
249 % Cordes
250 \ifthenelse{\equal{#1}{\vlnlastcord}}%
251 {}%
252 {\ifthenelse{\equal{#1}{.}}%
253 {}%
254 {\def\vlnlastcord{#1}%
255 \vlndoatnote{\vlnlastpos}%
256 {}%
257 {\vbox to0pt{%
258 \setbox0=\hbox{{\vlncordfont{%
259 \count@#1\relax%
260 \advance\count@ by1\relax%
261 \ifcase\count@%
262 \or 0\or I\or II\or III%
263 \fi}}}%
264 \vskip\vlnnotevdim\relax%
265 \vskip0.2mm\relax%
266 \box0}}%
267 {}%
268 }%
269 }%
270 \vlnnextnote%
271 \nointerlineskip%
272 }%
273 % Cordes
274 \def\vlncordposi{0}% G
275 \def\vlncordposii{7}% D
276 \def\vlncordposiii{14}% A
277 \def\vlncordposiv{21}% E
278 % Crochets
279 \def\vlnnotehook{}%
280 \def\vlnnotedrawtone#1#2#3#4#5{%
281 \ifthenelse{\equal{#1}{.}}%
282 {}%
283 {\vlnlastposbase#1\relax}%
284 \ifthenelse{\equal{#2}{.}}%
285 {}%
286 {\vlnlastposunit#2\relax}%
287 \ifthenelse{\equal{#3}{.}}%
288 {\vlnnotepos\vlnlastcord\relax}%
289 {\vlnnotepos#3\relax}%
290 \advance\vlnnotepos by1\relax%
291 \expandafter\vlnnotepos-\csname vlncordpos\romannumeral\vlnnotepos\endcsname\relax%
292 \ifthenelse{\equal{\the\vlnlastposbase}{0}}%
293 {\advance\vlnnotepos by\vlnlastposunit\relax}%
294 {\edef\tmp{\the\vlnlastposbase\the\vlnlastposunit}%
295 \advance\vlnnotepos by\tmp\relax}%
296 \vlnnotehook%
297 \vlnnotedraw crd{#3}pos{\the\vlnnotepos}fgr{#4}bow{#5}tim%
298 }%
299 \def\vlnnoteshift#1{%
300 \count@\vlnnotepos%
301 \modulo{\count@}{#1}%
302 \advance\count@ by1\relax%
303 \edef\tmp{\csname vlnnoteshift\romannumeral\count@\endcsname}%
304 \ifthenelse{\equal{\tmp}{}}%
305 {}%
306 {\advance\vlnnotepos by\tmp\relax}%
307 }%