]> git.donarmstrong.com Git - lilypond.git/blob - scm/slur.scm
630dc82cc918621fa0b405502401155be166b2de
[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 default-slur-extremity-rules
27   (list
28
29    ;; (cons (lambda (slur dir) (begin (display "before sanity check") (newline))#f) #f)
30
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)
34
35    ;; (cons (lambda (slur dir) (begin (display "before loose-end") (newline))#f) #f)
36    (cons (lambda (slur dir) (not (attached-to-stem slur dir)))  'loose-end)
37
38    ;; (cons (lambda (slur dir) (begin (display "before head") (newline))#f) #f)
39
40    (cons (lambda (slur dir)
41            ;; urg, code dup
42            (let* ((note-columns (ly-get-elt-property slur 'note-columns))
43                   (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
44                   (stem (ly-get-elt-property col 'stem)))
45              (and stem
46                   (not (= (ly-get-elt-property slur 'direction) 
47                           (ly-get-elt-property stem 'direction))))))  'head)
48
49    ;; (cons (lambda (slur dir) (begin (display "before stem") (newline))#f) #f)
50
51    (cons (lambda (slur dir)
52            ;; if attached-to-stem
53            (and (attached-to-stem slur dir)
54                 ;; and got beam
55                 ;; urg, code dup
56                 (let* ((note-columns (ly-get-elt-property slur 'note-columns))
57                        (col (if (= dir 1) (car note-columns) (car (reverse note-columns))))
58                        (stem (ly-get-elt-property col 'stem)))
59                   (and stem
60                        (ly-get-elt-property stem 'beam)
61                        ;; and beam on same side as slur
62                        (let ((beaming (ly-get-elt-property stem 'beaming)))
63                          (if (pair? beaming)
64                              (<= 1
65                                  (if (= dir -1) (car beaming) (cdr beaming)))
66                              #f))))))
67          'stem)
68
69    ;;(cons (lambda (slur dir) (begin (display "before loose-end") (newline))#f) #f)
70    (cons (lambda (slur dir) (not (attached-to-stem slur dir)))  'loose-end)
71    ;; (cons (lambda (slur dir) (begin (display "after loose-end") (newline))#f) #f)
72
73    ;; default case, attach to head
74    (cons (lambda (x y) #t)  'head)
75    ))
76
77
78 ;; This list defines the offsets for each type of attachment.
79 ;; The format of each element is
80 ;; (attachment stem-dir*dir slur-dir*dir)
81 ;; Different attachments have different default points:
82 ;;
83 ;; head: Default position is centered in X, on outer side of head Y
84 ;; along-side-stem: Default position is on stem X, on outer side of head Y
85 ;; stem: Default position is on stem X, at stem end Y
86 (define default-slur-extremity-offset-alist
87   '(
88     ((head 1 1) . (-0.25 . 0.25))
89     ((head 1 -1) . (-0.25 . -0.25))
90     ((head -1 1) . (-0.25 . 0.25))
91     ((head -1 -1) . (-0.85 . -0.25))
92
93     ((stem 1 1) . (0 . 0.5))
94     ((stem -1 -1) . (0 . -0.5))
95
96     ((loose-end 1 1) . (-0.4 . 0))
97     ((loose-end 1 -1) . (-0.4 . 0))
98     ((loose-end -1 -1) . (-4 . 0))
99     ((loose-end -1 1) . (-4 . 0))
100     ))
101
102
103 (define default-basic-slur-properties
104   `(
105    (molecule-callback . ,Slur::brew_molecule)
106    (thickness . 1.2)            
107    (spacing-procedure . ,Slur::set_spacing_rods)                
108    (minimum-length . 1.5)
109    (after-line-breaking-callback . ,Slur::after_line_breaking)
110    (extremity-rules . ,default-slur-extremity-rules)
111    (extremity-offset-alist . ,default-slur-extremity-offset-alist)
112    (de-uglify-parameters . ( 1.5  0.8  -2.0))
113    (details . ((height-limit . 2.0) (ratio . 0.333) (force-blowfit . 0.5)))
114    (beautiful . 0.5)
115    (y-free . 0.75)
116    (attachment-offset . ((0 . 0) . (0 . 0)))
117    (slope-limit . 0.8)
118    (meta . ,(element-description "Slur" general-element-interface slur-interface))
119    )
120   )