]> git.donarmstrong.com Git - lilypond.git/blob - scm/tablature.scm
Fix indentation in tablature.scm.
[lilypond.git] / scm / tablature.scm
1 ;;;; tablature.scm
2 ;;;;
3 ;;;; source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2009 Marc Hohl <marc@hohlart.de>
6
7 ;; default tunings for common string instruments
8 ;; guitar tunings
9 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
10 (define-public guitar-seven-string-tuning '(4 -1 -5 -10 -15 -20 -25))
11 (define-public guitar-drop-d-tuning '(4 -1 -5 -10 -15 -22))
12 (define-public guitar-open-g-tuning '(2 -1 -5 -10 -17 -22))
13 ;; bass tunings
14 (define-public bass-tuning '(-17 -22 -27 -32))
15 (define-public bass-four-string-tuning '(-17 -22 -27 -32))
16 (define-public bass-drop-d-tuning '(-17 -22 -27 -34))
17 (define-public bass-five-string-tuning '(-17 -22 -27 -32 -37))
18 (define-public bass-six-string-tuning '(-12 -17 -22 -27 -32 -37))
19 ;; mandolin
20 (define-public mandolin-tuning '(16 9 2 -5))
21 ;; tunings for 5-string banjo
22 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
23 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
24 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
25 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
26 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
27 ;; convert 5-string banjo tuning to 4-string by removing the 5th string
28 (define-public (four-string-banjo tuning)
29   (reverse (cdr (reverse tuning))))
30
31 ;; for more control over glyph-name calculations,
32 ;; we use a custom callback for tab noteheads
33 ;; which will ignore 'style = 'do
34 (define-public (tab-note-head::calc-glyph-name grob)
35   (let ((style (ly:grob-property grob 'style)))
36
37     (case style
38       ((cross) "2cross"))))
39
40 ;; ensure we only call notehead callback when
41 ;; 'style = 'cross
42 (define-public (tab-note-head::whiteout-if-style-set grob)
43   (let ((style (ly:grob-property grob 'style)))
44
45     (if (and (symbol? style)
46              (eq? style 'cross))
47         (stencil-whiteout (ly:note-head::print grob))
48         (ly:text-interface::print grob))))
49
50 ;; definitions for the "moderntab" clef:
51 ;; the "moderntab" clef will be added to the list of known clefs,
52 ;; so it can be used as any other clef: \clef "moderntab"
53 (add-new-clef "moderntab" "markup.moderntab" 0 0 0)
54
55 ;; define sans serif-style tab-Clefs as a markup:
56 (define-builtin-markup-command (customTabClef
57                                 layout props num-strings staff-space)
58   (integer? number?)
59   music
60   ()
61   "Draw a tab clef sans-serif style."
62   (define (square x) (* x x))
63   (let* ((scale-factor (/ staff-space 1.5))
64          (font-size (- (* num-strings 1.5 scale-factor) 7))
65          (base-skip (* (square (+ (* num-strings 0.195) 0.4)) scale-factor)))
66
67     (interpret-markup layout props
68                       (markup #:vcenter #:bold
69                               #:override (cons 'font-family 'sans)
70                               #:fontsize font-size
71                               #:override (cons 'baseline-skip base-skip)
72                               #:left-align #:center-column ("T" "A" "B")))))
73
74 ;; this function decides which clef to take
75 (define-public (clef::print-modern-tab-if-set grob)
76   (let ((glyph (ly:grob-property grob 'glyph)))
77
78     ;; which clef is wanted?
79     (if (string=? glyph "markup.moderntab")
80         ;; if it is "moderntab", we'll draw it
81         (let* ((staff-symbol (ly:grob-object grob 'staff-symbol))
82                (line-count (ly:grob-property staff-symbol 'line-count))
83                (staff-space (ly:grob-property staff-symbol 'staff-space 1)))
84
85           (grob-interpret-markup grob (make-customTabClef-markup line-count
86                                                                  staff-space)))
87         ;; otherwise, we simply use the default printing routine
88         (ly:clef::print grob))))
89
90 ;; if stems are drawn, it is nice to have a double stem for
91 ;; (dotted) half notes to distinguish them from quarter notes:
92 (define-public (tabvoice::draw-double-stem-for-half-notes grob)
93   (let ((stem (ly:stem::print grob)))
94
95     ;; is the note a (dotted) half note?
96     (if (= 1 (ly:grob-property grob 'duration-log))
97         ;; yes -> draw double stem
98         (ly:stencil-combine-at-edge stem X RIGHT stem 0.5)
99         ;; no -> draw simple stem
100         stem)))
101
102 ;; as default, the glissando line between fret numbers goes
103 ;; upwards, here we have a function to correct this behavior:
104 (define-public (glissando::calc-tab-extra-dy grob)
105   (let* ((original (ly:grob-original grob))
106          (left-bound (ly:spanner-bound original LEFT))
107          (right-bound (ly:spanner-bound original RIGHT))
108          (left-pitch (ly:event-property (event-cause left-bound) 'pitch))
109          (right-pitch (ly:event-property (event-cause right-bound) 'pitch)))
110
111     (if (< (ly:pitch-semitones right-pitch) (ly:pitch-semitones left-pitch))
112         -0.75
113         0.75)))
114
115 ;; for ties in tablature, fret numbers that are tied to should be invisible,
116 ;; except for 'tied to' numbers after a line break;; these will be
117 ;; parenthesized (thanks to Neil for his solution):
118 (define-public (parenthesize-tab-note-head grob)
119   ;; Helper function to parenthesize tab noteheads,
120   ;; since we can't use ParenthesesItem at this stage
121   ;; This is basically the same as the C++ function
122   ;; in accidental.cc, converted to Scheme
123   (let* ((font (ly:grob-default-font grob))
124          (open (stencil-whiteout
125                 (ly:font-get-glyph font "accidentals.leftparen")))
126          (close (stencil-whiteout
127                  (ly:font-get-glyph font "accidentals.rightparen")))
128          (me (ly:text-interface::print grob)))
129
130     (ly:stencil-combine-at-edge
131      (ly:stencil-combine-at-edge me X LEFT open) X RIGHT close)))
132
133 ;; ParenthesesItem doesn't work very well for TabNoteHead, since
134 ;; the parentheses are too small and clash with the staff-lines
135 ;; Define a callback for the 'stencils property which will tweak
136 ;; the parentheses' appearance for TabNoteHead
137 (define-public (parentheses-item::calc-tabstaff-parenthesis-stencils grob)
138   ;; the grob we want to parenthesize
139   (let ((victim (ly:grob-array-ref (ly:grob-object grob 'elements) 0)))
140
141     ;; check whether it's a note head
142     (if (grob::has-interface victim 'note-head-interface)
143         (begin
144           ;; tweak appearance before retrieving
145           ;; list of stencils '(left-paren right-paren)
146           ;; get the font-size from victim (=TabNoteHead) to handle
147           ;; grace notes properly
148           (ly:grob-set-property! grob 'font-size
149                                  (ly:grob-property victim 'font-size))
150           (ly:grob-set-property! grob 'padding 0)
151           ;; apply whiteout to each element of the list
152           (map stencil-whiteout
153                (parentheses-item::calc-parenthesis-stencils grob)))
154         (parentheses-item::calc-parenthesis-stencils grob))))
155
156 ;; the handler for ties in tablature;; split ties yield in a parenthesized
157 ;; fret number, otherwise the fret number will be invisible.
158 (define-public (tie::handle-tab-tie grob)
159   (let* ((original (ly:grob-original grob))
160          (tied-tab-note-head (ly:spanner-bound grob RIGHT))
161          (siblings (if (ly:grob? original)
162                        (ly:spanner-broken-into original) '())))
163
164     (if (and (>= (length siblings) 2)
165              (eq? (car (last-pair siblings)) grob))
166         ;; tie is split -> parenthesize
167         (ly:grob-set-property! tied-tab-note-head 'stencil
168                                (lambda (grob)
169                                  (parenthesize-tab-note-head grob)))
170
171         ;; tie is not split -> make fret number invisible
172         (ly:grob-set-property! tied-tab-note-head 'transparent #t))))
173
174 ;; repeat ties occur within alternatives in a repeat construct;
175 ;; the correspondig fret numbers are shown in parentheses:
176 (define-public (repeat-tie::parenthesize-tab-note-head grob)
177   (let ((tied-tab-note-head (ly:grob-object grob 'note-head)))
178
179     (ly:grob-set-property! tied-tab-note-head 'stencil
180                            (lambda (grob) (parenthesize-tab-note-head grob)))))