]> git.donarmstrong.com Git - lilypond.git/blob - scm/slur.scm
release: 1.3.79
[lilypond.git] / scm / slur.scm
1
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)))
6     (and
7      (eq? col (ly-get-spanner-bound slur dir))
8      stem
9      (ly-get-elt-property stem 'heads))))
10
11
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.
15 ;;
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
19 ;; rule is tried.
20 ;;
21 ;; Currently, we have attachments:
22 ;;
23 ;;    'head 'along-side-stem 'stem 'loose-end
24 ;;
25
26 (define slur-extremity-rules
27   (list
28
29    ;; (cons (lambda (slur dir) (begin (display "before head") (newline))#f) #f)
30
31    (cons (lambda (slur dir)
32            ;; urg, code dup
33            (let* ((note-columns (ly-get-elt-property slur 'note-columns))
34                   (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
35                   (stem (ly-get-elt-property col 'stem)))
36              (and stem
37                   (not (= (ly-get-elt-property slur 'direction) 
38                           (ly-get-elt-property stem 'direction))))))  'head)
39
40    ;; (cons (lambda (slur dir) (begin (display "before stem") (newline))#f) #f)
41
42    (cons (lambda (slur dir)
43            ;; if attached-to-stem
44            (and (attached-to-stem slur dir)
45                 ;; and got beam
46                 ;; urg, code dup
47                 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
48                        (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
49                        (stem (ly-get-elt-property col 'stem)))
50                   (and stem
51                        (ly-get-elt-property stem 'beam)
52                        ;; and beam on same side as slur
53                        (let ((beaming (ly-get-elt-property stem 'beaming)))
54                          (if (pair? beaming)
55                              (<= 1
56                                  (if (= dir -1) (car beaming) (cdr beaming)))
57                              #f))))))
58          'stem)
59
60    ;;(cons (lambda (slur dir) (begin (display "before loose-end") (newline))#f) #f)
61    (cons (lambda (slur dir) (not (attached-to-stem slur dir)))  'loose-end)
62    ;; (cons (lambda (slur dir) (begin (display "after loose-end") (newline))#f) #f)
63
64    ;; default case, attach to head
65    (cons (lambda (x y) #t)  'head)
66    ))
67
68
69 ;; This list defines the offsets for each type of attachment.
70 ;; The format of each element is
71 ;; (attachment stem-dir * attachment-dir slur-dir)
72 ;; Different attachments have different default points:
73 ;;
74 ;; head: Default position is centered in X, on outer side of head Y
75 ;; along-side-stem: Default position is on stem X, on outer side of head Y
76 ;; stem: Default position is on stem X, at stem end Y
77 (define slur-extremity-offset-alist
78   '(
79     ((head 1 1) . (-0.25 . 0.2))
80     ((head 1 -1) . (-0.25 . -0.25))
81     ((head -1 1) . (-0.25 . 0.25))
82     ((head -1 -1) . (-0.85 . -0.2))
83
84     ((stem 1 1) . (0 . 0.5))
85     ((stem -1 -1) . (0 . -0.5))
86     ))