]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam-settings.scm
Remove obsolete regression test.
[lilypond.git] / scm / beam-settings.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2009--2010 Carl Sorensen <c_sorensen@byu.edu>
4 ;;;;
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.
9 ;;;;
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.
14 ;;;;
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/>.
17
18 ;;; specify default beaming rules
19
20 ;;; format:
21 ;;;
22 ;;; alist of
23 ;;;   ((time-signature function) . (beam-type . grouping)) entries
24 ;;;
25 ;;; where
26 ;;;
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)
35 ;;;
36
37 (define-public default-beam-settings
38  `(
39    ;; in 2 2 time:
40    ;;   default: end beams on 1 2 note boundaries
41    ;;   end beams with 32nd notes each 1 4 beat
42    (((2 . 2) end) .
43     ((* . (1 1))
44     ((1 . 32) . (8 8 8 8))))
45
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))))
51
52    ;; in 3 2 time:
53    ;;   default: end beams on beats
54    ;;   end beams with 32nd notes each 1 4 beat
55    (((3 . 2) end) .
56     ((* . (1 1 1))
57      ((1 . 32) . (8 8 8 8 8 8))))
58
59     ;; in 3 4 time:
60     ;;   default: set grouping to (3) so we'll get
61     ;;     the proper measure grouping symbol
62     ;;
63     ;;   set all beams to end on beats, but 1 8 to beam entire measure
64    (((3 . 4) end) .((* . (3))
65                     ((1 . 8) . (6))
66                     ((1 . 16) . (4 4 4))
67                     ((1 . 32) . (8 8 8))
68                     ((1 . 64) . (16 16 16))
69                     ((1 . 128) . (32 32 32))))
70
71     ;; in 3 8 and 3 16 time time:
72     ;;   default: group on 3
73    (((3 . 8) end) . ((* . (3))))
74    (((3 . 16) end) . ((* . (3))))
75
76     ;; in 4 2 time:
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
80    (((4 . 2) end) .
81     ((* . (1 1 1 1))
82      ((1 . 16) . (4 4 4 4 4 4 4 4))
83      ((1 . 32) . (4 4 4 4
84                   4 4 4 4
85                   4 4 4 4
86                   4 4 4 4))))
87
88     ;; in 4 4 (common) time:
89     ;;   default: end beams on beats
90     ;;   end beams with 8th notes each 1 2 beat
91    (((4 . 4) end) .
92     ((* . (1 1 1 1))
93      ((1 . 8) . (4 4))))
94
95     ;; in 4 8 time:
96     ;;   default: group on 1 4 notes
97    (((4 . 8) end) . ((* . (2 2))))
98
99     ;; in 4 16 time:
100     ;;   default: group on beats
101    (((4 . 16) end) . ((* . (1 1 1 1))))
102
103     ;; in 6 4 time:
104     ;;   default group at 3 4
105     ;;   end beams with 16th or 32nd notes each 1 4 beat
106    (((6 . 4) end) .
107     ((* . (3 3))
108      ((1 . 16) . (4 4 4 4 4 4))
109      ((1 . 32) . (8 8 8 8 8 8))))
110
111     ;; in 6 8 time:
112     ;;   default: group at 3 8
113     ;;   end beams with 32nd notes each 1 8 beat
114    (((6 . 8) end) .
115     ((* . (3 3))
116      ((1 . 32) . (4 4 4 4 4 4))))
117
118     ;; in 6 16 time:
119     ;;   default: group at 3 16
120    (((6 . 16) end) . ((* . (3 3))))
121
122     ;; in 9 4 time:
123     ;;   default: group at 3 4
124     ;;   end beams with 16th or 32nd notes each 1 4 beat
125    (((9 . 4) end) .
126     ((* . (3 3 3))
127      ((1 . 16) . (4 4 4 4 4 4 4 4 4))
128      ((1 . 32) . (8 8 8 8 8 8 8 8 8))))
129
130     ;; in 9 8 time:
131     ;;   default: group at 3 8
132     ;;   use beatGrouping for all except 32nd notes
133     ;;   end beams with 32nd notes each 1 8 beat
134    (((9 . 8) end) .
135     ((* . (3 3 3))
136      ((1 . 32) . (4 4 4 4 4 4 4 4 4))))
137
138     ;; in 9 16 time
139     ;;   default: group at 3 8
140    (((9 . 16) end) . ((* . (3 3 3))))
141
142     ;; in 12 4 time:
143     ;;   default: group at 3 4
144     ;;   end beams with 16th or 32nd notes each 1 4 beat
145    (((12 . 4) end) .
146     ((* . (3 3 3 3))
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))))
149
150     ;; in 12 8 time:
151     ;;   default: group at 3 8
152     ;;   end beams with 32nd notes each 1 8 beat
153    (((12 . 8) end) .
154     ((* . (3 3 3 3))
155      ((1 . 32) . (4 4 4 4 4 4 4 4 4 4 4 4 4))))
156
157     ;; in 12 16 time:
158     ;;   default: group at 3 16
159    (((12 . 16) end) . ((* . (3 3 3 3))))
160
161     ;; in 5 8 time:
162     ;;   default: group (3 2)
163    (((5 . 8) end) . ((* . (3 2))))
164
165     ;; in 8 8 time:
166     ;;   default: group (3 3 2)
167    (((8 . 8) end) . ((* . (3 3 2))))
168   ))  ; end of alist definition
169
170 ;;; Functions for overriding beam settings
171 ;;;
172
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)))
177
178 (define-public (override-property-setting context property setting value)
179   "Like the C++ code that executes \\override, but without type
180 checking. "
181   (ly:context-set-property!
182     context property
183     (overridden-property-alist context property setting value)))
184
185 (define (revert-property-setting context property setting)
186   "Like the C++ code that executes \revert, but without type
187 checking. "
188
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."
192     (cond
193       ((null? alist) new)
194       ((equal? (car alist) entry) (revert-member (cdr alist) entry new))
195       (else (revert-member (cdr alist) entry (cons (car alist) new)))))
196
197   (ly:context-set-property!
198     context property
199     (revert-member (ly:context-property context property) setting '())))
200
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)
207     (let ((new-settings
208             (overridden-property-alist
209               c
210               'beamSettings
211               (list time-signature rule-type)
212               rule)))
213       (ly:context-set-property! c 'beamSettings new-settings)))
214
215   (let ((music-to-export
216           (context-spec-music
217             (make-apply-context make-setting)
218               (if (and (pair? rest) (symbol? (car rest)))
219                   (car rest)
220                   'Voice))))
221     (ly:export music-to-export)))
222
223 (define-public (score-override-beam-setting
224                  time-signature rule-type rule)
225   (override-beam-setting
226     time-signature rule-type rule 'Score))
227
228 (define-public (revert-beam-setting
229                   time-signature rule-type . rest)
230   (ly:export
231     (context-spec-music
232       (make-apply-context
233         (lambda (c)
234           (revert-property-setting
235             c
236             'beamSettings
237             (list time-signature rule-type))))
238       (if (and (pair? rest) (symbol? (car rest)))
239           (car rest)
240           'Voice))))