-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtabs.sty
346 lines (315 loc) · 11.4 KB
/
gtabs.sty
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
% package info and requirements:
\NeedsTeXFormat{LaTeX2e}
\def\gcs@date{2023/02/26}
\def\gcs@version{v0.1}
\def\gcs@description{Guitar Tabs with TikZ (CN)}
\ProvidesPackage{gtabs}[\gcs@date\space \gcs@version\space \gcs@description]
\RequirePackage{tikz,cnltx-base}
\usetikzlibrary{shapes.misc,arrows,calc}
% --------------------------------------------------------------------------
% message handling
\newcommand*\gcs@error@message{%
For details have a look at the `guitarchordschemes' manual.%
}
\cnltx@create@generic@message{gcs}{gtabs}{Error}{\gcs@error@message}
\cnltx@create@generic@message{gcs}{gtabs}{Warning}{}
\cnltx@create@generic@message{gcs}{gtabs}{WarningNoLine}{}
\cnltx@create@generic@message{gcs}{gtabs}{Info}{}
\newcommand*\gcs@missing@date@error[2]{%
\gcs@error
{#1: empty #2}
{#1: It seems you didn't specify the #2}%
}
\newrobustcmd*\gcs@def[1]{%
\ifdef{#1}
{%
\gcs@error
{The macro \string#1\space is already defined}
{%
The macro \string#1\space is already defined. Please let the package
author know%
}%
}
{\protected\def#1}%
}
\newrobustcmd*\gcs@deprecated@option[2]{%
\gcs@warning{Since version #1 the option `#2' has been dropped}%
}
% --------------------------------------------------------------------------
% package options and setup:
\newcommand*\gcs@finger@font{\sffamily\small}
\newcommand*\gcs@position@font{\sffamily}
\newcommand*\gcs@string@name@format{\sffamily\small}
\newcommand*\gcs@x@unit{.8cm}
\newcommand*\gcs@y@unit{.8cm}
\newcommand*\gcs@line@width{1pt}
\newcommand*\gcs@finger@radius{.1875}
\newcommand*\gcs@finger@x@offset{.375}
\newcommand*\gcs@finger@y@offset{.275}
\newcommand*\gcs@angle{0}
\newcommand*\gcs@string@number{6}
\newcommand*\gcs@setstringnumber[1]{%
\ifnumless{#1}{1}
{%
\gcs@warning{You can't use less than one string. Setting string number
to 1}%
\def\gcs@string@number{1}%
}
{%
\ifnumgreater{#1}{7}
{%
\gcs@warning{You can't use more than seven
strings. Setting string number to 6}%
\def\gcs@string@number{6}%
}
{\def\gcs@string@number{#1}}%
}%
}
\newcommand*\gcs@chordscheme@fret@number{4}
\newbool{gcs@restrict@boundingbox}
\newcommand*\gcs@restrictboundingbox[1]{
\ifbool{gcs@restrict@boundingbox}
{
\ifnumequal{\gcs@string@number}{1}
{\useasboundingbox (0,-.4) --++ (1.5*\csname gcs@#1@fret@number\endcsname,.8) ; }
{
\useasboundingbox
(bass)
rectangle
(1.5*\csname gcs@#1@fret@number\endcsname,{.8*(\gcs@string@number-1)}) ;
}
}{}
}
\pgfkeys{
gtabs/.cd ,
x-unit/.code = \def\gcs@x@unit{#1} ,
y-unit/.code = \def\gcs@y@unit{#1} ,
rotate/.code = \def\gcs@angle{#1} ,
strings/.code = \gcs@setstringnumber{#1} ,
finger-format/.code = \def\gcs@finger@font{#1} ,
finger-format+/.code =
\expandafter\def\expandafter\gcs@finger@font
\expandafter{\gcs@finger@font#1} ,
position-format/.code = \def\gcs@position@font{#1} ,
position-format+/.code =
\expandafter\def\expandafter\gcs@position@font
\expandafter{\gcs@position@font#1} ,
chord-frets/.code =
\ifnumless{#1}{4}
{%
\gcs@warning{You cannot use less than 4 frets for a chord!}%
\def\gcs@chordscheme@fret@number{4}%
}
{\def\gcs@chordscheme@fret@number{#1}} ,
line-width/.code = \def\gcs@line@width{#1} ,
finger-radius/.code = \def\gcs@finger@radius{#1} ,
finger-x-offset/.code = \def\gcs@finger@x@offset{#1} ,
finger-y-offset/.code = \def\gcs@finger@y@offset{#1} ,
finger-style/.code = \tikzset{finger style/.style={#1}} ,
ringing-style/.code = \tikzset{ringing style/.style={#1}} ,
muted-style/.code = \tikzset{muted style/.style={#1}} ,
restrict-bounding-box/.is if = gcs@restrict@boundingbox
}
% the setup command:
\newrobustcmd*\setchordscheme[1]{\pgfqkeys{/gtabs}{#1}}
% some defaults -- need to be set before options are processed:
\setchordscheme{
muted-style = {cross out,draw} ,
ringing-style = {draw} ,
finger-style = {fill}
}
\ProcessPgfOptions*
% --------------------------------------------------------------------------
% settings for the whole scheme:
\tikzset{
gcs/finger/.style =
{
xshift = \gcs@finger@x@offset*\gcs@x@unit ,
yshift = \gcs@finger@y@offset*\gcs@y@unit ,
font = \gcs@finger@font
}
}
% setting a chord scheme:
\pgfkeys{
gcs/chord/.cd ,
position/.code = \def\gcs@chord@position{#1} ,
finger/.code = \gcs@chord@finger{#1} ,
mute/.code = \gcs@chord@mute{#1} ,
ring/.code = \gcs@chord@ring{#1} ,
barre/.code = \gcs@chord@barre{#1} ,
fret-number/.code =
\ifnumless{#1}{4}
{%
\gcs@warning{You cannot use less than 4 frets for a chord!}%
\def\gcs@chordscheme@fret@number{4}%
}
{\def\gcs@chordscheme@fret@number{#1}}
}
% --------------------------------------------------------------------------
% the internal commands
% placing fingers:
% <fret>/<string>:<finger>
\newrobustcmd*\gcs@chord@finger[1]{%
\foreach \gcs@finger@spec in {#1}
{
\expandafter\gcs@get@finger@data\gcs@finger@spec::\q@stop
\ifdefvoid\gcs@finger@x
{\gcs@missing@date@error{finger}{position}}
{
\pgfmathsetmacro\gcs@finger@fret{1.5*\gcs@[email protected]}
\ifdefvoid\gcs@finger@y
{\gcs@missing@date@error{finger}{string}}
{
\pgfmathsetmacro\gcs@finger@string{(\gcs@string@number-\gcs@finger@y)*4/5}
\draw[finger style]
(\gcs@finger@fret,\gcs@finger@string)
circle
(\gcs@finger@radius*\gcs@x@unit) ;
\node[gcs/finger]
at (\gcs@finger@fret,\gcs@finger@string)
{\gcs@finger@number} ;
}
}
}
}
\let\gcs@scales@finger\gcs@chord@finger
\gcs@def\gcs@get@finger@data#1/#2:#3:#4\q@stop{%
\def\gcs@finger@x{#1}%
\def\gcs@finger@y{#2}%
\def\gcs@finger@number{#3}%
}
% placing a barre:
% <fret>/<string>-<string>:<finger>
\newrobustcmd*\gcs@chord@barre[1]{%
\foreach \gcs@barre@spec in {#1}
{
\expandafter\gcs@get@barre@data\gcs@barre@spec::\q@stop
\ifdefvoid\gcs@barre@x
{\gcs@missing@date@error{barre}{position}}
{\pgfmathsetmacro\gcs@barre@fret{1.5*\gcs@[email protected]}}
\ifdefvoid\gcs@barre@fromto
{\gcs@missing@date@error{barre}{string range}}
{
\expandafter\gcs@barre@getstrings\gcs@barre@fromto--\q@stop
\pgfmathsetmacro\gcs@barre@lower@string{(\gcs@string@number-\gcs@barre@lower@y)*4/5}
\pgfmathsetmacro\gcs@barre@upper@string{(\gcs@string@number-\gcs@barre@upper@y)*4/5}
\draw[finger style,round cap-round cap,line width=2*\gcs@finger@radius*\gcs@x@unit]
(\gcs@barre@fret,\gcs@barre@lower@string) node[gcs/finger] {\gcs@barre@finger}
++ (0,\gcs@finger@radius*\gcs@x@unit)
--
($(\gcs@barre@fret,\gcs@barre@upper@string)+(0,-\gcs@finger@radius*\gcs@x@unit)$)
;
}
}
}
\gcs@def\gcs@get@barre@data#1/#2:#3:#4\q@stop{%
\def\gcs@barre@x{#1}%
\def\gcs@barre@fromto{#2}%
\def\gcs@barre@finger{#3}%
}
\gcs@def\gcs@barre@getstrings#1-#2-#3\q@stop{%
\ifx#3-\relax
\def\gcs@barre@lower@y{#1}%
\def\gcs@barre@upper@y{#2}%
\else
\gcs@error
{barre: wrong string range syntax}
{barre: wrong string range syntax}%
\fi
}
% muted strings:
\newrobustcmd*\gcs@chord@mute[1]{%
\foreach \muted@string in {#1}
{
\pgfmathsetmacro\muted@string@pos{(6-\muted@string)*4/5}
\node[muted style] at (-1,\muted@string@pos) {} ;
}
}
% ringing strings:
\newrobustcmd*\gcs@chord@ring[1]{%
\foreach \ringing@string in {#1}
{
\pgfmathsetmacro\ringing@string@pos{(\gcs@string@number-\ringing@string)*4/5}
\draw[ringing style]
(-1,\ringing@string@pos) circle (\gcs@finger@radius*\gcs@x@unit) ;
}
}
% --------------------------------------------------------------------------
% the chord scheme command:
\newrobustcmd*\gcs@chordscheme[1]{%
\begingroup
\begin{tikzpicture}[
x=\gcs@x@unit,
y=\gcs@y@unit,
line width=\gcs@line@width,
baseline=(bass)
]
\begin{scope}[rotate=\gcs@angle,local bounding box=diagram]
\coordinate (bass) at (0,0) ;
\gcs@restrictboundingbox{chordscheme}
\pgfqkeys{/gcs/chord}{#1}%
\foreach \fretnumber
in {0,...,\gcs@chordscheme@fret@number}
{
\ifnumequal{\gcs@string@number}{1}
{
\draw (1.5*\fretnumber,-.4) --++ (0,.8) ;
}
{
\ifnumequal{\fretnumber}{0}
{
\ifdefvoid\gcs@chord@position
{
\draw[ultra thick] (1.5*\fretnumber-0.1,-0.025) -- ++(0,{.8*(\gcs@string@number-1) + 0.05}) ;
}
{
\draw (1.5*\fretnumber,-0.025) -- ++(0,{.8*(\gcs@string@number-1) + 0.05}) ;
}
}
{
\ifnumequal{\fretnumber}{\gcs@chordscheme@fret@number}
{}
{
\draw (1.5*\fretnumber,-0.025) -- ++(0,{.8*(\gcs@string@number-1) + 0.05}) ;
}
}
}
}
\foreach \gcs@string in {1,...,\gcs@string@number}
{
\draw
(0,{.8*(\gcs@string@number-\gcs@string)})
node[transform shape,
label={[text height=1.5ex,text depth=.2ex]left:%
\gcs@string@name@format\csuse{guitar@string@\gcs@string}}] {}
--++(1.5*\gcs@chordscheme@fret@number,0) ;
}
\ifdefvoid\gcs@chord@position
{}
{
\draw
(.75,{0.1*(\gcs@string@number-1)})
node[transform shape,
label={[text height=1.5ex, font=\gcs@position@font]%
below:\gcs@chord@position}] {} ;
}
\end{scope}
\end{tikzpicture}
\endgroup
}
% --------------------------------------------------------------------------
% the user commands:
\newrobustcmd*\chordscheme[1][]{\gcs@chordscheme{#1}}
% --------------------------------------------------------------------------
% the symbols for use outside of a scheme:
\newrobustcmd*\gcs@fingersymbol{%
\tikz\draw[finger style] (0,0) circle (\gcs@finger@radius*\gcs@x@unit);}
\newrobustcmd*\ringingstring{%
\tikz\draw[
ringing style,
line width=\gcs@line@width] (0,0) circle (\gcs@finger@radius*\gcs@x@unit);}
\newrobustcmd*\mutedstring{%
\tikz\node[
muted style,
line width=\gcs@line@width] at (0,0) {};}
\endinput