]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam-settings.scm
Update texinfo.tex.
[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: 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     ;;   end beams with 8th notes each 1 2 beat
77    (((4 . 4) end) .
78     ((* . (1 1 1 1))
79      ((1 . 8) . (4 4))))
80
81     ;; in 4 8 time:
82     ;;   default: group on 1 4 notes
83    (((4 . 8) end) . ((* . (2 2))))
84
85     ;; in 4 16 time:
86     ;;   default: group on beats
87    (((4 . 16) end) . ((* . (1 1 1 1))))
88
89     ;; in 6 4 time:
90     ;;   default group at 3 4
91     ;;   end beams with 16th or 32nd notes each 1 4 beat
92    (((6 . 4) end) .
93     ((* . (3 3))
94      ((1 . 16) . (4 4 4 4 4 4))
95      ((1 . 32) . (8 8 8 8 8 8))))
96
97     ;; in 6 8 time:
98     ;;   default: group at 3 8
99     ;;   end beams with 32nd notes each 1 8 beat
100    (((6 . 8) end) .
101     ((* . (3 3))
102      ((1 . 32) . (4 4 4 4 4 4))))
103
104     ;; in 6 16 time:
105     ;;   default: group at 3 16
106    (((6 . 16) end) . ((* . (3 3))))
107
108     ;; in 9 4 time:
109     ;;   default: group at 3 4
110     ;;   end beams with 16th or 32nd notes each 1 4 beat
111    (((9 . 4) end) .
112     ((* . (3 3 3))
113      ((1 . 16) . (4 4 4 4 4 4 4 4 4))
114      ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
115
116     ;; in 9 8 time:
117     ;;   default: group at 3 8
118     ;;   use beatGrouping for all except 32nd notes
119     ;;   end beams with 32nd notes each 1 8 beat
120    (((9 . 8) end) .
121     ((* . (3 3 3))
122      ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
123
124     ;; in 9 16 time
125     ;;   default: group at 3 8
126    (((9 . 16) end) . ((* . (3 3 3))))
127
128     ;; in 12 4 time:
129     ;;   default: group at 3 4
130     ;;   end beams with 16th or 32nd notes each 1 4 beat
131    (((12 . 4) end) .
132     ((* . (3 3 3 3))
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))))
135
136     ;; in 12 8 time:
137     ;;   default: group at 3 8
138     ;;   end beams with 32nd notes each 1 8 beat
139    (((12 . 8) end) .
140     ((* . (3 3 3 3))
141      ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
142
143     ;; in 12 16 time:
144     ;;   default: group at 3 16
145    (((12 . 16) end) . ((* . (3 3 3 3))))
146
147     ;; in 5 8 time:
148     ;;   default: group (3 2)
149    (((5 . 8) end) . ((* . (3 2))))
150
151     ;; in 8 8 time:
152     ;;   default: group (3 3 2)
153    (((8 . 8) end) . ((* . (3 3 2))))
154   ))  ; end of alist definition
155
156 ;;; Functions for overriding beam settings
157 ;;;
158
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)))
163
164 (define-public (override-property-setting context property setting value)
165   "Like the C++ code that executes \\override, but without type
166 checking. "
167   (ly:context-set-property!
168     context property
169     (overridden-property-alist context property setting value)))
170
171 (define (revert-property-setting context property setting)
172   "Like the C++ code that executes \revert, but without type
173 checking. "
174
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."
178     (cond
179       ((null? alist) new)
180       ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
181       (else (revert-member (cdr alist) entry (cons (car alist) new)))))
182
183   (ly:context-set-property!
184     context property
185     (revert-member (ly:context-property context property) setting '())))
186
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)
193     (let ((new-settings
194             (overridden-property-alist
195               c
196               'beamSettings
197               (list time-signature rule-type)
198               rule)))
199       (ly:context-set-property! c 'beamSettings new-settings)))
200
201   (let ((music-to-export
202           (context-spec-music
203             (make-apply-context make-setting)
204               (if (and (pair? rest) (symbol? (car rest)))
205                   (car rest)
206                   'Voice))))
207     (ly:export music-to-export)))
208
209 (define-public (score-override-beam-setting
210                  time-signature rule-type rule)
211   (override-beam-setting
212     time-signature rule-type rule 'Score))
213
214 (define-public (revert-beam-setting
215                   time-signature rule-type . rest)
216   (ly:export
217     (context-spec-music
218       (make-apply-context
219         (lambda (c)
220           (revert-property-setting
221             c
222             'beamSettings
223             (list time-signature rule-type))))
224       (if (and (pair? rest) (symbol? (car rest)))
225           (car rest)
226           'Voice))))