]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-spanner.cc
release: 1.1.62
[lilypond.git] / lily / axis-group-spanner.cc
1 /*
2   axis-group-spanner.cc -- implement Axis_group_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "axis-group-spanner.hh"
10 #include "debug.hh"
11 #include "item.hh"
12 #include "paper-column.hh"
13
14 /** Do stuff if we're not broken. In this case the last and first
15   columns usually are pre- and postbreak respectively,
16   so the items from these columns need adjusting.
17   */
18 void
19 Axis_group_spanner::do_break_processing_if_unbroken()
20 {
21   Link_array<Score_element> elems = elem_l_arr ();
22   Line_of_score *my_line = line_l();
23   for (int i=0; i < elems.size(); i++) 
24     {
25       if (!elems[i]->line_l()) 
26         {
27           Item * item_l = dynamic_cast<Item*> (elems[i]);
28           if  (item_l
29                && item_l->breakable_b ()
30                && item_l->break_status_dir() == 0) 
31             {
32               // last two checks are paranoia
33               Item * broken_item_l = 
34                 item_l->find_prebroken_piece (my_line);
35               add_element (broken_item_l);
36             }
37
38           Spanner *spanner_l = dynamic_cast<Spanner*> (elems[i]);
39           if (spanner_l)
40             {
41               Spanner *broken_spanner_l =
42                 spanner_l->find_broken_piece (my_line);
43               add_element (broken_spanner_l);
44             }
45           remove_element (elems[i]);
46         }
47       
48     }
49 }
50
51 void
52 Axis_group_spanner::do_break_processing()
53 {
54
55   bool breaking_self_b = ! Spanner::line_l();
56   if (!breaking_self_b)  
57     {
58       do_break_processing_if_unbroken();
59       Spanner::do_break_processing();
60       return;
61     }
62
63   break_into_pieces ();
64   Link_array<Score_element> loose_elems = elem_l_arr ();
65   remove_all();
66   
67   for (int i=0; i < loose_elems.size(); i++) 
68     {
69       Score_element * elt = loose_elems[i];
70       Line_of_score *elt_line = elt->line_l();
71         
72       if (! elt_line)
73         {
74           /* this piece doesn't know where it belongs.
75              Find out if it was broken, and use the broken remains
76              */
77
78           Item *it = dynamic_cast <Item *> (elt) ;        
79           if (Spanner * sp =dynamic_cast <Spanner *> (elt))
80             {
81               for (int j =0; j < sp->broken_into_l_arr_.size(); j++) 
82                 {
83                   Line_of_score *l = sp->broken_into_l_arr_[j]->line_l ();
84
85                   Axis_group_spanner * my_broken_l
86                     = dynamic_cast<Axis_group_spanner*>(find_broken_piece (l));
87                   
88                   Spanner * broken_span_l 
89                     = sp->find_broken_piece (l);
90                     
91                   if (broken_span_l) 
92                     my_broken_l->add_element (broken_span_l);
93                 }
94             }
95           else if (it && it->broken_original_b ())
96             {
97               // broken items
98               Direction  j=LEFT;
99               do 
100                 {
101                   Item * broken_item = it->find_prebroken_piece (j);
102                   Line_of_score * item_line_l = broken_item->line_l() ;
103                   if (! item_line_l) 
104                     continue;
105                     
106                   Axis_group_spanner * v
107                     = dynamic_cast<Axis_group_spanner*>(find_broken_piece (item_line_l));
108                   if (v)
109                     v->add_element (broken_item);
110                   else
111                     {
112                       broken_item->set_elt_property (transparent_scm_sym, SCM_BOOL_T);
113                       broken_item->set_empty (true);
114                     }
115
116                 }
117               while (flip(&j) != LEFT);
118             }
119         }
120       else 
121         {
122           /* this piece *does* know where it belongs.
123              Put it in appropriate piece of this spanner
124              */
125           Axis_group_spanner * my_broken_l
126             = dynamic_cast<Axis_group_spanner*> (find_broken_piece (elt->line_l()));
127           my_broken_l->add_element (elt);
128         }
129     }
130   
131   Spanner::do_break_processing();
132 }
133
134 void
135 Axis_group_spanner::do_print() const
136 {
137   Axis_group_element::do_print();
138
139   Spanner::do_print ();
140 }
141
142
143 Interval
144 Axis_group_spanner::do_width () const
145 {
146   return Spanner::do_width ();
147 }