1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2006--2015 Han-Wen Nienhuys <hanwen@lilypond.org>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (scm clip-region))
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;; The procedures shown in this list have been moved to
28 ;; (define-public (make-rhythmic-location bar-num num den)
29 ;; (define-public (rhythmic-location? a)
30 ;; (define-public (make-graceless-rhythmic-location loc)
31 ;; (define-public rhythmic-location-measure-position cdr)
32 ;; (define-public rhythmic-location-bar-number car)
33 ;; (define-public (rhythmic-location<? a b)
34 ;; (define-public (rhythmic-location<=? a b)
35 ;; (define-public (rhythmic-location>=? a b)
36 ;; (define-public (rhythmic-location>? a b)
37 ;; (define-public (rhythmic-location=? a b)
38 ;; (define-public (rhythmic-location->file-string a)
39 ;; (define-public (rhythmic-location->string a)
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;; Actual clipping logic.
46 ;; the total of this will be
47 ;; O(#systems * #regions)
49 ;; we can actually do better by sorting the regions as well,
50 ;; but let's leave that for future extensions.
52 (define-public (system-clipped-x-extent system-grob clip-region)
53 "Return the X-extent of @var{system-grob} when clipped with
54 @var{clip-region}. Return @code{#f} if not appropriate."
57 ((region-start (car clip-region))
58 (columns (ly:grob-object system-grob 'columns))
59 (region-end (cdr clip-region))
65 ((column (ly:grob-array-ref columns j))
66 (loc (ly:grob-property column 'rhythmic-location))
67 (grace-less (make-graceless-rhythmic-location loc))
70 (and (rhythmic-location? loc)
71 (rhythmic-location<=? region-start loc)
72 (or (rhythmic-location<? grace-less region-end)
73 (and (rhythmic-location=? grace-less region-end)
74 (eq? #t (ly:grob-property column 'non-musical))
80 (iota (ly:grob-array-length columns))))
83 (if (>= 1 (length candidate-columns))
85 (cons (car candidate-columns)
86 (car (last-pair candidate-columns)))))
93 (ly:grob-robust-relative-extent
94 (if (= 0 (car column-range))
96 (ly:grob-array-ref columns (car column-range)))
100 (ly:grob-robust-relative-extent
101 (if (= (1- (ly:grob-array-length columns)) (cdr column-range))
103 (ly:grob-array-ref columns (cdr column-range)))