1 ;;;; beam-settings.scm -- Handle auto-beam and subdivide-beam settings
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2009 Carl Sorensen <c_sorensen@byu.edu>
7 ;;; specify default beaming rules
12 ;;; ((time-signature function) . (beam-type . grouping)) entries
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)
26 (define-public default-beam-settings
29 ;; default: end beams on 1 2 note boundaries
30 ;; end beams with 32nd notes each 1 4 beat
33 ((1 . 32) . (8 8 8 8))))
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))))
42 ;; default: end beams on beats
43 ;; end beams with 32nd notes each 1 4 beat
46 ((1 . 32) . (8 8 8 8 8 8))))
49 ;; default: end beams on beats
50 ;; group 1/8 note beams on measure
51 (((3 . 4) end) .((* . (3))
54 ((1 . 64) . (16 16 16))
55 ((1 . 128) . (32 32 32))))
57 ;; in 3 8 and 3 16 time time:
58 ;; default: group on 3
59 (((3 . 8) end) . ((* . (3))))
60 (((3 . 16) end) . ((* . (3))))
63 ;; default: end beams on beats
64 ;; end beams with 16th notes each 1 4 beat
65 ;; end beams with 32nd notes each 1 8 beat
68 ((1 . 16) . (4 4 4 4 4 4 4 4))
74 ;; in 4 4 (common) time:
75 ;; default: end beams on beats
76 ;; end beams with 8th notes each 1 2 beat
77 ;; end beams with 32nd notes each 1 8 beat
85 ;; default: group on 1 4 notes
86 (((4 . 8) end) . ((* . (2 2))))
89 ;; default: group on beats
90 (((4 . 16) end) . ((* . (1 1 1 1))))
93 ;; default group at 3 4
94 ;; end beams with 16th or 32nd notes each 1 4 beat
97 ((1 . 16) . (4 4 4 4 4 4))
98 ((1 . 32) . (8 8 8 8 8 8))))
101 ;; default: group at 3 8
102 ;; end beams with 32nd notes each 1 8 beat
105 ((1 . 32) . (4 4 4 4 4 4))))
108 ;; default: group at 3 16
109 (((6 . 16) end) . ((* . (3 3))))
112 ;; default: group at 3 4
113 ;; end beams with 16th or 32nd notes each 1 4 beat
116 ((1 . 16) . (4 4 4 4 4 4 4 4 4))
117 ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
120 ;; default: group at 3 8
121 ;; use beatGrouping for all except 32nd notes
122 ;; end beams with 32nd notes each 1 8 beat
125 ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
128 ;; default: group at 3 8
129 (((9 . 16) end) . ((* . (3 3 3))))
132 ;; default: group at 3 4
133 ;; end beams with 16th or 32nd notes each 1 4 beat
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))))
140 ;; default: group at 3 8
141 ;; end beams with 32nd notes each 1 8 beat
144 ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
147 ;; default: group at 3 16
148 (((12 . 16) end) . ((* . (3 3 3 3))))
151 ;; default: group (3 2)
152 (((5 . 8) end) . ((* . (3 2))))
155 ;; default: group (3 3 2)
156 (((8 . 8) end) . ((* . (3 3 2))))
157 )) ; end of alist definition
159 ;;; Functions for overriding beam settings
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)))
167 (define-public (override-property-setting context property setting value)
168 "Like the C++ code that executes \\override, but without type
170 (ly:context-set-property!
172 (overridden-property-alist context property setting value)))
174 (define (revert-property-setting context property setting)
175 "Like the C++ code that executes \revert, but without type
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."
183 ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
184 (else (revert-member (cdr alist) entry (cons (car alist) new)))))
186 (ly:context-set-property!
188 (revert-member (ly:context-property context property) setting '())))
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)
197 (overridden-property-alist
200 (list time-signature rule-type)
202 (ly:context-set-property! c 'beamSettings new-settings)))
204 (let ((music-to-export
206 (make-apply-context make-setting)
207 (if (and (pair? rest) (symbol? (car rest)))
210 (ly:export music-to-export)))
212 (define-public (score-override-beam-setting
213 time-signature rule-type rule)
214 (override-beam-setting
215 time-signature rule-type rule 'Score))
217 (define-public (revert-beam-setting
218 time-signature rule-type . rest)
223 (revert-property-setting
226 (list time-signature rule-type))))
227 (if (and (pair? rest) (symbol? (car rest)))