]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie.cc
patch::: 1.3.11.hwn1
[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 #include "staff-symbol-referencer.hh"
15
16 void
17 Tie::set_head (Direction d, Note_head * head_l)
18 {
19   assert (!head (d));
20   index_set_cell (get_elt_property ("heads"), d, head_l->self_scm_);
21   
22   set_bounds (d, head_l);
23   add_dependency (head_l);
24 }
25
26 Tie::Tie()
27 {
28   set_elt_property ("heads", gh_cons (SCM_EOL, SCM_EOL));
29 }
30
31 Note_head* 
32 Tie::head (Direction d) const
33 {
34   SCM c = get_elt_property ("heads");
35   c = index_cell (c, d);
36
37   return dynamic_cast<Note_head*> (unsmob_element (c));  
38 }
39
40
41 /*
42   ugh: direction of the Tie is more complicated.  See [Ross] p136 and further
43  */
44 Direction
45 Tie::get_default_dir () const
46 {
47   Real p1 = Staff_symbol_referencer_interface (head (LEFT)).position_f () ;
48   Real p2 = Staff_symbol_referencer_interface (head (RIGHT)).position_f () ;  
49   
50   int m = int (p1  + p2);
51
52   /*
53     If dir is not determined: inverse of stem: down
54     (see stem::get_default_dir ())
55    */
56   Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction");
57   return (m == 0) ? other_dir (neutral_dir) : (m < 0) ? DOWN : UP;
58 }
59
60 void
61 Tie::do_add_processing()
62 {
63   if (!(head (LEFT) && head (RIGHT)))
64     warning (_ ("lonely tie"));
65
66   Direction d = LEFT;
67   Drul_array<Note_head *> new_head_drul;
68   new_head_drul[LEFT] = head(LEFT);
69   new_head_drul[RIGHT] = head(RIGHT);  
70   do {
71     if (!head (d))
72       new_head_drul[d] = head((Direction)-d);
73   } while (flip(&d) != LEFT);
74
75   index_set_cell (get_elt_property ("heads"), LEFT, new_head_drul[LEFT]->self_scm_ );
76   index_set_cell (get_elt_property ("heads"), RIGHT, new_head_drul[LEFT]->self_scm_ );
77
78 }
79
80 void
81 Tie::do_post_processing()
82 {
83   if (!head (LEFT) && !head (RIGHT))
84     {
85       programming_error ("Tie without heads.");
86       set_elt_property ("transparent", SCM_BOOL_T);
87       set_empty (X_AXIS);
88       set_empty (Y_AXIS);
89       return;
90     }
91
92   Real interline_f = paper_l ()->get_var ("interline");
93   Real internote_f = interline_f / 2;
94   Real x_gap_f = paper_l ()->get_var ("tie_x_gap");
95   Real y_gap_f = paper_l ()->get_var ("tie_y_gap");
96
97   /* 
98    Slur and tie placement [OSU]
99
100    Ties:
101
102        * x = inner vertical tangent - d * gap
103
104    */
105
106
107   /*
108     OSU: not different for outer notes, so why all this code?
109     ie,  can we drop this, or should it be made switchable.
110    */
111 #if 0
112   Direction d = LEFT;
113   do
114     {
115       Real head_width_f = head (d)
116         ? head (d)->extent (X_AXIS).length ()
117         : 0;
118       /*
119         side attached to outer (upper or lower) notehead of chord
120       */
121       if (head (d)
122           /*
123
124                 a~a~a;
125
126             to second tie, middle notehead seems not extremal
127
128             Getting scared a bit by score-element's comment:
129             // is this a good idea?
130           */
131           && (head (d)->get_elt_property ("extremal")
132               != SCM_UNDEFINED))
133         {
134         if (d == LEFT)
135             dx_f_drul_[d] += head_width_f;
136           dx_f_drul_[d] += -d * x_gap_f;
137         }
138       /*
139         side attached to inner notehead
140       */
141       else
142         {
143           dx_f_drul_[d] += -d * head_width_f;
144         }
145     } while (flip (&d) != LEFT);
146
147 #else
148
149   if (head (LEFT))
150     dx_f_drul_[LEFT] = head (LEFT)->extent (X_AXIS).length ();
151   else
152     dx_f_drul_[LEFT] = get_broken_left_end_align ();
153   dx_f_drul_[LEFT] += x_gap_f;
154   dx_f_drul_[RIGHT] -= x_gap_f;
155
156 #endif
157
158   /* 
159    Slur and tie placement [OSU]  -- check this
160
161    Ties:
162
163        * y = dx <  5ss: horizontal tangent
164          y = dx >= 5ss: y next interline - d * 0.25 ss
165
166          which probably means that OSU assumes that
167
168             dy <= 5 dx
169
170          for smal slurs
171    */
172
173
174   Real ypos = head (LEFT)
175     ? Staff_symbol_referencer_interface (head (LEFT)).position_f ()
176     : Staff_symbol_referencer_interface (head (RIGHT)).position_f () ;  
177
178   Real y_f = internote_f * ypos; 
179   int ypos_i = int (ypos);
180  
181   Real dx_f = extent (X_AXIS).length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
182   if (dx_f < paper_l ()->get_var ("tie_staffspace_length"))
183     {
184       if (abs (ypos_i) % 2)
185         y_f += get_direction () * internote_f;
186       y_f += get_direction () * y_gap_f;
187     }
188   else
189     {
190       if (! (abs (ypos_i) % 2))
191         y_f += get_direction () * internote_f;
192       y_f += get_direction () * internote_f;
193       y_f -= get_direction () * y_gap_f;
194     }
195   
196   dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = y_f;
197 }
198
199
200
201 Array<Rod>
202 Tie::get_rods () const
203 {
204   Array<Rod> a;
205   Rod r;
206   r.item_l_drul_ = spanned_drul_;
207   r.distance_f_ = paper_l ()->get_var ("tie_x_minimum");
208   a.push (r);
209   return a;
210 }
211