]> git.donarmstrong.com Git - lilypond.git/blob - scm/auto-beam.scm
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[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--2009 Jan Nieuwenhuizen <janneke@gnu.org>
6
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:
10 ;;
11 ;;  1. end <type>
12 ;;  2. end   *
13 ;;  3. if 1-2 not specified, begin anywhere, end at beatLength intervals
14 ;;
15 ;;  Rationale:
16 ;;
17 ;;  [user override]
18 ;;  1. override for specific duration type
19 ;;  2. override for all duration types in a time signature.
20 ;;
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
24
25
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)))
30
31   (define (ending-moments group-list start-beat beat-length)
32     (if (null? group-list)
33         '()
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)))))
37
38   ;; Start of actual auto-beam test routine
39   ;;
40   ;;
41   ;; Don't start auto beams on grace notes
42   (if (and (!= (ly:moment-grace-numerator (ly:context-now context)) 0)
43            (= dir START))
44       #f
45       (if (= dir START)
46           ;; start anywhere is currently implemented
47           #t
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)
58                         measure-pos
59                         (ly:moment-add measure-length measure-pos)))
60                  (type-grouping (ly:beam-grouping
61                                   settings
62                                   time-signature-fraction
63                                   function
64                                   type))
65                  (default-grouping (ly:beam-grouping
66                                      settings
67                                      time-signature-fraction
68                                      function
69                                      '*))
70                  (beat-grouping (if (null? type-grouping)
71                                   default-grouping
72                                   type-grouping))
73                  (grouping-moment (if (null? type-grouping)
74                                     beat-length
75                                     test-beam))
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
84                (or
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)))))))