]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie.cc
release: 1.2.4
[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 "paper-column.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
43   /*
44     If dir is not determined: inverse of stem: down
45     (see stem::get_default_dir ())
46    */
47   Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction");
48   return (m == 0) ? other_dir (neutral_dir) : (m < 0) ? DOWN : UP;
49 }
50
51 void
52 Tie::do_add_processing()
53 {
54   if (!(head_l_drul_[LEFT] && head_l_drul_[RIGHT]))
55     warning (_ ("lonely tie"));
56
57   Direction d = LEFT;
58   Drul_array<Note_head *> new_head_drul = head_l_drul_;
59   do {
60     if (!head_l_drul_[d])
61       new_head_drul[d] = head_l_drul_[(Direction)-d];
62   } while (flip(&d) != LEFT);
63   head_l_drul_ = new_head_drul;
64 }
65
66 void
67 Tie::do_post_processing()
68 {
69   assert (head_l_drul_[LEFT] || head_l_drul_[RIGHT]);
70
71   Real interline_f = paper_l ()->get_realvar (interline_scm_sym);
72   Real internote_f = interline_f / 2;
73   Real x_gap_f = paper_l ()->get_var ("tie_x_gap");
74   Real y_gap_f = paper_l ()->get_var ("tie_y_gap");
75
76   /* 
77    Slur and tie placement [OSU]
78
79    Ties:
80
81        * x = inner vertical tangent - d * gap
82
83    */
84
85
86   /*
87     OSU: not different for outer notes, so why all this code?
88     ie,  can we drop this, or should it be made switchable.
89    */
90 #if 0
91   Direction d = LEFT;
92   do
93     {
94       Real head_width_f = head_l_drul_[d]
95         ? head_l_drul_[d]->extent (X_AXIS).length ()
96         : 0;
97       /*
98         side attached to outer (upper or lower) notehead of chord
99       */
100       if (head_l_drul_[d]
101           /*
102             && head_l_drul_[d]->remove_elt_property (extremal_scm_sym) != SCM_BOOL_F)
103             ugh, ugh:
104
105                 a~a~a;
106
107             to second tie, middle notehead seems not extremal
108
109             Getting scared a bit by score-element's comment:
110             // is this a good idea?
111           */
112           && (head_l_drul_[d]->get_elt_property (extremal_scm_sym)
113               != SCM_BOOL_F))
114         {
115         if (d == LEFT)
116             dx_f_drul_[d] += head_width_f;
117           dx_f_drul_[d] += -d * x_gap_f;
118         }
119       /*
120         side attached to inner notehead
121       */
122       else
123         {
124           dx_f_drul_[d] += -d * head_width_f;
125         }
126     } while (flip (&d) != LEFT);
127
128 #else
129
130   if (head_l_drul_[LEFT])
131     dx_f_drul_[LEFT] = head_l_drul_[LEFT]->extent (X_AXIS).length ();
132   else
133     dx_f_drul_[LEFT] = spanned_drul_[LEFT]->extent (X_AXIS).length ();
134   dx_f_drul_[LEFT] += x_gap_f;
135   dx_f_drul_[RIGHT] -= x_gap_f;
136
137 #endif
138
139   /* 
140    Slur and tie placement [OSU]  -- check this
141
142    Ties:
143
144        * y = dx <  5ss: horizontal tangent
145          y = dx >= 5ss: y next interline - d * 0.25 ss
146
147          which probably means that OSU assumes that
148
149             dy <= 5 dx
150
151          for smal slurs
152    */
153
154   int ypos_i = head_l_drul_[LEFT] ? head_l_drul_[LEFT]->position_i ()
155     : head_l_drul_[RIGHT]->position_i ();
156
157   Real y_f = internote_f * ypos_i; 
158
159   Real dx_f = extent (X_AXIS).length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
160   if (dx_f < paper_l ()->get_var ("tie_staffspace_length"))
161     {
162       if (abs (ypos_i) % 2)
163         y_f += dir_ * internote_f;
164       y_f += dir_ * y_gap_f;
165     }
166   else
167     {
168       if (! (abs (ypos_i) % 2))
169         y_f += dir_ * internote_f;
170       y_f += dir_ * internote_f;
171       y_f -= dir_ * y_gap_f;
172     }
173   
174   dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = y_f;
175 }
176
177 void
178 Tie::do_substitute_element_pointer (Score_element*o, Score_element*n)
179 {
180   Note_head *new_l = n ? dynamic_cast<Note_head *> (n) : 0;
181   if (dynamic_cast <Item *> (o) == head_l_drul_[LEFT])
182     head_l_drul_[LEFT] = new_l;
183   else if (dynamic_cast <Item *> (o) == head_l_drul_[RIGHT])
184     head_l_drul_[RIGHT] = new_l;
185 }
186
187
188 Array<Rod>
189 Tie::get_rods () const
190 {
191   Array<Rod> a;
192   Rod r;
193   r.item_l_drul_ = spanned_drul_;
194   r.distance_f_ = paper_l ()->get_var ("tie_x_minimum");
195   a.push (r);
196   return a;
197 }