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