]> git.donarmstrong.com Git - lilypond.git/blob - ly/predefined-fretboards-init.ly
Web-ja: update introduction
[lilypond.git] / ly / predefined-fretboards-init.ly
1 %%%% This file is part of LilyPond, the GNU music typesetter.
2 %%%%
3 %%%% Copyright (C) 2008--2015 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.19.22"
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-void-function (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 @code{(cons @var{key-symbol} @var{tuning})}.")
37    (hash-set! chord-shape-table
38                (cons key-symbol tuning)
39                shape-definition))
40
41 #(define (chord-shape shape-code tuning)
42    (get-chord-shape shape-code tuning chord-shape-table))
43
44 % scheme function for copying/creating fretboard tables
45
46 #(define (make-fretboard-table . rest)
47   "Create a new fretboard table.  @code{rest} is an optional table name.
48 If present, the new fretboard table starts as a copy of the fretboard
49 table @code{rest}."
50   (if (null? rest)
51       (make-hash-table 101)
52       (let ((source-table (car rest)))
53         (hash-fold
54           (lambda (key value tab)
55             (hash-set! tab key value)
56             tab)
57           (make-hash-table 101)
58           source-table))))
59
60 % music function for adding a predefined diagram to
61 % fretboard-table
62
63 storePredefinedDiagram =
64 #(define-void-function
65    (fretboard-table chord tuning diagram-definition)
66    (hash-table? ly:music? pair? string-or-pair?)
67   (_i "Add predefined fret diagram defined by @var{diagram-definition}
68   for the chord pitches @var{chord} and the stringTuning @var{tuning}.")
69   (let* ((pitches (event-chord-pitches
70                     (car (extract-named-music chord 'EventChord))))
71          (hash-key (cons tuning pitches))
72          (verbose-definition (if (string? diagram-definition)
73                                  (parse-terse-string diagram-definition)
74                                  diagram-definition)))
75   (hash-set! fretboard-table
76              hash-key
77              verbose-definition)))