source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
*/
+
#include "beam.hh"
#include "box.hh"
#include "debug.hh"
-#include "lookup.hh"
+#include "font-interface.hh"
#include "molecule.hh"
-#include "p-col.hh"
+#include "paper-column.hh"
#include "paper-def.hh"
+#include "text-item.hh"
#include "tuplet-spanner.hh"
#include "stem.hh"
#include "note-column.hh"
#include "dimensions.hh"
+#include "group-interface.hh"
+#include "directional-element-interface.hh"
+#include "spanner.hh"
-
-Tuplet_spanner::Tuplet_spanner ()
+void
+Tuplet_spanner::set_interface (Score_element*me)
{
- parallel_beam_b_ = false;
+ me->set_interface (ly_symbol2scm ("tuplet-bracket"));
}
/*
- TODO. We should control the gap for lookup from here.
+ TODO.
*/
-Molecule*
-Tuplet_spanner::do_brew_molecule_p () const
+
+MAKE_SCHEME_CALLBACK(Tuplet_spanner,brew_molecule,1);
+
+SCM
+Tuplet_spanner::brew_molecule (SCM smob)
{
- Molecule* mol_p = new Molecule;
+ Score_element *me= unsmob_element (smob);
+ Molecule mol;
// Default behaviour: number always, bracket when no beam!
- bool bracket_visibility = !parallel_beam_b_;
+ bool par_beam = to_boolean (me->get_elt_property ("parallel-beam"));
+ bool bracket_visibility = !par_beam;
bool number_visibility = true;
- SCM visibility_sym =get_elt_property (tuplet_visibility_scm_sym);
- if (visibility_sym != SCM_BOOL_F)
+
+ SCM bracket = me->get_elt_property ("tuplet-bracket-visibility");
+ if (gh_boolean_p (bracket))
+ {
+ bracket_visibility = gh_scm2bool (bracket);
+ }
+ else if (bracket == ly_symbol2scm ("if-no-beam"))
+ bracket_visibility = !par_beam;
+
+ SCM numb = me->get_elt_property ("tuplet-number-visibility");
+ if (gh_boolean_p (numb))
{
- /* Property values:
- 0 show nothing
- 1 show number
- 2 show (number and bracket)-if-no-beam
- 3 show number, and bracket-if-no-beam
- 4 show number, and bracket
- */
- int value = gh_scm2int (SCM_CDR(visibility_sym));
- bracket_visibility = (value == 4 || (value > 1 && !parallel_beam_b_));
- number_visibility = (value > 2 || value == 1 ||
- (value == 2 && !parallel_beam_b_));
+ number_visibility = gh_scm2bool (numb);
}
+ else if (bracket == ly_symbol2scm ("if-no-beam"))
+ number_visibility = !par_beam;
- if (column_arr_.size ()){
- Real ncw = column_arr_.top ()->extent (X_AXIS).length ();
- Real w = extent (X_AXIS).length () + ncw;
- Molecule num (lookup_l ()->text ("italic",
- number_str_, paper_l ()));
- num.align_to (X_AXIS, CENTER);
- num.translate_axis (w/2, X_AXIS);
- Real interline = paper_l ()->get_realvar (interline_scm_sym);
- Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_]
- - column_arr_[0]->extent (Y_AXIS) [dir_];
- num.align_to (Y_AXIS, CENTER);
- num.translate_axis (dir_ * interline, Y_AXIS);
+ if (gh_pair_p (me->get_elt_property ("columns")))
+ {
+ Link_array<Score_element> column_arr=
+ Pointer_group_interface__extract_elements (me, (Score_element*)0, "columns");
+
+ Real ncw = column_arr.top ()->extent(column_arr.top (), X_AXIS).length ();
+ Real w = dynamic_cast<Spanner*>(me)->spanner_length () + ncw;
+
+ Real staff_space = 1.0;
+ Direction dir = Directional_element_interface::get (me);
+ Real dy = gh_scm2double (me->get_elt_property ("delta-y"));
+ SCM number = me->get_elt_property ("text");
+ if (gh_string_p (number) && number_visibility)
+ {
+ SCM properties = Font_interface::font_alist_chain (me);
+ Molecule num = Text_item::text2molecule (me, number, properties);
+ num.align_to (X_AXIS, CENTER);
+ num.translate_axis (w/2, X_AXIS);
+ num.align_to (Y_AXIS, CENTER);
+ num.translate_axis (dir * staff_space, Y_AXIS);
- num.translate_axis (dy/2, Y_AXIS);
-
- Real thick = paper_l ()->get_realvar (tuplet_thick_scm_sym);
- if (bracket_visibility)
- {
- mol_p->add_molecule (lookup_l ()->tuplet_bracket (dy, w, thick, interline, dir_));
- }
-
- if (number_visibility)
- {
- mol_p->add_molecule (num);
- }
- mol_p->translate_axis (dir_ * interline, Y_AXIS);
- }
- return mol_p;
+ num.translate_axis (dy/2, Y_AXIS);
+
+ mol.add_molecule (num);
+ }
+
+ if (bracket_visibility)
+ {
+ Real lt = me->paper_l ()->get_var ("stafflinethickness");
+
+ SCM thick = me->get_elt_property ("thick");
+ SCM gap = me->get_elt_property ("number-gap");
+
+ SCM at =gh_list(ly_symbol2scm ("tuplet"),
+ gh_double2scm (1.0),
+ gap,
+ gh_double2scm (w),
+ gh_double2scm (dy),
+ gh_double2scm (gh_scm2double (thick)* lt),
+ gh_int2scm (dir),
+ SCM_UNDEFINED);
+
+ Box b;
+ mol.add_molecule (Molecule (b, at));
+ }
+ }
+ return mol.create_scheme();
}
-
+
+
+
+
+/*
+ use first -> last note for slope, and then correct for disturbing
+ notes in between. */
void
-Tuplet_spanner::do_add_processing ()
+Tuplet_spanner::calc_position_and_height (Score_element*me,Real *offset, Real * dy)
{
- if (column_arr_.size ())
+ Link_array<Score_element> column_arr=
+ Pointer_group_interface__extract_elements (me, (Score_element*)0, "columns");
+
+
+ Score_element * commony = me->common_refpoint (me->get_elt_property ("columns"), Y_AXIS);
+ Score_element * commonx = me->common_refpoint (me->get_elt_property ("columns"), X_AXIS);
+
+ Direction d = Directional_element_interface::get (me);
+
+ /*
+ Use outer non-rest columns to determine slope
+ */
+ int l = 0;
+ while (l <column_arr.size() && Note_column::rest_b(column_arr[l]))
+ l ++;
+
+ int r = column_arr.size ()- 1;
+ while (r >= l && Note_column::rest_b(column_arr[r]))
+ r--;
+
+ if (l < r)
{
- set_bounds (LEFT, column_arr_[0]);
- set_bounds (RIGHT, column_arr_.top ());
+ *dy = column_arr[r]->extent (commony, Y_AXIS) [d]
+ - column_arr[l]->extent (commony, Y_AXIS) [d] ;
}
-}
+ else
+ * dy = 0;
+
+
+ *offset = - d * infinity_f;
+
+ if (!column_arr.size ())
+ return;
+
+ Real x0 = column_arr[0]->relative_coordinate (commonx, X_AXIS);
+ Real x1 = column_arr.top ()->relative_coordinate (commonx, X_AXIS);
+ Real factor = column_arr.size () > 1 ? 1/(x1 - x0) : 1.0;
+
+ for (int i = 0; i < column_arr.size (); i++)
+ {
+ Real notey = column_arr[i]->extent (commony, Y_AXIS)[d]
+ - me->relative_coordinate (commony, Y_AXIS);
+
+ Real x = column_arr[i]->relative_coordinate (commonx, X_AXIS) - x0;
+ Real tuplety = *dy * x * factor;
+
+ if (notey * d > (*offset + tuplety) * d)
+ *offset = notey - tuplety;
+ }
+}
+
+/*
+ use first -> last note for slope,
+*/
void
-Tuplet_spanner::do_post_processing ()
+Tuplet_spanner::calc_dy (Score_element*me,Real * dy)
+{
+ Link_array<Score_element> column_arr=
+ Pointer_group_interface__extract_elements (me, (Score_element*)0, "columns");
+
+ /*
+ ugh. refps.
+ */
+ Direction d = Directional_element_interface::get (me);
+ *dy = column_arr.top ()->extent (column_arr.top (), Y_AXIS) [d]
+ - column_arr[0]->extent (column_arr[0], Y_AXIS) [d];
+}
+MAKE_SCHEME_CALLBACK(Tuplet_spanner,after_line_breaking,1);
+
+SCM
+Tuplet_spanner::after_line_breaking (SCM smob)
{
- if (column_arr_.size())
- translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
+ Score_element * me = unsmob_element (smob);
+ Link_array<Note_column> column_arr=
+ Pointer_group_interface__extract_elements (me, (Note_column*)0, "columns");
+ Spanner *sp = dynamic_cast<Spanner*> (me);
+
- if (beam_l_arr_.size () == 1)
+ if (!column_arr.size ())
{
- Beam * beam_l = beam_l_arr_[0];
- if (!broken_b ()
- && spanned_drul_[LEFT]->column_l () == beam_l->spanned_drul_[LEFT]->column_l ()
- && spanned_drul_[RIGHT]->column_l () == beam_l->spanned_drul_[RIGHT]->column_l ())
- parallel_beam_b_ = true;
+ me->suicide ();
+ return SCM_UNSPECIFIED;
}
- // if (column_arr_.size () == 1)
- // bracket_visibility_b_ = false;
-}
+ Direction d = Directional_element_interface::get (me);
+ if (!d)
+ {
+ d = Tuplet_spanner::get_default_dir (me);
+ Directional_element_interface::set (me, d);
-void
-Tuplet_spanner::do_substitute_element_pointer (Score_element* o, Score_element* n)
-{
- if (Note_column *onc = dynamic_cast <Note_column *> (o))
- column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
- else if (Beam * b = dynamic_cast<Beam* > (o))
+ }
+ Real dy, offset;
+
+ calc_position_and_height (me,&offset,&dy);
+
+ me->set_elt_property ("delta-y", gh_double2scm (dy));
+
+ me->translate_axis (offset, Y_AXIS);
+
+ if (scm_ilength (me->get_elt_property ("beams")) == 1)
{
- beam_l_arr_.substitute (b, dynamic_cast<Beam*> (n));
+ SCM bs = me->get_elt_property ("beams");
+ Score_element *b = unsmob_element (gh_car (bs));
+ Spanner * beam_l = dynamic_cast<Spanner *> (b);
+ if (!sp->broken_b ()
+ && sp->get_bound (LEFT)->column_l () == beam_l->get_bound (LEFT)->column_l ()
+ && sp->get_bound (RIGHT)->column_l () == beam_l->get_bound (RIGHT)->column_l ())
+ me->set_elt_property ("parallel-beam", SCM_BOOL_T);
}
+ return SCM_UNSPECIFIED;
}
+
Direction
-Tuplet_spanner::get_default_dir () const
+Tuplet_spanner::get_default_dir (Score_element*me)
{
Direction d = UP;
- SCM dir_sym =get_elt_property (dir_forced_scm_sym);
- if (dir_sym != SCM_BOOL_F) {
- d= (Direction) gh_scm2int (SCM_CDR(dir_sym));
- if (d != CENTER)
- return d;
- }
-
- for (int i=0; i < column_arr_.size (); i ++)
+ SCM dir_sym =me->get_elt_property ("dir-forced");
+ if (isdir_b (dir_sym))
+ {
+ d= to_dir (dir_sym);
+ if (d != CENTER)
+ return d;
+ }
+
+ d = UP ;
+ for (SCM s = me->get_elt_property ("columns"); gh_pair_p (s); s = gh_cdr (s))
{
- if (column_arr_[i]->dir () < 0)
+ Score_element * nc = unsmob_element (gh_car (s));
+ if (Note_column::dir (nc) < 0)
{
d = DOWN;
break;
}
}
+
return d;
}
void
-Tuplet_spanner::add_beam (Beam *b)
+Tuplet_spanner::add_beam (Score_element*me, Score_element *b)
{
- add_dependency (b);
- beam_l_arr_.push (b);
+ me->add_dependency (b);
+ Pointer_group_interface::add_element (me, "beams",b);
}
void
-Tuplet_spanner::add_column (Note_column*n)
+Tuplet_spanner::add_column (Score_element*me, Item*n)
{
- column_arr_.push (n);
- add_dependency (n);
+ Pointer_group_interface::add_element (me, "columns",n);
+ me->add_dependency (n);
+
+ add_bound_item (dynamic_cast<Spanner*> (me), n);
}
+