]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie.cc
c47d0831ace4f2202fa737fe1cbe235e1b4f5c1a
[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--1998 Han-Wen Nienhuys <hanwen@stack.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 #include "main.hh"  // experimental features
15
16 IMPLEMENT_IS_TYPE_B1(Tie,Bow);
17
18 void
19 Tie::set_head (Direction d, Note_head * head_l)
20 {
21   assert (!head_l_drul_[d]);
22   head_l_drul_[d] = head_l;
23   set_bounds (d, head_l);
24
25   add_dependency (head_l);
26 }
27
28 Tie::Tie()
29 {
30   head_l_drul_[RIGHT] =0;
31   head_l_drul_[LEFT] =0;
32   same_pitch_b_ =false;
33 }
34
35
36 /*
37   ugh: direction of the Tie is more complicated.  See [Ross] p136 and further
38  */
39 void
40 Tie::set_default_dir()
41 {
42   int m= (head_l_drul_[LEFT]->position_i_ 
43           + head_l_drul_[RIGHT]->position_i_) /2;
44   dir_ =  (m < 0)? DOWN : UP;
45 }
46
47 void
48 Tie::do_add_processing()
49 {
50   if (!(head_l_drul_[LEFT] && head_l_drul_[RIGHT]))
51     warning (_("Lonely tie.. "));
52
53   Direction d = LEFT;
54   Drul_array<Note_head *> new_head_drul = head_l_drul_;
55   do {
56     if (!head_l_drul_[d])
57       new_head_drul[d] = head_l_drul_[(Direction)-d];
58   } while (flip(&d) != LEFT);
59   head_l_drul_ = new_head_drul;
60 }
61
62 void
63 Tie::do_post_processing()
64 {
65   // URG: share code with slur!
66   assert (head_l_drul_[LEFT] || head_l_drul_[RIGHT]);
67
68   Real notewidth = paper ()->note_width ();
69   Real interline_f = paper ()->interline_f ();
70   Real tie_min = paper ()->get_var ("tie_x_minimum");
71
72   /* 
73    [OSU]: slur and tie placement
74
75    ties:
76    * x = inner raakpunt - d * gap
77
78    * y = length < 5ss : horizontal raakpunt
79      y = length >= 5ss : y next interline - d * 0.25 ss
80      --> height <= 5 length ?? we use <= 3 length, now...
81    */
82
83   Real gap_f = paper ()->get_var ("slur_x_gap");
84
85   Direction d = LEFT;
86   do
87     {
88       dy_f_drul_[d] = .5 * interline_f * (head_l_drul_[d] 
89                        ? head_l_drul_[d]->position_i_
90                        : head_l_drul_[(Direction)-d]->position_i_);
91     }
92   while (flip(&d) != LEFT);
93
94   do
95     {
96       // tie attached to outer notehead
97       if (head_l_drul_[d] && head_l_drul_[d]->extremal_i_)
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])
107         {
108           dx_f_drul_[d] += d*0.5 * notewidth;
109         }
110       // uhm? loose end of tie // tie attached to stem
111       else
112         {
113           dx_f_drul_[d] = -d * (spanned_drul_[d]->width ().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           if (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT] < tie_min)
126             {
127               dx_f_drul_[d] -= d * tie_min 
128                 - (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]);
129               dx_f_drul_[d] = dx_f_drul_[(Direction)-d] + d * tie_min;
130             }
131
132           dy_f_drul_[d] = dy_f_drul_[(Direction) -d];
133         }
134     }
135   while (flip(&d) != LEFT);
136
137   /*
138     Avoid too steep ties
139       * slur from notehead to stemend: c''()b''
140    */
141   Real damp_f = paper ()->get_var ("tie_slope_damping");
142   Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
143     dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
144   d_off.x () += width ().length ();
145
146   Real ratio_f = abs (d_off.y () / d_off.x ());
147   if (ratio_f > damp_f)
148     dy_f_drul_[(Direction)(- dir_ * sign (d_off.y ()))] -=
149       dir_ * (damp_f - ratio_f) * d_off.x ();
150 }
151
152 void
153 Tie::do_substitute_dependency (Score_elem*o, Score_elem*n)
154 {
155   Note_head *new_l =n?(Note_head*)n->item():0;
156   if (o->item() == head_l_drul_[LEFT])
157     head_l_drul_[LEFT] = new_l;
158   else if (o->item() == head_l_drul_[RIGHT])
159     head_l_drul_[RIGHT] = new_l;
160 }
161