1\header {
2
3  texidoc = "In chords, ties keep closer to the note head vertically,
4but never collide with heads or stems.  Seconds are formatted up/@/down;
5the rest of the ties are positioned according to their vertical
6position.
7
8The code does not handle all cases.  Sometimes ties will printed on top
9of or very close to each other.  This happens in the last chords of
10each system."
11
12}
13
14\version "2.19.22"
15
16\paper {
17  indent = #0.0
18  ragged-right = ##t
19}
20
21
22
23generateTiePattern
24= #(define-music-function (is-long chords) (boolean? ly:music?)
25
26    "
27
28translate x y z to x~x y~y z~z
29
30"
31
32  (define (chord->tied-chord chord)
33    (let*
34	((ch1 (ly:music-deep-copy chord))
35	 (ch2 (ly:music-deep-copy chord))
36	 (dur1 (ly:make-duration
37		(if is-long
38		    1 2)))
39	 (dur2 (ly:make-duration
40		(if is-long
41		    3 2))))
42
43      (for-each (lambda (e)
44		  (ly:music-set-property! e 'duration dur1))
45		(ly:music-property ch1 'elements))
46
47      (for-each (lambda (e)
48		  (ly:music-set-property! e 'duration dur2))
49		(ly:music-property ch2 'elements))
50
51      (set! (ly:music-property ch1 'elements)
52	    (cons
53	     (make-music 'TieEvent)
54	     (ly:music-property ch1 'elements)))
55
56      (list ch1 ch2)))
57
58  (make-music 'SequentialMusic 'elements (append-map
59					  chord->tied-chord (ly:music-property  chords 'elements))))
60
61baseChords =
62\applyMusic #(lambda (mus)
63	      (ly:music-property mus 'element))
64\relative {
65  <c'' e>
66  <b c e>
67  <a c e>
68  <a b e>
69  <a b e f>
70  <a c d f>
71  <a c e f>
72  <f a e' f>
73  <c e f a>
74  <c e g a>
75  <f b e a>
76}
77
78testShort =
79{
80  \key c \major
81  \generateTiePattern ##f \baseChords
82}
83
84testLong =
85{
86  \key c \major
87  \generateTiePattern ##t \baseChords
88}
89
90\new Voice
91{
92  \time 2/4
93
94  \testShort \break
95  \transpose c d \testShort \break
96  \time 5/8
97  \testLong \break
98  \transpose c d \testLong \break
99}
100
101
102