1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2009 Marc Hohl <marc@hohlart.de>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
18 ;; default tunings for common string instruments
20 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
21 (define-public guitar-seven-string-tuning '(4 -1 -5 -10 -15 -20 -25))
22 (define-public guitar-drop-d-tuning '(4 -1 -5 -10 -15 -22))
23 (define-public guitar-open-g-tuning '(2 -1 -5 -10 -17 -22))
24 (define-public guitar-open-d-tuning '(2 -3 -6 -10 -15 -22))
25 (define-public guitar-dadgad-tuning '(2 -3 -7 -10 -15 -22))
26 (define-public guitar-lute-tuning '(4 -1 -6 -10 -15 -20))
27 (define-public guitar-asus4-tuning '(4 -3 -8 -10 -15 -20))
29 (define-public bass-tuning '(-17 -22 -27 -32))
30 (define-public bass-four-string-tuning '(-17 -22 -27 -32))
31 (define-public bass-drop-d-tuning '(-17 -22 -27 -34))
32 (define-public bass-five-string-tuning '(-17 -22 -27 -32 -37))
33 (define-public bass-six-string-tuning '(-12 -17 -22 -27 -32 -37))
35 (define-public mandolin-tuning '(16 9 2 -5))
36 ;; tunings for 5-string banjo
37 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
38 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
39 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
40 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
41 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
42 ;; convert 5-string banjo tuning to 4-string by removing the 5th string
43 (define-public (four-string-banjo tuning)
44 (reverse (cdr (reverse tuning))))
46 (define-public ukulele-tuning '(9 4 0 7)) ;ukulele a' e' c' g'
47 (define-public ukulele-d-tuning '(11 6 2 9)) ;ukulele d tuning, b' fis' d' a'
48 (define-public ukulele-tenor-tuning '(-5 0 4 9)) ;tenor ukulele, g c' e' a'
49 (define-public ukulele-baritone-tuning '(-10 -5 -1 4)) ;baritone ukulele, d g b e'
52 ;; for more control over glyph-name calculations,
53 ;; we use a custom callback for tab note heads
54 ;; which will ignore 'style = 'do
55 (define-public (tab-note-head::calc-glyph-name grob)
56 (let ((style (ly:grob-property grob 'style)))
61 ;; ensure we only call note head callback when
63 (define-public (tab-note-head::whiteout-if-style-set grob)
64 (let ((style (ly:grob-property grob 'style)))
66 (if (and (symbol? style)
68 (stencil-whiteout (ly:note-head::print grob))
69 (ly:text-interface::print grob))))
71 ;; definitions for the "moderntab" clef:
72 ;; the "moderntab" clef will be added to the list of known clefs,
73 ;; so it can be used as any other clef: \clef "moderntab"
74 (add-new-clef "moderntab" "markup.moderntab" 0 0 0)
76 ;; define sans serif-style tab-Clefs as a markup:
77 (define-builtin-markup-command (customTabClef
78 layout props num-strings staff-space)
82 "Draw a tab clef sans-serif style."
83 (define (square x) (* x x))
84 (let* ((scale-factor (/ staff-space 1.5))
85 (font-size (- (* num-strings 1.5 scale-factor) 7))
86 (base-skip (* (square (+ (* num-strings 0.195) 0.4)) scale-factor)))
88 (interpret-markup layout props
89 (markup #:vcenter #:bold
90 #:override (cons 'font-family 'sans)
92 #:override (cons 'baseline-skip base-skip)
93 #:left-align #:center-column ("T" "A" "B")))))
95 ;; this function decides which clef to take
96 (define-public (clef::print-modern-tab-if-set grob)
97 (let ((glyph (ly:grob-property grob 'glyph)))
99 ;; which clef is wanted?
100 (if (string=? glyph "markup.moderntab")
101 ;; if it is "moderntab", we'll draw it
102 (let* ((staff-symbol (ly:grob-object grob 'staff-symbol))
103 (line-count (ly:grob-property staff-symbol 'line-count))
104 (staff-space (ly:staff-symbol-staff-space grob)))
106 (grob-interpret-markup grob (make-customTabClef-markup line-count
108 ;; otherwise, we simply use the default printing routine
109 (ly:clef::print grob))))
111 ;; if stems are drawn, it is nice to have a double stem for
112 ;; (dotted) half notes to distinguish them from quarter notes:
113 (define-public (tabvoice::draw-double-stem-for-half-notes grob)
114 (let ((stem (ly:stem::print grob)))
116 ;; is the note a (dotted) half note?
117 (if (= 1 (ly:grob-property grob 'duration-log))
118 ;; yes -> draw double stem
119 (ly:stencil-combine-at-edge stem X RIGHT stem 0.5)
120 ;; no -> draw simple stem
123 ;; as default, the glissando line between fret numbers goes
124 ;; upwards, here we have a function to correct this behavior:
125 (define-public (glissando::calc-tab-extra-dy grob)
126 (let* ((original (ly:grob-original grob))
127 (left-bound (ly:spanner-bound original LEFT))
128 (right-bound (ly:spanner-bound original RIGHT))
129 (left-pitch (ly:event-property (event-cause left-bound) 'pitch))
130 (right-pitch (ly:event-property (event-cause right-bound) 'pitch)))
132 (if (< (ly:pitch-semitones right-pitch) (ly:pitch-semitones left-pitch))
136 ;; for ties in tablature, fret numbers that are tied to should be invisible,
137 ;; except for 'tied to' numbers after a line break;; these will be
138 ;; parenthesized (thanks to Neil for his solution):
139 (define-public (parenthesize-tab-note-head grob)
140 ;; Helper function to parenthesize tab noteheads,
141 ;; since we can't use ParenthesesItem at this stage
142 ;; This is basically the same as the C++ function
143 ;; in accidental.cc, converted to Scheme
144 (let* ((font (ly:grob-default-font grob))
145 (open (stencil-whiteout
146 (ly:font-get-glyph font "accidentals.leftparen")))
147 (close (stencil-whiteout
148 (ly:font-get-glyph font "accidentals.rightparen")))
149 (me (ly:text-interface::print grob)))
151 (ly:stencil-combine-at-edge
152 (ly:stencil-combine-at-edge me X LEFT open) X RIGHT close)))
154 ;; ParenthesesItem doesn't work very well for TabNoteHead, since
155 ;; the parentheses are too small and clash with the staff-lines
156 ;; Define a callback for the 'stencils property which will tweak
157 ;; the parentheses' appearance for TabNoteHead
158 (define-public (parentheses-item::calc-tabstaff-parenthesis-stencils grob)
159 ;; the grob we want to parenthesize
160 (let ((victim (ly:grob-array-ref (ly:grob-object grob 'elements) 0)))
162 ;; check whether it's a note head
163 (if (grob::has-interface victim 'note-head-interface)
165 ;; tweak appearance before retrieving
166 ;; list of stencils '(left-paren right-paren)
167 ;; get the font-size from victim (=TabNoteHead) to handle
168 ;; grace notes properly
169 (ly:grob-set-property! grob 'font-size
170 (ly:grob-property victim 'font-size))
171 (ly:grob-set-property! grob 'padding 0)
172 ;; apply whiteout to each element of the list
173 (map stencil-whiteout
174 (parentheses-item::calc-parenthesis-stencils grob)))
175 (parentheses-item::calc-parenthesis-stencils grob))))
177 ;; the handler for ties in tablature; according to TabNoteHead #'details,
178 ;; the 'tied to' note is handled differently after a line break
179 (define-public (tie::handle-tab-note-head grob)
180 (let* ((original (ly:grob-original grob))
181 (tied-tab-note-head (ly:spanner-bound grob RIGHT))
182 (siblings (if (ly:grob? original)
183 (ly:spanner-broken-into original) '())))
185 (if (and (>= (length siblings) 2)
186 (eq? (car (last-pair siblings)) grob))
187 ;; tie is split -> get TabNoteHead #'details
188 (let* ((details (ly:grob-property tied-tab-note-head 'details))
189 (tied-properties (assoc-get 'tied-properties details '()))
190 (tab-note-head-parenthesized (assoc-get 'parenthesize tied-properties #t))
191 ;; we need the begin-of-line entry in the 'break-visibility vector
192 (tab-note-head-visible
193 (vector-ref (assoc-get 'break-visibility
194 tied-properties #(#f #f #t)) 2)))
196 (if tab-note-head-visible
197 ;; tab note head is visible
198 (if tab-note-head-parenthesized
199 (ly:grob-set-property! tied-tab-note-head 'stencil
201 (parenthesize-tab-note-head grob))))
202 ;; tab note head is invisible
203 (ly:grob-set-property! tied-tab-note-head 'transparent #t)))
205 ;; tie is not split -> make fret number invisible
206 (ly:grob-set-property! tied-tab-note-head 'transparent #t))))
208 ;; repeat ties occur within alternatives in a repeat construct;
209 ;; TabNoteHead #'details handles the appearance in this case
210 (define-public (repeat-tie::handle-tab-note-head grob)
211 (let* ((tied-tab-note-head (ly:grob-object grob 'note-head))
212 (details (ly:grob-property tied-tab-note-head 'details))
213 (repeat-tied-properties (assoc-get 'repeat-tied-properties details '()))
214 (tab-note-head-visible (assoc-get 'note-head-visible repeat-tied-properties #t))
215 (tab-note-head-parenthesized (assoc-get 'parenthesize repeat-tied-properties #t)))
217 (if tab-note-head-visible
218 ;; tab note head is visible
219 (if tab-note-head-parenthesized
220 (ly:grob-set-property! tied-tab-note-head 'stencil
222 (parenthesize-tab-note-head grob))))
223 ;; tab note head is invisible
224 (ly:grob-set-property! tied-tab-note-head 'transparent #t))))
226 ;; the slurs should not be too far apart from the corresponding fret number, so
227 ;; we move the slur towards the TabNoteHeads:
228 (define-public (slur::draw-tab-slur grob)
229 ;; TODO: use a less "brute-force" method to decrease
230 ;; the distance between the slur ends and the fret numbers
231 (let* ((staff-space (ly:staff-symbol-staff-space grob))
232 (control-points (ly:grob-property grob 'control-points))
233 (new-control-points (map
238 (ly:grob-property grob 'direction)
242 (ly:grob-set-property! grob 'control-points new-control-points)
243 (ly:slur::print grob)))