]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
release: 1.3.69
[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 "rhythmic-head.hh"
15
16 Tie_column::Tie_column (SCM s)
17   : Spanner (s)
18 {
19
20 }
21 void
22 Tie_column::set_interface (Score_element*me)
23 {
24  me-> set_elt_property ("ties", SCM_EOL);
25   me->set_extent_callback (0, X_AXIS);
26   me->set_extent_callback (0, Y_AXIS);  
27 }
28
29 void
30 Tie_column::add_tie (Score_element*me,Tie *s)
31 {
32   Pointer_group_interface g (me, "ties");
33   if (!g.count ())
34     {
35       dynamic_cast<Spanner*> (me)->set_bound (LEFT, Tie::head (s,LEFT));
36       dynamic_cast<Spanner*> (me)->set_bound (RIGHT, Tie::head (s,RIGHT));
37     }
38   
39   Pointer_group_interface (me, "ties").add_element (s);
40   s->add_dependency (me);
41 }
42
43
44 int
45 tie_compare (Tie* const & s1,
46              Tie* const & s2)
47 {
48   return sign (Tie::position_f (s1) - Tie::position_f(s2));
49 }
50
51 /*
52   See [Ross p. 138].
53
54
55   In normal chord cases, the outer ties point outwards, and the
56   direction of the rest is determined by their staff position.
57
58   Ross forgets about the tie that is *on* the middle staff line. We
59   assume it goes UP. (TODO: make me settable) */
60 void
61 Tie_column::set_directions (Score_element*me)
62 {
63   Link_array<Tie> ties =
64     Pointer_group_interface__extract_elements (me, (Tie*)0, "ties");
65
66
67   Direction d = Directional_element_interface (me).get ();
68
69   if (d)
70     {
71       for (int i = ties.size (); i--;)
72         {
73           Tie * t = ties[i];
74           Directional_element_interface (t).set (d);
75         }
76       return;
77     }
78   
79   if (ties.size () == 1)
80     {
81       Tie * t = ties[0];      
82       Directional_element_interface (t).set (Tie::get_default_dir (t));
83       return;
84     }
85   
86   ties.sort (tie_compare);
87   Directional_element_interface tie0(ties[0]);
88   tie0.set (DOWN);
89   ties.del (0);
90   
91   Directional_element_interface tietop(ties.pop ());
92   tietop.set (UP);
93
94   for (int i=ties.size(); i--; )
95     {
96       Tie * t = ties[i];
97       Real p = Tie::position_f (t);
98       Direction d = (Direction) sign (p);
99       if (!d)
100         d = UP;
101       Directional_element_interface (t).set (d);
102     }
103   
104 }
105
106 MAKE_SCHEME_CALLBACK(Tie_column,after_line_breaking);
107 SCM
108 Tie_column::after_line_breaking (SCM smob)
109 {
110   set_directions (unsmob_element (smob));
111   return SCM_UNDEFINED;
112 }