]> Git — Sourcephile - julm/violon-tex.git/blob - violon.sty
Ajout : support des pauses.
[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{colVlnBowU}{rgb}{0.24,0.92,0.24}%
59 \definecolor{colVlnBowD}{rgb}{1,0,0}%
60 \definecolor{colVlnBowN}{gray}{0}%
61 \definecolor{colVlnLineHalfTone}{gray}{0.90}%
62 \definecolor{colVlnLineHalfToneBase}{gray}{0.50}%
63 % Portée
64 % Déclarations
65 \newdimen\vlnstaffhalftonelinevdim%
66 \newskip\vlnstaffhalftonelinevskip%
67 \newskip\vlnstaffvdim%
68 \newskip\vlnstaffintervskip%
69 \newskip\vlnstaffvskip%
70 % Initialisations
71 \def\vlnstaffhsize{\hsize}%
72 \def\vlnstaffmaxvsize{\textheight}%
73 \vlnstaffhalftonelinevdim=0.5pt%
74 \vlnstaffhalftonelinevskip=4pt\relax%
75 \advance\vlnstaffhalftonelinevskip by-\vlnstaffhalftonelinevdim%
76 \vlnstaffvdim=0pt\relax%
77 \vlnstaffvskip=0pt\relax%
78 \vlnstaffintervskip=\vlnstaffhalftonelinevskip\relax%
79 \advance\vlnstaffintervskip by\vlnstaffhalftonelinevdim\relax%
80 \def\vlnstaffhalftoneline{%
81 {\color{colVlnLineHalfTone}\hrule depth 0pt height \vlnstaffhalftonelinevdim width \vlnstaffhsize }}%
82 \def\vlnbasehalftoneline{%
83 {\color{colVlnLineHalfToneBase}\hrule depth 0pt height \vlnstaffhalftonelinevdim width \vlnstaffhsize }}%
84 \def\vlnstafftoneskip{%
85 \advance\vlnstaffvdim by\vlnstaffhalftonelinevskip%
86 \advance\vlnstaffvdim by\vlnstaffhalftonelinevdim%
87 \nobreak\vskip\vlnstaffhalftonelinevskip%
88 }%
89 \def\vlnstafffivehalftonelines{%
90 \vlnstafftoneskip\vlnstaffhalftoneline%
91 \vlnstafftoneskip\vlnstaffhalftoneline%
92 \vlnstafftoneskip\vlnstaffhalftoneline%
93 \vlnstafftoneskip\vlnstaffhalftoneline%
94 \vlnstafftoneskip\vlnbasehalftoneline%
95 }%
96 \def\vlnstaffallhalftonelines{%
97 \vlnstafffivehalftonelines%
98 \vlnstafffivehalftonelines%
99 \vlnstafffivehalftonelines%
100 \vlnstafffivehalftonelines%
101 }%
102 \def\vlnstaff{%
103 \nobreak\vskip\vlnstaffvdim%
104 \advance\vlnstaffvskip by\vlnstaffvdim\relax%
105 \count@\vlnstaffvskip\relax%
106 \advance\count@ by\vlnstaffvdim\relax%
107 \ifnum\count@>\vlnstaffmaxvsize%
108 \vlnstaffvskip=0pt\relax%
109 \break%
110 \else%
111 \advance\vlnstaffvskip by\vlnstaffintervskip\relax%
112 \nobreak\vskip\vlnstaffintervskip%
113 \fi%
114 \vlnnotehskip=0pt\relax%
115 \vlnstaffvdim=0pt\relax%
116 \vlnbasehalftoneline%
117 \vlnstaffallhalftonelines%
118 \advance\vlnstaffvdim by\vlnstaffhalftonelinevdim%
119 \nobreak\vskip-\vlnstaffvdim%
120 }%
121 % Notes
122 % Déclarations
123 % Variables
124 \newskip\vlnnotevskip%
125 \newskip\vlnnotehskip%
126 \newdimen\vlnnotevdim%
127 \newdimen\vlnnotevdimmore%
128 \newdimen\vlnnotehdim%
129 \newdimen\vlnnotehdimbase%
130 \newcount\vlnlastfinger%
131 \newcount\vlnlastposbase%
132 \newcount\vlnlastposunit%
133 \newcount\vlnnotepos%
134 \newcount\vlnlastpos%
135 % Initialisations
136 \vlnnotevskip=0pt\relax%
137 \vlnnotehskip=0pt\relax%
138 \vlnnotevdim=\vlnstaffhalftonelinevdim%
139 \vlnnotevdimmore=1pt\relax%
140 \vlnnotehdimbase=2cm\relax%
141 \advance\vlnnotevdim by\vlnnotevdimmore%
142 \advance\vlnnotevdim by\vlnnotevdimmore%
143 \def\vlnlastbow{}%
144 \def\vlnlastcord{}%
145 \def\vlnlasttimenum{}%
146 \def\vlnlasttimeden{}%
147 \def\vlnnotehdimmodetim{1}%
148 \def\vlnnotehdimmodetxt{}%
149 \parindent=0pt\relax%
150 \parskip=0pt\relax%
151 \parfillskip=0pt\relax%
152 \def\vlnlastposfinger{%
153 \csname vlnlastposfinger\romannumeral\vlnlastfinger\endcsname%
154 }%
155 \def\vlnlastfingerpos{%
156 \csname vlnlastfingerpos\romannumeral\vlnlastpos\endcsname%
157 }%
158 \def\vlntimefrac#1/#2{%
159 \leavevmode%
160 \hbox{#1}%
161 \kern-.4ex\lower.3ex\hbox{\bfseries\tiny /}%
162 \kern-.3ex\lower.6ex\hbox{#2}%
163 }%
164 \def\vlndoatnote#1#2#3#4{%
165 \nointerlineskip%
166 \vlnnotevskip\vlnstaffhalftonelinevskip%
167 \advance\vlnnotevskip by\vlnstaffhalftonelinevdim\relax%
168 \multiply\vlnnotevskip by#1\relax%
169 \advance\vlnnotevskip by-\vlnnotevdimmore\relax%
170 \nobreak\vskip\vlnnotevskip\relax%
171 \nobreak\vskip-\vlnnotevskip\relax%
172 \nobreak\vskip\vlnnotevskip\relax%
173 \vrule depth 0pt height 0pt width \vlnnotehskip\relax%
174 \setbox0=#3%
175 \advance\vlnnotevskip by \ht0\relax%
176 #2%
177 \box0%
178 #4%
179 \nobreak\vskip-\vlnnotevskip\relax%
180 \nointerlineskip%
181 }%
182 \def\vlnnextnote{%
183 \advance\vlnnotehskip by\vlnnotehdim\relax%
184 }%
185 \def\vlnnotedraw crd#1pos#2fgr#3bow#4tim#5#6{%
186 % Position
187 \ifthenelse{\equal{#2}{.}}%
188 {}%
189 {\vlnlastpos#2\relax}%
190 % Durée
191 \ifthenelse{\equal{#5}{.}}%
192 {}%
193 {\def\vlnlasttimenum{#5}}%
194 \ifthenelse{\equal{#6}{.}}%
195 {}%
196 {\def\vlnlasttimeden{#6}}%
197 \vlnnotehdim\vlnnotehdimbase%
198 \ifthenelse{\equal{}{\vlnnotehdimmodetim}}%
199 {}%
200 {\multiply\vlnnotehdim by\vlnlasttimenum\relax%
201 \divide\vlnnotehdim by\vlnlasttimeden\relax%
202 }%
203 % Automatic staff break
204 \count@\vlnnotehskip\relax%
205 \advance\count@ by\vlnnotehdim\relax%
206 \ifnum\count@>\vlnstaffhsize\vlnstaff\fi%
207 \ifthenelse{\equal{#5/#6}{\vlnlasttimenum/\vlnlasttimeden}}%
208 {}%
209 {\vlndoatnote{\vlnlastpos}%
210 {}%
211 {%
212 \ifthenelse{\equal{}{\vlnnotehdimmodetxt}}%
213 {}%
214 {\vbox to0pt{%
215 \setbox0=\hbox{%
216 \ifthenelse{\equal{\vlnlasttimeden}{1}}%
217 {{\vlntimefont{\vlnlasttimenum}}}%
218 {\vlntimefrac{\vlntimefont{\vlnlasttimenum}}/{\vlntimefont{\vlnlasttimeden}}}%
219 }%
220 \nobreak\vskip\vlnnotevdim\relax%
221 \nobreak\vskip0.2mm\relax%
222 \nobreak\hskip\vlnnotehdim\relax%
223 \nobreak\hskip-\wd0\relax%
224 \dp0=0pt\relax%
225 \box0}%
226 }%
227 }%
228 {}%
229 }%
230 % Archet
231 \ifthenelse{\equal{#4}{C}}%
232 {\ifthenelse{\equal{U}{\vlnlastbow}}%
233 {\def\vlnlastbow{D}}%
234 {\def\vlnlastbow{U}}}%
235 {\ifthenelse{\equal{#4}{.}}%
236 {}%
237 {\def\vlnlastbow{#4}}}%
238 \vlndoatnote{\vlnlastpos}%
239 {\begingroup\expandafter\color{colVlnBow\vlnlastbow}}%
240 {%
241 \hbox{%
242 \vrule depth 0pt height \vlnnotevdim width \vlnnotehdim\relax%
243 }%
244 }%
245 {\endgroup}%
246 % Doigts
247 \ifthenelse{\equal{#3}{.}}%
248 {}%
249 {\vlnlastfinger#3\relax}%
250 \ifthenelse{\equal{\the\vlnlastfinger}{\vlnlastfingerpos}\AND\equal{\the\vlnlastpos}{\vlnlastposfinger}}%
251 {}%
252 {%
253 \expandafter\edef\csname vlnlastfingerpos\romannumeral\vlnlastpos\endcsname{\the\vlnlastfinger}\relax%
254 \expandafter\edef\csname vlnlastposfinger\romannumeral\vlnlastfinger\endcsname{\the\vlnlastpos}\relax%
255 \vlndoatnote{\vlnlastpos}%
256 {}%
257 {\vbox to0pt{%
258 \setbox0=\hbox{{\vlnfingerfont{\the\vlnlastfinger}}}%
259 \nobreak\vskip-0.2mm\relax%
260 \vskip-\ht0\relax%
261 %\vskip-\dp0\relax%
262 \dp0=0pt\relax% NOTE: to prevent fonts like pnc to mess up the vertical alignment
263 \box0}}%
264 {}%
265 }%
266 % Cordes
267 \ifthenelse{\equal{#1}{\vlnlastcord}}%
268 {}%
269 {\ifthenelse{\equal{#1}{.}}%
270 {}%
271 {\def\vlnlastcord{#1}%
272 \vlndoatnote{\vlnlastpos}%
273 {}%
274 {\vbox to0pt{%
275 \setbox0=\hbox{{\vlncordfont{%
276 \count@#1\relax%
277 \advance\count@ by1\relax%
278 \ifcase\count@%
279 \or 0\or I\or II\or III%
280 \fi}}}%
281 \nobreak\vskip\vlnnotevdim\relax%
282 \nobreak\vskip0.2mm\relax%
283 \box0}}%
284 {}%
285 }%
286 }%
287 \vlnnextnote%
288 \nointerlineskip%
289 }%
290 % Cordes
291 \def\vlncordposi{0}% G
292 \def\vlncordposii{7}% D
293 \def\vlncordposiii{14}% A
294 \def\vlncordposiv{21}% E
295 % Crochets
296 \def\vlnnotehook{}%
297 \def\vlnnotedrawtone#1#2#3#4#5{%
298 \ifthenelse{\equal{#1}{.}}%
299 {}%
300 {\vlnlastposbase#1\relax}%
301 \ifthenelse{\equal{#2}{.}}%
302 {}%
303 {\vlnlastposunit#2\relax}%
304 \ifthenelse{\equal{#3}{.}}%
305 {\vlnnotepos\vlnlastcord\relax}%
306 {\vlnnotepos#3\relax}%
307 \advance\vlnnotepos by1\relax%
308 \expandafter\vlnnotepos-\csname vlncordpos\romannumeral\vlnnotepos\endcsname\relax%
309 \ifthenelse{\equal{\the\vlnlastposbase}{0}}%
310 {\advance\vlnnotepos by\vlnlastposunit\relax}%
311 {\edef\tmp{\the\vlnlastposbase\the\vlnlastposunit}%
312 \advance\vlnnotepos by\tmp\relax}%
313 \vlnnotehook%
314 \vlnnotedraw crd{#3}pos{\the\vlnnotepos}fgr{#4}bow{#5}tim%
315 }%
316 \def\vlnnoteshift#1{%
317 \count@\vlnnotepos%
318 \modulo{\count@}{#1}%
319 \advance\count@ by1\relax%
320 \edef\tmp{\csname vlnnoteshift\romannumeral\count@\endcsname}%
321 \ifthenelse{\equal{\tmp}{}}%
322 {}%
323 {\advance\vlnnotepos by\tmp\relax}%
324 }%