1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2009--2010 Carl Sorensen <c_sorensen@byu.edu>
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.
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.
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/>.
18 ;;; specify default beaming rules
23 ;;; ((time-signature function) . (beam-type . grouping)) entries
27 ;;; time-signature = time signature fraction (pair of numbers, (4 . 4) )
28 ;;; function = 'end or 'subdivide (possibly implement 'begin in the future)
29 ;;; beam-type = '* or (numerator . denominator); e.g. (1 . 16)
30 ;;; NOTE: numerator is kept in beam-type because of
31 ;;; tuplets, e.g. (2 . 24) = (2 . 3) * (1 . 8)
32 ;;; for eighth-note triplets.
33 ;;; grouping = a list of groups, in units of time signature denominator
34 ;;; (for default rules) or beam-type (for explicit rules)
37 (define-public default-beam-settings
40 ;; default: end beams on 1 2 note boundaries
41 ;; end beams with 32nd notes each 1 4 beat
44 ((1 . 32) . (8 8 8 8))))
46 ;; in 2 4, 2 8 and 2 16 time:
47 ;; default: end beams on beats
48 (((2 . 4) end) . ((* . (1 1))))
49 (((2 . 8) end) . ((* . (1 1))))
50 (((2 . 16) end) . ((* . (1 1))))
53 ;; default: end beams on beats
54 ;; end beams with 32nd notes each 1 4 beat
57 ((1 . 32) . (8 8 8 8 8 8))))
60 ;; default: set grouping to (3) so we'll get
61 ;; the proper measure grouping symbol
63 ;; set all beams to end on beats, but 1 8 to beam entire measure
64 (((3 . 4) end) .((* . (3))
68 ((1 . 64) . (16 16 16))
69 ((1 . 128) . (32 32 32))))
71 ;; in 3 8 and 3 16 time time:
72 ;; default: group on 3
73 (((3 . 8) end) . ((* . (3))))
74 (((3 . 16) end) . ((* . (3))))
77 ;; default: end beams on beats
78 ;; end beams with 16th notes each 1 4 beat
79 ;; end beams with 32nd notes each 1 8 beat
82 ((1 . 16) . (4 4 4 4 4 4 4 4))
88 ;; in 4 4 (common) time:
89 ;; default: end beams on beats
90 ;; end beams with 8th notes each 1 2 beat
96 ;; default: group on 1 4 notes
97 (((4 . 8) end) . ((* . (2 2))))
100 ;; default: group on beats
101 (((4 . 16) end) . ((* . (1 1 1 1))))
104 ;; default group at 3 4
105 ;; end beams with 16th or 32nd notes each 1 4 beat
108 ((1 . 16) . (4 4 4 4 4 4))
109 ((1 . 32) . (8 8 8 8 8 8))))
112 ;; default: group at 3 8
113 ;; end beams with 32nd notes each 1 8 beat
116 ((1 . 32) . (4 4 4 4 4 4))))
119 ;; default: group at 3 16
120 (((6 . 16) end) . ((* . (3 3))))
123 ;; default: group at 3 4
124 ;; end beams with 16th or 32nd notes each 1 4 beat
127 ((1 . 16) . (4 4 4 4 4 4 4 4 4))
128 ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
131 ;; default: group at 3 8
132 ;; use beatGrouping for all except 32nd notes
133 ;; end beams with 32nd notes each 1 8 beat
136 ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
139 ;; default: group at 3 8
140 (((9 . 16) end) . ((* . (3 3 3))))
143 ;; default: group at 3 4
144 ;; end beams with 16th or 32nd notes each 1 4 beat
147 ((1 . 16) . (4 4 4 4 4 4 4 4 4 4 4 4 4))
148 ((1 . 32) . (8 8 8 8 8 8 8 8 8 8 8 8 8))))
151 ;; default: group at 3 8
152 ;; end beams with 32nd notes each 1 8 beat
155 ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
158 ;; default: group at 3 16
159 (((12 . 16) end) . ((* . (3 3 3 3))))
162 ;; default: group (3 2)
163 (((5 . 8) end) . ((* . (3 2))))
166 ;; default: group (3 3 2)
167 (((8 . 8) end) . ((* . (3 3 2))))
168 )) ; end of alist definition
170 ;;; Functions for overriding beam settings
173 (define (overridden-property-alist context property setting value)
174 "Return an alist containing the current @{context} value of
175 @code{property} overriden by @code{(setting . value)}. "
176 (cons (cons setting value) (ly:context-property context property)))
178 (define-public (override-property-setting context property setting value)
179 "Like the C++ code that executes \\override, but without type
181 (ly:context-set-property!
183 (overridden-property-alist context property setting value)))
185 (define (revert-property-setting context property setting)
186 "Like the C++ code that executes \revert, but without type
189 (define (revert-member alist entry new)
190 "Return ALIST, with ENTRY removed. ALIST is not modified, instead
191 a fresh copy of the list-head is made."
194 ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
195 (else (revert-member (cdr alist) entry (cons (car alist) new)))))
197 (ly:context-set-property!
199 (revert-member (ly:context-property context property) setting '())))
201 (define-public (override-beam-setting
202 time-signature rule-type rule . rest)
203 "Override the beam settings for the context in @var{rest},
204 for @var{time-signature} and @var{rule-type}, with the
205 new rule alist @var{rule}. "
206 (define (make-setting c)
208 (overridden-property-alist
211 (list time-signature rule-type)
213 (ly:context-set-property! c 'beamSettings new-settings)))
215 (let ((music-to-export
217 (make-apply-context make-setting)
218 (if (and (pair? rest) (symbol? (car rest)))
221 (ly:export music-to-export)))
223 (define-public (score-override-beam-setting
224 time-signature rule-type rule)
225 (override-beam-setting
226 time-signature rule-type rule 'Score))
228 (define-public (revert-beam-setting
229 time-signature rule-type . rest)
234 (revert-property-setting
237 (list time-signature rule-type))))
238 (if (and (pair? rest) (symbol? (car rest)))