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