]> git.donarmstrong.com Git - lilypond.git/blob - scm/auto-beam.scm
remove split around-space hack.
[lilypond.git] / scm / auto-beam.scm
1 ;;;; auto-beam.scm -- Auto-beam-engraver settings
2 ;;;;
3 ;;;; source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6
7 ;;; specify generic beam begin and end times
8
9 ;;; format:
10 ;;;
11 ;;;   function shortest-duration-in-beam time-signature
12 ;;;
13 ;;; where
14 ;;;
15 ;;;     function = begin or end
16 ;;;     shortest-duration-in-beam = numerator denominator; e.g.: 1 16
17 ;;;     time-signature = numerator denominator, e.g.: 4 4
18 ;;;
19 ;;; unspecified or wildcard entries for duration or time-signature
20 ;;; are given by * *
21
22 ;;; maybe do:  '(end shortest-1 16 time-3 4) ?
23
24 ;;; in 3 2 time:
25 ;;;   end beams each 1 2 note
26 ;;;   end beams with 16th notes each 1 4 note
27 ;;;   end beams with 32th notes each 1 8 note
28
29 (define-public default-auto-beam-settings
30    `(
31      ((end * * 3 2) . ,(ly:make-moment 1 2))
32      ((end 1 16 3 2) . ,(ly:make-moment 1 4))
33      ((end 1 32 3 2) . ,(ly:make-moment 1 8))
34
35      ((begin 1 8 3 4) . ,(ly:make-moment 1 4))
36
37      ((end * * 3 4) . ,(ly:make-moment 3 4))
38      ((begin 1 16 3 4) . ,(ly:make-moment 1 16))
39      ((end 1 16 3 4) . ,(ly:make-moment 1 4))
40      ;;((begin 1 32 3 4) . ,(ly:make-moment 1 8))
41      ((end 1 32 3 4) . ,(ly:make-moment 1 8))
42
43      ((begin 1 16 3 8) . ,(ly:make-moment 1 8))
44      ((end * * 3 8) . ,(ly:make-moment 3 8))
45
46      ;; in common time:
47      ;;   end beams each 1 2 note
48      ;;   end beams with 32th notes each 1 8 note
49      ;;   end beams with 1 8 triplets each 1 4 note
50
51      ((end * * 4 4) . ,(ly:make-moment 1 2))
52      ((end 1 12 4 4) . ,(ly:make-moment 1 4))
53      ((end 1 16 4 4) . ,(ly:make-moment 1 4))
54      ((end 1 32 4 4) . ,(ly:make-moment 1 8))
55
56      ((end * * 2 4) . ,(ly:make-moment 1 4))
57      ((end 1 12 2 4) . ,(ly:make-moment 1 4))
58      ((end 1 16 2 4) . ,(ly:make-moment 1 4))
59      ((end 1 32 2 4) . ,(ly:make-moment 1 8))
60
61      ;; It seems that, because of a bug in the previous auto-beamer,
62      ;; we had the effect of this setting x
63      ;; ((end * * 2 8) . ,(ly:make-moment 2 8))
64
65      ((end * * 4 8) . ,(ly:make-moment 1 4))
66      ((end 1 16 4 8) . ,(ly:make-moment 1 4))
67      ((end 1 32 4 8) . ,(ly:make-moment 1 8))
68
69      ((end * * 4 16) . ,(ly:make-moment 1 8))
70
71      ((end * * 6 8) . ,(ly:make-moment 3 8))
72      ((end 1 16 6 8) . ,(ly:make-moment 3 8))
73      ((end 1 32 6 8) . ,(ly:make-moment 1 8))
74
75      ((end * * 9 8) . ,(ly:make-moment 3 8))
76      ((end 1 16 9 8) . ,(ly:make-moment 3 8))
77      ((end 1 32 9 8) . ,(ly:make-moment 1 8))
78
79      ((end * * 12 8) . ,(ly:make-moment 3 8))
80      ((end 1 16 12 8) . ,(ly:make-moment 3 8))
81      ((end 1 32 12 8) . ,(ly:make-moment 1 8))
82      ))
83
84
85 (define (override-property-setting context context-prop setting value)
86   "Like the C++ code that executes \\override, but without type
87 checking. "
88
89   (ly:context-set-property! context context-prop
90                            (cons (cons setting value)
91                                  (ly:context-property context context-prop)
92                                  )
93                            )
94   )
95
96 (define (revert-property-setting context setting)
97   "Like the C++ code that executes \revert, but without type
98 checking. "
99   
100   (define (revert-assoc alist key)
101     "Return ALIST, with KEY removed. ALIST is not modified, instead
102 a fresh copy of the  list-head is made."
103     (cond
104      ((null? alist) '())
105      ((equal? (caar alist) key) (cdr alist))
106      (else (cons (car alist) (revert-assoc alist key)))
107      ))
108
109   
110   
111     (ly:context-set-property!
112      context context-prop
113      (revert-assoc (ly:context-property context context-prop)
114                    setting))
115   )
116
117 (define-public (override-auto-beam-setting setting num den . rest)
118   (ly:export
119    (context-spec-music
120     (make-apply-context (lambda (c)
121                           (override-property-setting
122                            c 'autoBeamSettings
123                            setting (ly:make-moment num den))
124                           ))
125     (if (and (pair? rest) (symbol? (car rest)))
126         (car rest)
127         'Voice)
128   )))
129
130 (define-public (revert-auto-beam-setting setting . rest)
131   (ly:export
132    (context-spec-music
133     (make-apply-context (lambda (c)
134                           (revert-property-setting
135                            c 'autoBeamSettings
136                            setting)))
137     (if (and (pair? rest) (symbol? (car rest)))
138         (car rest)
139         'Voice))))
140