]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur.cc
release: 0.1.12
[lilypond.git] / lily / slur.cc
1 /*
2   slur.cc -- implement  Slur
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 /*
10   TODO:
11   
12   think about crossing stems.
13   Begin and end should be treated as a Script.
14  */
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"
25
26
27
28 void
29 Slur::add (Note_column*n)
30 {
31   encompass_arr_.push (n);
32   add_dependency (n);
33 }
34
35 void
36 Slur::set_default_dir()
37 {
38   dir_ = DOWN;
39   for (int i=0; i < encompass_arr_.size(); i ++) 
40     {
41       if (encompass_arr_[i]->dir_ < 0) 
42         {
43           dir_ =UP;
44           break;
45         }
46     }
47 }
48
49 void
50 Slur::do_pre_processing()
51 {
52   set_bounds(LEFT, encompass_arr_[0]);    
53   set_bounds(RIGHT, encompass_arr_.top());
54 }
55
56
57 void
58 Slur::do_substitute_dependency (Score_elem*o, Score_elem*n)
59 {
60   int i;
61   while ((i = encompass_arr_.find_i ((Note_column*)o->item())) >=0) 
62     {
63       if (n)
64         encompass_arr_[i] = (Note_column*)n->item();
65       else
66         encompass_arr_.del (i);
67     }
68 }
69
70
71 static int 
72 Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
73 {
74   return Item::left_right_compare(n1, n2);
75 }
76
77 void
78 Slur::do_post_processing()
79 {
80   encompass_arr_.sort (Note_column_compare);
81   if (!dir_)
82     set_default_dir();
83   Real inter_f = paper()->internote_f ();
84   
85   Drul_array<Note_column*> extrema;
86   extrema[LEFT] = encompass_arr_[0];
87   extrema[RIGHT] = encompass_arr_.top();
88
89   Direction d=LEFT;
90   Real nw_f = paper()->note_width ();
91  
92   while ((d *= -1) != LEFT);
93   do 
94     {
95       if  (extrema[d] != spanned_drul_[d]) 
96         {
97           dx_f_drul_[d] = -d 
98             *(spanned_drul_[d]->width ().length ()/nw_f -0.5);
99         }
100       else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_) 
101         pos_i_drul_[d] = (int)rint (extrema[d]->stem_l_->height()[dir_]/inter_f);
102       else 
103         pos_i_drul_[d] = (int)rint (extrema[d]->head_positions_interval()[dir_]);
104       pos_i_drul_[d] += dir_;
105     }
106   while ((d *= -1) != LEFT);
107 }
108
109 IMPLEMENT_IS_TYPE_B1(Slur,Spanner);