]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 1.1.32
[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--1999 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 bool
17 Note_column::rest_b () const
18 {
19   return rest_l_arr_.size ();
20 }
21
22 Note_column::Note_column()
23 {
24   stem_l_ = 0;
25   h_shift_b_ = false;
26   dir_ =CENTER;
27 }
28
29 void
30 Note_column::sort()
31 {
32   head_l_arr_.sort (Note_head::compare);
33 }
34   
35 Interval_t<int>
36 Note_column::head_positions_interval() const
37 {
38   ((Note_column*)this)->sort();
39   Interval_t<int>  iv;
40
41   iv.set_empty ();
42
43   if (head_l_arr_.size ())
44     iv = Interval_t<int>(head_l_arr_[0]->position_i_, 
45                          head_l_arr_.top()->position_i_);
46   
47   return iv;
48 }
49
50 void
51 Note_column::do_pre_processing()
52 {
53   if (!dir_)
54     {
55       if (stem_l_)
56         dir_ = stem_l_->dir_;
57       else if (head_l_arr_.size ())
58         {
59           //      assert (false);       // looks obsolete?
60           dir_ = sign (head_positions_interval().center ());
61         }
62     }
63   Script_column::do_pre_processing();
64 }
65
66   
67
68 void
69 Note_column::set_stem (Stem * stem_l)
70 {
71   add_support (stem_l);
72   stem_l_ = stem_l;
73   /* 
74      don't add stem to support; mostly invisible for rest-columns (and possibly taken . .)
75   */
76   Score_element::add_dependency (stem_l);
77   for (int i=0; i < script_l_arr_.size(); i++)
78     script_l_arr_[i]->set_stem (stem_l);
79 }
80
81 void
82 Note_column::add_script (Script *script_l)
83 {
84   Script_column::add_script (script_l) ;
85   if  (stem_l_)
86     script_l->set_stem (stem_l_);
87 }
88
89 void
90 Note_column::do_substitute_element_pointer (Score_element*o, Score_element*n)
91 {
92   if (stem_l_ == o) 
93     {
94       stem_l_ = n ? dynamic_cast<Stem *> (n):0;
95     }
96   if (dynamic_cast<Note_head *> (o))
97     {
98       head_l_arr_.substitute (dynamic_cast<Note_head *> (o), 
99                               (n)? dynamic_cast<Note_head *> (n) : 0);
100     }
101   Script_column::do_substitute_element_pointer (o,n);
102   if (dynamic_cast<Rest *> (o)) 
103     {
104       rest_l_arr_.substitute (dynamic_cast<Rest *> (o), 
105                               (n)? dynamic_cast<Rest *> (n) : 0);
106     }
107 }
108
109 void
110 Note_column::add_head (Rhythmic_head *h)
111 {
112   if (Rest*r=dynamic_cast<Rest *> (h))
113     {
114       rest_l_arr_.push (r);
115       add_support (r);  
116     }
117   if (Note_head *nh=dynamic_cast<Note_head *> (h))
118     {
119       head_l_arr_.push (nh);
120       add_support (nh);
121     }
122 }
123
124 /**
125   translate the rest symbols
126  */
127 void
128 Note_column::translate_rests (int dy_i)
129 {
130   invalidate_cache (Y_AXIS);
131   for (int i=0; i < rest_l_arr_.size(); i++)
132     rest_l_arr_[i]->position_i_ += dy_i;
133 }
134
135 void
136 Note_column::do_print() const
137 {
138 #ifndef NPRINT
139   DOUT << "rests: " << rest_l_arr_.size() << ", ";
140   DOUT << "heads: " << head_l_arr_.size();
141 #endif
142 }
143
144 void
145 Note_column::set_dotcol (Dot_column *d)
146 {
147   add_element (d);
148 }