lilypond-0.1.16
[lilypond.git] / lily / slur.cc
blobaadb9d44b9f393fe25944df636ad854be537e7bd
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_pre_processing()
52 set_bounds(LEFT, encompass_arr_[0]);
53 set_bounds(RIGHT, encompass_arr_.top());
57 void
58 Slur::do_substitute_dependency (Score_elem*o, Score_elem*n)
60 int i;
61 while ((i = encompass_arr_.find_i ((Note_column*)o->item())) >=0)
63 if (n)
64 encompass_arr_[i] = (Note_column*)n->item();
65 else
66 encompass_arr_.del (i);
71 static int
72 Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
74 return Item::left_right_compare(n1, n2);
77 void
78 Slur::do_post_processing()
80 encompass_arr_.sort (Note_column_compare);
81 if (!dir_)
82 set_default_dir();
83 Real inter_f = paper()->internote_f ();
85 Drul_array<Note_column*> extrema;
86 extrema[LEFT] = encompass_arr_[0];
87 extrema[RIGHT] = encompass_arr_.top();
89 Direction d=LEFT;
90 Real nw_f = paper()->note_width ();
92 do
94 if (extrema[d] != spanned_drul_[d])
96 dx_f_drul_[d] = -d
97 *(spanned_drul_[d]->width ().length ()/nw_f -0.5);
99 else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_)
100 pos_i_drul_[d] = (int)rint (extrema[d]->stem_l_->height()[dir_]/inter_f);
101 else
102 pos_i_drul_[d] = (int)rint (extrema[d]->head_positions_interval()[dir_]);
103 pos_i_drul_[d] += dir_;
105 while ((d *= -1) != LEFT);
108 IMPLEMENT_IS_TYPE_B1(Slur,Spanner);