]> git.donarmstrong.com Git - lilypond.git/blob - ly/base-tkit.ly
Web-ja: update introduction
[lilypond.git] / ly / base-tkit.ly
1 %\version "2.19.22"
2
3 %%% These are the general utility functions and storage
4 %   used by the built-in templates and the template kits
5 %   (tkits) supporting them.
6
7 % TODO: these may be more sensibly (re)defined as a scm file
8
9 #(define (get-id str)
10    "Return the identifier with the value str"
11    (ly:parser-lookup (string->symbol str)))
12
13 #(define (make-id a b)
14   "Return the identifier formed from concatenating the
15    two strings provided as arguments."
16    (get-id (string-append a b)))
17
18 #(define (cartesian a b)
19   "Return a list formed from concatenating every element
20    of list a with every element of list b (the cartesian
21    product a X b)."
22    (append-map
23     (lambda (x)
24       (map
25        (lambda (y)
26          (string-append x y))
27        b))
28     a))
29
30 #(define (define-missing-variables! ids)
31   "Check if each of the identifiers listed in the argument is
32    known to the parser.  If any are not, define them and set
33    their value to #f"
34    (for-each
35       (lambda (id)
36         (define sym (string->symbol id))
37           (if (null? (ly:parser-lookup sym))
38             (ly:parser-define! sym #f)))
39       ids))
40
41 % Define the lists used to hold the names and
42 % component names which form the variable names
43 % used in the templates.  These are populated by the
44 % set-music-definitions! procedure
45 % The variables defined here as empty lists will be provided
46 % by the template, and may be set to any values there.
47 #(define voice-prefixes '())   % eg "Soprano"
48 #(define all-music-names '())  % eg "SopranoMusic"
49 #(define lyrics-postfixes '())  % eg "Lyrics"
50 #(define lyrics-names '())     % eg "VerseOne"
51
52 % Define the derived variables to be populated
53 #(define all-music-lyrics-names '())  % eg "SopranoLyrics"
54 #(define AllMusic (make-music 'SequentialMusic 'void #t))
55 #(define KeepAlive AllMusic)   % used to ensure voices don't terminate
56 #(define have-music #f)        % -> #t when at least one music name
57                                 %    contains music
58 #(define voice-postfixes
59    ;; These names are used verbatim in code, so may not be changed
60    '("InstrumentName"
61      "MidiInstrument"
62      "Music"
63      "ShortInstrumentName"))
64
65 #(define variable-names
66    ;; These names are used verbatim in code, so may not be changed
67    '("Key"
68      "Layout"
69      "PianoDynamics"
70      "Time"
71      "TwoVoicesPerStaff"))
72
73 % Define the predicates used in the tkits and templates
74 #(define (above-or-below? x)
75   (member x '("Above" "Below")))
76
77 #(define (up-or-down? x)
78    (member x '("Down" "Up" "")))
79
80 #(define (voice-prefix? x)
81    (member x voice-prefixes))
82
83 #(define (vocal-lyrics-or-verses? x)
84   (or (member x lyrics-postfixes)
85       (member x lyrics-names)))
86
87
88 #(define (set-music-definitions! prefixes lyr-postfixes lyr-names)
89   "Populate the name definitions and their derivatives
90    with the values provided by the calling template"
91    (set! voice-prefixes prefixes)
92    (append! variable-names lyr-names)
93    (set! all-music-names
94          (cartesian voice-prefixes '("Music")))
95    (set! lyrics-postfixes lyr-postfixes)
96    (set! lyrics-names lyr-names)
97    (set! all-music-lyrics-names
98      (cartesian voice-prefixes (append
99                                 voice-postfixes
100                                 lyrics-postfixes)))
101    (define-missing-variables! (append
102                                   all-music-lyrics-names
103                                   variable-names))
104    (set! AllMusic
105      (make-simultaneous-music
106       (filter ly:music?
107               (map
108                (lambda (x)
109                  (get-id x))
110                all-music-names))))
111    (set! KeepAlive
112          (skip-of-length AllMusic))
113    (set! have-music
114          (ly:moment<?
115           (ly:make-moment 0)
116           (ly:music-length KeepAlive))))
117