lilypond-0.0.77.jcn1
[lilypond.git] / src / staffcolumn.cc
blob229ab699333afde2b260c4ac72e3bda4190c787c
1 /*
2 staffcolumn.cc -- implement Staff_column
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "staff.hh"
9 #include "voice.hh"
10 #include "timedescription.hh"
11 #include "scorecolumn.hh"
12 #include "staffcolumn.hh"
13 #include "commandrequest.hh"
14 #include "musicalrequest.hh"
15 #include "interval.hh"
16 #include "pscore.hh"
17 #include "item.hh"
18 #include "pcol.hh"
20 void
21 Staff_column::OK() const
23 #ifndef NDEBUG
24 assert (command_column_l_->when() == musical_column_l_->when());
25 #endif
28 Moment
29 Staff_column::when() const
31 return (command_column_l_)?
32 command_column_l_->when():
33 musical_column_l_->when();
36 void
37 Staff_column::add(Voice_element*ve)
39 for (iter_top(ve->reqs,j); j.ok(); j++) {
40 if (j->command()) {
41 Command_req * c_l = j->command();
42 if (c_l->timing()) {
43 timing_req_l_arr_.push(j->command()->timing());
45 if (!c_l->barcheck() && !c_l->partial() &&
46 !c_l->measuregrouping())
47 setup_one_request(j); // no need to bother children
48 } else {
49 if (j->rhythmic()) {
50 musical_column_l_->add_duration(j->rhythmic()->duration());
52 if (!j->musical()->skip())
53 setup_one_request(j);
58 Staff_column::Staff_column()
60 musical_column_l_ = 0;
61 command_column_l_ = 0;
62 staff_l_ = 0;
68 Staff_column::~Staff_column()
72 void
73 Staff_column::set_cols(Score_column*c1, Score_column*c2)
75 command_column_l_ = c1;
76 musical_column_l_ = c2;
79 void
80 Staff_column::setup_one_request(Request * j)
82 if (j->command()) // ugh
83 commandreq_l_arr_.push(j);
84 else if (j->musical())
85 musicalreq_l_arr_.push(j);
88 void
89 Staff_column::typeset_musical_item(Item*i)
91 assert(i);
92 Score_column * scorecolumn_l = musical_column_l_;
93 musical_column_l_->pcol_l_->pscore_l_->typeset_item(i, scorecolumn_l->pcol_l_,
94 staff_l_->pstaff_l_);
97 /**
98 align items in #item_l_arr#,
100 @return the width of the items after aligning.
102 Interval
103 align_items(Array<Item*> item_l_arr)
105 Interval wid(0,0);
106 for (int i =0; i < item_l_arr.size(); i++) {
107 Interval item_width= item_l_arr[i]->width();
108 Real dx =wid.right - item_width.left;
109 item_width += dx;
110 item_l_arr[i]->translate(Offset(dx ,0));
111 wid.unite(item_width);
113 return wid;
116 void
117 translate_items(Real x, Array<Item*> item_l_arr)
119 for (int i =0; i < item_l_arr.size(); i++)
120 item_l_arr[i]->translate(Offset(x, 0));
124 This still sux
126 void
127 Staff_column::typeset_breakable_items(Array<Item *> &pre_p_arr,
128 Array<Item *> &nobreak_p_arr,
129 Array<Item *> &post_p_arr)
131 PCol * c= command_column_l_->pcol_l_;
132 PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
134 if (!c->breakable_b()) {
135 for (int i =0; i < pre_p_arr.size(); i++)
136 delete pre_p_arr[i];
137 pre_p_arr.set_size(0);
138 for (int i =0; i < post_p_arr.size(); i++)
139 delete post_p_arr[i];
140 post_p_arr.set_size(0);
144 for (int i =0; i < pre_p_arr.size(); i++) {
145 ps_l->typeset_item(pre_p_arr[i], c, staff_l_->pstaff_l_,0);
147 for (int i =0; i < nobreak_p_arr.size(); i++) {
148 ps_l->typeset_item(nobreak_p_arr[i], c, staff_l_->pstaff_l_,1);
150 for (int i =0; i < post_p_arr.size(); i++) {
151 ps_l->typeset_item(post_p_arr[i], c, staff_l_->pstaff_l_,2);
154 Interval pre_wid= align_items(pre_p_arr);
155 translate_items( -pre_wid.right, pre_p_arr);
156 align_items(nobreak_p_arr);
157 Interval post_wid =align_items(post_p_arr);
158 translate_items (-post_wid.left , post_p_arr);
160 pre_p_arr.set_size(0);
161 post_p_arr.set_size(0);
162 nobreak_p_arr.set_size(0);