Debian Codegraph @

texmf-dist/source/generic/musixtex/musixcrd/musixcrd.dtx

raw
1 %\iffalse
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% musixcrd - typsetting chord symbols with %%
4 %% musixtex %%
5 %% main source file contains code, doc, and examples %%
6 %% $Id$ %%
7 %% copyright 2004 , Robert Hennig %%
8 %% this code is licensed in terms of the %%
9 %% GNU Public License %%
10 %% %%
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 %\fi
13 \ifx\makeatletter\undefined\def\makeatletter{\catcode`\@=11\relax}\fi
14 \ifx\makeatother\undefined\def\makeatother{\catcode`\@=12\relax}\fi
15
16 \makeatletter% ^^A allows to use @ as ordinary letter
17 %
18 % \def\backslash{\tt\char'134}
19 % \def\musixtex{MusiX\TeX}
20 % \def\musixcrd{MusixCrd}
21 % \def\crdexample#1{{\tt\backslash c #1 }$\rightarrow$ \c #1 \medskip}
22 % \def\pmx{PMX}
23 % \title{
24 % {\bf \musixcrd} \\
25 % --- Typesetting Chord Symbols with \musixtex --- \\
26 % Version 1.1 \\
27 % {\large $Revision$}}
28 %
29 % \author{Robert Hennig\thanks{[email protected]}}
30 % \maketitle
31 % \tableofcontents
32 %
33 % \section{Usage}
34 % This package was written to ease the typesetting of chord symbols
35 % for music scores.
36 % One point of focus was that the user should have not to much to type
37 % if placing the cord. So one macro will be used which takes characters
38 % as argument which describe the chord to type. \par
39 % Thought the syntax of the chord description could easily be altered they
40 % should become somewhat stable whereas the output format can be adapted to
41 % individual needs.
42 % Further the notenames can be transposed, so transposing a music piece
43 % with chord symbols can be done easily. \par
44 % The package can be used with \musixtex\ and \pmx\
45 % -- which also gave the idea for the usage of an short chord--description
46 % `language'.
47 % \footnote{If the default output functions are changed the package could
48 % also be used with \TeX{} and \LaTeX{} alone.}
49 % \par
50 %
51 % \DescribeMacro{\c}
52 % The main macro which the package defines is
53 % \verb*|\c |\synt{chord-list}\verb*| |. The argument is an space
54 % terminated \synt{chord-list}
55 % \footnote{This form of argument was choosen because it leads to a
56 % short notation inside \pmx\ e.g.: \\
57 % {\tt \backslash c AfM \backslash\ e8 f g4 \backslash c Gm7 \backslash\ b4 g}
58 % }.
59 % \begin{demo}[w]{\musixtex}
60 % \nobarnumbers
61 % \startextract
62 % \NOtes\c CM7 \hu e\c Dm7 \hu f\en\bar
63 % \NOTEs\c Ch/E \hu g\c F6/A \hu h\en\bar
64 % \NOtes\c 0-1E7/G \hl i\c Fd/Af \hl j\en
65 % \endextract
66 % \end{demo}
67 %
68 % \subsection{Syntax}
69 % \begin{grammar}
70 % <empty> ::= `'
71 %
72 % <digit> ::= `0' | `1' | `2' | `3' | `4' | `5' | `6' | `7' | `8' | `9'
73 %
74 % <number> ::= <digit> | `-' <digit>
75 %
76 % <vertical-shift> ::= <number> | <empty>
77 %
78 % <horizontal-shift> ::= <number> | <empty>
79 %
80 % <note-base-name> ::= `C' | `D' | `E' | `F' | `G' | `A' | `B'
81 %
82 % <accidental> ::= `s' | `f' | `ds' | `df'
83 %
84 % <note-name> ::= <empty> | <note-base-name>
85 % | <note-base-name> <accidental>
86 %
87 % <chord-qualifier> ::=
88 % `m' | `d' | `h' | `M' | `4' | `+5' | `-5' | `6' | `7' | `-9' | `+9'
89 %
90 % <chord-qualifier-list> ::= <empty>
91 % | <chord-qualifier> <chord-qualifier-list>
92 %
93 % <begin-bass-note> ::= <empty> | `/'
94 %
95 % <chord> ::= <vertical-shift> <horizontal-shift> \\
96 % <note-name> <chord-qualifier-list> \\
97 % <begin-bass-note> <note-name> <chord-qualifier-list>
98 %
99 % <chord-list> ::= <chord-list> `,' <chord-list> | <chord> | <empty>
100 % \end{grammar}
101 %
102 %
103 % \subsection{Semantics}
104 % \paragraph{\synt{vertical-shift}}
105 % \DescribeMacro{\crddefaultheight}
106 % Adjustment of the vertical chord position in internotes,
107 % relative to the default value defined with
108 % \verb*|\crddefaultheight|. You may change this default within
109 % your sheet.
110 % \begin{macrocode}
111 \def\crddefaultheight{10}
112 % \end{macrocode}
113 % \paragraph{\synt{horizontal-shift}}
114 % Horizontal adjustment in multiples of \verb*|\elemskip|.
115 %
116 % \paragraph{\synt{accidental}}
117 % Allowed accidentals are: sharp, flat, double-sharp, double-flat.
118 %
119 % \paragraph{\synt{note-name}}
120 % \DescribeMacro{\crdtranspose}
121 % The given note names are transposed by the number of quint steps
122 % given in \verb*|\crdtranspose|. You may change this value within
123 % your sheet.
124 % \begin{macrocode}
125 \def\crdtranspose{0}
126 % \end{macrocode}
127 % \paragraph{\synt{chord-qualifier}}
128 % Currently known qualifiers are:
129 % \begin{description}
130 % \item[m] minor
131 % \item[d] diminished
132 % \item[h] half-diminished
133 % \item[M] major
134 % \item[4] suspended fourth
135 % \item[+5] augmented fifth
136 % \item[-5] diminished fifth
137 % \item[6] 6th
138 % \item[7] 7th
139 % \item[9] 9th
140 % \item[-9] diminished 9th
141 % \item[+9] augmented 9th
142 % \end{description}
143 % Note that the syntax is independent of the visualization
144 % of the qualifier so different chord styles could be applied.
145 %
146 % \paragraph{\synt{begin-bass-note}}
147 % Use the `/' symbol to skip the \synt{note-name} and
148 % \synt{chord-qualifier-list} to allow the notation of
149 % bass-notes without chord-notes.
150 %
151 % \paragraph{\synt{chord-list}}
152 % With `,' separated chords are spread evenly
153 % within one bar. Use this notation if the horizontal positions
154 % of the chords do not line up with the notes.
155 %
156 %
157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 % \section{Implementation}
159 % \subsection{Input Guard}
160 % To prevent repeated defenition of the main macros
161 % we end the inclusion of this file if we already now
162 % about our macros.
163 % \begin{macrocode}
164 \ifx\crd@parser\undefined\else\makeatother\endinput\fi%
165 % \end{macrocode}
166 % \subsection{List Macros}
167 % For the parsing of the chord description some macros are needed which
168 % can do simple string operations. \medskip \\
169 % \DescribeMacro{\crd@append}
170 % \syntax{"\\crd@append"<tokens-a>"\\to"<tokens-b>}\\
171 % Append \synt{tokens-a} to \synt{tokens-b}.
172 % \begin{macrocode}
173 \def\crd@append#1\to#2{%
174 \toks0=\expandafter{#1}\toks2=\expandafter{#2}%
175 \edef#2{\the\toks2 \the\toks0}}
176 % \end{macrocode}
177 % \DescribeMacro{\crd@prepend}
178 % \syntax{"\\crd@prepend"<tokens-a>"\\by"<tokens-b>}\\
179 % Prepend \synt{tokens-a} by \synt{tokens-b}.
180 % \begin{macrocode}
181 \def\crd@prepend#1\by#2{%
182 \toks0=\expandafter{#1}\toks2=\expandafter{#2}%
183 \edef#1{\the\toks2 \the\toks0}}
184 % \end{macrocode}
185 % \DescribeMacro{\crd@movetoken}
186 % \syntax{"\\crd@movetoken"<tokens-a>"\\to"<tokens-b>}\\
187 % Move the first token of \synt{tokens-a} to the front of
188 % \synt{tokens-b}.
189 % \begin{macrocode}
190 \def\crd@movetoken#1\to#2{%
191 \ifx#1\empty\else\expandafter\crd@moveoff#1\crd@moveoff#1#2\fi}%
192 \def\crd@moveoff#1#2\crd@moveoff#3#4{\def#3{#2}\crd@prepend#4\by#1}
193 % \end{macrocode}
194 % \begin{demo}[w]{test}
195 % \makeatletter
196 % \def\l{oo} (\l) %
197 % \crd@append{ns}\to\l append:(\l) %
198 % \crd@prepend\l\by{sp} prepend:(\l)\\%
199 % \def\swap#1#2{(#1,#2) %
200 % \ifx#1\empty\else\crd@movetoken#1\to#2\swap#1#2\fi}
201 % \def\r{} movetoken:\\ \swap\l\r
202 % \makeatother
203 % \end{demo}
204 %
205 % \subsection{Parsing}
206 % To describe the syntatic items which exists for a distinct semantic
207 % a \synt{syntax-table} is used.
208 % For each item exists a coresponding macro which will be executed
209 % if it name matches. The name of the item consists of the
210 % \synt{syntax-table} name and the \emph{reverse} syntax of this item. \par
211 %
212 % \DescribeMacro{\crd@parse}
213 % The \syntax{"\\crd@parse"<tokens>"\\for"<syntax-table>} macro is used
214 % to test if the first part of \synt{tokens} has matches for the longest
215 % possible item described in \synt{syntax-table}.
216 % If an item matched its macro will be expanded and
217 % and the tokens of the item are cut of from the given \synt{tokens}.
218 % \DescribeMacro{\crd@parsematched}
219 % The conditional \verb|\crd@parsematched| is true if an item matched and
220 % false otherwise.
221 %
222 % \begin{macrocode}
223 \newif\ifcrd@parsematched% true if parse matched
224 \newcount\crd@parsedepth% internal register
225
226 \def\crd@parse#1\for#2{% parse tokens #1 for occurence of items of table #2
227 \crd@parsedepth=1 % default if not defined
228 \expandafter\ifx\csname#2depth\endcsname\relax\else%
229 \crd@parsedepth=\csname#2depth\endcsname%
230 \fi%
231 \def\stack{}%\def\crd@parseresult{}
232 \crd@parsematchedfalse% initialisation
233 \crd@parser#1\for#2% call the recursive part
234 }
235 \def\crd@parser#1\for#2{% recursive part of parser
236 \ifx#1\empty\else% is list filled ?
237 \ifnum\crd@parsedepth>0 % and do we have to read more chars into stack
238 \advance\crd@parsedepth by-1 %
239 \crd@movetoken#1\to\stack%
240 \crd@parser#1\for#2% recursive call
241 \ifcrd@parsematched\else% if still not matched
242 \expandafter\ifx\csname#2\stack\endcsname\relax% does item match
243 \crd@movetoken\stack\to#1% no match, put char back to source
244 \else% match
245 \csname#2\stack\endcsname%
246 \crd@parsematchedtrue% signal success
247 \fi%
248 \fi%
249 \fi%
250 \fi%
251 }
252 % \end{macrocode}
253 % For an example suppose that we want to express the
254 % semantic \synt{bool} by the following grammar:
255 % \begin{grammar}
256 % <bool> ::= `y' | `n' | `yes' | `no'
257 % \end{grammar}
258 %
259 % \begin{demo}[w]{bool}
260 % \def\bool{bool} % syntax-table with name `bool'
261 % \def\booldepth{3} % max length of text to looking for is 3
262 % \def\booly{true}
263 % \def\booln{false}
264 % \def\boolsey{true*} % reverse syntax !!!
265 % \def\boolon{false*} % reverse syntax !!!
266 % \makeatletter
267 % \def\p#1{ (#1) \crd@parse#1\for\bool : (#1)\\}
268 % \makeatother
269 % \def\l{nonyyestest} \p\l\p\l\p\l\p\l\p\l
270 % \end{demo}
271 %
272 %
273 % \subsection{Chord parsing}
274 % \subsubsection{Vertical and Horizontal shifting}
275 % \begin{macrocode}
276 \newcount\crd@vshift%
277 \newcount\crd@hshift%
278 \def\crd@number{crd@number}%
279 \def\crd@numberdepth{2}%
280 \expandafter\def\csname\crd@number0\endcsname{\crd@numberval=0 }%
281 \expandafter\def\csname\crd@number1\endcsname{\crd@numberval=1 }%
282 \expandafter\def\csname\crd@number2\endcsname{\crd@numberval=2 }%
283 \expandafter\def\csname\crd@number3\endcsname{\crd@numberval=3 }%
284 \expandafter\def\csname\crd@number4\endcsname{\crd@numberval=4 }%
285 \expandafter\def\csname\crd@number5\endcsname{\crd@numberval=5 }%
286 \expandafter\def\csname\crd@number6\endcsname{\crd@numberval=6 }%
287 \expandafter\def\csname\crd@number7\endcsname{\crd@numberval=7 }%
288 \expandafter\def\csname\crd@number8\endcsname{\crd@numberval=8 }%
289 \expandafter\def\csname\crd@number9\endcsname{\crd@numberval=9 }%
290 \expandafter\def\csname\crd@number1-\endcsname{\crd@numberval=-1 }%
291 \expandafter\def\csname\crd@number2-\endcsname{\crd@numberval=-2 }%
292 \expandafter\def\csname\crd@number3-\endcsname{\crd@numberval=-3 }%
293 \expandafter\def\csname\crd@number4-\endcsname{\crd@numberval=-4 }%
294 \expandafter\def\csname\crd@number5-\endcsname{\crd@numberval=-5 }%
295 \expandafter\def\csname\crd@number6-\endcsname{\crd@numberval=-6 }%
296 \expandafter\def\csname\crd@number7-\endcsname{\crd@numberval=-7 }%
297 \expandafter\def\csname\crd@number8-\endcsname{\crd@numberval=-8 }%
298 \expandafter\def\csname\crd@number9-\endcsname{\crd@numberval=-9 }%
299
300 \def\crd@bracketinit{%
301 \def\crd@bracketopen{}%
302 \def\crd@bracketclose{}%
303 }
304 \def\crd@bracket{crd@bracket}%
305 \def\crd@bracketdepth{1}%
306 \expandafter\def\csname\crd@bracket(\endcsname{%
307 \crd@append(\to\crd@bracketopen}%
308 \expandafter\def\csname\crd@bracket)\endcsname{%
309 \crd@append)\to\crd@bracketclose}%
310
311 % \end{macrocode}
312 % \subsubsection{Notes and Accidentals}
313 % \paragraph{Syntax}
314 % In order to allow transposition of notes we use the circle of fifth
315 % for representing notes.
316 % \DescribeMacro{\crd@quintval}
317 % The syntax table \verb|\crd@quintval| contains the mapping from note
318 % names to the note position in the circle of fifth. \\
319 % \DescribeMacro{\crd@quint}
320 % The count register \verb|\crd@quint| is used to receive the result.
321 % \begin{macrocode}
322 \newcount\crd@quint% register used to represent notes in the circle of
323 \def\crd@quintval{crd@quintval}%
324 \def\crd@quintvalA{\crd@quint=3 }% A
325 \def\crd@quintvalB{\crd@quint=5 }% B
326 \def\crd@quintvalC{\crd@quint=0 }% C
327 \def\crd@quintvalD{\crd@quint=2 }% D
328 \def\crd@quintvalE{\crd@quint=4 }% E
329 \def\crd@quintvalF{\crd@quint=-1 }% F
330 \def\crd@quintvalG{\crd@quint=1 }% G
331 % \end{macrocode}
332 % \DescribeMacro{\crd@quintmod}
333 % The modification of the note position in the circle of fifth
334 % which is caused by the accidentals is coded in the
335 % \verb|\crd@quintmod| syntax table.
336 % \begin{macrocode}
337 \def\crd@quintmod{crd@quintmod}
338 \def\crd@quintmoddepth{2}
339 \def\crd@quintmods{\advance\crd@quint by7 }% sharp
340 \def\crd@quintmodf{\advance\crd@quint by-7 }% flat
341 \def\crd@quintmodsd{\advance\crd@quint by14 }% double sharp
342 \def\crd@quintmodfd{\advance\crd@quint by-14 }% double flat
343 % \end{macrocode}
344 % \paragraph{Notenames and accidental symbols}
345 % After transpositon and enharmonic adaption an reverse mapping
346 % from the circle of fifth to notenames and accidentals is needed.
347 % \DescribeMacro{\crd@note}
348 % The mapping from circle of fifth to notenames without accidentals
349 % is specified in the \verb|\crd@note| table.
350 % \DescribeMacro{\crd@notelow}\DescribeMacro{\crd@notehigh}
351 % In addition we need to now where the notes without accidentals
352 % start and end which is defined in \verb|\crd@notelow| and
353 % \verb|crd@notehigh|.
354 % \begin{macrocode}
355 \def\crd@note{crd@note}
356 \expandafter\def\csname\crd@note3\endcsname{A}
357 \expandafter\def\csname\crd@note5\endcsname{B}
358 \expandafter\def\csname\crd@note0\endcsname{C}
359 \expandafter\def\csname\crd@note2\endcsname{D}
360 \expandafter\def\csname\crd@note4\endcsname{E}
361 \expandafter\def\csname\crd@note-1\endcsname{F}
362 \expandafter\def\csname\crd@note1\endcsname{G}
363 \def\crd@notelow{-1} % lowest quint without accidental
364 \def\crd@notehigh{5} % highest quint without accidental
365 % \end{macrocode}
366 %
367 % \DescribeMacro{\crd@sharp}\DescribeMacro{\crd@flat}
368 % \DescribeMacro{\crd@doublesharp}\DescribeMacro{\crd@doubleflat}
369 % The following macros define the representation of the
370 % (default) accidentals.
371 % \begin{macrocode}
372 \def\crd@sharp{\sharp}
373 \def\crd@flat{\flat}
374 \def\crd@doublesharp{\sharp\sharp}
375 \def\crd@doubleflat{\flat\flat}
376 % \end{macrocode}
377 % \paragraph{Parsing}
378 % \DescribeMacro{\crd@input}
379 % The following functions read their input from \verb|\crd@input|.\\
380 % \DescribeMacro{\crd@parsenote}
381 % The \syntax{"\\crd@parsenote"<note><accidental>}
382 % macro parses the input \verb|\crd@input| and if note and
383 % accidental could be detected the transposed note position
384 % in the circle of fifth will be calculated, transposed and
385 % adapted using the \verb|\crd@enharmonic| macro.
386 % Then the position in the circle of fifth is calculated back
387 % to the \synt{note} and \synt{accidental} representation which
388 % is stored in the arguments.
389 % \begin{macrocode}
390 \def\crd@parsenote#1#2{% parse input results: #1
391 \def#1{}\def#2{}%
392 \crd@parse\crd@input\for\crd@quintval%
393 \ifcrd@parsematched% we got an valid note
394 \crd@parse\crd@input\for\crd@quintmod%
395 \advance\crd@quint by\crdtranspose \relax% transposition, space is needed!
396 \crd@enharmonic%
397 \ifnum\crd@quint>\crd@notehigh % sharps ?
398 \advance\crd@quint by-7 %
399 \ifnum\crd@quint>\crd@notehigh % double sharp ?
400 \advance\crd@quint by-7 %
401 \ifnum\crd@quint>\crd@notehigh % too much sharps !
402 \relax ERROR:too much sharps%
403 \else\edef#2{\crd@doublesharp}\fi%
404 \else\edef#2{\crd@sharp}\fi%
405 \fi%
406 \ifnum\crd@quint<\crd@notelow % flats ?
407 \advance\crd@quint by7 %
408 \ifnum\crd@quint<\crd@notelow % double flat ?
409 \advance\crd@quint by7 %
410 \ifnum\crd@quint<\crd@notelow % too much flats !
411 \relax ERROR:too much flats%
412 \else\edef#2{\crd@doubleflat}\fi%
413 \else\edef#2{\crd@flat}\fi%
414 \fi%
415 \expandafter\ifx\csname\crd@note\number\crd@quint\endcsname\relax%
416 ERROR:notename for (\number\crd@quint) is not defined.
417 \fi%
418 \edef#1{\csname\crd@note\number\crd@quint\endcsname}% set note
419 \fi%
420 }
421 % \end{macrocode}
422 %
423 %
424 % \DescribeMacro{\crd@enharmonic}
425 % To allow different enharmonic adaptions the \verb|\crd@enharmonic|
426 % macro is provided which default behaviour is to do nothing.
427 % \begin{macrocode}
428 \def\crd@enharmonic{}%
429 % \end{macrocode}
430 %
431 % \begin{demo}[w]{noteparsing}
432 % \makeatletter
433 % \def\parsenoter{\crd@parsenote\n\a%
434 % \ifx\n\empty\else{\crd@notetype\n\a}\parsenoter\fi}%
435 % \def\parsenotes#1{%
436 % \let\crd@flat=\crd@noteflat%
437 % \let\crd@sharp=\crd@notesharp%
438 % \def\crd@input{#1}\parsenoter}
439 % \makeatother
440 %
441 % \parsenotes{CDfDEfEFFsGAfAsB}
442 % \end{demo}
443 %
444 %
445 % \subsubsection{Chord Qualifiers}
446 % To cover a broad range of different styles for setting chord qualifiers
447 % the design is open for extensions. For the sake of demonstration and
448 % simple usability an default implementation is provided and discussed
449 % furtherwards. \\
450 % Suppose we want to distinguish 3 different kinds of qualifiers,
451 % some go down, some go up and alterations are put in brackets.
452 % \DescribeMacro{\crd@qualinit}
453 % We choose to use 3 lists (macros) to hold the parsing results.
454 % For initialisation of these lists the \verb|\crd@qualinit| macro
455 % has to be implemented.
456 % \begin{macrocode}
457 \def\crd@qualinit{%
458 \def\crd@lo{}% lower extensions
459 \def\crd@up{}% upper extensioins
460 \def\crd@alt{}% alterations
461 }
462 % \end{macrocode}
463 % \DescribeMacro{\crd@qual}
464 % Now the syntax table \verb|\crd@qual| has to be defined which fills
465 % the lists appropriatly.
466 % \begin{macrocode}
467 \def\crd@qual{crd@qual}%
468 \def\crd@qualdepth{2}
469 \def\crd@qualm{\crd@append{\crd@smalltype m}\to\crd@lo}% minor
470 \def\crd@qualM{\crd@append{\crd@capitaltype M}\to\crd@up}% major7
471 \expandafter\def\csname\crd@qual4\endcsname% 4
472 {\crd@append{\crd@numbertype4}\to\crd@lo}
473 \expandafter\def\csname\crd@qual5+\endcsname% aug. 5
474 {\crd@append{\crd@numbertype\crd@numbersharp5}\to\crd@alt}
475 \expandafter\def\csname\crd@qual5-\endcsname% dim. 5
476 {\crd@append{\crd@numbertype\crd@numberflat5}\to\crd@alt}
477 \expandafter\def\csname\crd@qual6\endcsname% 6
478 {\crd@append{\crd@numbertype6}\to\crd@up}
479 \expandafter\def\csname\crd@qual7\endcsname% dominant 7
480 {\crd@append{\crd@numbertype7}\to\crd@up}
481 \def\crd@quald{\crd@append{\crd@dim}\to\crd@up}% diminished
482 \def\crd@qualh{\crd@append{\crd@hdim}\to\crd@up}% half diminished
483 \expandafter\def\csname\crd@qual9-\endcsname% -9
484 {\crd@append{\crd@numbertype\crd@numberflat9}\to\crd@alt}
485 \expandafter\def\csname\crd@qual9+\endcsname% +9
486 {\crd@append{\crd@numbertype\crd@numbersharp9}\to\crd@alt}
487 % \end{macrocode}
488 %
489 % \begin{demo}[w]{qualparsing}
490 % \makeatletter
491 % \def\parsequal#1{\def\crd@input{#1}%
492 % \crd@qualinit%
493 % \loop\crd@parse\crd@input\for\crd@qual%
494 % \ifcrd@parsematched\repeat%
495 % (\crd@lo,\crd@up,\crd@alt)%
496 % }%
497 % \makeatother
498 %
499 % \parsequal{mMdh4+5-567-9+9}
500 % \end{demo}
501 %
502 % \subsubsection{Parsing the whole chord}
503 % We are now ready to parse the whole chord, consisting
504 % of chordnote, qualifiers and bassnote. However
505 % if one likes to set only a bassnote one needs to tell
506 % that there is no chord note to set. For this purpose
507 % the \DescribeMacro{\crd@skipcrdnote} \verb|\crd@skipcrdnote|
508 % syntax table defines the `/' item which does this skip.
509 % \begin{macrocode}
510 \def\crd@skipcrdnote{crd@skipcrdnote}
511 \expandafter\def\csname\crd@skipcrdnote/\endcsname{}
512 % \end{macrocode}
513 % \DescribeMacro{\crd@parsecrd}
514 %
515 % \begin{macrocode}
516 \def\crd@parsecrd{%
517 \crd@vshift=0 %
518 \let\crd@numberval=\crd@vshift%
519 \crd@parse\crd@input\for\crd@number%
520 \crd@hshift=0 %
521 \let\crd@numberval=\crd@hshift%
522 \crd@parse\crd@input\for\crd@number%
523 \crd@bracketinit%
524 \crd@parse\crd@input\for\crd@bracket%
525 \def\crd@crdnote{}% chord note
526 \def\crd@crdacc{}% chord note accidental
527 \def\crd@bassnote{}% bass note
528 \def\crd@bassacc{}% bass note accidental
529 \crd@qualinit% initialize qualifiers
530 \let\crd@flat=\crd@noteflat%
531 \let\crd@doubleflat=\crd@notedoubleflat%
532 \let\crd@sharp=\crd@notesharp%
533 \let\crd@doublesharp=\crd@notedoublesharp%
534 \crd@parsenote\crd@crdnote\crd@crdacc% read chord note
535 \loop\crd@parse\crd@input\for\crd@qual% read qualifiers
536 \ifcrd@parsematched\repeat%
537 \crd@parse\crd@input\for\crd@skipcrdnote% skip eventually
538 \let\crd@flat=\crd@bassflat%
539 \let\crd@doubleflat=\crd@bassdoubleflat%
540 \let\crd@sharp=\crd@basssharp%
541 \let\crd@doublesharp=\crd@bassdoublesharp%
542 \crd@parsenote\crd@bassnote\crd@bassacc% read bass note
543 \crd@parse\crd@input\for\crd@bracket%
544 \crd@formatcrd\hfil% call rendering
545 }
546 % \end{macrocode}
547 % \subsubsection{ Multiple chords}
548 % \DescribeMacro{\crd@parsecrds}
549 % The \verb|\crd@parsecrds| macro is used to read more then one
550 % chord. This can be usefull if no corresponding note over which
551 % one can put the note exist.
552 % \DescribeMacro{\crd@crddelim}
553 % The syntax table \verb|\crd@crddelim| is used.
554 % \begin{macrocode}
555 \def\crd@crddelim{crd@crddelim}%
556 \expandafter\def\csname\crd@crddelim,\endcsname{}%
557 \def\crd@parsecrds{%
558 \crd@parsecrd%
559 \crd@parse\crd@input\for\crd@crddelim%
560 \ifcrd@parsematched\crd@parsecrds\fi%
561 }
562 % \end{macrocode}
563 % \begin{demo}[w]{multiple chords}
564 % \c (Cm),2CM,Cm7
565 % \end{demo}
566 % \DescribeMacro{\c}
567 % The main entry point for the user is the
568 % \verb*|\c |\synt{chord-list}\verb*| | macro which calls the
569 % \verb|\crd@output| routine with the formatted chords.
570 % \begin{macrocode}
571 \def\crd#1 {\def\crd@input{#1}\crd@output\crd@parsecrds}
572 \let\cedilla=\c
573 \let\c=\crd
574 % \end{macrocode}
575 %
576 % \subsection{Formatting}
577 % To allow the use of different fonts the
578 % notion of fontstyles is introduced.
579 % The initialisation of fontstyles is done in different macros.
580 % \DescribeMacro{\crd@fontstylea}
581 % \begin{macrocode}
582 \def\crd@fontstylea{%
583 \font\crd@eightrm=cmr8
584 \font\crd@eightit=cmmi8
585 \font\crd@seventeenrm=cmr17
586 \font\crd@fourteenrm=cmr14
587 \font\crd@twelverm=cmr12
588 \font\crd@ninerm=cmr9
589 \font\crd@smallninerm=cmr9 scaled 900
590 \font\crd@bigninerm=cmr9 scaled 1100
591 \let\crd@notetype=\crd@seventeenrm
592 \def\crd@noteflat{\raise0.6ex\hbox{\kern-0.085em\musictwenty2}}
593 \def\crd@notedoubleflat{\raise0.6ex\hbox{\kern-0.085em\musictwenty3}}
594 \def\crd@notesharp{\raise0.8ex\hbox{\musictwenty4}}
595 \def\crd@notedoublesharp{\raise0.8ex\hbox{\musictwenty5}}
596 \let\crd@basstype=\crd@fourteenrm
597 \def\crd@bassflat{\raise.5ex\hbox{\musicsixteen2}}
598 \def\crd@bassdoubleflat{\raise0.6ex\hbox{\kern-0.085em\musicsixteen3}}
599 \def\crd@basssharp{\raise1ex\hbox{\musicsixteen4}}
600 \def\crd@bassdoublesharp{\raise0.8ex\hbox{\musicsixteen5}}
601 \let\crd@numbertype=\crd@ninerm
602 \def\crd@numberflat{\raise.5ex\hbox{\musiceleven2}}
603 \def\crd@numbersharp{\raise1ex\hbox{\musiceleven4}}
604 \def\crd@numberminus{\crd@ninerm-}
605 \def\crd@numberplus{\crd@ninerm+}
606 \let\crd@capitaltype=\crd@smallninerm % capitals
607 \let\crd@smalltype=\crd@bigninerm % small
608 \def\crd@hdim{\crd@eightit$\circ$\kern-4.4pt\raise.9pt\hbox{\crd@eightrm/}}
609 \def\crd@dim{\crd@eightit$\circ$}
610 }
611 % \end{macrocode}
612 % The formating of the chords is done in the
613 % \DescribeMacro{\crd@formatcrd}
614 % \verb|\crd@formatcrd| macro. The parse results are
615 % stored in the following macros:
616 % \verb|\crd@crdnote| -- chord note,
617 % \verb|\crd@crdacc| -- chord note accidental,
618 % \verb|\crd@bassnote| -- bass note and
619 % \verb|\crd@bassacc| -- bass note accidental.
620 %
621 %
622 %\iffalse % dont include this, just experimental code
623 %<*gobble>
624 \def\mymatrix#1{\null\,\vcenter{\normalbaselines\m@th
625 \ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
626 \mathstrut\crcr\noalign{\kern-\baselineskip}
627 #1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}
628 \def\crd@formatcrdb{%
629 ${\rm \crd@crdnote}\crd@crdacc%
630 ^{\crd@up}_{\raise0pt\hbox{{\rm \crd@lo}}}
631 \ifx\crd@alt\empty\else\left(\mymatrix\crd@alt\right)\fi%
632 \ifx\crd@bassnote\empty\else% do we have an bass note set ?
633 /{\rm \crd@bassnote}\crd@bassacc%
634 \fi$%
635 }
636 %</gobble>
637 %\fi
638 % \begin{macrocode}
639 \def\crd@formatcrda{%
640 \hbox{\kern\crd@hshift\elemskip\raise\crd@vshift\internote\hbox{%
641 {\crd@notetype\crd@bracketopen}%
642 {\crd@notetype\crd@crdnote\crd@crdacc}%
643 \vbox{%
644 \hbox{%
645 \crd@up%
646 \ifx\crd@alt\empty\else\crd@numbertype(\crd@alt\crd@numbertype)\fi%
647 }%
648 \nointerlineskip\vskip1pt%
649 \hbox{\vphantom{\crd@capitaltype M}\crd@lo}}%
650 \ifx\crd@bassnote\empty\else%
651 {\crd@basstype/%
652 \lower0.5ex\hbox{\kern-0.17em \crd@bassnote\crd@bassacc}}%
653 \fi%\
654 {\crd@notetype\crd@bracketclose}%
655 }}
656 }
657 % \end{macrocode}
658 % \begin{macrocode}
659 \let\crd@formatcrd=\crd@formatcrda
660 \crd@fontstylea
661 % \end{macrocode}
662 %
663 % \begin{demo}[w]{formatting}
664 % \generalsignature{0}\generalmeter{\meterfrac44}
665 % \nobarnumbers
666 % \startextract
667 % \NOtes\c Cm,CM,Dm7 \hu f\en\bar
668 % \endextract
669 % \end{demo}
670 %
671 %
672 % \DescribeMacro{\crd@output}
673 % The output function puts the formatted chords on their place.
674 %
675 % \begin{macrocode}
676 \def\crd@musixOutput#1{\hbox{\zchar{\crddefaultheight}{\hbox to\elemskip{#1\hss}}}}
677 \let\crd@output=\crd@musixOutput
678 % \end{macrocode}
679 %
680 %
681 \makeatother
682 %
683 % \section{Customization}
684 % If the default implementation does not suite the needs
685 % some tips of how to change the default behaviour will be
686 % given.
687 % \subsection{Changing the extensions}
688 % \begin{description}
689 % \item[Q:] How do I get the symbol $Dm^{M7}$ ?
690 % \item[A:] The M has to be put to the upper extensions list, so we
691 % have to change the definition in the \verb|\crd@qual| table:
692 % \def\crddefaultheight{0}
693 % \begin{demo}[w]{$Dm^{M7}$}
694 % \makeatletter%
695 % \def\crd@qualM{\crd@append{\crd@capitaltype M}\to\crd@up}% major7
696 % \makeatother%
697 % \c DmM7 %
698 % \end{demo}
699 % \item[Q:] How do I get the symbol $Dm^{7-5}$ ?
700 % \item[A:]
701 % \begin{itemize}
702 % \renewcommand{\labelitemi}{-}
703 % \item
704 % The predefined symbol can be found by using `h' -- for
705 % half dimineshed.
706 % \begin{demo}[w]{h}
707 % \c Dh %
708 % \end{demo}
709 % \item
710 % to ge the diminished fifth explicit to the upper extensions one could
711 % either change the definition of the `h' to:
712 % \begin{demo}[w]{Dmh : $Dm^{7-5}$}
713 % \makeatletter%
714 % \def\crd@qualh%
715 % {\crd@append{\crd@numbertype 7-5}\to\crd@up}% half diminished
716 % \makeatother%
717 % \c Dmh %
718 % \end{demo}
719 % \item
720 % or may introduce an mapping for the -5 and has to write: D7-5
721 % \begin{demo}[w]{Dm7-5 : $Dm^{7-5}$}
722 % \makeatletter%
723 % \expandafter\def\csname\crd@qual5-\endcsname% dimin. 5
724 % {\crd@append{\crd@numberminus\crd@numbertype5}\to\crd@up}%
725 % \makeatother%
726 % \c Dm7-5 %
727 % \end{demo}
728 % \end{itemize}
729 % \end{description}
730 %
731 % \subsection{change fonts}
732 % \begin{description}
733 % \item[Q:] How do I change the font?
734 % \item[A:] One has to create his own fontstyle definition
735 % with a suitable formatting like for example:
736 % \begin{demo}[w]{change fonts}
737 % \makeatletter%
738 % \def\crd@fontstyleb{%
739 % \font\crd@newfont=cmssbx10%
740 % \let\crd@notetype=\crd@newfont%
741 % \def\crd@noteflat{\raise2pt\hbox{\musixchar90}}%
742 % \def\crd@notedoubleflat{\crd@noteflat\crd@noteflat}%
743 % \def\crd@notesharp{\raise3.5pt\hbox{\musixchar92}}%
744 % \def\crd@notedoublesharp{\crd@notesharp\crd@notesharp}%
745 % \let\crd@basstype=\crd@newfont%
746 % \def\crd@bassflat{\crd@noteflat}%
747 % \def\crd@bassdoubleflat{\crd@notedoubleflat}%
748 % \def\crd@basssharp{\crd@notesharp}%
749 % \def\crd@bassdoublesharp{\crd@notedoublesharp}%
750 % \let\crd@numbertype=\crd@newfont%
751 % \def\crd@numberflat{\crd@noteflat}%
752 % \def\crd@numbersharp{\crd@notesharp}%
753 % \def\crd@numberminus{\crd@newfont-}%
754 % \def\crd@numberplus{\crd@newfont+}%
755 % \let\crd@capitaltype=\crd@newfont % capitals in extension
756 % \let\crd@smalltype=\crd@newfont % small letters in extension
757 % \def\crd@hdim%
758 % {\crd@newfont$\circ$\kern-4.4pt\raise.9pt\hbox{\crd@newfont/}}%
759 % \def\crd@dim{\crd@newfont$\circ$}%
760 % }%
761 % \def\crd@formatcrdb{%
762 % \hbox{\kern\crd@hshift\elemskip\raise\crd@vshift\internote\hbox{%
763 % {\crd@notetype\crd@crdnote\crd@crdacc}%
764 % \crd@lo%
765 % \raise4pt%
766 % \hbox{%
767 % \crd@up%
768 % \ifx\crd@alt\empty\else\crd@numbertype(\crd@alt\crd@numbertype)\fi%
769 % }%
770 % \ifx\crd@bassnote\empty\else%
771 % {\crd@basstype/\crd@bassnote\crd@bassacc}%
772 % \fi%\
773 % }}
774 % }
775 % \crd@fontstyleb%
776 % \let\crd@formatcrd=\crd@formatcrdb
777 % \makeatother%
778 % \nobarnumbers%
779 % \startextract\NOtes\c D7,AfM7 \hu f\en\bar\endextract%
780 % \end{demo}
781 % \end{description}
782 % Contributions for improving either the current fontstyle
783 % or the definition of new ones are welcome.
784 %
785 % \section{Todo}
786 %
787 % The actual implementation is not really open for changing
788 % the input format and the way the chords are displayed.
789 % One should implement an middle layer which is fixed and
790 % offer various implementations either for the input format
791 % and the output format which are written using this layer.
792 %
793 % \section{Change Log}
794 %
795 % \begin{description}
796 % \item[Version 1.0] (2.11.2004) \par Initial version.
797 % \item[Version 1.1] (1.7.2005) \par
798 % Added input guard and resetting of parameters
799 % if file is included more than once.
800 % \end{description}
801 %
802 % \Finale \PrintIndex
803 %
804 %\iffalse
805 %<*gobble>
806 %%% Local Variables:
807 %%% mode: plain-tex
808 %%% TeX-master: t
809 %%% End:
810 %</gobble>
811 %\fi