Debian Codegraph @

texmf-dist/source/latex/xpiano/xpiano.dtx

raw
1 % \iffalse meta-comment
2 %<*internal>
3 \iffalse
4 %</internal>
5 %<*readme>
6 xpiano - An extension of piano.sty by Émile Daneault
7 ====================================================
8
9 This package is an extension of piano.sty, written in expl3
10 in answer to a couple of questions on TeX.StackExchange
11
12 http://tex.stackexchange.com/questions/162184/
13 http://tex.stackexchange.com/questions/246276/
14
15 It features extended syntax and several options, like setting
16 the color, adding numbers for pitch analysis, one or two
17 octaves and others.
18
19 Installation
20 ------------
21
22 The package is supplied in .dtx format; run 'tex xpiano.dtx'
23 for extracting the style file and 'pdflatex xpiano.dtx' for
24 building the documentation.
25
26 Note that this package requires LaTeX3 support.
27
28 License
29 -------
30
31 This package is licensed under the LPPL license.
32 %</readme>
33 %<*internal>
34 \fi
35 \def\nameofplainTeX{plain}
36 \ifx\fmtname\nameofplainTeX\else
37 \expandafter\begingroup
38 \fi
39 %</internal>
40 %<*install>
41 \input l3docstrip.tex
42 \keepsilent
43 \askforoverwritefalse
44 \preamble
45 ---------------------------------------------------------------
46 The xpiano package --- Extension of piano.sty by \string\'Emile Daneault
47 Maintained by Enrico Gregorio
48 Email: enrico DOT gregorio AT univr DOT it
49 Released under the LaTeX Project Public License v1.3c or later
50 See http://www.latex-project.org/lppl.txt
51 ---------------------------------------------------------------
52 \endpreamble
53 \postamble
54 Copyright (C) 2015 by
55 Enrico Gregorio <enrico DOT gregorio AT univr DOT it>
56
57 It may be distributed and/or modified under the conditions of
58 the LaTeX Project Public License (LPPL), either version 1.3c of
59 this license or (at your option) any later version. The latest
60 version of this license is in the file:
61 http://www.latex-project.org/lppl.txt
62
63 This work is "maintained" (as per LPPL maintenance status) by
64 Enrico Gregorio.
65
66 This work consists of the file xpiano.dtx
67 and the derived files xpiano.pdf,
68 xpiano.sty and
69 xpiano.ins.
70 \endpostamble
71 \usedir{tex/latex/xpiano}
72 \generate{
73 \file{\jobname.sty}{\from{\jobname.dtx}{package}}
74 }
75 %</install>
76 %<install>\endbatchfile
77 %<*internal>
78 \usedir{source/latex/xpiano}
79 \generate{
80 \file{\jobname.ins}{\from{\jobname.dtx}{install}}
81 }
82 \nopreamble\nopostamble
83 \usedir{doc/latex/xpiano}
84 \generate{
85 \file{README.txt}{\from{\jobname.dtx}{readme}}
86 }
87 \ifx\fmtname\nameofplainTeX
88 \expandafter\endbatchfile
89 \else
90 \expandafter\endgroup
91 \fi
92 %</internal>
93 %<*driver|package>
94 \RequirePackage{expl3,xparse}
95 %</driver|package>
96 %<*driver>
97 \documentclass{l3doc}
98 \usepackage{booktabs,array,xpiano}
99 %\DisableImplementation
100 \begin{document}
101 \DocInput{\jobname.dtx}
102 \end{document}
103 %</driver>
104 % \fi
105 %
106 %\GetFileInfo{\jobname.sty}
107 %
108 %\title{^^A
109 % \textsf{xpiano} --- An extension of \pkg{piano.sty} \\
110 % (originally written by \'Emile Daneault)\thanks{^^A
111 % This file describes \fileversion, last revised \filedate.^^A
112 % }^^A
113 %}
114 %\author{^^A
115 % Enrico Gregorio\thanks
116 % {^^A
117 % Email: \texttt{enrico DOT gregorio AT univr DOT it}^^A
118 % }^^A
119 %}
120 %\date{Released \filedate}
121 %
122 %\maketitle
123 %
124 % \changes{v1.0}{2015/05/23}{First public release}
125 %
126 %\begin{abstract}
127 % The package provides macros for typesetting virtual keyboards
128 % limited to two octaves, for showing notes represented by a
129 % colored circle. Optionally the number used for pitch analysis
130 % can be shown.
131 %\end{abstract}
132 %
133 %\tableofcontents
134 %
135 %\begin{documentation}
136 %
137 %\section{Introduction}
138 %
139 % Simple keyboard representations can be useful for people involved
140 % in music. This package builds upon \pkg{piano.sty} by \'Emile
141 % Daneault (available on CTAN), adding several features:
142 %\begin{itemize}
143 % \item the number of notes is arbitrary;
144 % \item the color of the circles is customizable;
145 % \item the number used for pitch analysis can be shown;
146 % \item the width of the keys and the length of the black keys
147 % are customizable;
148 % \item it's possible to show one or two octaves, optionally
149 % adding a trailing C;
150 %\end{itemize}
151 % The package provides the commands
152 %\begin{itemize}
153 % \item \cs{keyboard}\oarg{options}\marg{notes}
154 % \item \cs{keyboardsetup}\marg{options}
155 % \item \cs{Keyboard} with up to seven optional arguments
156 %\end{itemize}
157 % The last command is intended for users of \pkg{piano.sty}
158 % who can recycle their diagrams by just changing the lowercase
159 % \cs{keyboard} into \cs{Keyboard} with no other change.
160 %
161 %\section{Usage}
162 %
163 % The basic command is \cs{keyboard}, which takes as mandatory
164 % argument the list of notes to mark. The notes can be expressed in
165 % different ways:
166 %\begin{itemize}
167 % \item the convention of \pkg{piano.sty} where they are\\
168 % \texttt{Co Cso Do Dso Eo Fo Fso Go Gso Ao Aso Bo}\\
169 % \texttt{Ct Cst Dt Dst Et Ft Fst Gt Gst At Ast Bt}
170 % \item the German names\\
171 % \texttt{C~~Ciss~~D~~Diss~~E~~F~~Fiss~~G~~Giss~~A~~Aiss~~B}\\
172 % \texttt{C'~Ciss' D' Diss' E' F' Fiss' G' Giss' A' Aiss' B'}
173 % \item the English names\\
174 % \texttt{C~~Cs~~D~~Ds~~E~~F~~Fs~~G~~Gs~~A~~As~~B}\\
175 % \texttt{C' Cs' D' Ds' E' F' Fs' G' Gs' A' As' B'}
176 % \item the ``pitch analysis'' convention\\
177 % \texttt{0~~1~~2~~3~~4~~5~~6~~7~~8~~9~~10~~11}\\
178 % \texttt{0' 1' 2' 3' 4' 5' 6' 7' 8' 9' 10' 11'}
179 %\end{itemize}
180 % In the lists above, the lines denote the first and second octaves,
181 % respectively. For the German style names, the enharmonic equivalents
182 % are also available, \texttt{Dess Ess Gess Ass Bess} (with the primed
183 % correspondents).
184 %
185 % The example in the documentation of \pkg{piano.sty} can so be input
186 % in any of the following equivalent forms
187 % \DescribeMacro{\keyboard}\DescribeMacro{\Keyboard}
188 %\begin{flushleft}\ttfamily
189 % \cs{Keyboard}[Co][Eo][Gso][Ct][Et]\\
190 % \cs{keyboard}\{Co,Eo,Gso,Ct,Et\}\\
191 % \cs{keyboard}\{C,E,Giss,C',E'\}\\
192 % \cs{keyboard}\{C,E,Gs,C',E'\}\\
193 % \cs{keyboard}\{0,4,8,0',4'\}
194 %\end{flushleft}
195 % producing the following diagram
196 %\begin{center}
197 % \keyboard{Co,Eo,Gso,Ct,Et}
198 %\end{center}
199 %
200 % Each \cs{keyboard} command can receive an optional argument, where
201 % options for drawing the keyboard are set with a key-value syntax.
202 % The keys are listed in table~\ref{tab-keys}. As usual, the boolean
203 % valued keys can be simply specified by name, the \texttt{=true}
204 % value is implicit. The default \texttt{pianodefault} color is
205 % defined as in \pkg{piano.sty} by \verb|\definecolor{pianodefault}{RGB}{255,127,0}|.
206 %
207 %\begin{table}[htp]
208 % \centering\small
209 % \caption{The keys for setup}\label{tab-keys}
210 % \medskip
211 %\begin{tabular}{>{\ttfamily}lll>{\raggedright\arraybackslash}p{.4\textwidth}}
212 % \toprule
213 % Key & Type & Default & Explanation \\
214 % \midrule
215 % color & Literal & \texttt{pianodefault} & The color of the note markers \\
216 % single & Boolean & \texttt{false} & Draw just one octave \\
217 % ext & Boolean & \texttt{false} & Add a trailing C \\
218 % size & Dimension & \texttt{0.5cm} & The width of a white key \\
219 % height & Numeric & \texttt{4} & The ratio between height and width of white keys \\
220 % ratio & Numeric & \texttt{0.75} & The ratio between the height of the black and the white keys \\
221 % numbers & Boolean & \texttt{false} & Show the pitch analysis number \\
222 % font & Literal & \cs{tiny} & The font specification for the number \\
223 % numbercolor & Literal & \texttt{black} & The color of the numbers \\
224 % 10 & Literal & \texttt{10} & The representation of the number~10 \\
225 % 11 & Literal & \texttt{11} & The representation of the number~11 \\
226 % \bottomrule
227 %\end{tabular}
228 %\end{table}
229 %
230 % The settings to the key in the optional argument to \cs{keyboard} is
231 % local to the diagram being drawn. For instance, the following input
232 % will mark all possible notes in one octave with $t$ and $e$ for ten and eleven as
233 % numbers:
234 %\begin{flushleft}\ttfamily
235 % \cs{keyboard}[\\
236 % ~~single,\\
237 % ~~ext,\\
238 % ~~size=1cm,\\
239 % ~~font=\cs{small},\\
240 % ~~numbers,\\
241 % ~~ratio=0.67,\\
242 % ~~10=\$t\$, 11=\$e\$,\\
243 % ]\{C,Cs,D,Ds,E,F,Fs,G,Gs,A,As,B,C'\}
244 %\end{flushleft}
245 %\begin{center}
246 % \keyboard[
247 % single,
248 % ext,
249 % size=1cm,
250 % font=\small,
251 % numbers,
252 % ratio=0.67,
253 % 10=$t$, 11=$e$,
254 % ]{C,Cs,D,Ds,E,F,Fs,G,Gs,A,As,B,C'}
255 %\end{center}
256 %
257 % \DescribeMacro{\keyboardsetup}
258 % The \cs{keyboardsetup} command can be used to set the options from
259 % one point on; the best place is of course the preamble, so the
260 % choice will affect all diagrams. However this command obeys the
261 % usual scoping rules. For instance, if you want most of your diagrams
262 % to have the pitch numbers and be larger than the standard ones, you
263 % can say in the preamble
264 %\begin{flushleft}\ttfamily
265 % \cs{keyboardsetup}\{\\
266 % ~~numbers,\\
267 % ~~size=0.8cm,\\
268 % ~~ratio=0.67,\\
269 % ~~font=\cs{small},\\
270 % ~~10=\$t\$, 11=\$e\$,\\
271 % \}
272 %\end{flushleft}
273 % and specify \texttt{numbers=false} in the optional argument to
274 % \cs{keyboard} for the occasional diagram which you don't want to be
275 % numbered.
276 %
277 %\section{Cautions}
278 %
279 % The \texttt{color} key accepts any color in the syntax of the
280 % \pkg{xcolor} package. Note that the package is loaded without
281 % options, so if you want to load it with some options (or load a
282 % package that does so), you must do it before loading \pkg{xpiano}.
283 %
284 %\end{documentation}
285 %
286 %\begin{implementation}
287 %
288 %\section{Implementation}
289 %
290 % \begin{macrocode}
291 %<*package>
292 % \end{macrocode}
293 %
294 % \begin{macrocode}
295 %<@@=xpiano>
296 % \end{macrocode}
297 %
298 %\subsection{Preliminaries}
299 % The usual preliminaries, with the declaration of the package and the
300 % guard against too old versions of \LaTeX3 packages.
301 % \begin{macrocode}
302 \ProvidesExplPackage {xpiano} {2015/05/23} {1.0}
303 {An extension of piano.sty by \'Emile Daneault}
304 \@ifpackagelater { expl3 } { 2015/03/01 }
305 { }
306 {
307 \PackageError { xpiano } { Support~package~expl3~too~old }
308 {
309 You~need~to~update~your~installation~of~the~bundles~'l3kernel'~and~
310 'l3packages'.\MessageBreak
311 Loading~xpiano~will~abort!
312 }
313 \tex_endinput:D
314 }
315 % \end{macrocode}
316 % The support package and the definition of the default color
317 % \begin{macrocode}
318 \RequirePackage{xcolor}
319 \definecolor{pianodefault}{RGB}{255,127,0}
320 % \end{macrocode}
321 %
322 %\subsection{The user level commands}
323 %
324 % \begin{macro}{\keyboard,\keyboardsetup,\Keyboard,\xpiano_keyboard:nn}
325 % Nothing really complicated: just pass control to inner functions.
326 % \begin{macrocode}
327 \NewDocumentCommand{\keyboard}{ O{}m }
328 {
329 \xpiano_keyboard:nn { #1 } { #2 }
330 }
331 \NewDocumentCommand{\keyboardsetup}{ m }
332 {
333 \keys_set:nn { piano } { #1 }
334 }
335 % compatibility with piano.sty (just change \keyboard to \Keyboard)
336 \NewDocumentCommand{\Keyboard}{O{}O{}O{}O{}O{}}
337 {
338 \keyboard{#1,#2,#3,#4,#5}
339 }
340 % \end{macrocode}
341 % \end{macro}
342 %
343 %\subsection{The key-value interface}
344 % \begin{macro}{
345 % \l_@@_font_tl ,
346 % \l_@@_single_bool ,
347 % \l_@@_ext_bool ,
348 % \l_@@_size_dim ,
349 % \l_@@_height_tl ,
350 % \l_@@_numbers_bool ,
351 % \l_@@_color_tl ,
352 % \l_@@_numbercolor_tl ,
353 % \l_@@_ten ,
354 % \l_@@_eleven_tl ,
355 % \l_@@_ratio_fp ,
356 % \l_@@_width_tl ,
357 % \l_@@_blacknote_height_tl
358 % }
359 % \begin{macrocode}
360 \keys_define:nn { piano }
361 {
362 font .tl_set:N = \l_@@_font_tl,
363 single .bool_set:N = \l_@@_single_bool,
364 ext .bool_set:N = \l_@@_ext_bool,
365 size .dim_set:N = \l_@@_size_dim,
366 height .tl_set:N = \l_@@_height_tl,
367 numbers .bool_set:N = \l_@@_numbers_bool,
368 color .tl_set:N = \l_@@_color_tl,
369 numbercolor .tl_set:N = \l_@@_numbercolor_tl,
370 10 .tl_set:N = \l_@@_ten_tl,
371 11 .tl_set:N = \l_@@_eleven_tl,
372 ratio .fp_set:N = \l_@@_ratio_fp,
373 font .initial:n = \tiny,
374 single .initial:n = false,
375 single .default:n = true,
376 ext .initial:n = false,
377 ext .default:n = true,
378 size .initial:n = 0.5cm,
379 height .initial:n = 4,
380 numbers .initial:n = false,
381 numbers .default:n = true,
382 color .initial:n = {pianodefault},
383 numbercolor .initial:n = black,
384 10 .initial:n = 10,
385 11 .initial:n = 11,
386 ratio .initial:n = 0.75,
387 }
388 \tl_new:N \l_@@_width_tl
389 \tl_new:N \l_@@_blacknote_height_tl
390 % \end{macrocode}
391 % \end{macro}
392 %
393 % \subsection{The note names}
394 %
395 % We want to allow for several input conventions, so each possible
396 % note name is converted into an internal numeric representation.
397 % Using a property list variable is the best strategy.
398 % \begin{macro}{\g_@@_notes_prop}
399 % \begin{macrocode}
400 \prop_new:N \g_@@_notes_prop
401 % Daneault convention
402 \prop_gput:Nnn \g_@@_notes_prop { Co } { 0 }
403 \prop_gput:Nnn \g_@@_notes_prop { Cso } { 1 }
404 \prop_gput:Nnn \g_@@_notes_prop { Do } { 2 }
405 \prop_gput:Nnn \g_@@_notes_prop { Dso } { 3 }
406 \prop_gput:Nnn \g_@@_notes_prop { Eo } { 4 }
407 \prop_gput:Nnn \g_@@_notes_prop { Fo } { 5 }
408 \prop_gput:Nnn \g_@@_notes_prop { Fso } { 6 }
409 \prop_gput:Nnn \g_@@_notes_prop { Go } { 7 }
410 \prop_gput:Nnn \g_@@_notes_prop { Gso } { 8 }
411 \prop_gput:Nnn \g_@@_notes_prop { Ao } { 9 }
412 \prop_gput:Nnn \g_@@_notes_prop { Aso } { 10 }
413 \prop_gput:Nnn \g_@@_notes_prop { Bo } { 11 }
414 \prop_gput:Nnn \g_@@_notes_prop { Ct } { 0' }
415 \prop_gput:Nnn \g_@@_notes_prop { Cst } { 1' }
416 \prop_gput:Nnn \g_@@_notes_prop { Dt } { 2' }
417 \prop_gput:Nnn \g_@@_notes_prop { Dst } { 3' }
418 \prop_gput:Nnn \g_@@_notes_prop { Et } { 4' }
419 \prop_gput:Nnn \g_@@_notes_prop { Ft } { 5' }
420 \prop_gput:Nnn \g_@@_notes_prop { Fst } { 6' }
421 \prop_gput:Nnn \g_@@_notes_prop { Gt } { 7' }
422 \prop_gput:Nnn \g_@@_notes_prop { Gst } { 8' }
423 \prop_gput:Nnn \g_@@_notes_prop { At } { 9' }
424 \prop_gput:Nnn \g_@@_notes_prop { Ast } { 10' }
425 \prop_gput:Nnn \g_@@_notes_prop { Bt } { 11' }
426 % German (?) convention
427 \prop_gput:Nnn \g_@@_notes_prop { C } { 0 }
428 \prop_gput:Nnn \g_@@_notes_prop { Ciss } { 1 }
429 \prop_gput:Nnn \g_@@_notes_prop { Dess } { 1 }
430 \prop_gput:Nnn \g_@@_notes_prop { D } { 2 }
431 \prop_gput:Nnn \g_@@_notes_prop { Diss } { 3 }
432 \prop_gput:Nnn \g_@@_notes_prop { Ess } { 3 }
433 \prop_gput:Nnn \g_@@_notes_prop { E } { 4 }
434 \prop_gput:Nnn \g_@@_notes_prop { F } { 5 }
435 \prop_gput:Nnn \g_@@_notes_prop { Fiss } { 6 }
436 \prop_gput:Nnn \g_@@_notes_prop { Gess } { 6 }
437 \prop_gput:Nnn \g_@@_notes_prop { G } { 7 }
438 \prop_gput:Nnn \g_@@_notes_prop { Giss } { 8 }
439 \prop_gput:Nnn \g_@@_notes_prop { Ass } { 8 }
440 \prop_gput:Nnn \g_@@_notes_prop { A } { 9 }
441 \prop_gput:Nnn \g_@@_notes_prop { Aiss } { 10 }
442 \prop_gput:Nnn \g_@@_notes_prop { Bess } { 10 }
443 \prop_gput:Nnn \g_@@_notes_prop { B } { 11 }
444 \prop_gput:Nnn \g_@@_notes_prop { C' } { 0' }
445 \prop_gput:Nnn \g_@@_notes_prop { Ciss' } { 1' }
446 \prop_gput:Nnn \g_@@_notes_prop { Dess' } { 1' }
447 \prop_gput:Nnn \g_@@_notes_prop { D' } { 2' }
448 \prop_gput:Nnn \g_@@_notes_prop { Diss' } { 3' }
449 \prop_gput:Nnn \g_@@_notes_prop { Ess' } { 3' }
450 \prop_gput:Nnn \g_@@_notes_prop { E' } { 4' }
451 \prop_gput:Nnn \g_@@_notes_prop { F' } { 5' }
452 \prop_gput:Nnn \g_@@_notes_prop { Fiss' } { 6' }
453 \prop_gput:Nnn \g_@@_notes_prop { Gess' } { 6' }
454 \prop_gput:Nnn \g_@@_notes_prop { G' } { 7' }
455 \prop_gput:Nnn \g_@@_notes_prop { Giss' } { 8' }
456 \prop_gput:Nnn \g_@@_notes_prop { Ass' } { 8' }
457 \prop_gput:Nnn \g_@@_notes_prop { A' } { 9' }
458 \prop_gput:Nnn \g_@@_notes_prop { Aiss' } { 10' }
459 \prop_gput:Nnn \g_@@_notes_prop { Bess' } { 10' }
460 \prop_gput:Nnn \g_@@_notes_prop { B' } { 11' }
461 % English (?) convention
462 \prop_gput:Nnn \g_@@_notes_prop { C } { 0 }
463 \prop_gput:Nnn \g_@@_notes_prop { Cs } { 1 }
464 \prop_gput:Nnn \g_@@_notes_prop { D } { 2 }
465 \prop_gput:Nnn \g_@@_notes_prop { Ds } { 3 }
466 \prop_gput:Nnn \g_@@_notes_prop { E } { 4 }
467 \prop_gput:Nnn \g_@@_notes_prop { F } { 5 }
468 \prop_gput:Nnn \g_@@_notes_prop { Fs } { 6 }
469 \prop_gput:Nnn \g_@@_notes_prop { G } { 7 }
470 \prop_gput:Nnn \g_@@_notes_prop { Gs } { 8 }
471 \prop_gput:Nnn \g_@@_notes_prop { A } { 9 }
472 \prop_gput:Nnn \g_@@_notes_prop { As } { 10 }
473 \prop_gput:Nnn \g_@@_notes_prop { B } { 11 }
474 \prop_gput:Nnn \g_@@_notes_prop { C' } { 0' }
475 \prop_gput:Nnn \g_@@_notes_prop { Cs' } { 1' }
476 \prop_gput:Nnn \g_@@_notes_prop { D' } { 2' }
477 \prop_gput:Nnn \g_@@_notes_prop { Ds' } { 3' }
478 \prop_gput:Nnn \g_@@_notes_prop { E' } { 4' }
479 \prop_gput:Nnn \g_@@_notes_prop { F' } { 5' }
480 \prop_gput:Nnn \g_@@_notes_prop { Fs' } { 6' }
481 \prop_gput:Nnn \g_@@_notes_prop { G' } { 7' }
482 \prop_gput:Nnn \g_@@_notes_prop { Gs' } { 8' }
483 \prop_gput:Nnn \g_@@_notes_prop { A' } { 9' }
484 \prop_gput:Nnn \g_@@_notes_prop { As' } { 10' }
485 \prop_gput:Nnn \g_@@_notes_prop { B' } { 11' }
486 % Pitch analysis convention
487 \prop_gput:Nnn \g_@@_notes_prop { 0 } { 0 }
488 \prop_gput:Nnn \g_@@_notes_prop { 1 } { 1 }
489 \prop_gput:Nnn \g_@@_notes_prop { 2 } { 2 }
490 \prop_gput:Nnn \g_@@_notes_prop { 3 } { 3 }
491 \prop_gput:Nnn \g_@@_notes_prop { 4 } { 4 }
492 \prop_gput:Nnn \g_@@_notes_prop { 5 } { 5 }
493 \prop_gput:Nnn \g_@@_notes_prop { 6 } { 6 }
494 \prop_gput:Nnn \g_@@_notes_prop { 7 } { 7 }
495 \prop_gput:Nnn \g_@@_notes_prop { 8 } { 8 }
496 \prop_gput:Nnn \g_@@_notes_prop { 9 } { 9 }
497 \prop_gput:Nnn \g_@@_notes_prop { 10 } { 10 }
498 \prop_gput:Nnn \g_@@_notes_prop { 11 } { 11 }
499 \prop_gput:Nnn \g_@@_notes_prop { 0' } { 0' }
500 \prop_gput:Nnn \g_@@_notes_prop { 1' } { 1' }
501 \prop_gput:Nnn \g_@@_notes_prop { 2' } { 2' }
502 \prop_gput:Nnn \g_@@_notes_prop { 3' } { 3' }
503 \prop_gput:Nnn \g_@@_notes_prop { 4' } { 4' }
504 \prop_gput:Nnn \g_@@_notes_prop { 5' } { 5' }
505 \prop_gput:Nnn \g_@@_notes_prop { 6' } { 6' }
506 \prop_gput:Nnn \g_@@_notes_prop { 7' } { 7' }
507 \prop_gput:Nnn \g_@@_notes_prop { 8' } { 8' }
508 \prop_gput:Nnn \g_@@_notes_prop { 9' } { 9' }
509 \prop_gput:Nnn \g_@@_notes_prop { 10' } { 10' }
510 \prop_gput:Nnn \g_@@_notes_prop { 11' } { 11' }
511 % \end{macrocode}
512 % \end{macro}
513 %
514 %\subsection{The main function}
515 %
516 % \begin{macro}{\xpiano_keyboard:nn}
517 % The main function opens a group in order not to clobber the default
518 % values for the keys; then the local settings are looked at and the
519 % number of keys to draw is set according to the request of one or two
520 % octaves and the possible trailing~C\@. The vertical position for the
521 % black notes is stored in a token list for efficiency.
522 % \begin{macrocode}
523 \cs_new_protected:Npn \xpiano_keyboard:nn #1 #2
524 {
525 \group_begin:
526 \keys_set:nn { piano } { #1 }
527 \bool_if:NTF \l_@@_ext_bool
528 {
529 \tl_set:Nx \l_@@_width_tl
530 {
531 \bool_if:NTF \l_@@_single_bool { 8 } { 15 }
532 }
533 }
534 {
535 \tl_set:Nx \l_@@_width_tl
536 {
537 \bool_if:NTF \l_@@_single_bool { 7 } { 14 }
538 }
539 }
540 \tl_set:Nx \l_@@_blacknote_height_tl
541 {
542 \fp_eval:n {0.5+(1-\l_@@_ratio_fp)*\l_@@_height_tl}
543 }
544 % \end{macrocode}
545 % After the preliminary, the unit length is set and a \texttt{picture}
546 % is started and the keys are drawn.
547 % \begin{macrocode}
548 %% Draw the keyboard
549 \setlength{\unitlength}{\l_@@_size_dim}
550 \begin{picture}(\l_@@_width_tl,\l_@@_height_tl)
551 % White keys
552 \multiput(0,0)(1,0){\l_@@_width_tl}{\line(0,1){\l_@@_height_tl}}
553
554 % Boundary
555 \put(0,0){\line(0,1){\l_@@_height_tl}}
556 \put(0,0){\line(1,0){\l_@@_width_tl}}
557 \put(\l_@@_width_tl,0){\line(0,1){\l_@@_height_tl}}
558 \put(0,\l_@@_height_tl){\line(1,0){\l_@@_width_tl}}
559
560 % Black keys
561 \linethickness{.6\l_@@_size_dim}
562 \multiput(1,\l_@@_height_tl)(1,0){2}
563 {
564 \line(0,-1){\fp_eval:n {\l_@@_ratio_fp*\l_@@_height_tl}}
565 }
566 \multiput(4,\l_@@_height_tl)(1,0){3}
567 {
568 \line(0,-1){\fp_eval:n {\l_@@_ratio_fp*\l_@@_height_tl}}
569 }
570 \bool_if:NF \l_@@_single_bool
571 {
572 \multiput(8,\l_@@_height_tl)(1,0){2}
573 {
574 \line(0,-1){\fp_eval:n {\l_@@_ratio_fp*\l_@@_height_tl}}
575 }
576 \multiput(11,\l_@@_height_tl)(1,0){3}
577 {
578 \line(0,-1){\fp_eval:n {\l_@@_ratio_fp*\l_@@_height_tl}}
579 }
580 }
581 % \end{macrocode}
582 % Now the notes are drawn; the color is set to the desired one and the
583 % second argument to \cs{piano_keyboard:nn} is mapped as a comma
584 % separated list, passing control to an auxiliary function, for
585 % simplicity. Finally the picture is finished and the group is closed.
586 % \begin{macrocode}
587 % The notes
588 \color{\l_@@_color_tl}
589 \clist_map_inline:nn { #2 }
590 {
591 \@@_do_key:n { ##1 }
592 }
593 \end{picture}
594 \group_end:
595 }
596 % \end{macrocode}
597 % \end{macro}
598 % \begin{macro}{\@@_add_note:nn,\@@_do_key:n}
599 % The auxiliary function mentioned before converts the input into the
600 % internal representation using \cs{prop_item:Nn} and doing a
601 % \cs{str_case:nn} test. Another auxiliary function does the actual
602 % drawing, just in order not to complicate the code in
603 % \cs{str_case:fn}.
604 % \begin{macrocode}
605 \cs_new_protected:Npn \@@_add_note:nn #1 #2
606 {
607 \put(#2){\circle*{0.5}}
608 \bool_if:NT \l_@@_numbers_bool
609 {
610 \put(#2)
611 {
612 \makebox(0,0)
613 {
614 \normalfont\color{\l_@@_numbercolor_tl}\l_@@_font_tl #1
615 }
616 }
617 }
618 }
619
620 \cs_new_protected:Npn \@@_do_key:n #1
621 {
622 \str_case:fn { \prop_item:Nn \g_@@_notes_prop {#1} }
623 {
624 {0}{\@@_add_note:nn {0}{0.5,0.5}}
625 {2}{\@@_add_note:nn {2}{1.5,0.5}}
626 {4}{\@@_add_note:nn {4}{2.5,0.5}}
627 {5}{\@@_add_note:nn {5}{3.5,0.5}}
628 {7}{\@@_add_note:nn {7}{4.5,0.5}}
629 {9}{\@@_add_note:nn {9}{5.5,0.5}}
630 {11}{\@@_add_note:nn {\l_@@_eleven_tl}{6.5,0.5}}
631 {0'}{\@@_add_note:nn {0}{7.5,0.5}}
632 {2'}{\@@_add_note:nn {2}{8.5,0.5}}
633 {4'}{\@@_add_note:nn {4}{9.5,0.5}}
634 {5'}{\@@_add_note:nn {5}{10.5,0.5}}
635 {7'}{\@@_add_note:nn {7}{11.5,0.5}}
636 {9'}{\@@_add_note:nn {9}{12.5,0.5}}
637 {11'}{\@@_add_note:nn {\l_@@_eleven_tl}{13.5,0.5}}
638 {1}{\@@_add_note:nn {1}{1,\l_@@_blacknote_height_tl}}
639 {3}{\@@_add_note:nn {3}{2,\l_@@_blacknote_height_tl}}
640 {6}{\@@_add_note:nn {6}{4,\l_@@_blacknote_height_tl}}
641 {8}{\@@_add_note:nn {8}{5,\l_@@_blacknote_height_tl}}
642 {10}{\@@_add_note:nn {\l_@@_ten_tl}{6,\l_@@_blacknote_height_tl}}
643 {1'}{\@@_add_note:nn {1}{8,\l_@@_blacknote_height_tl}}
644 {3'}{\@@_add_note:nn {3}{9,\l_@@_blacknote_height_tl}}
645 {6'}{\@@_add_note:nn {6}{11,\l_@@_blacknote_height_tl}}
646 {8'}{\@@_add_note:nn {8}{12,\l_@@_blacknote_height_tl}}
647 {10'}{\@@_add_note:nn {\l_@@_ten_tl}{13,\l_@@_blacknote_height_tl}}
648 }
649 }
650 % \end{macrocode}
651 % \end{macro}
652 %
653 % \begin{macro}{\str_case:fn}
654 % We also need a variant of \cs{str_case:nn}
655 % \begin{macrocode}
656 \cs_generate_variant:Nn \str_case:nn {f}
657 % \end{macrocode}
658 % \end{macro}
659 % That's all, folks!
660 % \begin{macrocode}
661 %</package>
662 % \end{macrocode}
663 %
664 %\end{implementation}
665 %
666 % \PrintChanges
667 %
668 % \PrintIndex