]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam-settings.scm
Bump documentation license to v1.3+.
[lilypond.git] / scm / beam-settings.scm
1 ;;;; beam-settings.scm --  Handle auto-beam and subdivide-beam settings
2 ;;;;
3 ;;;; source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2009 Carl Sorensen <c_sorensen@byu.edu>
6
7 ;;; specify default beaming rules
8
9 ;;; format:
10 ;;;
11 ;;; alist of
12 ;;;   ((time-signature function) . (beam-type . grouping)) entries
13 ;;;
14 ;;; where
15 ;;;
16 ;;;     time-signature = time signature fraction (pair of numbers, (4 . 4) )
17 ;;;     function = 'end or 'subdivide (possibly implement 'begin in the future)
18 ;;;     beam-type = '* or (numerator . denominator); e.g. (1 . 16)
19 ;;;       NOTE: numerator is kept in beam-type because of
20 ;;;             tuplets, e.g. (2 . 24) = (2 . 3) * (1 . 8)
21 ;;;             for eighth-note triplets.
22 ;;;     grouping = a list of groups, in units of time signature denominator
23 ;;;         (for default rules) or beam-type (for explicit rules)
24 ;;;
25
26 (define-public default-beam-settings
27  `(
28    ;; in 2 2 time:
29    ;;   default: end beams on 1 2 note boundaries
30    ;;   end beams with 32nd notes each 1 4 beat
31    (((2 . 2) end) .
32     ((* . (1 1))
33     ((1 . 32) . (8 8 8 8))))
34
35    ;; in 2 4, 2 8 and 2 16 time:
36    ;;   default: end beams on beats
37    (((2 . 4) end) . ((* . (1 1))))
38    (((2 . 8) end) . ((* . (1 1))))
39    (((2 . 16) end) . ((* . (1 1))))
40
41    ;; in 3 2 time:
42    ;;   default: end beams on beats
43    ;;   end beams with 32nd notes each 1 4 beat
44    (((3 . 2) end) .
45     ((* . (1 1 1))
46      ((1 . 32) . (8 8 8 8 8 8))))
47
48     ;; in 3 4 time:
49     ;;   default: set grouping to (3) so we'll get
50     ;;     the proper measure grouping symbol
51     ;;
52     ;;   set all beams to end on beats, but 1 8 to beam entire measure
53    (((3 . 4) end) .((* . (3))
54                     ((1 . 8) . (6))
55                     ((1 . 16) . (4 4 4))
56                     ((1 . 32) . (8 8 8))
57                     ((1 . 64) . (16 16 16))
58                     ((1 . 128) . (32 32 32))))
59
60     ;; in 3 8 and 3 16 time time:
61     ;;   default: group on 3
62    (((3 . 8) end) . ((* . (3))))
63    (((3 . 16) end) . ((* . (3))))
64
65     ;; in 4 2 time:
66     ;;   default: end beams on beats
67     ;;   end beams with 16th notes each 1 4 beat
68     ;;   end beams with 32nd notes each 1 8 beat
69    (((4 . 2) end) .
70     ((* . (1 1 1 1))
71      ((1 . 16) . (4 4 4 4 4 4 4 4))
72      ((1 . 32) . (4 4 4 4
73                   4 4 4 4
74                   4 4 4 4
75                   4 4 4 4))))
76
77     ;; in 4 4 (common) time:
78     ;;   default: end beams on beats
79     ;;   end beams with 8th notes each 1 2 beat
80    (((4 . 4) end) .
81     ((* . (1 1 1 1))
82      ((1 . 8) . (4 4))))
83
84     ;; in 4 8 time:
85     ;;   default: group on 1 4 notes
86    (((4 . 8) end) . ((* . (2 2))))
87
88     ;; in 4 16 time:
89     ;;   default: group on beats
90    (((4 . 16) end) . ((* . (1 1 1 1))))
91
92     ;; in 6 4 time:
93     ;;   default group at 3 4
94     ;;   end beams with 16th or 32nd notes each 1 4 beat
95    (((6 . 4) end) .
96     ((* . (3 3))
97      ((1 . 16) . (4 4 4 4 4 4))
98      ((1 . 32) . (8 8 8 8 8 8))))
99
100     ;; in 6 8 time:
101     ;;   default: group at 3 8
102     ;;   end beams with 32nd notes each 1 8 beat
103    (((6 . 8) end) .
104     ((* . (3 3))
105      ((1 . 32) . (4 4 4 4 4 4))))
106
107     ;; in 6 16 time:
108     ;;   default: group at 3 16
109    (((6 . 16) end) . ((* . (3 3))))
110
111     ;; in 9 4 time:
112     ;;   default: group at 3 4
113     ;;   end beams with 16th or 32nd notes each 1 4 beat
114    (((9 . 4) end) .
115     ((* . (3 3 3))
116      ((1 . 16) . (4 4 4 4 4 4 4 4 4))
117      ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
118
119     ;; in 9 8 time:
120     ;;   default: group at 3 8
121     ;;   use beatGrouping for all except 32nd notes
122     ;;   end beams with 32nd notes each 1 8 beat
123    (((9 . 8) end) .
124     ((* . (3 3 3))
125      ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
126
127     ;; in 9 16 time
128     ;;   default: group at 3 8
129    (((9 . 16) end) . ((* . (3 3 3))))
130
131     ;; in 12 4 time:
132     ;;   default: group at 3 4
133     ;;   end beams with 16th or 32nd notes each 1 4 beat
134    (((12 . 4) end) .
135     ((* . (3 3 3 3))
136      ((1 . 16) . (4 4 4 4 4 4 4 4 4 4 4 4 4))
137      ((12 . 4) . (8 8 8 8 8 8 8 8 8 8 8 8 8))))
138
139     ;; in 12 8 time:
140     ;;   default: group at 3 8
141     ;;   end beams with 32nd notes each 1 8 beat
142    (((12 . 8) end) .
143     ((* . (3 3 3 3))
144      ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
145
146     ;; in 12 16 time:
147     ;;   default: group at 3 16
148    (((12 . 16) end) . ((* . (3 3 3 3))))
149
150     ;; in 5 8 time:
151     ;;   default: group (3 2)
152    (((5 . 8) end) . ((* . (3 2))))
153
154     ;; in 8 8 time:
155     ;;   default: group (3 3 2)
156    (((8 . 8) end) . ((* . (3 3 2))))
157   ))  ; end of alist definition
158
159 ;;; Functions for overriding beam settings
160 ;;;
161
162 (define (overridden-property-alist context property setting value)
163   "Return an alist containing the current @{context} value of
164 @code{property} overriden by @code{(setting . value)}. "
165   (cons (cons setting value) (ly:context-property context property)))
166
167 (define-public (override-property-setting context property setting value)
168   "Like the C++ code that executes \\override, but without type
169 checking. "
170   (ly:context-set-property!
171     context property
172     (overridden-property-alist context property setting value)))
173
174 (define (revert-property-setting context property setting)
175   "Like the C++ code that executes \revert, but without type
176 checking. "
177
178   (define (revert-member alist entry new)
179     "Return ALIST, with ENTRY removed.  ALIST is not modified, instead
180 a fresh copy of the list-head is made."
181     (cond
182       ((null? alist) new)
183       ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
184       (else (revert-member (cdr alist) entry (cons (car alist) new)))))
185
186   (ly:context-set-property!
187     context property
188     (revert-member (ly:context-property context property) setting '())))
189
190 (define-public (override-beam-setting
191                   time-signature rule-type rule . rest)
192   "Override the beam settings for the context in @var{rest},
193 for @var{time-signature} and  @var{rule-type}, with the
194 new rule alist @var{rule}. "
195   (define (make-setting c)
196     (let ((new-settings
197             (overridden-property-alist
198               c
199               'beamSettings
200               (list time-signature rule-type)
201               rule)))
202       (ly:context-set-property! c 'beamSettings new-settings)))
203
204   (let ((music-to-export
205           (context-spec-music
206             (make-apply-context make-setting)
207               (if (and (pair? rest) (symbol? (car rest)))
208                   (car rest)
209                   'Voice))))
210     (ly:export music-to-export)))
211
212 (define-public (score-override-beam-setting
213                  time-signature rule-type rule)
214   (override-beam-setting
215     time-signature rule-type rule 'Score))
216
217 (define-public (revert-beam-setting
218                   time-signature rule-type . rest)
219   (ly:export
220     (context-spec-music
221       (make-apply-context
222         (lambda (c)
223           (revert-property-setting
224             c
225             'beamSettings
226             (list time-signature rule-type))))
227       (if (and (pair? rest) (symbol? (car rest)))
228           (car rest)
229           'Voice))))