]> git.donarmstrong.com Git - lilypond.git/blob - ly/string-tunings-init.ly
string-tunings-init.ly: let \contextStringTunings affect only current context.
[lilypond.git] / ly / string-tunings-init.ly
1 %%%% This file is part of LilyPond, the GNU music typesetter.
2 %%%%
3 %%%% Copyright (C) 2010--2011 Carl D. Sorensen <c_sorensen@byu.edu>
4 %%%%
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.
9 %%%%
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.
14 %%%%
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/>.
17
18 \version "2.14.0"
19
20 %%  A stringTuning is a list of pitches ordered by string number
21 %%  from 1 to N.
22 %%  Here we define a number of default string tunings.
23
24 %% A scheme function for converting a chord to a string tuning
25 #(define (chord->tuning parser tuning-symbol chord)
26   (let* ((ev-chord (car (extract-named-music chord 'EventChord)))
27          (pitches (event-chord-pitches ev-chord)))
28     (ly:parser-define! parser tuning-symbol (reverse pitches))))
29
30 %% A music function for converting a chord to a string tuning.
31 %% The music argument for \makeStringTuning must be a chord in
32 %% absolute mode ordered from the highest string number to the
33 %% lowest string number
34
35 makeStringTuning =
36 #(define-music-function (parser location tuning chord)
37    (symbol? ly:music?)
38    (_ "Convert @{chord} to a string tuning stored in @code{tuning}.
39 @{chord} must be in absolute pitches and should have the highest
40 string number (generally the lowest pitch) first.  @code{tuning}
41 should be a string that will be converted to a symbol.")
42    (begin
43      (chord->tuning parser tuning chord)
44      (make-music 'SequentialMusic 'void #t)))
45
46
47 %% A music function for converting a chord to a string tuning
48 %% and setting the current context stringTunings property to
49 %% the newly-defined-string tuning.
50
51 contextStringTuning =
52 #(define-music-function (parser location tuning chord)
53    (symbol? ly:music?)
54    (_ "Convert @{chord} to a string tuning stored in @code{tuning},
55 and set @code{stringTunings} of the current context to the
56 newly-defined tuning.
57 @{chord} must be in absolute pitches and should have the highest
58 string number (generally the lowest pitch) first.  @code{tuning}
59 should be a string that will be converted to a symbol.")
60   (chord->tuning parser tuning chord)
61   #{ \set stringTunings #(ly:parser-lookup $parser $tuning)
62   #})
63
64 %% A music function for converting an alist to string-tunings
65 makeDefaultStringTunings =
66 #(define-music-function (parser location default-tuning-alist)
67    (cheap-list?)
68    (_ "Define default string tunings for each element of
69 @code{default-tuning-alist}.")
70    (begin
71      (for-each (lambda (alist-entry)
72                  (chord->tuning parser (car alist-entry) (cdr alist-entry)))
73                default-tuning-alist)
74      (make-music 'SequentialMusic 'void #t)))
75
76 % tuning definitions require default pitchnames
77 \languageSaveAndChange #default-language
78
79 %% Define alist of default string tunings
80 defaultStringTunings =
81 #`(
82    ;; guitar tunings
83    (guitar-tuning . ,#{<e, a, d g b e'>#})
84    (guitar-seven-string-tuning . ,#{<b,, e, a, d g b e'>#})
85    (guitar-drop-d-tuning . ,#{<d, a, d g b e'>#})
86    (guitar-open-g-tuning . ,#{<d, g, d g b d'>#})
87    (guitar-open-d-tuning . ,#{<d, a, d fis a d'>#})
88    (guitar-dadgad-tuning . ,#{<d, a, d g a d'>#})
89    (guitar-lute-tuning . ,#{<e, a, d fis b e'>#})
90    (guitar-asus4-tuning . ,#{<e, a, d e a e'>#})
91
92    ;; bass tunings
93    (bass-tuning . ,#{<e,, a,, d, g,>#})
94    (bass-four-string-tuning . ,#{<e,, a,, d, g,>#})
95    (bass-drop-d-tuning . ,#{<d,, a,, d, g,>#})
96    (bass-five-string-tuning . ,#{<b,,, e,, a,, d, g,>#})
97    (bass-six-string-tuning . ,#{<b,,, e,, a,, d, g, c>#})
98
99    ;; mandolin tunings
100    (mandolin-tuning . ,#{<g d' a' e''>#})
101
102    ;; tunings for 5-string banjo
103    (banjo-open-g-tuning . ,#{<g' d g b d'>#})
104    (banjo-c-tuning . ,#{<g' c g b d'>#})
105    (banjo-modal-tuning . ,#{<g' d g c' d'>#})
106    (banjo-open-d-tuning . ,#{<a' d fis a d'>#})
107    (banjo-open-dm-tuning . ,#{<a' d fis a d'>#})
108
109    ;; ukulele tunings
110    (ukulele-tuning . ,#{<g' c' e' a'>#})
111    (ukulele-d-tuning . ,#{<a' d' fis' b'>#})
112    (tenor-ukulele-tuning . ,#{<a' e' c' g>#})
113    (baritone-ukulele-tuning . ,#{<e' b g d>#})
114
115    ;; orchestral strings
116    (violin-tuning . ,#{<g d' a' e''>#})
117    (viola-tuning . ,#{<c g d' a'>#})
118    (cello-tuning . ,#{<c, g, d a>#})
119    (double-bass-tuning . ,#{<e,, a,, d, g,>#})
120   )
121
122 %% convert 5-string banjo tuning to 4-string by removing the 5th string
123 #(define-public (four-string-banjo tuning)
124    (reverse (cdr (reverse tuning))))
125
126 %% make all of the default string tunings
127
128 \makeDefaultStringTunings #defaultStringTunings
129
130 % restore the language
131 \languageRestore
132