]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
release: 1.3.55
[lilypond.git] / lily / tie-column.cc
1 /*   
2   tie-column.cc --  implement Tie_column
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "tie-column.hh"
11 #include "group-interface.hh"
12 #include "tie.hh"
13 #include "directional-element-interface.hh"
14 #include "note-head.hh"
15
16 Tie_column::Tie_column (SCM s)
17   : Spanner (s)
18 {
19   set_elt_pointer ("ties", SCM_EOL);
20   set_extent_callback (0, X_AXIS);
21   set_extent_callback (0, Y_AXIS);  
22   set_elt_property ("transparent", SCM_BOOL_T);
23 }
24
25 void
26 Tie_column::add_tie (Tie *s)
27 {
28   Pointer_group_interface g (this, "ties");
29   if (!g.count ())
30     {
31       set_bound (LEFT, s->head (LEFT));
32       set_bound (RIGHT, s->head (RIGHT));
33     }
34   
35   Pointer_group_interface (this, "ties").add_element (s);
36   s->add_dependency (this);
37 }
38
39
40 int
41 tie_compare (Tie* const & s1,
42              Tie* const & s2)
43 {
44   return sign (s1->position_f () - s2->position_f());
45 }
46
47 /*
48   See [Ross p. 138].
49
50
51   In normal chord cases, the outer ties point outwards, and the
52   direction of the rest is determined by their staff position.
53
54   Ross forgets about the tie that is *on* the middle staff line. We
55   assume it goes UP. (TODO: make this settable) */
56 void
57 Tie_column::set_directions ()
58 {
59   Link_array<Tie> s =
60     Pointer_group_interface__extract_elements (this, (Tie*)0, "ties");
61
62
63   Direction d = directional_element (this).get ();
64
65   if (d)
66     {
67       for (int i = s.size (); i--;)
68         directional_element (s[i]).set (d);
69       return;
70     }
71   
72   if (s.size () == 1)
73     {
74       directional_element (s[0]).set (s[0]->get_default_dir ());
75       return;
76     }
77   
78   s.sort (tie_compare);
79   directional_element (s[0]).set (DOWN);
80   s.del (0);
81   directional_element (s.pop ()).set (UP);
82
83   for (int i=s.size(); i--; )
84     {
85       Real p = s[i]->position_f ();
86       Direction d = (Direction) sign (p);
87       if (!d)
88         d = UP;
89
90       directional_element (s[i]).set (d);
91     }
92   
93 }
94
95 void
96 Tie_column::after_line_breaking ()
97 {
98   set_directions ();
99 }