]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 0.1.13
[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 Han-Wen Nienhuys <hanwen@stack.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   return Interval_t<int> (head_l_arr_[0]->position_i_, 
42                           head_l_arr_.top()->position_i_);
43
44 }
45
46 void
47 Note_column::do_pre_processing()
48 {
49
50   if (!dir_)
51     {
52       if (stem_l_)
53         dir_ = stem_l_->dir_;
54       else if (head_l_arr_.size ())
55         {
56           dir_ = (head_positions_interval().center () >=  5) ? DOWN:UP;
57         }
58     }
59   Script_column::do_pre_processing();
60 }
61
62   
63
64 void
65 Note_column::set (Stem * stem_l)
66 {
67   add_support (stem_l);
68   stem_l_ = stem_l;
69   /* 
70      don't add stem to support; mostly invisible for rest-columns (and possibly taken . .)
71     
72    */
73   Score_elem::add_dependency (stem_l);
74   for (int i=0; i < script_l_arr_.size(); i++)
75     script_l_arr_[i]->set_stem (stem_l);
76
77 }
78
79 void
80 Note_column::add (Script *script_l)
81 {
82   Script_column::add (script_l) ;
83   if  (stem_l_)
84     script_l->set_stem (stem_l_);
85 }
86
87 void
88 Note_column::do_substitute_dependency (Score_elem*o, Score_elem*n)
89 {
90   if (stem_l_ == o) 
91     {
92       stem_l_ = n ? (Stem*)n->item():0;
93     }
94   if (o->is_type_b (Note_head::static_name ()))
95     {
96       head_l_arr_.substitute ((Note_head*)o->item(), 
97                               (n)? (Note_head*)n->item() : 0);
98     }
99   Script_column::do_substitute_dependency (o,n);
100   if (o->is_type_b (Rest::static_name ())) 
101     {
102       rest_l_arr_.substitute ((Rest*)o->item(), 
103                               (n)? (Rest*)n->item() : 0);
104     }
105 }
106
107 void
108 Note_column::add (Rhythmic_head *h)
109 {
110   if (h->is_type_b (Rest::static_name ()))
111     {
112       rest_l_arr_.push ((Rest*)h);
113       add_support (h);  
114     }
115   if (h->is_type_b (Note_head::static_name ()))
116     {
117       head_l_arr_.push ((Note_head*) h);
118       add_support (h);
119     }
120 }
121
122 /**
123   translate the rest symbols
124  */
125 void
126 Note_column::translate_rests (int dy_i)
127 {
128   for (int i=0; i < rest_l_arr_.size(); i++)
129     rest_l_arr_[i]->position_i_ += dy_i;
130 }
131
132 void
133 Note_column::do_print() const
134 {
135 #ifndef NPRINT
136   DOUT << "rests: " << rest_l_arr_.size() << ", ";
137   DOUT << "heads: " << head_l_arr_.size();
138 #endif
139 }
140
141 void
142 Note_column::set (Dot_column *d)
143 {
144   add_element (d);
145 }