lilypond-0.1.56
[lilypond.git] / src / staff-column.cc
blob546a2a66e1a89c60e556f9d7a681aad393b43f5c
1 /*
2 staff-column.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 "time-description.hh"
11 #include "score-column.hh"
12 #include "staff-column.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"
19 #include "voice-element.hh"
21 void
22 Staff_column::OK() const
24 #ifndef NDEBUG
25 assert (command_column_l_->when() == musical_column_l_->when());
26 #endif
29 Moment
30 Staff_column::when() const
32 return (command_column_l_)?
33 command_column_l_->when():
34 musical_column_l_->when();
37 void
38 Staff_column::add(Voice_element*ve)
40 for (iter_top(ve->reqs,j); j.ok(); j++) {
41 if (j->command()) {
42 Command_req * c_l = j->command();
43 if (c_l->timing()) {
44 timing_req_l_arr_.push(j->command()->timing());
46 if (c_l->groupchange())
47 creationreq_l_arr_.push(c_l);
48 else if (!c_l->barcheck() && !c_l->partial() &&
49 !c_l->measuregrouping())
50 setup_one_request(j); // no need to bother children
51 } else {
52 if (j->rhythmic()) {
53 musical_column_l_->add_duration(j->rhythmic()->duration());
55 if (!j->musical()->skip())
56 setup_one_request(j);
61 Staff_column::Staff_column()
63 musical_column_l_ = 0;
64 command_column_l_ = 0;
65 staff_l_ = 0;
71 Staff_column::~Staff_column()
75 void
76 Staff_column::set_cols(Score_column*c1, Score_column*c2)
78 command_column_l_ = c1;
79 musical_column_l_ = c2;
82 void
83 Staff_column::setup_one_request(Request * j)
85 if (j->command()) // ugh
86 commandreq_l_arr_.push(j);
87 else if (j->musical())
88 musicalreq_l_arr_.push(j);
91 void
92 Staff_column::typeset_musical_item(Item*i)
94 assert(i);
95 Score_column * scorecolumn_l = musical_column_l_;
96 musical_column_l_->pcol_l_->pscore_l_->typeset_item(i, scorecolumn_l->pcol_l_,
97 staff_l_->pstaff_l_);
101 align items in #item_l_arr#,
103 @return the width of the items after aligning.
105 Interval
106 align_items(Array<Item*> item_l_arr)
108 Interval wid(0,0);
109 for (int i =0; i < item_l_arr.size(); i++) {
110 Interval item_width= item_l_arr[i]->width();
111 Real dx =wid.right - item_width.left;
112 item_width += dx;
113 item_l_arr[i]->translate(Offset(dx ,0));
114 wid.unite(item_width);
116 return wid;
119 void
120 translate_items(Real x, Array<Item*> item_l_arr)
122 for (int i =0; i < item_l_arr.size(); i++)
123 item_l_arr[i]->translate(Offset(x, 0));
127 This still sux
129 void
130 Staff_column::typeset_breakable_items(Array<Item *> &pre_p_arr,
131 Array<Item *> &nobreak_p_arr,
132 Array<Item *> &post_p_arr)
134 PCol * c= command_column_l_->pcol_l_;
135 PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
137 if (!c->breakable_b()) {
138 for (int i =0; i < pre_p_arr.size(); i++)
139 delete pre_p_arr[i];
140 pre_p_arr.set_size(0);
141 for (int i =0; i < post_p_arr.size(); i++)
142 delete post_p_arr[i];
143 post_p_arr.set_size(0);
147 for (int i =0; i < pre_p_arr.size(); i++) {
148 ps_l->typeset_item(pre_p_arr[i], c, staff_l_->pstaff_l_,0);
150 for (int i =0; i < nobreak_p_arr.size(); i++) {
151 ps_l->typeset_item(nobreak_p_arr[i], c, staff_l_->pstaff_l_,1);
153 for (int i =0; i < post_p_arr.size(); i++) {
154 ps_l->typeset_item(post_p_arr[i], c, staff_l_->pstaff_l_,2);
157 Interval pre_wid= align_items(pre_p_arr);
158 translate_items( -pre_wid.right, pre_p_arr);
159 align_items(nobreak_p_arr);
160 Interval post_wid =align_items(post_p_arr);
161 translate_items (-post_wid.left , post_p_arr);
163 pre_p_arr.set_size(0);
164 post_p_arr.set_size(0);
165 nobreak_p_arr.set_size(0);