]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam-settings.scm
Modify autobeam and grouping properties
[lilypond.git] / scm / beam-settings.scm
1 ;;;; default-beam-settings.scm -- Default 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: end beams on beats
50     ;;   group 1/8 note beams on measure
51    (((3 . 4) end) .((* . (3))
52                     ((1 16) . (4 4 4))
53                     ((1 32) . (8 8 8))
54                     ((1 64) . (16 16 16))
55                     ((1 128) . (32 32 32))))
56
57     ;; in 3 8 and 3 16 time time:
58     ;;   default: group on 3
59    (((3 . 8) end) . ((* . (3))))
60    (((3 . 16) end) . ((* . (3))))
61
62     ;; in 4 2 time:
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
66    (((4 . 2) end) .
67     ((* . (1 1 1 1))
68      ((1 . 16) . (4 4 4 4 4 4 4 4))
69      ((1 . 32) . (4 4 4 4
70                   4 4 4 4
71                   4 4 4 4
72                   4 4 4 4))))
73
74     ;; in 4 4 (common) time:
75     ;;   default: end beams on beats
76     ;;  use beatLength for all except 32nd notes:
77     ;;  end beams with 32nd notes each 1 8 beat
78    (((4 . 4) end) .
79     ((* . (2 2))
80      ((1 . 32) . (4 4 4 4
81                   4 4 4 4))))
82
83     ;; in 4 8 time:
84     ;;   default: group on 1 4 notes
85    (((4 . 8) end) . ((* . (2 2))))
86
87     ;; in 4 16 time:
88     ;;   default: group on beats
89    (((4 . 16) end) . ((* . (1 1 1 1))))
90
91     ;; in 6 4 time:
92     ;;   default group at 3 4
93     ;;   end beams with 16th or 32nd notes each 1 4 beat
94    (((6 . 4) end) .
95     ((* . (3 3))
96      ((1 . 16) . (4 4 4 4 4 4))
97      ((1 . 32) . (8 8 8 8 8 8))))
98
99     ;; in 6 8 time:
100     ;;   default: group at 3 8
101     ;;   end beams with 32nd notes each 1 8 beat
102    (((6 . 8) end) .
103     ((* . (3 3))
104      ((6 . 8) . (4 4 4 4 4 4))))
105
106     ;; in 6 16 time:
107     ;;   default: group at 3 16
108    (((6 . 16) end) . ((* . (3 3))))
109
110     ;; in 9 4 time:
111     ;;   default: group at 3 4
112     ;;   end beams with 16th or 32nd notes each 1 4 beat
113    (((9 . 4) end) .
114     ((* . (3 3 3))
115      ((1 . 16) . (4 4 4 4 4 4 4 4 4))
116      ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
117
118     ;; in 9 8 time:
119     ;;   default: group at 3 8
120     ;;   use beatGrouping for all except 32nd notes
121     ;;   end beams with 32nd notes each 1 8 beat
122    (((9 . 8) end) .
123     ((* . (3 3 3))
124      ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
125
126     ;; in 9 16 time
127     ;;   default: group at 3 8
128    (((9 . 16) end) . ((* . (3 3 3))))
129
130     ;; in 12 4 time:
131     ;;   default: group at 3 4
132     ;;   end beams with 16th or 32nd notes each 1 4 beat
133    (((12 . 4) end) .
134     ((* . (3 3 3 3))
135      ((1 . 16) . (4 4 4 4 4 4 4 4 4 4 4 4 4))
136      ((12 . 4) . (8 8 8 8 8 8 8 8 8 8 8 8 8))))
137
138     ;; in 12 8 time:
139     ;;   default: group at 3 8
140     ;;   end beams with 32nd notes each 1 8 beat
141    (((12 . 8) end) .
142     ((* . (3 3 3 3))
143      ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
144
145     ;; in 12 16 time:
146     ;;   default: group at 3 16
147    (((12 . 16) end) . ((* . (3 3 3 3))))
148
149     ;; in 5 8 time:
150     ;;   default: group (3 2)
151    (((5 . 8) end) . ((* . (3 2))))
152
153     ;; in 8 8 time:
154     ;;   default: group (3 3 2)
155    (((8 . 8) end) . ((* . (3 3 2))))
156   ))  ; end of alist definition
157
158 ;;; Functions for overriding beam settings
159 ;;;
160
161 (define (overridden-property-alist context property setting value)
162   "Return an alist containing the current @{context} value of
163 @code{property} overriden by @code{(setting . value)}. "
164   (cons (cons setting value) (ly:context-property context property)))
165
166 (define-public (override-property-setting context property setting value)
167   "Like the C++ code that executes \\override, but without type
168 checking. "
169   (ly:context-set-property!
170     context property
171     (overridden-property-alist context property setting value)))
172
173 (define (revert-property-setting context property setting)
174   "Like the C++ code that executes \revert, but without type
175 checking. "
176
177   (define (revert-member alist entry new)
178     "Return ALIST, with ENTRY removed.  ALIST is not modified, instead
179 a fresh copy of the list-head is made."
180     (cond
181       ((null? alist) new)
182       ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
183       (else (revert-member (cdr alist) entry (cons (car alist) new)))))
184
185   (ly:context-set-property!
186     context property
187     (revert-member (ly:context-property context property) setting '())))
188
189 (define-public (override-beam-setting
190                   time-signature rule-type rule . rest)
191   "Override the beam settings for the context in @var{rest},
192 for @var{time-signature} and  @var{rule-type}, with the
193 new rule alist @var{rule}. "
194   (define (make-setting c)
195     (let ((new-settings
196             (overridden-property-alist
197               c
198               'beamSettings
199               (list time-signature rule-type)
200               rule)))
201       (ly:context-set-property! c 'beamSettings new-settings)))
202
203   (let ((music-to-export
204           (context-spec-music
205             (make-apply-context make-setting)
206               (if (and (pair? rest) (symbol? (car rest)))
207                   (car rest)
208                   'Voice))))
209     (ly:export music-to-export)))
210
211 (define-public (score-override-beam-setting
212                  time-signature rule-type rule)
213   (override-beam-setting
214     time-signature rule-type rule 'Score))
215
216 (define-public (revert-beam-setting
217                   time-signature rule-type . rest)
218   (ly:export
219     (context-spec-music
220       (make-apply-context
221         (lambda (c)
222           (revert-property-setting
223             c
224             'beamSettings
225             (list time-signature rule-type))))
226       (if (and (pair? rest) (symbol? (car rest)))
227           (car rest)
228           'Voice))))