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
82 ;; default: group on 1 4 notes
83 (((4 . 8) end) . ((* . (2 2))))
86 ;; default: group on beats
87 (((4 . 16) end) . ((* . (1 1 1 1))))
90 ;; default group at 3 4
91 ;; end beams with 16th or 32nd notes each 1 4 beat
94 ((1 . 16) . (4 4 4 4 4 4))
95 ((1 . 32) . (8 8 8 8 8 8))))
98 ;; default: group at 3 8
99 ;; end beams with 32nd notes each 1 8 beat
102 ((1 . 32) . (4 4 4 4 4 4))))
105 ;; default: group at 3 16
106 (((6 . 16) end) . ((* . (3 3))))
109 ;; default: group at 3 4
110 ;; end beams with 16th or 32nd notes each 1 4 beat
113 ((1 . 16) . (4 4 4 4 4 4 4 4 4))
114 ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
117 ;; default: group at 3 8
118 ;; use beatGrouping for all except 32nd notes
119 ;; end beams with 32nd notes each 1 8 beat
122 ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
125 ;; default: group at 3 8
126 (((9 . 16) end) . ((* . (3 3 3))))
129 ;; default: group at 3 4
130 ;; end beams with 16th or 32nd notes each 1 4 beat
133 ((1 . 16) . (4 4 4 4 4 4 4 4 4 4 4 4 4))
134 ((12 . 4) . (8 8 8 8 8 8 8 8 8 8 8 8 8))))
137 ;; default: group at 3 8
138 ;; end beams with 32nd notes each 1 8 beat
141 ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
144 ;; default: group at 3 16
145 (((12 . 16) end) . ((* . (3 3 3 3))))
148 ;; default: group (3 2)
149 (((5 . 8) end) . ((* . (3 2))))
152 ;; default: group (3 3 2)
153 (((8 . 8) end) . ((* . (3 3 2))))
154 )) ; end of alist definition
156 ;;; Functions for overriding beam settings
159 (define (overridden-property-alist context property setting value)
160 "Return an alist containing the current @{context} value of
161 @code{property} overriden by @code{(setting . value)}. "
162 (cons (cons setting value) (ly:context-property context property)))
164 (define-public (override-property-setting context property setting value)
165 "Like the C++ code that executes \\override, but without type
167 (ly:context-set-property!
169 (overridden-property-alist context property setting value)))
171 (define (revert-property-setting context property setting)
172 "Like the C++ code that executes \revert, but without type
175 (define (revert-member alist entry new)
176 "Return ALIST, with ENTRY removed. ALIST is not modified, instead
177 a fresh copy of the list-head is made."
180 ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
181 (else (revert-member (cdr alist) entry (cons (car alist) new)))))
183 (ly:context-set-property!
185 (revert-member (ly:context-property context property) setting '())))
187 (define-public (override-beam-setting
188 time-signature rule-type rule . rest)
189 "Override the beam settings for the context in @var{rest},
190 for @var{time-signature} and @var{rule-type}, with the
191 new rule alist @var{rule}. "
192 (define (make-setting c)
194 (overridden-property-alist
197 (list time-signature rule-type)
199 (ly:context-set-property! c 'beamSettings new-settings)))
201 (let ((music-to-export
203 (make-apply-context make-setting)
204 (if (and (pair? rest) (symbol? (car rest)))
207 (ly:export music-to-export)))
209 (define-public (score-override-beam-setting
210 time-signature rule-type rule)
211 (override-beam-setting
212 time-signature rule-type rule 'Score))
214 (define-public (revert-beam-setting
215 time-signature rule-type . rest)
220 (revert-property-setting
223 (list time-signature rule-type))))
224 (if (and (pair? rest) (symbol? (car rest)))