]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie.cc
release: 1.1.39
[lilypond.git] / lily / tie.cc
1 /*
2   tie.cc -- implement Tie
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "paper-def.hh"
10 #include "tie.hh"
11 #include "note-head.hh"
12 #include "p-col.hh"
13 #include "debug.hh"
14
15
16
17 void
18 Tie::set_head (Direction d, Note_head * head_l)
19 {
20   assert (!head_l_drul_[d]);
21   head_l_drul_[d] = head_l;
22   set_bounds (d, head_l);
23
24   add_dependency (head_l);
25 }
26
27 Tie::Tie()
28 {
29   head_l_drul_[RIGHT] =0;
30   head_l_drul_[LEFT] =0;
31   same_pitch_b_ =false;
32 }
33
34
35 /*
36   ugh: direction of the Tie is more complicated.  See [Ross] p136 and further
37  */
38 Direction
39 Tie::get_default_dir() const
40 {
41   int m= (head_l_drul_[LEFT]->position_i_ 
42           + head_l_drul_[RIGHT]->position_i_) /2;
43   return(m < 0)? DOWN : UP;
44 }
45
46 void
47 Tie::do_add_processing()
48 {
49   if (!(head_l_drul_[LEFT] && head_l_drul_[RIGHT]))
50     warning (_ ("lonely tie"));
51
52   Direction d = LEFT;
53   Drul_array<Note_head *> new_head_drul = head_l_drul_;
54   do {
55     if (!head_l_drul_[d])
56       new_head_drul[d] = head_l_drul_[(Direction)-d];
57   } while (flip(&d) != LEFT);
58   head_l_drul_ = new_head_drul;
59 }
60
61 void
62 Tie::do_post_processing()
63 {
64   // URG: share code with slur!
65   assert (head_l_drul_[LEFT] || head_l_drul_[RIGHT]);
66
67   // URG
68   Real notewidth = paper_l ()->note_width () * 0.8;
69   Real interline_f = paper_l ()->get_realvar (interline_scm_sym);
70
71   /* 
72    [OSU]: slur and tie placement
73
74    ties:
75    * x = inner raakpunt - d * gap
76
77    * y = length < 5ss : horizontal raakpunt
78      y = length >= 5ss : y next interline - d * 0.25 ss
79      --> height <= 5 length ?? we use <= 3 length, now...
80    */
81
82   Real gap_f = paper_l ()->get_var ("slur_x_gap");
83
84   Direction d = LEFT;
85   do
86     {
87       dy_f_drul_[d] = .5 * interline_f * (head_l_drul_[d] 
88                        ? head_l_drul_[d]->position_i_
89                        : head_l_drul_[(Direction)-d]->position_i_);
90     }
91   while (flip(&d) != LEFT);
92
93   do
94     {
95       // tie attached to outer notehead
96       if (head_l_drul_[d]
97           && head_l_drul_[d]->remove_elt_property (extremal_scm_sym) != SCM_BOOL_F)
98         {
99           if (d == LEFT)
100             dx_f_drul_[d] += notewidth;
101           dx_f_drul_[d] += -d * gap_f;
102           /* attach to outer 3/4 end of head */
103           dy_f_drul_[d] += dir_ * 0.25 * interline_f;
104         }
105       // tie attached to inner notehead
106       else if (head_l_drul_[d] && d == LEFT)
107         {
108           dx_f_drul_[d] += -d * notewidth;
109         }
110       // uhm? loose end of tie // tie attached to stem
111       else
112         {
113           dx_f_drul_[d] = -d * (spanned_drul_[d]->extent (X_AXIS).length () 
114                                 -0.5 * notewidth);
115         }
116     }
117   while (flip(&d) != LEFT);
118
119   // now that both are set, do dependent
120   do
121     {
122       // tie attached to outer notehead
123       if (!head_l_drul_[d])
124         {
125           dy_f_drul_[d] = dy_f_drul_[(Direction) -d];
126         }
127     }
128   while (flip(&d) != LEFT);
129
130   /*
131     Avoid too steep ties
132       * slur from notehead to stemend: c''()b''
133    */
134   Real damp_f = paper_l ()->get_var ("tie_slope_damping");
135   Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
136     dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
137   d_off.x () += extent (X_AXIS).length ();
138
139   Real ratio_f = abs (d_off.y () / d_off.x ());
140   if (ratio_f > damp_f)
141     dy_f_drul_[(Direction)(- dir_ * sign (d_off.y ()))] +=
142       dir_ * (ratio_f - damp_f) * d_off.x ();
143 }
144
145 void
146 Tie::do_substitute_element_pointer (Score_element*o, Score_element*n)
147 {
148   Note_head *new_l =n?dynamic_cast<Note_head *> (n):0;
149   if (dynamic_cast <Item *> (o) == head_l_drul_[LEFT])
150     head_l_drul_[LEFT] = new_l;
151   else if (dynamic_cast <Item *> (o) == head_l_drul_[RIGHT])
152     head_l_drul_[RIGHT] = new_l;
153 }
154
155
156 Array<Rod>
157 Tie::get_rods () const
158 {
159   Array<Rod> a;
160   Rod r;
161   r.item_l_drul_ = spanned_drul_;
162   r.distance_f_ = paper_l ()->get_var ("tie_x_minimum");
163   a.push (r);
164   return a;
165 }