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