]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 0.0.54
[lilypond.git] / lily / note-column.cc
1 /*
2   note-column.cc -- implement Note_column
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "note-column.hh"
10 #include "debug.hh"
11 #include "script.hh"
12 #include "notehead.hh"
13 #include "stem.hh"
14
15 IMPLEMENT_STATIC_NAME(Note_column);
16
17
18 void
19 Note_column::add(Stem*stem_l)
20 {
21     assert(!stem_l_);
22     stem_l_ = stem_l;
23     add_dependency(stem_l);
24 }
25
26 void
27 Note_column::add(Notehead* n_l)
28 {
29     if (head_l_arr_.size()){
30         if (n_l->rest_b_ != rest_b_) return; // ugly fix. Should think about integrating rests into colunms.
31     } else
32         rest_b_ = n_l->rest_b_;
33     
34     head_l_arr_.push(n_l);
35     add_dependency(n_l);
36 }
37
38 void
39 Note_column::add(Script*s_l)
40 {
41     script_l_arr_.push(s_l);
42     add_dependency(s_l);
43 }
44
45 void
46 Note_column::translate(Offset o)
47 {
48     for (int i=0; i < head_l_arr_.size(); i++)
49         head_l_arr_[i]->translate(o);
50     for (int i=0; i < script_l_arr_.size(); i++) 
51         script_l_arr_[i]->translate(o);
52     if (stem_l_)
53         stem_l_->translate(o);
54 }
55
56
57 void
58 Note_column::do_print()const
59 {
60     mtor << "heads: " << head_l_arr_.size() << '\n'; 
61     mtor << "scripts: " << script_l_arr_.size() << '\n'; 
62 }
63
64 Interval
65 Note_column::do_height()const return r
66 {
67     if (stem_l_)
68          r.unite(stem_l_->height());
69     for (int i=0; i < head_l_arr_.size(); i++)
70         r.unite(head_l_arr_[i]->height());
71     for (int i=0; i < script_l_arr_.size(); i++) 
72         r.unite(script_l_arr_[i]->height());
73 }
74
75 Interval
76 Note_column::do_width()const return r;
77 {
78     if (stem_l_)
79          r.unite(stem_l_->width());
80     for (int i=0; i < head_l_arr_.size(); i++)
81         r.unite(head_l_arr_[i]->width());
82     for (int i=0; i < script_l_arr_.size(); i++) 
83         r.unite(script_l_arr_[i]->width());
84 }
85
86 void
87 Note_column::do_pre_processing()
88 {
89     if (stem_l_ && !dir_i_)
90         dir_i_ = stem_l_->dir_i_;
91     
92     if (!script_l_arr_.size()) 
93         return;
94
95     Array<Script*> placed_l_arr_a[4];
96     for (int i=0; i < script_l_arr_.size(); i++) {
97         Script*s_l = script_l_arr_[i];
98         int j = (s_l->dir_i_ >0) ? 0 : 2;
99         if (!s_l->inside_staff_b_) 
100             j ++;
101         
102         placed_l_arr_a[j].push(s_l);
103     }
104     for (int j =0; j <4; j++) {
105         placed_l_arr_a[j].sort( Script::compare);
106     }
107     
108     Notehead *top_head_l=0;
109     Notehead *bot_head_l=0;
110     for (int i=0; i< head_l_arr_.size(); i++) {
111         if (head_l_arr_[i]->extremal == -1)
112             bot_head_l = head_l_arr_[i];
113         else if (head_l_arr_[i]->extremal == 1)
114             top_head_l = head_l_arr_[i];
115     }
116     /* argh. This sux. */
117     if (!top_head_l) 
118         top_head_l = bot_head_l;
119     if (!bot_head_l) 
120         bot_head_l = top_head_l;
121     assert(bot_head_l && top_head_l);
122     Item *support_l=top_head_l;
123     int j;
124     for (j = 0; j < 2; j++ ) {
125         for (int i=0; i < placed_l_arr_a[j].size(); i++) {
126             placed_l_arr_a[j][i]->add_support(support_l);
127             support_l = placed_l_arr_a[j][i];
128         }
129     }
130     
131     support_l=bot_head_l;
132     for (; j < 4; j++ ) {
133         for (int i=0; i < placed_l_arr_a[j].size(); i++) {
134             placed_l_arr_a[j][i]->add_support(support_l);
135             support_l = placed_l_arr_a[j][i];
136         }
137     }
138 }
139
140 Note_column::Note_column()
141 {
142     h_shift_b_ =false;
143     stem_l_ =0;
144     rest_b_ = false;
145     dir_i_ =0;
146 }
147 void
148 Note_column::sort()
149 {
150     head_l_arr_.sort( Notehead::compare);
151 }
152     
153 Interval_t<int>
154 Note_column::head_positions_interval()const
155 {
156     (    (Note_column*)this)->sort();
157     return Interval_t<int> ( head_l_arr_[0]->position, 
158                              head_l_arr_.top()->position);
159
160 }