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);
35 Tuplet_spanner::do_brew_molecule_p () const
37 Molecule* mol_p = new Molecule;
39 // Default behaviour: number always, bracket when no beam!
40 bool par_beam = to_boolean (get_elt_property ("parallel-beam"));
41 bool bracket_visibility = !par_beam;
42 bool number_visibility = true;
44 SCM bracket = get_elt_property ("tuplet-bracket-visibility");
45 if (gh_boolean_p (bracket))
47 bracket_visibility = gh_scm2bool (bracket);
49 else if (bracket == ly_symbol2scm ("if-no-beam"))
50 bracket_visibility = !par_beam;
52 SCM numb = get_elt_property ("tuplet-number-visibility");
53 if (gh_boolean_p (numb))
55 number_visibility = gh_scm2bool (numb);
57 else if (bracket == ly_symbol2scm ("if-no-beam"))
58 number_visibility = !par_beam;
60 if (gh_pair_p (get_elt_property ("columns")))
62 Link_array<Note_column> column_arr=
63 Group_interface__extract_elements (this, (Note_column*)0, "columns");
65 Real ncw = column_arr.top ()->extent(X_AXIS).length ();
66 Real w = spanner_length () + ncw;
69 Real staff_space = paper_l ()->get_var ("interline");
70 Direction dir = directional_element (this).get ();
71 Real dy = gh_scm2double (get_elt_property ("delta-y"));
72 SCM number = get_elt_property ("text");
73 if (gh_string_p (number) && number_visibility)
76 num (lookup_l ()->text ("italic",
77 ly_scm2string (number), paper_l ()));
78 num.align_to (X_AXIS, CENTER);
79 num.translate_axis (w/2, X_AXIS);
80 num.align_to (Y_AXIS, CENTER);
81 num.translate_axis (dir * staff_space, Y_AXIS);
83 num.translate_axis (dy/2, Y_AXIS);
85 mol_p->add_molecule (num);
88 Real thick = paper_l ()->get_var ("tuplet_thick");
89 if (bracket_visibility)
91 Real gap = paper_l () -> get_var ("tuplet_spanner_gap");
92 Real height = staff_space;
93 Atom *at = new Atom (gh_list(ly_symbol2scm ("tuplet"),
94 gh_double2scm (height),
98 gh_double2scm (thick),
102 mol_p->add_atom (at->self_scm_);
105 mol_p->translate_axis (dir * staff_space, Y_AXIS);
111 Tuplet_spanner::do_add_processing ()
113 if (gh_pair_p (get_elt_property ("columns")))
115 Link_array<Note_column> column_arr=
116 Group_interface__extract_elements (this, (Note_column*)0, "columns");
118 set_bounds (LEFT, column_arr[0]);
119 set_bounds (RIGHT, column_arr.top ());
124 use first -> last note for slope, and then correct for disturbing
127 Tuplet_spanner::calc_position_and_height (Real *offset, Real * dy) const
129 Link_array<Note_column> column_arr=
130 Group_interface__extract_elements (this, (Note_column*)0, "columns");
133 Direction d = directional_element (this).get ();
134 *dy = column_arr.top ()->extent (Y_AXIS) [d]
135 - column_arr[0]->extent (Y_AXIS) [d];
137 *offset = - d * infinity_f;
139 Real x0 = column_arr[0]->hpos_f ();
140 Real x1 = column_arr.top ()->hpos_f ();
142 Real factor = column_arr.size () > 1 ? 1/(x1 - x0) : 1.0;
144 for (int i = 0; i < column_arr.size (); i++)
146 Real notey = column_arr[i]->extent (Y_AXIS)[d];
147 Real x = column_arr[i]->hpos_f () - x0;
148 Real tuplety = *dy * x * factor;
150 if (notey * d > (*offset + tuplety) * d)
151 *offset = notey - tuplety;
156 Tuplet_spanner::do_post_processing ()
158 Link_array<Note_column> column_arr=
159 Group_interface__extract_elements (this, (Note_column*)0, "columns");
161 if (!column_arr.size ())
163 set_elt_property ("transparent", SCM_BOOL_T);
168 Direction d = directional_element (this).get ();
171 d = get_default_dir ();
172 directional_element (this).set (d);
177 calc_position_and_height (&offset, &dy);
178 set_elt_property ("delta-y", gh_double2scm (dy));
180 translate_axis (offset, Y_AXIS);
182 if (scm_ilength (get_elt_property ("beams")) == 1)
184 SCM bs = get_elt_property ("beams");
185 Score_element *b = unsmob_element (gh_car (bs));
186 Beam * beam_l = dynamic_cast<Beam*> (b);
188 && spanned_drul_[LEFT]->column_l () == beam_l->spanned_drul_[LEFT]->column_l ()
189 && spanned_drul_[RIGHT]->column_l () == beam_l->spanned_drul_[RIGHT]->column_l ())
190 set_elt_property ("parallel-beam", SCM_BOOL_T);
196 Tuplet_spanner::get_default_dir () const
199 SCM dir_sym =get_elt_property ("dir-forced");
200 if (isdir_b (dir_sym))
208 for (SCM s = get_elt_property ("columns"); gh_pair_p (s); s = gh_cdr (s))
210 Score_element * sc = unsmob_element (gh_car (s));
211 Note_column * nc = dynamic_cast<Note_column*> (sc);
223 Tuplet_spanner::add_beam (Beam *b)
226 Group_interface gi (this, "beams");
231 Tuplet_spanner::add_column (Note_column*n)
233 Group_interface gi (this, "columns");