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"
26 Tuplet_spanner::set_interface (Score_element*me)
28 me->set_interface (ly_symbol2scm ("tuplet-bracket"));
35 MAKE_SCHEME_CALLBACK(Tuplet_spanner,brew_molecule);
38 Tuplet_spanner::brew_molecule (SCM smob)
40 Score_element *me= unsmob_element (smob);
43 // Default behaviour: number always, bracket when no beam!
44 bool par_beam = to_boolean (me->get_elt_property ("parallel-beam"));
45 bool bracket_visibility = !par_beam;
46 bool number_visibility = true;
48 SCM bracket = me->get_elt_property ("tuplet-bracket-visibility");
49 if (gh_boolean_p (bracket))
51 bracket_visibility = gh_scm2bool (bracket);
53 else if (bracket == ly_symbol2scm ("if-no-beam"))
54 bracket_visibility = !par_beam;
56 SCM numb = me->get_elt_property ("tuplet-number-visibility");
57 if (gh_boolean_p (numb))
59 number_visibility = gh_scm2bool (numb);
61 else if (bracket == ly_symbol2scm ("if-no-beam"))
62 number_visibility = !par_beam;
64 if (gh_pair_p (me->get_elt_property ("columns")))
66 Link_array<Score_element> column_arr=
67 Pointer_group_interface__extract_elements (me, (Score_element*)0, "columns");
69 Real ncw = column_arr.top ()->extent(X_AXIS).length ();
70 Real w = dynamic_cast<Spanner*>(me)->spanner_length () + ncw;
72 Real staff_space = me->paper_l ()->get_var ("interline");
73 Direction dir = Directional_element_interface::get (me);
74 Real dy = gh_scm2double (me->get_elt_property ("delta-y"));
75 SCM number = me->get_elt_property ("text");
76 if (gh_string_p (number) && number_visibility)
79 num (me->lookup_l ()->text ("italic",
80 ly_scm2string (number), me->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 if (bracket_visibility)
93 SCM ss = me->paper_l ()->get_scmvar ("staffspace");
94 SCM lt = me->paper_l ()->get_scmvar ("stafflinethickness");
96 SCM thick = me->get_elt_property ("thick");
97 SCM gap = me->get_elt_property ("number-gap");
99 SCM at =gh_list(ly_symbol2scm ("tuplet"),
101 scm_product (gap, ss),
104 scm_product (thick, lt),
109 mol.add_molecule (Molecule (b, at));
112 return mol.create_scheme();
119 use first -> last note for slope, and then correct for disturbing
122 Tuplet_spanner::calc_position_and_height (Score_element*me,Real *offset, Real * dy)
124 Link_array<Score_element> column_arr=
125 Pointer_group_interface__extract_elements (me, (Score_element*)0, "columns");
128 Score_element * commony = me->common_refpoint (me->get_elt_property ("columns"), Y_AXIS);
129 Score_element * commonx = me->common_refpoint (me->get_elt_property ("columns"), X_AXIS);
131 Direction d = Directional_element_interface::get (me);
134 Use outer non-rest columns to determine slope
137 while (l <column_arr.size() && Note_column::rest_b(column_arr[l]))
140 int r = column_arr.size ()- 1;
141 while (r >= l && Note_column::rest_b(column_arr[r]))
146 *dy = column_arr[r]->extent (Y_AXIS) [d] + column_arr[r]->relative_coordinate (commony, Y_AXIS)
147 - column_arr[l]->extent (Y_AXIS) [d] - column_arr[l]->relative_coordinate (commony, Y_AXIS);
153 *offset = - d * infinity_f;
155 if (!column_arr.size ())
158 Real x0 = column_arr[0]->relative_coordinate (commonx, X_AXIS);
159 Real x1 = column_arr.top ()->relative_coordinate (commonx, X_AXIS);
161 Real factor = column_arr.size () > 1 ? 1/(x1 - x0) : 1.0;
163 for (int i = 0; i < column_arr.size (); i++)
165 Real notey = column_arr[i]->extent (Y_AXIS)[d]
166 + column_arr[i]->relative_coordinate (commony, Y_AXIS)
167 - me->relative_coordinate (commony, Y_AXIS);
169 Real x = column_arr[i]->relative_coordinate (commonx, X_AXIS) - x0;
170 Real tuplety = *dy * x * factor;
172 if (notey * d > (*offset + tuplety) * d)
173 *offset = notey - tuplety;
178 use first -> last note for slope,
181 Tuplet_spanner::calc_dy (Score_element*me,Real * dy)
183 Link_array<Score_element> column_arr=
184 Pointer_group_interface__extract_elements (me, (Score_element*)0, "columns");
186 Direction d = Directional_element_interface::get (me);
187 *dy = column_arr.top ()->extent (Y_AXIS) [d]
188 - column_arr[0]->extent (Y_AXIS) [d];
190 MAKE_SCHEME_CALLBACK(Tuplet_spanner,after_line_breaking);
193 Tuplet_spanner::after_line_breaking (SCM smob)
195 Score_element * me = unsmob_element (smob);
196 Link_array<Note_column> column_arr=
197 Pointer_group_interface__extract_elements (me, (Note_column*)0, "columns");
198 Spanner *sp = dynamic_cast<Spanner*> (me);
201 if (!column_arr.size ())
204 return SCM_UNSPECIFIED;
207 Direction d = Directional_element_interface::get (me);
210 d = Tuplet_spanner::get_default_dir (me);
211 Directional_element_interface::set (me, d);
216 calc_position_and_height (me,&offset,&dy);
218 me->set_elt_property ("delta-y", gh_double2scm (dy));
220 me->translate_axis (offset, Y_AXIS);
222 if (scm_ilength (me->get_elt_property ("beams")) == 1)
224 SCM bs = me->get_elt_property ("beams");
225 Score_element *b = unsmob_element (gh_car (bs));
226 Spanner * beam_l = dynamic_cast<Spanner *> (b);
228 && sp->get_bound (LEFT)->column_l () == beam_l->get_bound (LEFT)->column_l ()
229 && sp->get_bound (RIGHT)->column_l () == beam_l->get_bound (RIGHT)->column_l ())
230 me->set_elt_property ("parallel-beam", SCM_BOOL_T);
232 return SCM_UNSPECIFIED;
237 Tuplet_spanner::get_default_dir (Score_element*me)
240 SCM dir_sym =me->get_elt_property ("dir-forced");
241 if (isdir_b (dir_sym))
249 for (SCM s = me->get_elt_property ("columns"); gh_pair_p (s); s = gh_cdr (s))
251 Score_element * nc = unsmob_element (gh_car (s));
252 if (Note_column::dir (nc) < 0)
263 Tuplet_spanner::add_beam (Score_element*me, Score_element *b)
265 me->add_dependency (b);
266 Pointer_group_interface gi (me, "beams");
271 Tuplet_spanner::add_column (Score_element*me, Item*n)
273 Pointer_group_interface gi (me, "columns");
275 me->add_dependency (n);
277 add_bound_item (dynamic_cast<Spanner*> (me), n);