2 plet-spanner.cc -- implement Tuplet_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
14 #include "molecule.hh"
15 #include "paper-column.hh"
16 #include "paper-def.hh"
17 #include "tuplet-spanner.hh"
19 #include "note-column.hh"
20 #include "dimensions.hh"
21 #include "group-interface.hh"
22 #include "directional-element-interface.hh"
25 Tuplet_spanner::Tuplet_spanner ()
27 set_elt_property ("beams", SCM_EOL);
28 set_elt_property ("columns", SCM_EOL);
31 set_elt_property ("delta-y", gh_int2scm (0));
38 Tuplet_spanner::do_brew_molecule () const
42 // Default behaviour: number always, bracket when no beam!
43 bool par_beam = to_boolean (get_elt_property ("parallel-beam"));
44 bool bracket_visibility = !par_beam;
45 bool number_visibility = true;
47 SCM bracket = get_elt_property ("tuplet-bracket-visibility");
48 if (gh_boolean_p (bracket))
50 bracket_visibility = gh_scm2bool (bracket);
52 else if (bracket == ly_symbol2scm ("if-no-beam"))
53 bracket_visibility = !par_beam;
55 SCM numb = get_elt_property ("tuplet-number-visibility");
56 if (gh_boolean_p (numb))
58 number_visibility = gh_scm2bool (numb);
60 else if (bracket == ly_symbol2scm ("if-no-beam"))
61 number_visibility = !par_beam;
63 if (gh_pair_p (get_elt_property ("columns")))
65 Link_array<Note_column> column_arr=
66 Group_interface__extract_elements (this, (Note_column*)0, "columns");
68 Real ncw = column_arr.top ()->extent(X_AXIS).length ();
69 Real w = spanner_length () + ncw;
72 Real staff_space = paper_l ()->get_var ("interline");
73 Direction dir = directional_element (this).get ();
74 Real dy = gh_scm2double (get_elt_property ("delta-y"));
75 SCM number = get_elt_property ("text");
76 if (gh_string_p (number) && number_visibility)
79 num (lookup_l ()->text ("italic",
80 ly_scm2string (number), paper_l ()));
81 num.align_to (X_AXIS, CENTER);
82 num.translate_axis (w/2, X_AXIS);
83 num.align_to (Y_AXIS, CENTER);
84 num.translate_axis (dir * staff_space, Y_AXIS);
86 num.translate_axis (dy/2, Y_AXIS);
88 mol.add_molecule (num);
91 Real thick = paper_l ()->get_var ("tuplet_thick");
92 if (bracket_visibility)
94 Real gap = paper_l () -> get_var ("tuplet_spanner_gap");
95 Real height = staff_space;
96 SCM at =gh_list(ly_symbol2scm ("tuplet"),
97 gh_double2scm (height),
101 gh_double2scm (thick),
106 mol.add_molecule (Molecule (b, at));
109 //mol.translate_axis (dir * staff_space, Y_AXIS);
115 Tuplet_spanner::do_add_processing ()
117 if (gh_pair_p (get_elt_property ("columns")))
119 Link_array<Note_column> column_arr=
120 Group_interface__extract_elements (this, (Note_column*)0, "columns");
122 set_bound (LEFT, column_arr[0]);
123 set_bound (RIGHT, column_arr.top ());
130 use first -> last note for slope, and then correct for disturbing
133 Tuplet_spanner::calc_position_and_height (Real *offset, Real * dy) const
135 Link_array<Note_column> column_arr=
136 Group_interface__extract_elements (this, (Note_column*)0, "columns");
139 Score_element * common = common_refpoint (get_elt_property ("columns"), Y_AXIS);
141 Direction d = directional_element (this).get ();
144 Use outer non-rest columns to determine slope
147 while (l <column_arr.size() && column_arr[l]->rest_b())
150 int r = column_arr.size ()- 1;
151 while (r >= l && column_arr[r]->rest_b())
156 *dy = column_arr[r]->extent (Y_AXIS) [d] + column_arr[r]->relative_coordinate (common, Y_AXIS)
157 - column_arr[l]->extent (Y_AXIS) [d] - column_arr[l]->relative_coordinate (common, Y_AXIS);
163 *offset = - d * infinity_f;
165 Real x0 = column_arr[0]->relative_coordinate (0, X_AXIS);
166 Real x1 = column_arr.top ()->relative_coordinate (0, X_AXIS);
168 Real factor = column_arr.size () > 1 ? 1/(x1 - x0) : 1.0;
170 for (int i = 0; i < column_arr.size (); i++)
172 Real notey = column_arr[i]->extent (Y_AXIS)[d] +
173 column_arr[i]->relative_coordinate (common, Y_AXIS)
175 Real x = column_arr[i]->relative_coordinate (0, X_AXIS) - x0;
176 Real tuplety = *dy * x * factor;
178 if (notey * d > (*offset + tuplety) * d)
179 *offset = notey - tuplety;
184 use first -> last note for slope,
187 Tuplet_spanner::calc_dy (Real * dy) const
189 Link_array<Note_column> column_arr=
190 Group_interface__extract_elements (this, (Note_column*)0, "columns");
193 Direction d = directional_element (this).get ();
194 *dy = column_arr.top ()->extent (Y_AXIS) [d]
195 - column_arr[0]->extent (Y_AXIS) [d];
199 Tuplet_spanner::after_line_breaking ()
201 Link_array<Note_column> column_arr=
202 Group_interface__extract_elements (this, (Note_column*)0, "columns");
204 if (!column_arr.size ())
206 set_elt_property ("transparent", SCM_BOOL_T);
207 set_extent_callback (0, X_AXIS);
208 set_extent_callback (0, Y_AXIS);
211 Direction d = directional_element (this).get ();
214 d = get_default_dir ();
215 directional_element (this).set (d);
220 calc_position_and_height (&offset,&dy);
222 set_elt_property ("delta-y", gh_double2scm (dy));
224 translate_axis (offset, Y_AXIS);
226 if (scm_ilength (get_elt_property ("beams")) == 1)
228 SCM bs = get_elt_property ("beams");
229 Score_element *b = unsmob_element (gh_car (bs));
230 Beam * beam_l = dynamic_cast<Beam*> (b);
232 && get_bound (LEFT)->column_l () == beam_l->get_bound (LEFT)->column_l ()
233 && get_bound (RIGHT)->column_l () == beam_l->get_bound (RIGHT)->column_l ())
234 set_elt_property ("parallel-beam", SCM_BOOL_T);
240 Tuplet_spanner::get_default_dir () const
243 SCM dir_sym =get_elt_property ("dir-forced");
244 if (isdir_b (dir_sym))
252 for (SCM s = get_elt_property ("columns"); gh_pair_p (s); s = gh_cdr (s))
254 Score_element * sc = unsmob_element (gh_car (s));
255 Note_column * nc = dynamic_cast<Note_column*> (sc);
267 Tuplet_spanner::add_beam (Beam *b)
270 Group_interface gi (this, "beams");
275 Tuplet_spanner::add_column (Note_column*n)
277 Group_interface gi (this, "columns");