2 ;; clip-region.scm -- implement rhythmic-location and EPS musical clipping
4 ;; source file of the GNU LilyPond music typesetter
6 ;; (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
9 (define-module (scm clip-region))
14 (define-public (make-rhythmic-location bar-num num den)
16 bar-num (ly:make-moment num den)))
18 (define-public (rhythmic-location? a)
21 (ly:moment? (cdr a))))
23 (define-public (make-graceless-rhythmic-location loc)
24 (make-rhythmic-location
26 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
27 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
30 (define-public rhythmic-location-measure-position cdr)
31 (define-public rhythmic-location-bar-number car)
33 (define-public (rhythmic-location<? a b)
35 ((< (car a) (car b)) #t)
36 ((> (car a) (car b)) #f)
38 (ly:moment<? (cdr a) (cdr b)))))
40 (define-public (rhythmic-location<=? a b)
41 (not (rhythmic-location<? b a)))
42 (define-public (rhythmic-location>=? a b)
43 (rhythmic-location<? a b))
44 (define-public (rhythmic-location>? a b)
45 (rhythmic-location<? b a))
47 (define-public (rhythmic-location=? a b)
48 (and (rhythmic-location<=? a b)
49 (rhythmic-location<=? b a)))
52 (define-public (rhythmic-location->file-string a)
55 (ly:moment-main-numerator (cdr a))
56 (ly:moment-main-denominator (cdr a))))
58 (define-public (rhythmic-location->string a)
59 (ly:format "bar ~a ~a"
61 (ly:moment->string (cdr a))))
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;; Actual clipping logic.
67 ;; the total of this will be
68 ;; O(#systems * #regions)
70 ;; we can actually do better by sorting the regions as well,
71 ;; but let's leave that for future extensions.
73 (define-public (system-clipped-x-extent system-grob clip-region)
74 "Return the X-extent of the SYSTEM-GROB when clipped with
75 CLIP-REGION. Return #f if not appropriate."
78 ((region-start (car clip-region))
79 (columns (ly:grob-object system-grob 'columns))
80 (region-end (cdr clip-region))
86 ((column (ly:grob-array-ref columns j))
87 (loc (ly:grob-property column 'rhythmic-location))
88 (grace-less (make-graceless-rhythmic-location loc))
91 (and (rhythmic-location? loc)
92 (rhythmic-location<=? region-start loc)
93 (or (rhythmic-location<? grace-less region-end)
94 (and (rhythmic-location=? grace-less region-end)
95 (eq? #t (ly:grob-property column 'non-musical))
101 (iota (ly:grob-array-length columns))))
104 (if (>= 1 (length candidate-columns))
106 (cons (car candidate-columns)
107 (car (last-pair candidate-columns)))))
114 (ly:grob-robust-relative-extent
115 (if (= 0 (car column-range))
117 (ly:grob-array-ref columns (car column-range)))
121 (ly:grob-robust-relative-extent
122 (if (= (1- (ly:grob-array-length columns)) (cdr column-range))
124 (ly:grob-array-ref columns (cdr column-range)))