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