]> git.donarmstrong.com Git - lilypond.git/blob - src/stcol.cc
release: 0.0.34
[lilypond.git] / src / stcol.cc
1 /*
2   stcol.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 "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"
19
20 void
21 Staff_column::OK() const
22 {
23 #ifndef NDEBUG
24     assert (command_column_l_->when() == musical_column_l_->when());
25 #endif
26 }
27
28 Moment
29 Staff_column::when() const
30 {
31     return (command_column_l_)?
32         command_column_l_->when():
33         musical_column_l_->when();
34 }
35
36 void
37 Staff_column::add(Voice_element*ve)
38 {
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());
44             }
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());
51             }
52             if (!j->musical()->skip())
53                 setup_one_request(j);
54         }
55     }
56 }
57
58 Staff_column::Staff_column()
59 {
60     musical_column_l_ = 0;
61     command_column_l_ = 0;
62     staff_l_ = 0;
63 }
64
65
66
67
68 Staff_column::~Staff_column()
69 {
70 }
71
72 void
73 Staff_column::set_cols(Score_column*c1, Score_column*c2)
74 {
75     command_column_l_ = c1;
76     musical_column_l_ = c2;
77 }
78
79 void
80 Staff_column::setup_one_request(Request * j)
81 {
82     if (j->nonmus()) // ugh
83         commandreq_l_arr_.push(j);
84     else if (j->musical())
85         musicalreq_l_arr_.push(j);
86 }
87
88 void
89 Staff_column::typeset_musical_item(Item*i)
90 {
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_);
95 }
96
97 /**
98   align items in #item_l_arr#, return the width.
99  */
100 Interval
101 align_items(Array<Item*> item_l_arr)
102 {
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);
108     }
109     return wid;
110 }
111
112 void 
113 translate_items(Real x,  Array<Item*> item_l_arr)
114 {
115     for  (int i =0; i < item_l_arr.size(); i++) 
116         item_l_arr[i]->translate(Offset(x, 0));
117 }
118 /*
119   UGR
120   This still sux
121   */
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)
126 {
127     PCol * c= command_column_l_->pcol_l_;
128     PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
129     
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);
137     }
138
139       
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);
142     }
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);
145     }
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);
148     }
149
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);
155
156     pre_p_arr.set_size(0);
157     post_p_arr.set_size(0);
158     nobreak_p_arr.set_size(0);
159 }