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