]> git.donarmstrong.com Git - lilypond.git/blob - ly/predefined-fretboards-init.ly
Doc-de: fixing linkage
[lilypond.git] / ly / predefined-fretboards-init.ly
1 %%%% This file is part of LilyPond, the GNU music typesetter.
2 %%%%
3 %%%% Copyright (C) 2008--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 % chord-shape-table is a hash-table of chord shapes
21 % in the form of diagram-descriptions that can be
22 % fret-diagram-verbose markup-llsts or
23 % fret-diagram-terse strings.
24 % The hash keys are pairs of scheme symbols and
25 % string tunings.  For convenience, the symbols in
26 % this file are LilyPond chordmode chord descriptions,
27 % but that is unnecessary.
28
29 % music function for adding a chord shape to
30 % chord-shape-table
31
32 addChordShape =
33 #(define-music-function (parser location key-symbol tuning shape-definition)
34    (symbol? pair? string-or-pair?)
35    (_i "Add chord shape @var{shape-definition} to the @var{chord-shape-table}
36 hash with the key @var{(cons key-symbol tuning)}.")
37    (hash-set! chord-shape-table
38                (cons key-symbol tuning)
39                shape-definition)
40    (make-music 'SequentialMusic 'void #t))
41
42 #(define (chord-shape shape-code tuning)
43    (get-chord-shape shape-code tuning chord-shape-table))
44
45 % scheme function for copying/creating fretboard tables
46
47 #(define (make-fretboard-table . rest)
48   "Create a new fretboard table.  @code{rest} is an optional table name.
49 If present, the new fretboard table starts as a copy of the fretboard
50 table @code{rest}."
51   (if (null? rest)
52       (make-hash-table 101)
53       (let ((source-table (car rest)))
54         (hash-fold
55           (lambda (key value tab)
56             (hash-set! tab key value)
57             tab)
58           (make-hash-table 101)
59           source-table))))
60
61 % music function for adding a predefined diagram to
62 % fretboard-table
63
64 storePredefinedDiagram =
65 #(define-music-function
66    (parser location fretboard-table chord tuning diagram-definition)
67    (hash-table? ly:music? pair? string-or-pair?)
68   (_i "Add predefined fret diagram defined by @var{diagram-definition}
69   for the chord pitches @var{chord} and the stringTuning @var{tuning}.")
70   (let* ((pitches (event-chord-pitches
71                     (car (extract-named-music chord 'EventChord))))
72          (hash-key (cons tuning pitches))
73          (verbose-definition (if (string? diagram-definition)
74                                  (parse-terse-string diagram-definition)
75                                  diagram-definition)))
76   (hash-set! fretboard-table
77              hash-key
78              verbose-definition)
79   (make-music 'SequentialMusic 'void #t)))