2 ;;; slur.scm -- Slur scheme stuff
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
9 (define (attached-to-stem slur dir)
10 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
11 (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
12 (stem (ly-get-elt-property col 'stem)))
14 (eq? col (ly-get-spanner-bound slur dir))
16 (ly-get-elt-property stem 'heads))))
19 ;; Slur-extremity-rules is a list of rules. Each rule is a pair
20 ;; (fuction . attachment), where function takes two arguments,
21 ;; the slur and the direction of the attachment.
23 ;; The rules are tried starting from the car of this list. If the
24 ;; function part (car) evaluates to #t, the corresponding
25 ;; attachment (cdr) is used for the slur's dir. Otherwise, the next
28 ;; Currently, we have attachments:
30 ;; 'head 'along-side-stem 'stem 'loose-end
33 (define default-slur-extremity-rules
36 ;; (cons (lambda (slur dir) (begin (display "before sanity check") (newline))#f) #f)
38 ;; urg: don't crash on a slur without note-columns
39 (cons (lambda (slur dir)
40 (< (length (ly-get-elt-property slur 'note-columns)) 1)) 'head)
42 ;; (cons (lambda (slur dir) (begin (display "before loose-end") (newline))#f) #f)
43 (cons (lambda (slur dir) (not (attached-to-stem slur dir))) 'loose-end)
45 ;; (cons (lambda (slur dir) (begin (display "before head") (newline))#f) #f)
47 (cons (lambda (slur dir)
49 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
50 (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
51 (stem (ly-get-elt-property col 'stem)))
53 (not (= (ly-get-elt-property slur 'direction)
54 (ly-get-elt-property stem 'direction)))))) 'head)
56 ;; (cons (lambda (slur dir) (begin (display "before stem") (newline))#f) #f)
58 (cons (lambda (slur dir)
59 ;; if attached-to-stem
60 (and (attached-to-stem slur dir)
63 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
64 (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
65 (stem (ly-get-elt-property col 'stem)))
67 (ly-get-elt-property stem 'beam)
68 ;; and beam on same side as slur
69 (let ((beaming (ly-get-elt-property stem 'beaming)))
70 ;; (display "beaming (") (display dir) (display "): ") (write beaming) (newline)
72 (>= (if (= dir -1) (cdr beaming) (car beaming))
77 ;; (cons (lambda (slur dir) (begin (display "before loose-end") (newline))#f) #f)
78 (cons (lambda (slur dir) (not (attached-to-stem slur dir))) 'loose-end)
79 ;; (cons (lambda (slur dir) (begin (display "after loose-end") (newline))#f) #f)
81 ;; default case, attach to head
82 (cons (lambda (x y) #t) 'head)
86 ;; This list defines the offsets for each type of attachment.
87 ;; The format of each element is
88 ;; (attachment stem-dir*dir slur-dir*dir)
89 ;; Different attachments have different default points:
91 ;; head: Default position is centered in X, on outer side of head Y
92 ;; along-side-stem: Default position is on stem X, on outer side of head Y
93 ;; stem: Default position is on stem X, at stem end Y
94 (define default-slur-extremity-offset-alist
96 ((head 1 1) . (-0.25 . 0.25))
97 ((head 1 -1) . (-0.25 . -0.25))
98 ((head -1 1) . (-0.25 . 0.25))
99 ((head -1 -1) . (-0.85 . -0.25))
101 ((stem 1 1) . (0 . 0.5))
102 ((stem -1 -1) . (0 . -0.5))
104 ((loose-end 1 1) . (-0.4 . 0))
105 ((loose-end 1 -1) . (-0.4 . 0))
106 ((loose-end -1 -1) . (-4 . 0))
107 ((loose-end -1 1) . (-4 . 0))