]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 1.1.1
[lilypond.git] / lily / note-column.cc
1 /*
2   note-column.cc -- implement Note_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "dot-column.hh"
9 #include "note-column.hh"
10 #include "script.hh"
11 #include "note-head.hh"
12 #include "stem.hh"
13 #include "rest.hh"
14 #include "debug.hh"
15
16 IMPLEMENT_IS_TYPE_B1(Note_column,Script_column);
17
18 bool
19 Note_column::rest_b () const
20 {
21   return rest_l_arr_.size ();
22 }
23
24 Note_column::Note_column()
25 {
26   stem_l_ = 0;
27   h_shift_b_ = false;
28   dir_ =CENTER;
29 }
30
31 void
32 Note_column::sort()
33 {
34   head_l_arr_.sort (Note_head::compare);
35 }
36   
37 Interval_t<int>
38 Note_column::head_positions_interval() const
39 {
40   ((Note_column*)this)->sort();
41  Interval_t<int>  iv;
42
43  iv.set_empty ();
44
45  if (head_l_arr_.size ())
46    iv = Interval_t<int>(head_l_arr_[0]->position_i_, 
47                           head_l_arr_.top()->position_i_);
48   
49   return iv;
50 }
51
52 Interval 
53 Note_column::width () const
54 {
55   if (head_l_arr_.size ())
56     return head_l_arr_[0]->width ();
57   else
58     return Interval (0,0);
59 }
60
61 void
62 Note_column::do_pre_processing()
63 {
64
65   if (!dir_)
66     {
67       if (stem_l_)
68         dir_ = stem_l_->dir_;
69       else if (head_l_arr_.size ())
70         {
71           dir_ = (head_positions_interval().center () >=  5) ? DOWN:UP;
72         }
73     }
74   Script_column::do_pre_processing();
75 }
76
77   
78
79 void
80 Note_column::set_stem (Stem * stem_l)
81 {
82   add_support (stem_l);
83   stem_l_ = stem_l;
84   /* 
85      don't add stem to support; mostly invisible for rest-columns (and possibly taken . .)
86    */
87   Score_element::add_dependency (stem_l);
88   for (int i=0; i < script_l_arr_.size(); i++)
89     script_l_arr_[i]->set_stem (stem_l);
90 }
91
92 void
93 Note_column::add_script (Script *script_l)
94 {
95   Script_column::add_script (script_l) ;
96   if  (stem_l_)
97     script_l->set_stem (stem_l_);
98 }
99
100 void
101 Note_column::do_substitute_dependency (Score_element*o, Score_element*n)
102 {
103   if (stem_l_ == o) 
104     {
105       stem_l_ = n ? dynamic_cast<Stem *> (n):0;
106     }
107   if (dynamic_cast<Note_head *> (o))
108     {
109       head_l_arr_.substitute (dynamic_cast<Note_head *> (o), 
110                               (n)? dynamic_cast<Note_head *> (n) : 0);
111     }
112   Script_column::do_substitute_dependency (o,n);
113   if (dynamic_cast<Rest *> (o)) 
114     {
115       rest_l_arr_.substitute (dynamic_cast<Rest *> (o), 
116                               (n)? dynamic_cast<Rest *> (n) : 0);
117     }
118 }
119
120 void
121 Note_column::add_head (Rhythmic_head *h)
122 {
123   if (dynamic_cast<Rest *> (h))
124     {
125       rest_l_arr_.push ((Rest*)h);
126       add_support (h);  
127     }
128   if (dynamic_cast<Note_head *> (h))
129     {
130       head_l_arr_.push ((Note_head*) h);
131       add_support (h);
132     }
133 }
134
135 /**
136   translate the rest symbols
137  */
138 void
139 Note_column::translate_rests (int dy_i)
140 {
141   invalidate_cache (Y_AXIS);
142   for (int i=0; i < rest_l_arr_.size(); i++)
143     rest_l_arr_[i]->position_i_ += dy_i;
144 }
145
146 void
147 Note_column::do_print() const
148 {
149 #ifndef NPRINT
150   DOUT << "rests: " << rest_l_arr_.size() << ", ";
151   DOUT << "heads: " << head_l_arr_.size();
152 #endif
153 }
154
155 void
156 Note_column::set_dotcol (Dot_column *d)
157 {
158   add_element (d);
159 }