lilypond-0.1.37
[lilypond.git] / lily / slur.cc
blob2597c5e03212c409b7027e6566bc18451034e70d
1 /*
2 slur.cc -- implement Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 /*
10 TODO:
12 think about crossing stems.
13 Begin and end should be treated as a Script.
15 #include "slur.hh"
16 #include "scalar.hh"
17 #include "lookup.hh"
18 #include "paper-def.hh"
19 #include "note-column.hh"
20 #include "stem.hh"
21 #include "p-col.hh"
22 #include "molecule.hh"
23 #include "debug.hh"
24 #include "boxes.hh"
28 void
29 Slur::add (Note_column*n)
31 encompass_arr_.push (n);
32 add_dependency (n);
35 void
36 Slur::set_default_dir()
38 dir_ = DOWN;
39 for (int i=0; i < encompass_arr_.size(); i ++)
41 if (encompass_arr_[i]->dir_ < 0)
43 dir_ =UP;
44 break;
49 void
50 Slur::do_add_processing()
52 set_bounds(LEFT, encompass_arr_[0]);
53 if (encompass_arr_.size () > 1)
54 set_bounds(RIGHT, encompass_arr_.top());
57 void
58 Slur::do_pre_processing ()
60 // don't set directions
63 void
64 Slur::do_substitute_dependency (Score_elem*o, Score_elem*n)
66 int i;
67 while ((i = encompass_arr_.find_i ((Note_column*)o->item())) >=0)
69 if (n)
70 encompass_arr_[i] = (Note_column*)n->item();
71 else
72 encompass_arr_.del (i);
77 static int
78 Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
80 return Item::left_right_compare(n1, n2);
83 void
84 Slur::do_post_processing()
86 encompass_arr_.sort (Note_column_compare);
87 if (!dir_)
88 set_default_dir();
89 Real inter_f = paper()->internote_f ();
91 Drul_array<Note_column*> extrema;
92 extrema[LEFT] = encompass_arr_[0];
93 extrema[RIGHT] = encompass_arr_.top();
95 Direction d=LEFT;
96 Real nw_f = paper()->note_width ();
98 do
100 if (extrema[d] != spanned_drul_[d])
102 dx_f_drul_[d] = -d
103 *(spanned_drul_[d]->width ().length ()/nw_f -0.5);
105 else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_)
106 pos_i_drul_[d] = (int)rint (extrema[d]->stem_l_->height()[dir_]/inter_f);
107 else
108 pos_i_drul_[d] = (int)rint (extrema[d]->head_positions_interval()[dir_]);
109 pos_i_drul_[d] += dir_;
111 while ((d *= -1) != LEFT);
114 IMPLEMENT_IS_TYPE_B1(Slur,Spanner);