lilypond-1.5.8
[lilypond.git] / src / stcol.cc
blobc12a0d898f0eec117d2b37a46decb37672032bb5
1 /*
2 stcol.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 "sccol.hh"
12 #include "stcol.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->nonmus()) {
41 Nonmusical_req * c_l = j->nonmus();
42 if (c_l->timing()) {
43 timing_req_l_arr_.push(j->nonmus()->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->nonmus()) // 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 * sccol_l = musical_column_l_;
93 musical_column_l_->pcol_l_->pscore_l_->typeset_item(i, sccol_l->pcol_l_,
94 staff_l_->pstaff_l_);
97 /**
98 align items in #item_l_arr#, return the width.
100 Interval
101 align_items(Array<Item*> item_l_arr)
103 Interval wid(0,0);
104 for (int i =0; i < item_l_arr.size(); i++) {
105 Interval item_width= item_l_arr[i]->width();
106 item_l_arr[i]->translate(Offset( wid.right - item_width.left ,0));
107 wid.unite(item_width);
109 return wid;
112 void
113 translate_items(Real x, Array<Item*> item_l_arr)
115 for (int i =0; i < item_l_arr.size(); i++)
116 item_l_arr[i]->translate(Offset(x, 0));
120 This still sux
122 void
123 Staff_column::typeset_breakable_items(Array<Item *> &pre_p_arr,
124 Array<Item *> &nobreak_p_arr,
125 Array<Item *> &post_p_arr)
127 PCol * c= command_column_l_->pcol_l_;
128 PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
130 if (!c->breakable_b()) {
131 for (int i =0; i < pre_p_arr.size(); i++)
132 delete pre_p_arr[i];
133 pre_p_arr.set_size(0);
134 for (int i =0; i < post_p_arr.size(); i++)
135 delete post_p_arr[i];
136 post_p_arr.set_size(0);
140 for (int i =0; i < pre_p_arr.size(); i++) {
141 ps_l->typeset_item(pre_p_arr[i], c, staff_l_->pstaff_l_,0);
143 for (int i =0; i < nobreak_p_arr.size(); i++) {
144 ps_l->typeset_item(nobreak_p_arr[i], c, staff_l_->pstaff_l_,1);
146 for (int i =0; i < post_p_arr.size(); i++) {
147 ps_l->typeset_item(post_p_arr[i], c, staff_l_->pstaff_l_,2);
150 Interval pre_wid= align_items(pre_p_arr);
151 translate_items( -pre_wid.right, pre_p_arr);
152 align_items(nobreak_p_arr);
153 Interval post_wid =align_items(post_p_arr);
154 translate_items (-post_wid.left , post_p_arr);
156 pre_p_arr.set_size(0);
157 post_p_arr.set_size(0);
158 nobreak_p_arr.set_size(0);