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