1 ;;;; auto-beam.scm -- Auto-beam-engraver settings
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;; Determine end moment for auto beaming (or begin moment, but mostly
8 ;; 0== anywhere). We only consider the current time signature.
9 ;; In order of decreasing priority:
13 ;; 3. if 1-2 not specified, begin anywhere, end at beatLength intervals
18 ;; 1. override for specific duration type
19 ;; 2. override for all duration types in a time signature.
21 ;; defined in scm/beam-settings.scm:
22 ;; 1. Default grouping for common time signatures
23 ;; 2. exceptions for specific time signature, for specific duration type
26 (define-public (default-auto-beam-check context dir test-beam)
27 (define (get name default)
28 (let ((value (ly:context-property context name)))
29 (if (not (null? value)) value default)))
31 (define (ending-moments group-list start-beat beat-length)
32 (if (null? group-list)
34 (let ((new-start (+ start-beat (car group-list))))
35 (cons (ly:moment-mul (ly:make-moment new-start 1) beat-length)
36 (ending-moments (cdr group-list) new-start beat-length)))))
38 ;; Start of actual auto-beam test routine
41 ;; Don't start auto beams on grace notes
42 (if (and (!= (ly:moment-grace-numerator (ly:context-now context)) 0)
46 ;; start anywhere is currently implemented
48 (let* ((beat-length (get 'beatLength (ly:make-moment 1 4)))
49 (measure-length (get 'measureLength (ly:make-moment 1 1)))
50 (time-signature-fraction
51 (get 'timeSignatureFraction '(4 . 4)))
52 (measure-pos (get 'measurePosition ZERO-MOMENT))
53 (settings (get 'beamSettings '()))
54 (function (if (= dir START) 'begin 'end))
55 (type (cons (ly:moment-main-numerator test-beam)
56 (ly:moment-main-denominator test-beam)))
57 (pos (if (>= (ly:moment-main-numerator measure-pos) 0)
59 (ly:moment-add measure-length measure-pos)))
60 (type-grouping (ly:beam-grouping
62 time-signature-fraction
65 (default-grouping (ly:beam-grouping
67 time-signature-fraction
70 (beat-grouping (if (null? type-grouping)
73 (grouping-moment (if (null? type-grouping)
76 (grouping-moments (ending-moments
77 beat-grouping 0 grouping-moment)))
78 (if (null? beat-grouping)
79 ;; no rule applies, so end at beatLength
80 (= (ly:moment-main-denominator
81 (ly:moment-div pos beat-length)) 1)
82 ;; otherwise, end at beginning of measure or
83 ;; at specified moment
85 ;; start/end at beginning of measure
86 (= (ly:moment-main-numerator pos) 0)
87 ;; end if measure-pos matches a specified ending moment
88 (member measure-pos grouping-moments)))))))