2 (define (attached-to-stem slur dir)
3 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
4 (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
5 (stem (ly-get-elt-property col 'stem)))
7 (eq? col (ly-get-spanner-bound slur dir))
9 (ly-get-elt-property stem 'heads))))
12 ;; Slur-extremity-rules is a list of rules. Each rule is a pair
13 ;; (fuction . attachment), where function takes two arguments,
14 ;; the slur and the direction of the attachment.
16 ;; The rules are tried starting from the car of this list. If the
17 ;; function part (car) evaluates to #t, the corresponding
18 ;; attachment (cdr) is used for the slur's dir. Otherwise, the next
21 ;; Currently, we have attachments:
23 ;; 'head 'along-side-stem 'stem 'loose-end
26 (define slur-extremity-rules
29 ;; (cons (lambda (slur dir) (begin (display "before head") (newline))#f) #f)
31 ;; urg: don't crash on a slur without note-columns
32 (cons (lambda (slur dir)
33 (< (length (ly-get-elt-property slur 'note-columns)) 1)) 'head)
35 ;; urg: don't crash on a slur without note-columns
36 (cons (lambda (slur dir)
37 (< (length (ly-get-elt-property slur 'note-columns)) 1)) 'head)
39 (cons (lambda (slur dir)
41 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
42 (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
43 (stem (ly-get-elt-property col 'stem)))
45 (not (= (ly-get-elt-property slur 'direction)
46 (ly-get-elt-property stem 'direction)))))) 'head)
48 ;; (cons (lambda (slur dir) (begin (display "before stem") (newline))#f) #f)
50 (cons (lambda (slur dir)
51 ;; if attached-to-stem
52 (and (attached-to-stem slur dir)
55 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
56 (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
57 (stem (ly-get-elt-property col 'stem)))
59 (ly-get-elt-property stem 'beam)
60 ;; and beam on same side as slur
61 (let ((beaming (ly-get-elt-property stem 'beaming)))
64 (if (= dir -1) (car beaming) (cdr beaming)))
68 ;;(cons (lambda (slur dir) (begin (display "before loose-end") (newline))#f) #f)
69 (cons (lambda (slur dir) (not (attached-to-stem slur dir))) 'loose-end)
70 ;; (cons (lambda (slur dir) (begin (display "after loose-end") (newline))#f) #f)
72 ;; default case, attach to head
73 (cons (lambda (x y) #t) 'head)
77 ;; This list defines the offsets for each type of attachment.
78 ;; The format of each element is
79 ;; (attachment stem-dir * attachment-dir slur-dir)
80 ;; Different attachments have different default points:
82 ;; head: Default position is centered in X, on outer side of head Y
83 ;; along-side-stem: Default position is on stem X, on outer side of head Y
84 ;; stem: Default position is on stem X, at stem end Y
85 (define slur-extremity-offset-alist
87 ((head 1 1) . (-0.25 . 0.2))
88 ((head 1 -1) . (-0.25 . -0.25))
89 ((head -1 1) . (-0.25 . 0.25))
90 ((head -1 -1) . (-0.85 . -0.2))
92 ((stem 1 1) . (0 . 0.5))
93 ((stem -1 -1) . (0 . -0.5))
95 ((loose-end -1 1) . (-4 . 0))
96 ((loose-end -1 -1) . (-4 . 0))
97 ((loose-end 1 1) . (-0.4 . 0))
98 ((loose-end 1 -1) . (-0.4 . 0))