blob: 0dce437271722dc590d2b1b4be671d783d30e97f (
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
\LeadsheetsExplLibrary{chords}{2014/08/10 printing chords}
\msg_new:nnn {leadsheets} {no-chords}
{ No~ more~ chords~ left~ for~ verse~ type~ `#1'~ \msg_line_context: }
\tl_new:N \l__leadsheets_current_chord_tl
\tl_new:N \l__leadsheets_chord_stack_alignment_tl
\tl_set:Nn \l__leadsheets_chord_stack_alignment_tl {c}
\bool_new:N \l__leadsheets_smash_chords_bool
\bool_new:N \g__leadsheets_smash_next_chord_bool
\bool_new:N \l__leadsheets_chord_gobble_after_bool
\bool_new:N \l__leadsheets_record_chords_bool
\bool_new:N \l__leadsheets_chord_print_bool
\bool_set_true:N \l__leadsheets_chord_print_bool
\prop_new:N \g__leadsheets_chords_sequences_prop
\seq_new:N \l__leadsheets_chords_sequences_seq
\dim_new:N \l__leadsheets_empty_chord_dim
\dim_set:Nn \l__leadsheets_empty_chord_dim {1em}
\cs_new:Npn \leadsheets_chord_print:n #1 {#1}
\cs_generate_variant:Nn \leadsheets_chord_print:n {V}
\cs_new_protected:Npn \leadsheets_chord:nnn #1#2#3
{
\leadsheets_if_record_chords:T
{ \seq_put_right:Nn \l__leadsheets_chords_sequences_seq { {#3} } }
\leadsheets_set_chord:nnn
{#1}
{#2}
{ \leadsheets_chord_write:n {#3} }
}
\cs_new_protected:Npn \leadsheets_set_chord:nnn #1#2#3
{
\bool_if:NTF #1
{ \bool_set_true:N \l__leadsheets_chord_gobble_after_bool }
{ \bool_set_false:N \l__leadsheets_chord_gobble_after_bool }
\bool_if:NT #2
{ \bool_set_true:N \g__leadsheets_smash_next_chord_bool }
\__leadsheets_set_chord:nwn {#3}
}
\cs_new_protected:Npn \__leadsheets_set_chord:nwn #1#2~#3
{
\leadsheets_place_above:Vnn
\l__leadsheets_chord_stack_alignment_tl
{#1}
{
\tl_if_blank:nTF {#2}
{\skip_horizontal:N \l__leadsheets_empty_chord_dim}
{#2}
}
\tl_if_blank:nF {#3}
{ \bool_if:NF \l__leadsheets_chord_gobble_after_bool {\c_space_tl} }
#3
}
\cs_new_protected:Npn \leadsheets_chord_write:n #1
{
% \bool_if:NT \l__leadsheets_chord_print_bool
% {
\tl_set:Nn \l__leadsheets_current_chord_tl {#1}
\bool_if:nT
{
\leadsheets_if_property_p:Vn \l_leadsheets_current_song_id_tl {key}
&&
( \l__leadsheets_transpose_bool || \l__leadsheets_transpose_capo_bool )
}
{
\leadsheets_transpose:xVN
{ \leadsheets_get_property:Vn \l_leadsheets_current_song_id_tl {key} }
\l__leadsheets_transpose_steps_int
\l__leadsheets_current_chord_tl
}
\bool_if:nTF
{
! \leadsheets_if_property_p:Vn \l_leadsheets_current_song_id_tl {key}
&&
( \l__leadsheets_transpose_bool || \l__leadsheets_transpose_capo_bool )
}
{
\msg_warning:nnV {leadsheets}
{transpose-key}
\l_leadsheets_current_song_id_tl
}
\leadsheets_chord_print:V \l__leadsheets_current_chord_tl
% }
}
\cs_generate_variant:Nn \leadsheets_chord_write:n { V }
\cs_new_protected:Npn \leadsheets_place_above:nnn #1#2#3
{
\bool_if:NTF \l__leadsheets_chord_print_bool
{
\group_begin:
\leadsheets_ignore_lines:
\bool_if:NT \g__leadsheets_smash_next_chord_bool
{
\bool_set_true:N \l__leadsheets_smash_chords_bool
\bool_gset_false:N \g__leadsheets_smash_next_chord_bool
}
\linespread{1} \selectfont
\begin{tabular} [b] {@{}#1@{}}
\bool_if:NTF \l__leadsheets_smash_chords_bool
{\makebox[0pt][c]{#2}}
{#2} \\
#3
\end{tabular}
\group_end:
}
{#3}
}
\cs_generate_variant:Nn \leadsheets_place_above:nnn { V }
\keys_define:nn {leadsheets}
{
smash-chords .bool_set:N = \l__leadsheets_smash_chords_bool ,
smash-next-chord .bool_set:N = \g__leadsheets_smash_next_chord_bool ,
empty-chord-dim .dim_set:N = \l__leadsheets_empty_chord_dim ,
remember-chords .bool_set:N = \l__leadsheets_record_chords_bool ,
align-chords .tl_set:N = \l__leadsheets_chord_stack_alignment_tl ,
chord-cs .code:n =
\cs_set_protected:Npn \leadsheets_chord_print:n {#1} ,
chord-cs .initial:n = \chordname ,
print-chords .bool_set:N = \l__leadsheets_chord_print_bool
}
\NewDocumentCommand \chord {st-m} { \leadsheets_chord:nnn {#1} {#2} {#3} }
\NewDocumentCommand \writechord {m}
{ \leadsheets_chord_write:n {#1} }
% --------------------------------------------------------------------------
% record changes for a verse and automatically print them in the next:
\prg_new_conditional:Npnn \leadsheets_if_record_chords: {T,F,TF}
{
\bool_if:nTF
{
\l__leadsheets_record_chords_bool &&
! \prop_if_in_p:NV
\g__leadsheets_chords_sequences_prop
\l_leadsheets_verse_type_tl &&
!\l__leadsheets_measuring_bool
}
{ \prg_return_true: }
{ \prg_return_false: }
}
\prg_new_conditional:Npnn \leadsheets_if_recall_chords: {T,F,TF}
{
\bool_if:nTF
{
\l__leadsheets_record_chords_bool &&
\prop_if_in_p:NV
\g__leadsheets_chords_sequences_prop
\l_leadsheets_verse_type_tl
&&
!\l__leadsheets_measuring_bool
}
{ \prg_return_true: }
{ \prg_return_false: }
}
\cs_new:Npn \leadsheets_remember_or_recall_chords:w
{
\leadsheets_if_recall_chords:TF
{ \__leadsheets_recall_chord:w }
{ \chord }
}
\cs_new_protected:Npn \leadsheets_recall_chord:nn #1#2
{
\seq_pop_left:NNF \l__leadsheets_chords_sequences_seq
\l__leadsheets_tmpa_tl
{ \msg_error:nnV {leadsheets} {no-chords} \l_leadsheets_verse_type_tl }
\leadsheets_set_chord:nnn
{#1}
{#2}
{ \leadsheets_chord_write:V \l__leadsheets_tmpa_tl }
}
\NewDocumentCommand \__leadsheets_recall_chord:w {st-}
{ \leadsheets_recall_chord:nn {#1} {#2} }
\endinput
|