- (if (= dir START)
- ;; start anywhere is currently implemented
- #t
- (let* ((beat-length (get 'beatLength (ly:make-moment 1 4)))
- (measure-length (get 'measureLength (ly:make-moment 1 1)))
- (time-signature-fraction
- (get 'timeSignatureFraction '(4 . 4)))
- (settings (get 'beamSettings '()))
- (function (if (= dir START) 'begin 'end))
- (type (cons (ly:moment-main-numerator test-beam)
- (ly:moment-main-denominator test-beam)))
- (pos (if (>= (ly:moment-main-numerator measure-pos) 0)
- measure-pos
- (ly:moment-add measure-length measure-pos)))
- (type-grouping (ly:beam-grouping
- settings
- time-signature-fraction
- function
- type))
- (default-grouping (ly:beam-grouping
- settings
- time-signature-fraction
- function
- '*))
- (beat-grouping (if (null? type-grouping)
- default-grouping
- type-grouping))
- (grouping-moment (if (null? type-grouping)
- beat-length
- test-beam))
- (grouping-moments (ending-moments
- beat-grouping 0 grouping-moment)))
- (if (null? beat-grouping)
- ;; no rule applies, so end at beatLength
- (= (ly:moment-main-denominator
- (ly:moment-div pos beat-length)) 1)
- ;; otherwise, end at beginning of measure or
- ;; at specified moment
- (or
- ;; start/end at beginning of measure
- (= (ly:moment-main-numerator pos) 0)
- ;; end if measure-pos matches a specified ending moment
- (member pos grouping-moments)))))))
+ (let* ((base-moment (get 'baseMoment (ly:make-moment 1 4)))
+ (measure-length (get 'measureLength (ly:make-moment 1 1)))
+ (time-signature-fraction
+ (get 'timeSignatureFraction '(4 . 4)))
+ (beat-structure (get 'beatStructure '(1 1 1 1)))
+ (beat-endings (ending-moments beat-structure 0 base-moment))
+ (exceptions (sort (assoc-get 'end
+ (get 'beamExceptions '())
+ '())
+ beaming<?))
+ (function (if (= dir START) 'begin 'end))
+ (beam-half-measure (get 'beamHalfMeasure #t))
+ (type (moment->fraction test-beam))
+ (non-grace (ly:make-moment
+ (ly:moment-main-numerator measure-pos)
+ (ly:moment-main-denominator measure-pos)))
+ (pos (if (ly:moment<? non-grace ZERO-MOMENT)
+ (ly:moment-add measure-length non-grace)
+ non-grace))
+ (type-grouping (assoc-get type exceptions '()))
+ (default-rule (if (null? type-grouping)
+ (larger-setting test-beam exceptions)
+ '()))
+ (default-grouping (if (pair? default-rule)
+ (cdr default-rule)
+ '()))
+ (default-beat-length (if (pair? default-rule)
+ (car default-rule)
+ '()))
+ (exception-grouping (if (null? type-grouping)
+ default-grouping
+ type-grouping))
+ (grouping-moment (if (null? type-grouping)
+ (fraction->moment default-beat-length)
+ test-beam))
+ (exception-moments (ending-moments
+ exception-grouping 0 grouping-moment)))
+
+ (if (= dir START)
+ ;; Start rules -- #t if beam is allowed to start
+ (or beam-half-measure ;; Start anywhere, but option for mid-measure
+ (not (equal? (ly:moment-add pos pos) measure-length))
+ (not (= 3 (car time-signature-fraction))) ;; in triple meter
+ (not (= (cdr type) ;; when the beamed note is 1/6 of a measure
+ (* 2 (cdr time-signature-fraction)))))
+ ;; End rules -- #t if beam is required to end
+ (or (= (ly:moment-main-numerator pos) 0) ;; end at measure beginning
+ (if (null? exception-grouping)
+ (beat-end? pos beat-endings) ;; no exception, so check beat ending
+ (member pos exception-moments))))))) ;; check exception rule
+