summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/leadsheets/leadsheets.library.chordnames.code.tex
blob: 8c875b60906be818ce586857b01e931756e96689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
\LeadsheetsExplLibrary{chordnames}{2015/07/02 typesetting chord names with easy syntax}

\leadsheets_load_library:n {musicsymbols}

% \bool_new:N \l__leadsheets_output_notation_german_bool
% \bool_new:N \l__leadsheets_input_notation_german_bool

\tl_new:N \l__leadsheets_chord_tl
\tl_new:N \l__leadsheets_tension_tl
\tl_new:N \l__leadsheets_format_tl

\cs_new_protected:Npn \leadsheets_tension_sym:Nn #1#2
  { \tl_replace_all:Nnn #1 {#2} { \textsuperscript{#2} } }

\cs_new_protected:Npn \leadsheets_chord_sym:Nnn #1#2#3
  { \tl_replace_all:Nnn #1 {#2} {#3} }
\cs_generate_variant:Nn \leadsheets_chord_sym:Nnn {NnV}

\tl_new:N \l__leadsheets_sharp_tl
\tl_new:N \l__leadsheets_flat_tl
\tl_new:N \l__leadsheets_doublesharp_tl
\tl_new:N \l__leadsheets_doubleflat_tl
\tl_new:N \l__leadsheets_full_dim_tl
\tl_new:N \l__leadsheets_half_dim_tl
\tl_new:N \l__leadsheets_aug_tl
\tl_new:N \l__leadsheets_major_tl
\tl_new:N \l__leadsheets_minor_tl
\tl_new:N \l__leadsheets_sus_tl
\tl_new:N \l__leadsheets_dim_tl
\tl_new:N \l__leadsheets_add_tl
\tl_new:N \l__leadsheets_major_seven_tl
\tl_new:N \l__leadsheets_german_B_tl
\tl_new:N \l__leadsheets_german_H_tl

\tl_set:Nn \l__leadsheets_sharp_tl       {\sharp}
\tl_set:Nn \l__leadsheets_flat_tl        {\flat}
\tl_set:Nn \l__leadsheets_doublesharp_tl {\doublesharp}
\tl_set:Nn \l__leadsheets_doubleflat_tl  {\doubleflat}
\tl_set:Nn \l__leadsheets_half_dim_tl    {\o{}}
\tl_set:Nn \l__leadsheets_full_dim_tl    {o}
\tl_set:Nn \l__leadsheets_aug_tl         {+}
\tl_set:Nn \l__leadsheets_major_tl       {}
\tl_set:Nn \l__leadsheets_minor_tl       {m}
\tl_set:Nn \l__leadsheets_sus_tl         {\textsuperscript{sus}}
\tl_set:Nn \l__leadsheets_dim_tl         {\textsuperscript{dim}}
\tl_set:Nn \l__leadsheets_add_tl         {\textsuperscript{add}}
\tl_set:Nn \l__leadsheets_major_seven_tl {\textsuperscript{maj7}}
\tl_set:Nn \l__leadsheets_major_nine_tl  {\textsuperscript{maj9}}
\tl_set:Nn \l__leadsheets_german_B_tl    {B}
\tl_set:Nn \l__leadsheets_german_H_tl    {H}

\group_begin:
% for convenient input of sharps:
\char_set_catcode_other:N \#
% because ^ is active in the song environment:
\char_set_catcode_active:N \^
% # is other so we need another parameter character:
\char_set_catcode_parameter:N \!

\cs_gset_protected:Npn \leadsheets_chord:
  {
    \group_begin:
      \tl_use:N \l__leadsheets_format_tl
      \char_set_catcode_other:N \#
      \char_set_catcode_active:N \^
      \leadsheets_chord_aux:n
  }

\cs_gset_protected:Npn \leadsheets_chord_aux:n !1
 {
    \tl_set:Nn \l__leadsheets_chord_tl {!1}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {maj7}
      {\l__leadsheets_major_seven_tl}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {maj9}
      {\l__leadsheets_major_nine_tl}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {sus}
      {\l__leadsheets_sus_tl}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {^} {\textsuperscript}
    \bool_if:NT \l__leadsheets_output_notation_german_bool
      {
        \leadsheets_chord_sym:NnV \l__leadsheets_chord_tl {B} \l__leadsheets_german_B_tl
        \leadsheets_chord_sym:NnV \l__leadsheets_chord_tl {H} \l__leadsheets_german_H_tl
      }
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {#b} {}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {b#} {}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {##}
      {\l__leadsheets_doublesharp_tl}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {bb}
      {\l__leadsheets_doubleflat_tl}
    \leadsheets_chord_sym:NnV  \l__leadsheets_chord_tl {#} \l__leadsheets_sharp_tl
    \leadsheets_chord_sym:NnV  \l__leadsheets_chord_tl {b} \l__leadsheets_flat_tl
    \leadsheets_chord_sym:NnV  \l__leadsheets_chord_tl {dim} \l__leadsheets_dim_tl
    \leadsheets_chord_sym:NnV  \l__leadsheets_chord_tl {add} \l__leadsheets_add_tl
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {0}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {1}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {2}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {3}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {4}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {5}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {6}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {7}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {8}
    \leadsheets_tension_sym:Nn \l__leadsheets_chord_tl {9}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {/o}
      {\textsuperscript{\l__leadsheets_half_dim_tl}}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {o}
      {\textsuperscript{\l__leadsheets_full_dim_tl}}
    \leadsheets_chord_sym:Nnn  \l__leadsheets_chord_tl {+}
      {\textsuperscript{\l__leadsheets_aug_tl}}
    \leadsheets_chord_sym:Nnn \l__leadsheets_chord_tl  {(}
      { \leadsheets_tension:w( }
    \leadsheets_chord_sym:Nnn \l__leadsheets_chord_tl  {mi}
      {\l__leadsheets_minor_tl}
    \leadsheets_chord_sym:Nnn \l__leadsheets_chord_tl  {ma}
      {\l__leadsheets_major_tl}
    \tl_replace_all:Nnn \l__leadsheets_chord_tl
      {\textsuperscript\textsuperscript}
      {\textsuperscript}
    \tl_use:N \l__leadsheets_chord_tl
    \group_end:
  }

\group_end:

\cs_new_protected:Npn \leadsheets_tension:w (#1)
  {
    \group_begin:
      \tl_set:Nn \l__leadsheets_tension_tl {#1}
      \leadsheets_chord_sym:Nnn \l__leadsheets_tension_tl
        {\textsuperscript}
        {\use:n}
      \textsuperscript { ( \tl_use:N \l__leadsheets_tension_tl ) }
    \group_end:
  }

\keys_define:nn {leadsheets/chords}
  {
    format       .tl_set:N = \l__leadsheets_format_tl ,
    sharp        .tl_set:N = \l__leadsheets_sharp_tl ,
    flat         .tl_set:N = \l__leadsheets_flat_tl ,
    double-sharp .tl_set:N = \l__leadsheets_doublesharp_tl ,
    double-flat  .tl_set:N = \l__leadsheets_doubleflat_tl ,
    half-dim     .tl_set:N = \l__leadsheets_half_dim_tl ,
    full-dim     .tl_set:N = \l__leadsheets_full_dim_tl ,
    aug          .tl_set:N = \l__leadsheets_aug_tl ,
    major        .tl_set:N = \l__leadsheets_major_tl ,
    minor        .tl_set:N = \l__leadsheets_minor_tl ,
    sus          .tl_set:N = \l__leadsheets_sus_tl ,
    add          .tl_set:N = \l__leadsheets_add_tl ,
    dim          .tl_set:N = \l__leadsheets_dim_tl ,
    major-seven  .tl_set:N = \l__leadsheets_major_seven_tl ,
    major-nine   .tl_set:N = \l__leadsheets_major_nine_tl ,
    german-B     .tl_set:N = \l__leadsheets_german_B_tl ,
    german-H     .tl_set:N = \l__leadsheets_german_H_tl
    % since version 0.2 those are defined in the `chords` library:
    % output-notation .choice: ,
    % input-notation .choice: ,
  }

\NewDocumentCommand \setchords {m}
  { \keys_set:nn {leadsheets/chords} {#1} }

\NewDocumentCommand \chordname {} { \leadsheets_chord: }

\endinput

HISTORY:

2014/08/10 - first version
2015/05/08 - drop `literal' option for input and output notation
           - input/output notation is now handled by the `chords' library
           - German output of B and H can be customized
2015/05/22 - improvements to the chord macros
2015/07/02 - this is not a use library any more