]> git.donarmstrong.com Git - lilypond.git/blob - src/staff-column.cc
release: 0.0.38
[lilypond.git] / src / staff-column.cc
1 /*
2   staff-column.cc -- implement Staff_column
3
4   source file of the LilyPond music typesetter
5
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"
20
21 void
22 Staff_column::OK() const
23 {
24 #ifndef NDEBUG
25     assert (command_column_l_->when() == musical_column_l_->when());
26 #endif
27 }
28
29 Moment
30 Staff_column::when() const
31 {
32     return (command_column_l_)?
33         command_column_l_->when():
34         musical_column_l_->when();
35 }
36
37 void
38 Staff_column::add(Voice_element*ve)
39 {
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());
45             }
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());
54             }
55             if (!j->musical()->skip())
56                 setup_one_request(j);
57         }
58     }
59 }
60
61 Staff_column::Staff_column()
62 {
63     musical_column_l_ = 0;
64     command_column_l_ = 0;
65     staff_l_ = 0;
66 }
67
68
69
70
71 Staff_column::~Staff_column()
72 {
73 }
74
75 void
76 Staff_column::set_cols(Score_column*c1, Score_column*c2)
77 {
78     command_column_l_ = c1;
79     musical_column_l_ = c2;
80 }
81
82 void
83 Staff_column::setup_one_request(Request * j)
84 {
85     if (j->command()) // ugh
86         commandreq_l_arr_.push(j);
87     else if (j->musical())
88         musicalreq_l_arr_.push(j);
89 }
90
91 void
92 Staff_column::typeset_musical_item(Item*i)
93 {
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_);
98 }
99
100 /**
101   align items in #item_l_arr#,
102
103   @return the width of the items after aligning.
104  */
105 Interval
106 align_items(Array<Item*> item_l_arr)
107 {
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);
115     }
116     return wid;
117 }
118
119 void 
120 translate_items(Real x,  Array<Item*> item_l_arr)
121 {
122     for  (int i =0; i < item_l_arr.size(); i++) 
123         item_l_arr[i]->translate(Offset(x, 0));
124 }
125 /*
126   UGR
127   This still sux
128   */
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)
133 {
134     PCol * c= command_column_l_->pcol_l_;
135     PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
136     
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);
144     }
145
146       
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);
149     }
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);
152     }
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);
155     }
156
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);
162
163     pre_p_arr.set_size(0);
164     post_p_arr.set_size(0);
165     nobreak_p_arr.set_size(0);
166 }