/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 1996--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 1996--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "staff-symbol-referencer.hh"
#include "text-interface.hh"
#include "warn.hh"
+#include "unpure-pure-container.hh"
System::System (System const &src)
: Spanner (src)
all_elements_ = 0;
pscore_ = 0;
rank_ = 0;
- checked_footnotes_ = false;
init_elements ();
}
{
all_elements_ = 0;
rank_ = 0;
- checked_footnotes_ = false;
init_elements ();
}
{
System *child = dynamic_cast<System *> (broken_intos_[i]);
child->all_elements_->remove_duplicates ();
+
for (vsize j = 0; j < child->all_elements_->size (); j++)
{
Grob *g = child->all_elements_->grob (j);
}
}
- if (be_verbose_global)
- message (_f ("Element count %d", count + element_count ()) + "\n");
+ debug_output (_f ("Element count %d", count + element_count ()) + "\n");
}
SCM
SCM lines = scm_c_make_vector (broken_intos_.size (), SCM_EOL);
for (vsize i = 0; i < broken_intos_.size (); i++)
{
- if (be_verbose_global)
- progress_indication ("[");
+ debug_output ("[", false);
System *system = dynamic_cast<System *> (broken_intos_[i]);
scm_vector_set_x (lines, scm_from_int (i),
system->get_paper_system ());
- if (be_verbose_global)
- progress_indication (to_string (i) + "]");
+ debug_output (to_string (i) + "]", false);
}
return lines;
}
-void
-System::populate_footnote_grob_vector ()
-{
- extract_grob_set (this, "all-elements", all_elts);
- for (vsize i = 0; i < all_elts.size (); i++)
- if (all_elts[i]->internal_has_interface (ly_symbol2scm ("footnote-interface")))
- footnote_grobs_.push_back (all_elts[i]);
-
- sort (footnote_grobs_.begin (), footnote_grobs_.end (), Grob::less);
- checked_footnotes_ = true;
-}
-
-void
-System::get_footnote_grobs_in_range (vector<Grob *> &out, vsize start, vsize end)
+vector<Grob *>
+System::get_footnote_grobs_in_range (vsize start, vsize end)
{
- if (!checked_footnotes_)
- populate_footnote_grob_vector ();
-
- for (vsize i = 0; i < footnote_grobs_.size (); i++)
+ vector<Grob *> out;
+ extract_grob_set (this, "footnotes-before-line-breaking", footnote_grobs);
+ for (vsize i = 0; i < footnote_grobs.size (); i++)
{
- int pos = footnote_grobs_[i]->spanned_rank_interval ()[LEFT];
+ Grob *at_bat = footnote_grobs[i];
+ int pos = at_bat->spanned_rank_interval ()[LEFT];
bool end_of_line_visible = true;
- if (Spanner *s = dynamic_cast<Spanner *>(footnote_grobs_[i]))
+ if (Spanner *s = dynamic_cast<Spanner *>(at_bat))
{
Direction spanner_placement = robust_scm2dir (s->get_property ("spanner-placement"), LEFT);
if (spanner_placement == CENTER)
spanner_placement = LEFT;
pos = s->spanned_rank_interval ()[spanner_placement];
+ if (s->original ())
+ {
+ Spanner *orig = dynamic_cast<Spanner *>(s->original ());
+ at_bat = spanner_placement == LEFT ? orig->broken_intos_[0] : orig->broken_intos_.back ();
+ pos = at_bat->spanned_rank_interval ()[RIGHT];
+ }
}
- if (Item *item = dynamic_cast<Item *>(footnote_grobs_[i]))
+ if (Item *item = dynamic_cast<Item *>(at_bat))
{
if (!Item::break_visible (item))
continue;
// safeguard to bring down the column rank so that end of line footnotes show up on the correct line
- end_of_line_visible = (LEFT == item->break_status_dir ());
+ if (pos == int (start) && item->break_status_dir () != RIGHT)
+ continue;
+ if (pos == int (end) && item->break_status_dir () != LEFT)
+ continue;
+ if (pos != int (end) && pos != int (start) && item->break_status_dir () != CENTER)
+ continue;
}
if (pos < int (start))
continue;
if (pos > int (end))
- break;
+ continue;
if (pos == int (start) && end_of_line_visible)
continue;
if (pos == int (end) && !end_of_line_visible)
continue;
- if (!footnote_grobs_[i]->is_live ())
+ if (!at_bat->is_live ())
continue;
- out.push_back (footnote_grobs_[i]);
+ out.push_back (at_bat);
}
+ return out;
}
-vector<Stencil *>
-System::get_footnotes_in_range (vsize start, vsize end)
+vector<Real>
+System::get_footnote_heights_in_range (vsize start, vsize end)
{
- vector<Grob *> footnote_grobs;
- get_footnote_grobs_in_range (footnote_grobs, start, end);
- vector<Stencil *> out;
+ return internal_get_note_heights_in_range (start, end, true);
+}
+
+vector<Real>
+System::get_in_note_heights_in_range (vsize start, vsize end)
+{
+ return internal_get_note_heights_in_range (start, end, false);
+}
+
+vector<Real>
+System::internal_get_note_heights_in_range (vsize start, vsize end, bool foot)
+{
+ vector<Grob *> footnote_grobs = get_footnote_grobs_in_range (start, end);
+ vector<Real> out;
+
+ for (vsize i = footnote_grobs.size (); i--;)
+ if (foot
+ ? !to_boolean (footnote_grobs[i]->get_property ("footnote"))
+ : to_boolean (footnote_grobs[i]->get_property ("footnote")))
+ footnote_grobs.erase (footnote_grobs.begin () + i);
for (vsize i = 0; i < footnote_grobs.size (); i++)
{
props, footnote_markup);
Stencil *footnote_stencil = unsmob_stencil (footnote_stl);
- out.push_back (footnote_stencil);
+ out.push_back (footnote_stencil->extent (Y_AXIS).length ());
}
return out;
vsize
System::num_footnotes ()
{
- return footnote_grobs_.size ();
+ extract_grob_set (this, "footnotes-after-line-breaking", footnote_grobs);
+ return footnote_grobs.size ();
+}
+
+bool
+grob_2D_less (Grob *g1, Grob *g2)
+{
+ int sri[] = {0, 0};
+ Grob *gs[] = {g1, g2};
+
+ for (int i = 0; i < 2; i++)
+ {
+ sri[i] = gs[i]->spanned_rank_interval ()[LEFT];
+ if (Spanner *s = dynamic_cast<Spanner *> (gs[i]))
+ {
+ if (s->broken_intos_.size ())
+ s = (scm_to_int (s->broken_intos_[0]->get_property ("spanner-placement")) == LEFT
+ ? s->broken_intos_[0]
+ : s->broken_intos_.back ());
+ gs[i] = s;
+ if (robust_scm2double (s->get_property ("X-offset"), 0.0) > 0)
+ sri[i] = s->spanned_rank_interval ()[RIGHT];
+ }
+ }
+
+ if (sri[0] == sri[1])
+ return Grob::vertical_less (gs[0], gs[1]);
+
+ return sri[0] < sri[1];
+}
+
+MAKE_SCHEME_CALLBACK (System, footnotes_before_line_breaking, 1);
+SCM
+System::footnotes_before_line_breaking (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ vector<Grob *> footnotes;
+ SCM grobs_scm = Grob_array::make_array ();
+ extract_grob_set (me, "all-elements", elts);
+ for (vsize i = 0; i < elts.size (); i++)
+ if (elts[i]->internal_has_interface (ly_symbol2scm ("footnote-interface")))
+ footnotes.push_back (elts[i]);
+
+ unsmob_grob_array (grobs_scm)->set_array (footnotes);
+ return grobs_scm;
}
-vector<Grob *>*
-System::footnote_grobs ()
+MAKE_SCHEME_CALLBACK (System, footnotes_after_line_breaking, 1);
+SCM
+System::footnotes_after_line_breaking (SCM smob)
{
- return &footnote_grobs_;
+ Spanner *sys_span = unsmob_spanner (smob);
+ System *sys = dynamic_cast<System *> (sys_span);
+ Interval_t<int> sri = sys->spanned_rank_interval ();
+ vector<Grob *> footnote_grobs = sys->get_footnote_grobs_in_range (sri[LEFT], sri[RIGHT]);
+ vector_sort (footnote_grobs, grob_2D_less);
+
+ SCM grobs_scm = Grob_array::make_array ();
+ unsmob_grob_array (grobs_scm)->set_array (footnote_grobs);
+ return grobs_scm;
}
void
Interval iv (pure_height (this, st, end));
system->set_property ("pure-Y-extent", ly_interval2scm (iv));
- get_footnote_grobs_in_range (system->footnote_grobs_, st, end);
-
system->set_bound (LEFT, c[0]);
system->set_bound (RIGHT, c.back ());
SCM system_labels = SCM_EOL;
for (vsize i = 0; i < all_elements_->size (); i++)
all_elements_->grob (i)->discretionary_processing ();
- if (be_verbose_global)
- message (_f ("Grob count %d", element_count ()));
+ debug_output (_f ("Grob count %d", element_count ()));
/*
order is significant: broken grobs are added to the end of the
pl->set_property ("page-break-penalty", right_bound->get_property ("page-break-penalty"));
pl->set_property ("page-turn-penalty", right_bound->get_property ("page-turn-penalty"));
+ if (right_bound->original () == dynamic_cast<System *> (original ())->get_bound (RIGHT))
+ pl->set_property ("last-in-score", SCM_BOOL_T);
+
Interval staff_refpoints;
if (Grob *align = get_vertical_alignment ())
{
return 0;
}
+// Finds the neighboring staff in the given direction over bounds
+Grob *
+System::get_neighboring_staff (Direction dir, Grob *vertical_axis_group, Interval_t<int> bounds)
+{
+ Grob *align = get_vertical_alignment ();
+ if (!align)
+ return 0;
+
+ extract_grob_set (align, "elements", elts);
+ vsize start = (dir == UP) ? 0 : elts.size () - 1;
+ vsize end = (dir == UP) ? elts.size () : VPOS;
+
+ Grob *out = 0;
+
+ for (vsize i = start; i != end; i += dir)
+ {
+ if (elts[i] == vertical_axis_group)
+ return out;
+
+ if (Hara_kiri_group_spanner::has_interface (elts[i]))
+ Hara_kiri_group_spanner::consider_suicide (elts[i]);
+
+ bounds.intersect (elts[i]->spanned_rank_interval ());
+ if (elts[i]->is_live () && !bounds.is_empty ())
+ out = elts[i];
+ }
+
+ return 0;
+}
+
Interval
System::pure_refpoint_extent (vsize start, vsize end)
{
return pure ? get_pure_bound (d, start, end) : get_bound (d);
}
+enum
+{
+ SPACEABLE_STAVES,
+ NONSPACEABLE_STAVES,
+ ALL_STAVES
+};
+
+static SCM
+get_maybe_spaceable_staves (SCM smob, int filter)
+{
+ System *me = dynamic_cast<System *> (unsmob_grob (smob));
+ Grob *align = me->get_vertical_alignment ();
+ SCM ret = SCM_EOL;
+
+ if (align)
+ {
+ SCM *tail = &ret;
+ extract_grob_set (align, "elements", staves);
+
+ for (vsize i = 0; i < staves.size (); ++i)
+ {
+ bool spaceable = Page_layout_problem::is_spaceable (staves[i]);
+ if (staves[i]->is_live ()
+ && ((filter == ALL_STAVES)
+ || (filter == SPACEABLE_STAVES && spaceable)
+ || (filter == NONSPACEABLE_STAVES && !spaceable)))
+ {
+ *tail = scm_cons (staves[i]->self_scm (), SCM_EOL);
+ tail = SCM_CDRLOC (*tail);
+ }
+ }
+ }
+
+ return ret;
+}
+
+MAKE_SCHEME_CALLBACK (System, get_staves, 1)
+SCM
+System::get_staves (SCM smob)
+{
+ return get_maybe_spaceable_staves (smob, ALL_STAVES);
+}
+
+MAKE_SCHEME_CALLBACK (System, get_spaceable_staves, 1)
+SCM
+System::get_spaceable_staves (SCM smob)
+{
+ return get_maybe_spaceable_staves (smob, SPACEABLE_STAVES);
+}
+
+MAKE_SCHEME_CALLBACK (System, get_nonspaceable_staves, 1)
+SCM
+System::get_nonspaceable_staves (SCM smob)
+{
+ return get_maybe_spaceable_staves (smob, NONSPACEABLE_STAVES);
+}
+
ADD_INTERFACE (System,
"This is the top-level object: Each object in a score"
" ultimately has a @code{System} object as its X and"
/* properties */
"all-elements "
"columns "
+ "footnote-stencil "
+ "footnotes-before-line-breaking "
+ "footnotes-after-line-breaking "
+ "in-note-direction "
+ "in-note-padding "
+ "in-note-stencil "
"labels "
"pure-Y-extent "
"skyline-horizontal-padding "