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 (SCM s)
28 set_elt_pointer ("beams", SCM_EOL);
29 set_elt_pointer ("columns", SCM_EOL);
32 set_elt_property ("delta-y", gh_int2scm (0));
38 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Tuplet_spanner)
40 Tuplet_spanner::do_brew_molecule () const
44 // Default behaviour: number always, bracket when no beam!
45 bool par_beam = to_boolean (get_elt_property ("parallel-beam"));
46 bool bracket_visibility = !par_beam;
47 bool number_visibility = true;
49 SCM bracket = get_elt_property ("tuplet-bracket-visibility");
50 if (gh_boolean_p (bracket))
52 bracket_visibility = gh_scm2bool (bracket);
54 else if (bracket == ly_symbol2scm ("if-no-beam"))
55 bracket_visibility = !par_beam;
57 SCM numb = get_elt_property ("tuplet-number-visibility");
58 if (gh_boolean_p (numb))
60 number_visibility = gh_scm2bool (numb);
62 else if (bracket == ly_symbol2scm ("if-no-beam"))
63 number_visibility = !par_beam;
65 if (gh_pair_p (get_elt_pointer ("columns")))
67 Link_array<Note_column> column_arr=
68 Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
70 Real ncw = column_arr.top ()->extent(X_AXIS).length ();
71 Real w = spanner_length () + ncw;
74 Real staff_space = paper_l ()->get_var ("interline");
75 Direction dir = directional_element (this).get ();
76 Real dy = gh_scm2double (get_elt_property ("delta-y"));
77 SCM number = get_elt_property ("text");
78 if (gh_string_p (number) && number_visibility)
81 num (lookup_l ()->text ("italic",
82 ly_scm2string (number), paper_l ()));
83 num.align_to (X_AXIS, CENTER);
84 num.translate_axis (w/2, X_AXIS);
85 num.align_to (Y_AXIS, CENTER);
86 num.translate_axis (dir * staff_space, Y_AXIS);
88 num.translate_axis (dy/2, Y_AXIS);
90 mol.add_molecule (num);
93 if (bracket_visibility)
95 SCM ss = paper_l ()->get_scmvar ("staffspace");
96 SCM lt = paper_l ()->get_scmvar ("stafflinethickness");
98 SCM thick = get_elt_property ("thick");
99 SCM gap = get_elt_property ("number-gap");
101 SCM at =gh_list(ly_symbol2scm ("tuplet"),
103 scm_product (gap, ss),
106 scm_product (thick, lt),
111 mol.add_molecule (Molecule (b, at));
118 Tuplet_spanner::do_add_processing ()
120 if (gh_pair_p (get_elt_pointer ("columns")))
122 Link_array<Note_column> column_arr=
123 Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
125 set_bound (LEFT, column_arr[0]);
126 set_bound (RIGHT, column_arr.top ());
133 use first -> last note for slope, and then correct for disturbing
136 Tuplet_spanner::calc_position_and_height (Real *offset, Real * dy) const
138 Link_array<Note_column> column_arr=
139 Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
142 Score_element * common = common_refpoint (get_elt_pointer ("columns"), Y_AXIS);
144 Direction d = directional_element (this).get ();
147 Use outer non-rest columns to determine slope
150 while (l <column_arr.size() && column_arr[l]->rest_b())
153 int r = column_arr.size ()- 1;
154 while (r >= l && column_arr[r]->rest_b())
159 *dy = column_arr[r]->extent (Y_AXIS) [d] + column_arr[r]->relative_coordinate (common, Y_AXIS)
160 - column_arr[l]->extent (Y_AXIS) [d] - column_arr[l]->relative_coordinate (common, Y_AXIS);
166 *offset = - d * infinity_f;
168 if (!column_arr.size ())
171 Real x0 = column_arr[0]->relative_coordinate (0, X_AXIS);
172 Real x1 = column_arr.top ()->relative_coordinate (0, X_AXIS);
174 Real factor = column_arr.size () > 1 ? 1/(x1 - x0) : 1.0;
176 for (int i = 0; i < column_arr.size (); i++)
178 Real notey = column_arr[i]->extent (Y_AXIS)[d] +
179 column_arr[i]->relative_coordinate (common, Y_AXIS)
181 Real x = column_arr[i]->relative_coordinate (0, X_AXIS) - x0;
182 Real tuplety = *dy * x * factor;
184 if (notey * d > (*offset + tuplety) * d)
185 *offset = notey - tuplety;
190 use first -> last note for slope,
193 Tuplet_spanner::calc_dy (Real * dy) const
195 Link_array<Note_column> column_arr=
196 Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
199 Direction d = directional_element (this).get ();
200 *dy = column_arr.top ()->extent (Y_AXIS) [d]
201 - column_arr[0]->extent (Y_AXIS) [d];
205 Tuplet_spanner::after_line_breaking ()
207 Link_array<Note_column> column_arr=
208 Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
210 if (!column_arr.size ())
215 Direction d = directional_element (this).get ();
218 d = get_default_dir ();
219 directional_element (this).set (d);
224 calc_position_and_height (&offset,&dy);
226 set_elt_property ("delta-y", gh_double2scm (dy));
228 translate_axis (offset, Y_AXIS);
230 if (scm_ilength (get_elt_pointer ("beams")) == 1)
232 SCM bs = get_elt_pointer ("beams");
233 Score_element *b = unsmob_element (gh_car (bs));
234 Beam * beam_l = dynamic_cast<Beam*> (b);
236 && get_bound (LEFT)->column_l () == beam_l->get_bound (LEFT)->column_l ()
237 && get_bound (RIGHT)->column_l () == beam_l->get_bound (RIGHT)->column_l ())
238 set_elt_property ("parallel-beam", SCM_BOOL_T);
244 Tuplet_spanner::get_default_dir () const
247 SCM dir_sym =get_elt_property ("dir-forced");
248 if (isdir_b (dir_sym))
256 for (SCM s = get_elt_pointer ("columns"); gh_pair_p (s); s = gh_cdr (s))
258 Score_element * sc = unsmob_element (gh_car (s));
259 Note_column * nc = dynamic_cast<Note_column*> (sc);
271 Tuplet_spanner::add_beam (Beam *b)
274 Pointer_group_interface gi (this, "beams");
279 Tuplet_spanner::add_column (Note_column*n)
281 Pointer_group_interface gi (this, "columns");