]> Git — Sourcephile - julm/violon-tex.git/blob - violon.sty
Correction : évite de redéfinir \romannumeral car ça gêne d'autres pacquets l'utilisant.
[julm/violon-tex.git] / violon.sty
1 % This file is part of Violon, a violin score engine.
2 % Copyright (C) 2009-2012 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&autogeree.net.
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 \expandafter\color{colVlnBowFingerCord\vlnlastcord}%
38 \fontfamily{pnc}\bfseries\sssmall}%
39 \gdef\vlncordfont{%
40 \color{colVlnBowCord}%
41 \fontfamily{pnc}\bfseries\sssmall}%
42 \gdef\vlnnamefont{%
43 \expandafter\color{colVlnBowNameOctave\the\vlnlastposoctave}%
44 \fontfamily{pnc}\scshape\ssssmall}%
45 \gdef\vlnpartfont{%
46 \color{colVlnPart}%
47 \fontfamily{pnc}\bfseries\sssmall}%
48 \gdef\vlntimefont{%
49 \fontfamily{pnc}\bfseries\ssssmall}%
50 % Algèbre
51 \newcount\@calc@mod@cnt%
52 \def\modulo#1#2{%
53 \@calc@mod@cnt=#1\relax%
54 \divide\@calc@mod@cnt by#2\relax%
55 \multiply\@calc@mod@cnt by#2\relax%
56 \advance#1 by-\@calc@mod@cnt%
57 }%
58 % Convertisseurs
59 \def\romannumeralz#1{%
60 \ifnum#1>\z@\romannumeral#1\else\number#1\fi%
61 }%
62 % Moteur
63 % Constantes
64 % Couleurs
65 %\definecolor{colVlnBowU}{rgb}{0.24,0.92,0.24}%
66 %\definecolor{colVlnBowD}{rgb}{0.80,0,0}%
67 %\definecolor{colVlnBowU}{rgb}{0.30,0.75,0.75}%
68 \definecolor{colVlnBowU}{gray}{0.50}%
69 \definecolor{colVlnBowD}{gray}{0}%
70 \definecolor{colVlnBowN}{gray}{1}%
71 \definecolor{colVlnBowCord}{rgb}{0,1,0}%
72 \definecolor{colVlnBowFinger}{rgb}{0,0,0}%
73 \definecolor{colVlnBowFingerCord0}{rgb}{0,0,0}%
74 \definecolor{colVlnBowFingerCord1}{rgb}{0,0.66,0}%
75 \definecolor{colVlnBowFingerCord2}{rgb}{0,0,1}%
76 \definecolor{colVlnBowFingerCord3}{rgb}{1,0,0}%
77 \definecolor{colVlnBowName}{rgb}{1,0,0}%
78 \definecolor{colVlnBowNameOctave0}{rgb}{0,0,0}%
79 \definecolor{colVlnBowNameOctave1}{rgb}{0,0.66,0}%
80 \definecolor{colVlnBowNameOctave2}{rgb}{0,0,1}%
81 \definecolor{colVlnBowNameOctave3}{rgb}{1,0,0}%
82 \definecolor{colVlnLineHalfToneEven}{gray}{0.98}%
83 \definecolor{colVlnLineHalfToneOdd}{gray}{1}%
84 \definecolor{colVlnLineHalfToneFifth}{gray}{0.92}%
85 \definecolor{colVlnPart}{gray}{0}%
86 \definecolor{colVlnBar}{gray}{.85}%
87 \definecolor{colVlnCrescD}{rgb}{0,0.66,0}%
88 \definecolor{colVlnCrescU}{rgb}{1,0,0}%
89 % Portée
90 % Déclarations
91 \newdimen\vlnstaffhalftonelinevdim%
92 \newskip\vlnstaffvdim%
93 \def\vlnstaffvdimpre{3.25pt}%
94 \newskip\vlnstaffintervskip%
95 \newskip\vlnstaffvskip%
96 % Initialisations
97 \def\vlnstaffhsize{\hsize}%
98 \def\vlnstaffmaxvsize{\textheight}%
99 \vlnstaffhalftonelinevdim=3pt%
100 \vlnstaffvdim=0pt\relax%
101 \vlnstaffvskip=0pt\relax%
102 \vlnstaffintervskip=\vlnstaffhalftonelinevdim\relax%
103 \multiply\vlnstaffintervskip by 2\relax%
104 \def\vlnstaffhalftoneline#1{%
105 {\color{colVlnLineHalfTone#1}\hrule depth 0pt height \vlnstaffhalftonelinevdim width \vlnstaffhsize }}%
106 \def\vlnstafftoneskip{%
107 \advance\vlnstaffvdim by\vlnstaffhalftonelinevdim%
108 \nobreak%
109 }%
110 \def\vlnstafffivehalftonelines{%
111 \vlnstaffhalftoneline{Odd}\vlnstafftoneskip%
112 \vlnstaffhalftoneline{Even}\vlnstafftoneskip%
113 \vlnstaffhalftoneline{Odd}\vlnstafftoneskip%
114 \vlnstaffhalftoneline{Even}\vlnstafftoneskip%
115 \vlnstaffhalftoneline{Fifth}\vlnstafftoneskip%
116 }%
117 \def\vlnstaffallhalftonelines{%
118 \vlnstaffhalftoneline{Fifth}\vlnstafftoneskip%
119 \vlnstafffivehalftonelines%
120 \vlnstafffivehalftonelines%
121 \vlnstafffivehalftonelines%
122 \vlnstafffivehalftonelines%
123 \vlnstafffivehalftonelines%
124 }%
125 \def\vlnstaff{%
126 \nobreak\vskip\vlnstaffvdimpre%
127 \nobreak\vskip\vlnstaffvdim%
128 \advance\vlnstaffvskip by\vlnstaffvdim\relax%
129 \count@\vlnstaffvskip\relax%
130 \advance\count@ by\vlnstaffvdim\relax%
131 \ifnum\count@>\vlnstaffmaxvsize%
132 \vlnstaffvskip=0pt\relax%
133 \break%
134 \else%
135 \advance\vlnstaffvskip by\vlnstaffintervskip\relax%
136 \nobreak\vskip\vlnstaffintervskip%
137 \fi%
138 \vlnnotehskip=0pt\relax%
139 \vlnstaffvdim=0pt\relax%
140 \vlnstaffallhalftonelines%
141 \advance\vlnstaffvdim by\vlnstaffhalftonelinevdim%
142 \nobreak\vskip-\vlnstaffvdim%
143 }%
144 % Notes
145 % Déclarations
146 % Variables
147 \newskip\vlnnotevskip%
148 \newskip\vlnnotehskip%
149 \newdimen\dimen@%
150 \newdimen\dimen@@%
151 \newdimen\vlnnotevdim%
152 \newdimen\vlnnotevdimmore%
153 \newdimen\vlnnotehdim%
154 \newdimen\vlnnotehdimbase%
155 \newcount\vlnlastfinger%
156 \newcount\vlnlastposbase%
157 \newcount\vlnlastposunit%
158 \newcount\vlnlastposoctave%
159 \def\vlnlastname{}%
160 \def\vlnlastletter{}%
161 \def\vlnlastshift{}%
162 \newcount\vlnnotepos%
163 \newcount\vlnlastpos%
164 \gdef\vlncrescleft{}%
165 \gdef\vlncrescright{}%
166 % Initialisations
167 \vlnnotevskip=0pt\relax%
168 \vlnnotehskip=0pt\relax%
169 \vlnnotevdim=\vlnstaffhalftonelinevdim%
170 \vlnnotevdimmore=1pt\relax%
171 \vlnnotehdimbase=2cm\relax%
172 %\advance\vlnnotevdim by\vlnnotevdimmore%
173 %\advance\vlnnotevdim by\vlnnotevdimmore%
174 \def\vlnlastbow{}%
175 \def\vlnlastrealbow{}%
176 \def\vlnlastcord{}%
177 \def\vlnlasttimenum{}%
178 \def\vlnlasttimeden{}%
179 \def\vlnnotehdimmodetim{t}%
180 \def\vlnnotehdimmodetxt{}%
181 \parindent=0pt\relax%
182 \parskip=0pt\relax%
183 \parfillskip=0pt\relax%
184 \def\vlnlastposfinger{%
185 \csname vlnlastposfinger\romannumeralz\vlnlastfinger\endcsname%
186 }%
187 \def\vlnlastfingerpos{%
188 \csname vlnlastfingerpos\romannumeralz\vlnlastpos\endcsname%
189 }%
190 \def\vlnlastposname{%
191 \csname vlnlastposname\romannumeralz\vlnlastpos\endcsname%
192 }%
193 \def\vlntimefrac#1/#2{%
194 \leavevmode%
195 \hbox{#1}%
196 \kern-.4ex\lower.3ex\hbox{\bfseries\tiny /}%
197 \kern-.3ex\lower.6ex\hbox{#2}%
198 }%
199 \def\vlndoatnote#1#2#3#4{%
200 \nointerlineskip%
201 \vlnnotevskip=0pt\relax%
202 \advance\vlnnotevskip by\vlnstaffhalftonelinevdim\relax%
203 \multiply\vlnnotevskip by#1\relax%
204 \advance\vlnnotevskip by\vlnstaffhalftonelinevdim\relax%
205 %\advance\vlnnotevskip by-\vlnnotevdimmore\relax%
206 \nobreak\vskip\vlnnotevskip\relax%
207 \vrule depth 0pt height 0pt width \vlnnotehskip\relax%
208 \setbox0=#3%
209 \advance\vlnnotevskip by \ht0\relax%
210 #2%
211 \box0%
212 #4%
213 \nobreak\vskip-\vlnnotevskip\relax%
214 \nointerlineskip%
215 }%
216 \def\vlnnextnote{%
217 \advance\vlnnotehskip by\vlnnotehdim\relax%
218 }%
219 \def\vlnnotedraw crd#1pos#2fgr#3bow#4nam#5tim#6#7{%
220 % Position
221 \ifthenelse{\equal{#2}{.}}%
222 {}%
223 {\vlnlastpos#2\relax}%
224 % Durée
225 \ifthenelse{\equal{#6}{.}}%
226 {}%
227 {\def\vlnlasttimenum{#6}}%
228 \ifthenelse{\equal{#7}{.}}%
229 {}%
230 {\def\vlnlasttimeden{#7}}%
231 \vlnnotehdim\vlnnotehdimbase%
232 \ifthenelse{\equal{}{\vlnnotehdimmodetim}}%
233 {}%
234 {\multiply\vlnnotehdim by\vlnlasttimenum\relax%
235 \divide\vlnnotehdim by\vlnlasttimeden\relax%
236 }%
237 % Automatic staff break
238 \count@\vlnnotehskip\relax%
239 \advance\count@ by\vlnnotehdim\relax%
240 \ifnum\count@>\vlnstaffhsize\vlnstaff\fi%
241 \def\vlnnotehdimmodetxtdo{%
242 \vbox to0pt{%
243 \ifthenelse{\equal{}{\vlnnotehdimmodetxt}}%
244 {\null}%
245 {%
246 \setbox0=\hbox{%
247 \ifthenelse{\equal{\vlnlasttimeden}{1}}%
248 {{\vlntimefont{\vlnlasttimenum}}}%
249 {\vlntimefrac{\vlntimefont{\vlnlasttimenum}}/{\vlntimefont{\vlnlasttimeden}}}%
250 }%
251 \nobreak\vskip\vlnnotevdim\relax%
252 \nobreak\vskip0.2mm\relax%
253 \nobreak\hskip\vlnnotehdim\relax%
254 \nobreak\hskip-\wd0\relax%
255 \dp0=0pt\relax%
256 \box0}%
257 }%
258 }%
259 \ifthenelse{\equal{#6/#7}{\vlnlasttimenum/\vlnlasttimeden}}%
260 {}%
261 {\vlndoatnote{\vlnlastpos}%
262 {}%
263 {\vlnnotehdimmodetxtdo}%
264 {}%
265 }%
266 % Archet
267 \ifthenelse{\equal{#4}{C}}%
268 {\ifthenelse{\equal{U}{\vlnlastrealbow}}%
269 {\def\vlnlastbow{D}}%
270 {\def\vlnlastbow{U}}}%
271 {\ifthenelse{\equal{#4}{.}}%
272 {\def\vlnlastbow{\vlnlastrealbow}}%
273 {\def\vlnlastbow{#4}}}%
274 \ifthenelse{\equal{\vlnlastbow}{N}}%
275 {}%
276 {\edef\vlnlastrealbow{\vlnlastbow}}%
277 \vlndoatnote{\vlnlastpos}%
278 {\begingroup\expandafter\color{colVlnBow\vlnlastbow}}%
279 {%
280 \hbox{%
281 \ifthenelse{\equal{\vlnlastbow}{N}}
282 {}%
283 {%
284 \vrule depth 0pt height \vlnnotevdim width \vlnnotehdim\relax%
285 \nobreak\hskip-\vlnnotehdim\relax%
286 \dimen@\vlnnotevdim%
287 \divide\dimen@ by3\relax%
288 \dimen@@\vlnnotehdim%
289 \divide\dimen@@ by2\relax%
290 \ifthenelse{\equal{\vlncrescleft}{}}%
291 {%
292 \ifthenelse{\equal{\vlncrescright}{}}%
293 {%
294 }%
295 {%
296 \vrule depth 0pt height 0pt width \dimen@@\relax%
297 \color{colVlnCresc\vlncrescright}%
298 \vrule depth 0pt height \dimen@ width \dimen@@\relax%
299 }%
300 }%
301 {%
302 \ifthenelse{\equal{\vlncrescright}{}}%
303 {%
304 \color{colVlnCresc\vlncrescleft}%
305 \vrule depth 0pt height \dimen@ width \dimen@@\relax%
306 }%
307 {%
308 \color{colVlnCresc\vlncrescleft}%
309 \vrule depth 0pt height \dimen@ width \dimen@@\relax%
310 \color{colVlnCresc\vlncrescright}%
311 \vrule depth 0pt height \dimen@ width \dimen@@\relax%
312 }%
313 }%
314 \global\let\vlncrescleft\vlncrescright%
315 }%
316 }%
317 }%
318 {\endgroup}%
319 % Cordes
320 \ifthenelse{\equal{#1}{\vlnlastcord}}%
321 {}%
322 {\ifthenelse{\equal{#1}{.}}%
323 {}%
324 {\def\vlnlastcord{#1}%
325 %\vlndoatnote{\vlnlastpos}%
326 % {}%
327 % {\vbox to0pt{%
328 % \setbox0=\hbox{{\vlncordfont{%
329 % \count@#1\relax%
330 % \advance\count@ by1\relax%
331 % \ifcase\count@%
332 % \or 0\or 1\or 2\or 3%
333 % \fi}}}%
334 % %\nobreak\vskip\vlnnotevdim\relax%
335 % %\nobreak\vskip0.2mm\relax%
336 % \nobreak\vskip-0.2mm\relax%
337 % \nobreak\vskip-\ht0\relax%
338 % \nobreak\hskip\vlnnotehdim\relax%
339 % \nobreak\hskip-\wd0\relax%
340 % \box0}}%
341 % {}%
342 }%
343 }%
344 % Doigts
345 \ifthenelse{\equal{#3}{.}}%
346 {}%
347 {\vlnlastfinger#3\relax}%
348 \ifthenelse{\equal{\vlnlastbow}{N}%
349 % \OR\equal{\the\vlnlastfinger}{\vlnlastfingerpos}%
350 % \AND\equal{\the\vlnlastpos}{\vlnlastposfinger}%
351 % \AND\equal{\the\vlnlastcord}{\thevlnlastlastcord}%
352 }%
353 {}%
354 {%
355 \expandafter\edef\csname vlnlastfingerpos\romannumeralz\vlnlastpos\endcsname{\the\vlnlastfinger}%
356 \expandafter\edef\csname vlnlastposfinger\romannumeralz\vlnlastfinger\endcsname{\the\vlnlastpos}%
357 \vlndoatnote{\vlnlastpos}%
358 {}%
359 {\vbox to0pt{%
360 \setbox0=\hbox{{\vlnfingerfont{\the\vlnlastfinger}}}%
361 \nobreak\vskip\vlnnotevdim\relax%
362 \nobreak\vskip0.2mm\relax%
363 \dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
364 \box0}}%
365 {}%
366 }%
367 % Nom
368 \ifthenelse{\equal{#5}{\vlnlastname}\AND\equal{#2}{\vlnlastpos}}%
369 {}%
370 {%
371 \def\vlnlastname{#5}%
372 \expandafter\edef\csname vlnlastposname\romannumeralz\vlnlastpos\endcsname{#5}%
373 \ifthenelse{\equal{\vlnlastbow}{N}}%
374 {}%
375 {%\edef\vlnlastname{#5}%
376 \vlndoatnote{\vlnlastpos}%
377 {}%
378 {\vbox to0pt{%
379 \setbox0=\hbox{{\vlnnamefont{#5}}}%
380 \nobreak\vskip-0.275mm\relax%
381 \nobreak\vskip-\ht0\relax%
382 %\vskip-\dp0\relax%
383 \dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
384 \box0}}%
385 {}%
386 }%
387 }%
388 \@ifnextchar&{%
389 \def\next&{%
390 \nointerlineskip%
391 }%
392 \next%
393 }{%
394 \vlnnextnote%
395 \nointerlineskip%
396 }%
397 }%
398 % Cordes
399 \def\vlncordposi{0}% G
400 \def\vlncordposii{7}% D
401 \def\vlncordposiii{14}% A
402 \def\vlncordposiv{21}% E
403 % Crochets
404 \def\vlnnotehook{}%
405 % Demi-tons alphabétiques sans modification
406 \expandafter\def\csname vlnnotetoneofnameG=\endcsname{0}%
407 \expandafter\def\csname vlnnotetoneofnameG+\endcsname{1}%
408 \expandafter\def\csname vlnnotetoneofnameA-\endcsname{1}%
409 \expandafter\def\csname vlnnotetoneofnameA=\endcsname{2}%
410 \expandafter\def\csname vlnnotetoneofnameA+\endcsname{3}%
411 \expandafter\def\csname vlnnotetoneofnameB-\endcsname{3}%
412 \expandafter\def\csname vlnnotetoneofnameB=\endcsname{4}%
413 \expandafter\def\csname vlnnotetoneofnameB+\endcsname{5}%
414 \expandafter\def\csname vlnnotetoneofnameC-\endcsname{4}%
415 \expandafter\def\csname vlnnotetoneofnameC=\endcsname{5}%
416 \expandafter\def\csname vlnnotetoneofnameC+\endcsname{6}%
417 \expandafter\def\csname vlnnotetoneofnameD-\endcsname{6}%
418 \expandafter\def\csname vlnnotetoneofnameD=\endcsname{7}%
419 \expandafter\def\csname vlnnotetoneofnameD+\endcsname{8}%
420 \expandafter\def\csname vlnnotetoneofnameE-\endcsname{8}%
421 \expandafter\def\csname vlnnotetoneofnameE=\endcsname{9}%
422 \expandafter\def\csname vlnnotetoneofnameE+\endcsname{10}%
423 \expandafter\def\csname vlnnotetoneofnameF-\endcsname{9}%
424 \expandafter\def\csname vlnnotetoneofnameF=\endcsname{10}%
425 \expandafter\def\csname vlnnotetoneofnameF+\endcsname{11}%
426 \expandafter\def\csname vlnnotetoneofnameG-\endcsname{11}%
427 % Modifications
428 \expandafter\def\csname vlnshiftsymbol-\endcsname{\kern-0.7pt$\flat$}%
429 \expandafter\def\csname vlnshiftsymbol=\endcsname{}%
430 \expandafter\def\csname vlnshiftsymbol+\endcsname{\kern-0.7pt$\sharp$}%
431 \def\vlnnotedrawtonebyname#1#2#3#4#5#6{%
432 \ifthenelse{\equal{#1}{.}}%
433 {}%
434 {\vlnlastposoctave#1\relax}%
435 \ifthenelse{\equal{#2}{.}}%
436 {}%
437 {\def\vlnlastletter{#2}}%
438 \ifthenelse{\equal{#3}{.}}%
439 {}%
440 {\def\vlnlastshift{#3}}%
441 \edef\tmp{\csname vlnnotetoneofname\vlnlastletter\vlnlastshift\endcsname}%
442 \vlnnotepos\tmp%
443 \count@\vlnlastposoctave\relax%
444 \multiply\count@ by12\relax%
445 \advance\vlnnotepos by\count@%
446 \ifthenelse{\equal{#4}{.}}%
447 {\count@\vlnlastcord}%
448 {\count@#4}%
449 \advance\count@ by1\relax%
450 \advance\vlnnotepos by-\csname vlncordpos\romannumeralz\count@\endcsname%
451 \edef\nam{\vlnlastletter\csname vlnshiftsymbol\vlnlastshift\endcsname}%
452 \vlnnotedraw crd{#4}pos{\the\vlnnotepos}fgr{#5}bow{#6}nam{\nam}tim%
453 }%
454 \def\vlnpart#1{%
455 \vlndoatnote{0}%
456 {}%
457 {\vbox to0pt{%
458 \setbox0=\hbox{{\vlnpartfont{#1}}}%
459 \nobreak\vskip-0.3mm\relax%
460 \nobreak\vskip-\ht0\relax%
461 \dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
462 \box0}}%
463 {}%
464 }%
465 \def\vlnbar{%
466 \vlndoatnote{0}%
467 {}%
468 {\vbox to0pt{%
469 \dimen@\vlnstaffvdim%
470 \advance\dimen@ by -\vlnnotevdim\relax%
471 \advance\dimen@ by -\vlnnotevdim\relax%
472 \setbox0=\hbox{\color{colVlnBar}\vrule depth 0pt height \dimen@ width 0.1pt\relax}%
473 \nobreak\vskip\vlnnotevdim\relax%
474 \dp0=0pt\relax%
475 \box0}}%
476 {}%
477 }%
478 \def\vlncresc#1{%
479 \global\let\vlncrescleft\vlncrescright%
480 \xdef\vlncrescright{#1}%
481 }%