OLD | NEW |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1998--2011 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1998--2011 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 bool include_my_extent, | 55 bool include_my_extent, |
56 bool pure, int start, int end, | 56 bool pure, int start, int end, |
57 Real *current_offset) | 57 Real *current_offset) |
58 { | 58 { |
59 Real ss = Staff_symbol_referencer::staff_space (me); | 59 Real ss = Staff_symbol_referencer::staff_space (me); |
60 | 60 |
61 extract_grob_set (me, "side-support-elements", support); | 61 extract_grob_set (me, "side-support-elements", support); |
62 | 62 |
63 Grob *common = common_refpoint_of_array (support, me->get_parent (a), a); | 63 Grob *common = common_refpoint_of_array (support, me->get_parent (a), a); |
64 Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (me); | 64 Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (me); |
65 bool include_staff = | 65 bool include_staff = |
66 staff_symbol | 66 staff_symbol |
67 && a == Y_AXIS | 67 && a == Y_AXIS |
68 && scm_is_number (me->get_property ("staff-padding")) | 68 && scm_is_number (me->get_property ("staff-padding")) |
69 && !to_boolean (me->get_property ("quantize-position")); | 69 && !to_boolean (me->get_property ("quantize-position")); |
70 | 70 |
71 Interval dim; | 71 Interval dim; |
72 Interval staff_extents; | 72 Interval staff_extents; |
73 if (include_staff) | 73 if (include_staff) |
74 { | 74 { |
75 common = staff_symbol->common_refpoint (common, Y_AXIS); | 75 common = staff_symbol->common_refpoint (common, Y_AXIS); |
76 staff_extents = staff_symbol->maybe_pure_extent (common, Y_AXIS, pure, sta
rt, end); | 76 staff_extents = staff_symbol->maybe_pure_extent (common, Y_AXIS, pure, sta
rt, end); |
77 | 77 |
78 if (include_staff) | 78 if (include_staff) |
79 dim.unite (staff_extents); | 79 dim.unite (staff_extents); |
80 } | 80 } |
81 | 81 |
82 Direction dir = get_grob_direction (me); | 82 Direction dir = get_grob_direction (me); |
83 | 83 |
84 for (vsize i = 0; i < support.size (); i++) | 84 for (vsize i = 0; i < support.size (); i++) |
85 { | 85 { |
86 Grob *e = support[i]; | 86 Grob *e = support[i]; |
87 | 87 |
88 // In the case of a stem, we will find a note head as well | 88 // In the case of a stem, we will find a note head as well |
89 // ignoring the stem solves cyclic dependencies if the stem is | 89 // ignoring the stem solves cyclic dependencies if the stem is |
90 // attached to a cross-staff beam. | 90 // attached to a cross-staff beam. |
91 if (a == Y_AXIS | 91 if (a == Y_AXIS |
92 && Stem::has_interface (e) | 92 && Stem::has_interface (e) |
93 && dir == - get_grob_direction (e)) | 93 && dir == - get_grob_direction (e)) |
94 continue; | 94 continue; |
95 | 95 |
96 if (e) | 96 if (e) |
97 { | 97 { |
98 if (use_extents) | 98 if (use_extents) |
99 dim.unite (e->maybe_pure_extent (common, a, pure, start, end)); | 99 dim.unite (e->maybe_pure_extent (common, a, pure, start, end)); |
100 else | 100 else |
101 { | 101 { |
102 Real x = e->maybe_pure_coordinate (common, a, pure, start, end); | 102 Real x = e->maybe_pure_coordinate (common, a, pure, start, end); |
103 dim.unite (Interval (x, x)); | 103 dim.unite (Interval (x, x)); |
104 } | 104 } |
105 } | 105 } |
(...skipping 23 matching lines...) Expand all Loading... |
129 programming_error ("direction unknown, but aligned-side wanted"); | 129 programming_error ("direction unknown, but aligned-side wanted"); |
130 dir = DOWN; | 130 dir = DOWN; |
131 } | 131 } |
132 total_off += -iv[-dir]; | 132 total_off += -iv[-dir]; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 if (current_offset) | 136 if (current_offset) |
137 total_off = dir * max (dir * total_off, | 137 total_off = dir * max (dir * total_off, |
138 dir * (*current_offset)); | 138 dir * (*current_offset)); |
139 | 139 |
140 | 140 |
141 /* FIXME: 1000 should relate to paper size. */ | 141 /* FIXME: 1000 should relate to paper size. */ |
142 if (fabs (total_off) > 1000) | 142 if (fabs (total_off) > 1000) |
143 { | 143 { |
144 string msg | 144 string msg |
145 = String_convert::form_string ("Improbable offset for grob %s: %f", | 145 = String_convert::form_string ("Improbable offset for grob %s: %f", |
146 me->name ().c_str (), total_off); | 146 me->name ().c_str (), total_off); |
147 | 147 |
148 programming_error (msg); | 148 programming_error (msg); |
149 if (strict_infinity_checking) | 149 if (strict_infinity_checking) |
150 scm_misc_error (__FUNCTION__, "Improbable offset.", SCM_EOL); | 150 scm_misc_error (__FUNCTION__, "Improbable offset.", SCM_EOL); |
151 } | 151 } |
| 152 |
152 return scm_from_double (total_off); | 153 return scm_from_double (total_off); |
153 } | 154 } |
154 | 155 |
155 | 156 |
156 MAKE_SCHEME_CALLBACK (Side_position_interface, y_aligned_on_support_refpoints, 1
); | 157 MAKE_SCHEME_CALLBACK (Side_position_interface, y_aligned_on_support_refpoints, 1
); |
157 SCM | 158 SCM |
158 Side_position_interface::y_aligned_on_support_refpoints (SCM smob) | 159 Side_position_interface::y_aligned_on_support_refpoints (SCM smob) |
159 { | 160 { |
160 return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, false,
0, 0, 0); | 161 return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, false,
0, 0, 0); |
161 } | 162 } |
162 | 163 |
163 MAKE_SCHEME_CALLBACK (Side_position_interface, pure_y_aligned_on_support_refpoin
ts, 3); | 164 MAKE_SCHEME_CALLBACK (Side_position_interface, pure_y_aligned_on_support_refpoin
ts, 3); |
164 SCM | 165 SCM |
165 Side_position_interface::pure_y_aligned_on_support_refpoints (SCM smob, SCM star
t, SCM end) | 166 Side_position_interface::pure_y_aligned_on_support_refpoints (SCM smob, SCM star
t, SCM end) |
166 { | 167 { |
167 return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, | 168 return general_side_position (unsmob_grob (smob), Y_AXIS, false, false, |
168 » » » » true, scm_to_int (start), scm_to_int (end), 0); | 169 » » » » true, scm_to_int (start), scm_to_int (end), 0); |
169 } | 170 } |
170 | 171 |
171 | 172 |
172 /* | 173 /* |
173 Position next to support, taking into account my own dimensions and padding. | 174 Position next to support, taking into account my own dimensions and padding. |
174 */ | 175 */ |
175 SCM | 176 SCM |
176 axis_aligned_side_helper (SCM smob, Axis a, bool pure, int start, int end, SCM c
urrent_off_scm) | 177 axis_aligned_side_helper (SCM smob, Axis a, bool pure, int start, int end, SCM c
urrent_off_scm) |
177 { | 178 { |
178 Real r; | 179 Real r; |
179 Real *current_off_ptr = 0; | 180 Real *current_off_ptr = 0; |
180 if (scm_is_number (current_off_scm)) | 181 if (scm_is_number (current_off_scm)) |
181 { | 182 { |
182 r = scm_to_double (current_off_scm); | 183 r = scm_to_double (current_off_scm); |
183 current_off_ptr = &r; | 184 current_off_ptr = &r; |
184 } | 185 } |
185 | 186 |
186 return Side_position_interface::aligned_side (unsmob_grob (smob), a, pure, sta
rt, end, current_off_ptr); | 187 return Side_position_interface::aligned_side (unsmob_grob (smob), a, pure, sta
rt, end, current_off_ptr); |
187 } | 188 } |
188 | 189 |
189 | 190 |
190 MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Side_position_interface, x_aligned_side, 2, 1
, ""); | 191 MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Side_position_interface, x_aligned_side, 2, 1
, ""); |
191 SCM | 192 SCM |
192 Side_position_interface::x_aligned_side (SCM smob, SCM current_off) | 193 Side_position_interface::x_aligned_side (SCM smob, SCM current_off) |
193 { | 194 { |
194 return axis_aligned_side_helper (smob, X_AXIS, false, 0, 0, current_off); | 195 return axis_aligned_side_helper (smob, X_AXIS, false, 0, 0, current_off); |
195 } | 196 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 Real my_off = me->get_parent (Y_AXIS)->maybe_pure_coordinate (common,
Y_AXIS, pure, start, end); | 249 Real my_off = me->get_parent (Y_AXIS)->maybe_pure_coordinate (common,
Y_AXIS, pure, start, end); |
249 Real staff_off = staff->maybe_pure_coordinate (common, Y_AXIS, pure, s
tart, end); | 250 Real staff_off = staff->maybe_pure_coordinate (common, Y_AXIS, pure, s
tart, end); |
250 Real ss = Staff_symbol::staff_space (staff); | 251 Real ss = Staff_symbol::staff_space (staff); |
251 Real position = 2 * (my_off + o - staff_off) / ss; | 252 Real position = 2 * (my_off + o - staff_off) / ss; |
252 Real rounded = directed_round (position, dir); | 253 Real rounded = directed_round (position, dir); |
253 Grob *head = me->get_parent (X_AXIS); | 254 Grob *head = me->get_parent (X_AXIS); |
254 | 255 |
255 if (fabs (position) <= 2 * Staff_symbol_referencer::staff_radius (me)
+ 1 | 256 if (fabs (position) <= 2 * Staff_symbol_referencer::staff_radius (me)
+ 1 |
256 /* In case of a ledger lines, quantize even if we're outside the s
taff. */ | 257 /* In case of a ledger lines, quantize even if we're outside the s
taff. */ |
257 || (Note_head::has_interface (head) | 258 || (Note_head::has_interface (head) |
258 » » | 259 |
259 && abs (Staff_symbol_referencer::get_position (head)) > abs (p
osition))) | 260 && abs (Staff_symbol_referencer::get_position (head)) > abs (p
osition))) |
260 { | 261 { |
261 o += (rounded - position) * 0.5 * ss; | 262 o += (rounded - position) * 0.5 * ss; |
262 if (Staff_symbol_referencer::on_line (me, int (rounded))) | 263 if (Staff_symbol_referencer::on_line (me, int (rounded))) |
263 o += dir * 0.5 * ss; | 264 o += dir * 0.5 * ss; |
264 } | 265 } |
265 } | 266 } |
266 else if (scm_is_number (me->get_property ("staff-padding")) && dir) | 267 else if (scm_is_number (me->get_property ("staff-padding")) && dir) |
267 { | 268 { |
268 Interval iv = me->maybe_pure_extent (me, a, pure, start, end); | 269 Interval iv = me->maybe_pure_extent (me, a, pure, start, end); |
269 » | 270 |
270 » Real padding | 271 » Real staff_padding |
271 = Staff_symbol_referencer::staff_space (me) | 272 = Staff_symbol_referencer::staff_space (me) |
272 * scm_to_double (me->get_property ("staff-padding")); | 273 * scm_to_double (me->get_property ("staff-padding")); |
273 | 274 |
274 » Grob *common = me->common_refpoint (staff, Y_AXIS); | 275 Grob *parent = me->get_parent (Y_AXIS); |
275 | 276 Grob *common = me->common_refpoint (staff, Y_AXIS); |
276 » Interval staff_size = staff->maybe_pure_extent (common, Y_AXIS, pure,
start, end); | 277 Real parent_position = parent->maybe_pure_coordinate (common, Y_AXIS,
pure, start, end); |
277 » Real diff = dir*staff_size[dir] + padding - dir * (o + iv[-dir]); | 278 Real staff_position = staff->maybe_pure_coordinate (common, Y_AXIS, pu
re, start, end); |
278 » o += dir * max (diff, 0.0); | 279 Interval staff_extent = staff->maybe_pure_extent (staff, a, pure, star
t, end); |
| 280 Real diff = (dir * staff_extent[dir] + staff_padding |
| 281 - dir * (o + iv[-dir]) |
| 282 + dir * (staff_position - parent_position)); |
| 283 o += dir * max (diff, 0.0); |
279 } | 284 } |
280 } | 285 } |
281 return scm_from_double (o); | 286 return scm_from_double (o); |
282 } | 287 } |
283 | 288 |
284 void | 289 void |
285 Side_position_interface::set_axis (Grob *me, Axis a) | 290 Side_position_interface::set_axis (Grob *me, Axis a) |
286 { | 291 { |
287 if (!scm_is_number (me->get_property ("side-axis"))) | 292 if (!scm_is_number (me->get_property ("side-axis"))) |
288 { | 293 { |
289 me->set_property ("side-axis", scm_from_int (a)); | 294 me->set_property ("side-axis", scm_from_int (a)); |
290 chain_offset_callback (me, | 295 chain_offset_callback (me, |
291 (a==X_AXIS) | 296 (a==X_AXIS) |
292 ? x_aligned_side_proc | 297 ? x_aligned_side_proc |
293 : y_aligned_side_proc, | 298 : y_aligned_side_proc, |
294 a); | 299 a); |
295 } | 300 } |
296 } | 301 } |
297 | 302 |
298 Axis | 303 Axis |
299 Side_position_interface::get_axis (Grob *me) | 304 Side_position_interface::get_axis (Grob *me) |
300 { | 305 { |
301 if (scm_is_number (me->get_property ("side-axis"))) | 306 if (scm_is_number (me->get_property ("side-axis"))) |
302 return Axis (scm_to_int (me->get_property ("side-axis"))); | 307 return Axis (scm_to_int (me->get_property ("side-axis"))); |
303 | 308 |
304 string msg = String_convert::form_string ("side-axis not set for grob %s.", | 309 string msg = String_convert::form_string ("side-axis not set for grob %s.", |
305 me->name ().c_str ()); | 310 me->name ().c_str ()); |
306 me->programming_error (msg); | 311 me->programming_error (msg); |
307 return NO_AXES; | 312 return NO_AXES; |
308 } | 313 } |
309 | 314 |
310 MAKE_SCHEME_CALLBACK (Side_position_interface, move_to_extremal_staff, 1); | 315 MAKE_SCHEME_CALLBACK (Side_position_interface, move_to_extremal_staff, 1); |
311 SCM | 316 SCM |
312 Side_position_interface::move_to_extremal_staff (SCM smob) | 317 Side_position_interface::move_to_extremal_staff (SCM smob) |
313 { | 318 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 /* properties */ | 370 /* properties */ |
366 "direction " | 371 "direction " |
367 "minimum-space " | 372 "minimum-space " |
368 "padding " | 373 "padding " |
369 "quantize-position " | 374 "quantize-position " |
370 "side-axis " | 375 "side-axis " |
371 "side-support-elements " | 376 "side-support-elements " |
372 "slur-padding " | 377 "slur-padding " |
373 "staff-padding " | 378 "staff-padding " |
374 ); | 379 ); |
OLD | NEW |