]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-loose-columns.cc
(set_loose_columns): oops: use
[lilypond.git] / lily / spacing-loose-columns.cc
1 /*
2   spacing-loose-columns.cc -- implement loose column spacing.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "system.hh"
10 #include "paper-column.hh"
11 #include "column-x-positions.hh"
12 #include "pointer-group-interface.hh"
13 #include "staff-spacing.hh"
14 #include "note-spacing.hh"
15 #include "spacing-spanner.hh"
16
17 #include "moment.hh"
18
19 /* Find the loose columns in POSNS, and drape them around the columns
20    specified in BETWEEN-COLS.  */
21 void
22 set_loose_columns (System *which, Column_x_positions const *posns)
23 {
24   int loose_col_count = posns->loose_cols_.size ();
25   if (!loose_col_count)
26     return;
27
28   for (int i = 0; i < loose_col_count; i++)
29     {
30       int divide_over = 1;
31       Item *loose = dynamic_cast<Item *> (posns->loose_cols_[i]);
32       Paper_column *col = dynamic_cast<Paper_column *> (loose);
33
34       if (col->get_system ())
35         continue;
36
37       Item *left = 0;
38       Item *right = 0;
39
40       vector<Item*> clique;
41       while (1)
42         {
43           SCM between = loose->get_object ("between-cols");
44           if (!scm_is_pair (between))
45             break;
46
47           Item *le = dynamic_cast<Item *> (unsmob_grob (scm_car (between)));
48           Item *re = dynamic_cast<Item *> (unsmob_grob (scm_cdr (between)));
49
50           if (! (le && re))
51             break;
52
53           if (!left && le)
54             {
55               left = le->get_column ();
56               if (!left->get_system ())
57                 left = left->find_prebroken_piece (RIGHT);
58
59               clique.push_back (left);
60             }
61
62           clique.push_back (loose);
63
64           divide_over++;
65           loose = right = re->get_column ();
66         }
67
68       if (!right->get_system ())
69         right = right->find_prebroken_piece (LEFT);
70
71       Grob *common = right->common_refpoint (left, X_AXIS);
72
73       clique.push_back (right);
74
75       vector<Real> clique_spacing;
76       clique_spacing.push_back (0.0);
77       for (vsize j = 1; j < clique.size () - 1; j ++)
78         {
79           Grob *clique_col = clique[j];
80
81           Paper_column *loose_col = dynamic_cast<Paper_column *> (clique[j]);
82           Paper_column *next_col = dynamic_cast<Paper_column *> (clique[j + 1]);
83
84           Grob *spacing = unsmob_grob (clique_col->get_object ("spacing"));
85           if (Grob *grace_spacing = unsmob_grob (clique_col->get_object ("grace-spacing")))
86             {
87               spacing = grace_spacing;
88             }
89           
90           Spacing_options options;
91           options.init_from_grob (spacing);
92
93           bool expand_only = false;
94           Real base_note_space = 0.0;
95
96           if (Paper_column::is_musical (next_col)
97               && Paper_column::is_musical (loose_col))
98             base_note_space = Spacing_spanner::note_spacing (spacing, loose_col, next_col, 
99                                                              &options, &expand_only);
100           else
101             {
102               Real fixed, space;
103               
104               Spacing_spanner::standard_breakable_column_spacing (spacing, 
105                                                                   loose_col, next_col,
106                                                                   &fixed, &space,
107                                                                   &options);
108
109               base_note_space = space;
110             }
111
112           base_note_space = max (base_note_space,
113                                  robust_relative_extent (loose_col, loose_col, X_AXIS)[RIGHT]
114                                  - robust_relative_extent (next_col, next_col, X_AXIS)[LEFT]);
115           
116           clique_spacing.push_back (base_note_space);
117         }
118
119       Real default_padding = 1.0;
120       clique_spacing.push_back (default_padding);
121
122       Real right_point = robust_relative_extent (clique.back (), common, X_AXIS)[LEFT];
123       
124           
125       Grob *finished_right_column = clique.back ();
126       
127       for (vsize j = clique.size () - 2; j > 0; j--)
128         {
129           Paper_column *clique_col = dynamic_cast<Paper_column *> (clique[j]);
130           
131           right_point = finished_right_column->relative_coordinate (common, X_AXIS);
132
133           Real distance_to_next = clique_spacing[j];
134           
135           Real my_offset = right_point - distance_to_next;
136
137           clique_col->set_system (which);
138           clique_col->translate_axis (my_offset - clique_col->relative_coordinate (common, X_AXIS), X_AXIS);      
139
140           finished_right_column = clique_col;
141         }
142  
143     }
144 }
145