2 plet-spanner.cc -- implement Tuplet_bracket
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
14 #include "font-interface.hh"
15 #include "molecule.hh"
16 #include "paper-column.hh"
17 #include "paper-def.hh"
18 #include "text-item.hh"
19 #include "tuplet-spanner.hh"
21 #include "note-column.hh"
22 #include "dimensions.hh"
23 #include "group-interface.hh"
24 #include "directional-element-interface.hh"
26 #include "staff-symbol-referencer.hh"
30 staff-line collisions for horizontal tuplet brackets.
34 in the case that there is no bracket, but there is a (single) beam,
35 follow beam precisely for determining tuplet number location.
42 Tuplet_bracket::set_interface (Grob*me)
44 me->set_interface (ly_symbol2scm ("tuplet-bracket"));
47 MAKE_SCHEME_CALLBACK (Tuplet_bracket,brew_molecule,1);
49 Tuplet_bracket::brew_molecule (SCM smob)
51 Grob *me= unsmob_grob (smob);
53 Link_array<Grob> column_arr=
54 Pointer_group_interface__extract_grobs (me, (Grob*)0, "columns");
57 if (!column_arr.size ())
58 return mol.smobbed_copy ();
61 Grob *b1 = Note_column::stem_l (column_arr[0]);
62 Grob *b2 = Note_column::stem_l (column_arr.top());
64 b1 = b1 ? Stem::beam_l (b1) : 0;
65 b2 = b2 ? Stem::beam_l (b2) : 0;
68 Spanner*sp = dynamic_cast<Spanner*> (me);
70 // Default behaviour: number always, bracket when no beam!
71 bool par_beam = b1 && (b1 == b2) && !sp->broken_b() ;
73 bool bracket_visibility = !par_beam;
74 bool number_visibility = true;
76 SCM bracket = me->get_grob_property ("tuplet-bracket-visibility");
77 if (gh_boolean_p (bracket))
79 bracket_visibility = gh_scm2bool (bracket);
81 else if (bracket == ly_symbol2scm ("if-no-beam"))
82 bracket_visibility = !par_beam;
84 SCM numb = me->get_grob_property ("tuplet-number-visibility");
85 if (gh_boolean_p (numb))
87 number_visibility = gh_scm2bool (numb);
89 else if (numb == ly_symbol2scm ("if-no-beam"))
90 number_visibility = !par_beam;
93 Real ncw = column_arr.top ()->extent (column_arr.top (), X_AXIS).length ();
94 Real w = sp->spanner_length () + ncw;
96 Direction dir = Directional_element_interface::get (me);
97 Real dy = gh_scm2double (me->get_grob_property ("delta-y"));
98 SCM number = me->get_grob_property ("text");
99 if (gh_string_p (number) && number_visibility)
101 SCM properties = Font_interface::font_alist_chain (me);
102 Molecule num = Text_item::text2molecule (me, number, properties);
103 num.align_to (X_AXIS, CENTER);
104 num.translate_axis (w/2, X_AXIS);
105 num.align_to (Y_AXIS, CENTER);
107 num.translate_axis (dy/2, Y_AXIS);
109 mol.add_molecule (num);
112 if (bracket_visibility)
114 Real lt = me->paper_l ()->get_var ("stafflinethickness");
116 SCM thick = me->get_grob_property ("thick");
117 SCM gap = me->get_grob_property ("number-gap");
119 SCM at =scm_list_n (ly_symbol2scm ("tuplet"),
124 gh_double2scm (gh_scm2double (thick)* lt),
129 mol.add_molecule (Molecule (b, at));
132 return mol.smobbed_copy ();
139 use first -> last note for slope, and then correct for disturbing
142 Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
144 Link_array<Grob> column_arr=
145 Pointer_group_interface__extract_grobs (me, (Grob*)0, "columns");
148 Grob * commony = me->common_refpoint (me->get_grob_property ("columns"), Y_AXIS);
149 Grob * commonx = me->common_refpoint (me->get_grob_property ("columns"), X_AXIS);
151 Direction d = Directional_element_interface::get (me);
154 Use outer non-rest columns to determine slope
157 while (l <column_arr.size () && Note_column::rest_b (column_arr[l]))
160 int r = column_arr.size ()- 1;
161 while (r >= l && Note_column::rest_b (column_arr[r]))
166 *dy = column_arr[r]->extent (commony, Y_AXIS) [d]
167 - column_arr[l]->extent (commony, Y_AXIS) [d] ;
173 *offset = - d * infinity_f;
175 if (!column_arr.size ())
178 Real x0 = column_arr[0]->relative_coordinate (commonx, X_AXIS);
179 Real x1 = column_arr.top ()->relative_coordinate (commonx, X_AXIS);
181 Real factor = column_arr.size () > 1 ? 1/ (x1 - x0) : 1.0;
183 for (int i = 0; i < column_arr.size (); i++)
185 Real notey = column_arr[i]->extent (commony, Y_AXIS)[d]
186 - me->relative_coordinate (commony, Y_AXIS);
188 Real x = column_arr[i]->relative_coordinate (commonx, X_AXIS) - x0;
189 Real tuplety = *dy * x * factor;
191 if (notey * d > (*offset + tuplety) * d)
192 *offset = notey - tuplety;
200 horizontal brackets should not collide with staff lines.
206 // quantize, then do collision check.
207 Real ss= Staff_symbol_referencer::staff_space (me);
210 *offset = rint (*offset);
211 if (Staff_symbol_referencer::on_staffline (me, (int) rint (*offset)))
220 use first -> last note for slope,
223 Tuplet_bracket::calc_dy (Grob*me,Real * dy)
225 Link_array<Grob> column_arr=
226 Pointer_group_interface__extract_grobs (me, (Grob*)0, "columns");
231 Direction d = Directional_element_interface::get (me);
232 *dy = column_arr.top ()->extent (column_arr.top (), Y_AXIS) [d]
233 - column_arr[0]->extent (column_arr[0], Y_AXIS) [d];
235 MAKE_SCHEME_CALLBACK (Tuplet_bracket,after_line_breaking,1);
238 Tuplet_bracket::after_line_breaking (SCM smob)
240 Grob * me = unsmob_grob (smob);
241 Link_array<Note_column> column_arr=
242 Pointer_group_interface__extract_grobs (me, (Note_column*)0, "columns");
244 if (!column_arr.size ())
247 return SCM_UNSPECIFIED;
250 Direction d = Directional_element_interface::get (me);
253 d = Tuplet_bracket::get_default_dir (me);
254 Directional_element_interface::set (me, d);
259 calc_position_and_height (me,&offset,&dy);
261 if (!gh_number_p (me->get_grob_property ("delta-y")))
262 me->set_grob_property ("delta-y", gh_double2scm (dy));
264 me->translate_axis (offset, Y_AXIS);
265 return SCM_UNSPECIFIED;
270 Tuplet_bracket::get_default_dir (Grob*me)
273 SCM dir_sym =me->get_grob_property ("dir-forced");
274 if (ly_dir_p (dir_sym))
282 for (SCM s = me->get_grob_property ("columns"); gh_pair_p (s); s = ly_cdr (s))
284 Grob * nc = unsmob_grob (ly_car (s));
285 if (Note_column::dir (nc) < 0)
296 Tuplet_bracket::add_column (Grob*me, Item*n)
298 Pointer_group_interface::add_grob (me, ly_symbol2scm ("columns"), n);
299 me->add_dependency (n);
301 add_bound_item (dynamic_cast<Spanner*> (me), n);