]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 1.1.38
[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
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   set_axes (X_AXIS,X_AXIS);
25   stem_l_ = 0;
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 Direction
50 Note_column::dir () const
51 {
52   if (stem_l_)
53     return stem_l_->dir_;
54   else if (head_l_arr_.size ())
55     return sign (head_positions_interval().center ());
56
57   assert (false);
58   return CENTER;
59 }
60
61
62 void
63 Note_column::set_stem (Stem * stem_l)
64 {
65   stem_l_ = stem_l;
66   add_dependency (stem_l);
67   add_element (stem_l);
68 }
69
70
71 void
72 Note_column::do_substitute_element_pointer (Score_element*o, Score_element*n)
73 {
74   if (stem_l_ == o) 
75     {
76       stem_l_ = n ? dynamic_cast<Stem *> (n):0;
77     }
78   if (dynamic_cast<Note_head *> (o))
79     {
80       head_l_arr_.substitute (dynamic_cast<Note_head *> (o), 
81                               (n)? dynamic_cast<Note_head *> (n) : 0);
82     }
83
84   if (dynamic_cast<Rest *> (o)) 
85     {
86       rest_l_arr_.substitute (dynamic_cast<Rest *> (o), 
87                               (n)? dynamic_cast<Rest *> (n) : 0);
88     }
89 }
90
91 void
92 Note_column::add_head (Rhythmic_head *h)
93 {
94   if (Rest*r=dynamic_cast<Rest *> (h))
95     {
96       rest_l_arr_.push (r);
97     }
98   if (Note_head *nh=dynamic_cast<Note_head *> (h))
99     {
100       head_l_arr_.push (nh);
101     }
102   add_element (h);
103 }
104
105 /**
106   translate the rest symbols
107  */
108 void
109 Note_column::translate_rests (int dy_i)
110 {
111   invalidate_cache (Y_AXIS);
112   for (int i=0; i < rest_l_arr_.size(); i++)
113     rest_l_arr_[i]->position_i_ += dy_i;
114 }
115
116 void
117 Note_column::do_print() const
118 {
119 #ifndef NPRINT
120   DOUT << "rests: " << rest_l_arr_.size() << ", ";
121   DOUT << "heads: " << head_l_arr_.size();
122 #endif
123 }
124
125 void
126 Note_column::set_dotcol (Dot_column *d)
127 {
128   add_element (d);
129 }