X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fledger-line-spanner.cc;h=bf7444dea0ec73b0a08b9841ffbe691c825c2128;hb=8d540cf685bfda800b1ea99bef1ae236dba6280d;hp=1bca089b142d42ceb6fa631ec52381310860c5dd;hpb=75eebcb49e52d296b1da3e1074e0825d2c780db4;p=lilypond.git diff --git a/lily/ledger-line-spanner.cc b/lily/ledger-line-spanner.cc index 1bca089b14..bf7444dea0 100644 --- a/lily/ledger-line-spanner.cc +++ b/lily/ledger-line-spanner.cc @@ -24,7 +24,7 @@ struct Ledger_line_spanner DECLARE_SCHEME_CALLBACK (set_spacing_rods, (SCM)); static Stencil brew_ledger_lines (Grob *me, int pos, - int interspaces, + Interval, Real, Real, Interval x_extent, Real left_shorten); @@ -35,15 +35,15 @@ struct Ledger_line_spanner Stencil Ledger_line_spanner::brew_ledger_lines (Grob *staff, int pos, - int interspaces, + Interval staff_extent, Real halfspace, Real ledgerlinethickness, Interval x_extent, Real left_shorten) { - int line_count = ((abs (pos) < interspaces) + int line_count = (staff_extent.contains (pos) ? 0 - : (abs (pos) - interspaces) / 2); + : sign (pos) * int (rint(pos - staff_extent[Direction (sign (pos))])) / 2); Stencil stencil; if (line_count) { @@ -59,7 +59,7 @@ Ledger_line_spanner::brew_ledger_lines (Grob *staff, = Lookup::round_filled_box (Box (x_extent, y_extent), blotdiameter); Direction dir = (Direction)sign (pos); - Real offs = (Staff_symbol_referencer::on_staffline (staff, pos)) + Real offs = (Staff_symbol_referencer::on_line (staff, pos)) ? 0.0 : -dir * halfspace; @@ -119,7 +119,10 @@ Ledger_line_spanner::set_spacing_rods (SCM smob) // find size of note heads. Grob *staff = Staff_symbol_referencer::get_staff_symbol (me); if (!staff) - return SCM_EOL; + { + me->suicide (); + return SCM_EOL; + } Real min_length_fraction = robust_scm2double (me->get_property ("minimum-length-fraction"), 0.15); @@ -129,19 +132,22 @@ Ledger_line_spanner::set_spacing_rods (SCM smob) Item *previous_column = 0; Item *current_column = 0; - int interspaces = Staff_symbol::line_count (staff) - 1; + Real halfspace = Staff_symbol::staff_space (staff) / 2; + Interval staff_extent = staff->extent (staff, Y_AXIS); + staff_extent *= 1 / halfspace; + /* Run through heads using a loop. Since Ledger_line_spanner can contain a lot of noteheads, superlinear performance is too slow. */ extract_item_set (me, "note-heads", heads); - for (int i = heads.size (); i--;) + for (vsize i = heads.size (); i--;) { Item *h = heads[i]; int pos = Staff_symbol_referencer::get_rounded_position (h); - if (abs (pos) <= interspaces) + if (staff_extent.contains (pos)) continue; Item *column = h->get_column (); @@ -203,7 +209,7 @@ Ledger_line_spanner::print (SCM smob) extract_grob_set (me, "note-heads", heads); - if (heads.is_empty ()) + if (heads.empty ()) return SCM_EOL; // find size of note heads. @@ -211,6 +217,11 @@ Ledger_line_spanner::print (SCM smob) if (!staff) return SCM_EOL; + Real halfspace = Staff_symbol::staff_space (staff) / 2; + + Interval staff_extent = staff->extent (staff, Y_AXIS); + staff_extent *= 1 / halfspace; + Real length_fraction = robust_scm2double (me->get_property ("length-fraction"), 0.25); @@ -223,20 +234,18 @@ Ledger_line_spanner::print (SCM smob) { Axis a = Axis (i); common[a] = common_refpoint_of_array (heads, me, a); - for (int i = heads.size (); i--;) + for (vsize i = heads.size (); i--;) if (Grob *g = unsmob_grob (me->get_object ("accidental-grob"))) common[a] = common[a]->common_refpoint (g, a); } - int interspaces = Staff_symbol::line_count (staff) - 1; Ledger_requests reqs; - for (int i = heads.size (); i--;) + for (vsize i = heads.size (); i--;) { Item *h = dynamic_cast (heads[i]); int pos = Staff_symbol_referencer::get_rounded_position (h); - if (pos - && abs (pos) > interspaces) + if (pos && !staff_extent.contains (pos)) { Interval head_extent = h->extent (common[X_AXIS], X_AXIS); Interval ledger_extent = head_extent; @@ -264,8 +273,8 @@ Ledger_line_spanner::print (SCM smob) Direction d = DOWN; do { - if (abs (last->second[d].position_) > interspaces - && abs (i->second[d].position_) > interspaces) + if (!staff_extent.contains (last->second[d].position_) + && !staff_extent.contains (i->second[d].position_)) { Real center = (last->second[d].head_extent_[RIGHT] @@ -277,12 +286,14 @@ Ledger_line_spanner::print (SCM smob) Ledger_request &lr = ((which == LEFT) ? * last : *i).second[d]; // due tilt of quarter note-heads + /* FIXME */ bool both - = (abs (last->second[d].position_) > interspaces + 1 - && abs (i->second[d].position_) > interspaces + 1); - + = (!staff_extent.contains (last->second[d].position_ + - sign (last->second[d].position_)) + && !staff_extent.contains (i->second[d].position_ + - sign (i->second[d].position_))); Real limit = (center + (both ? which * gap / 2 : 0)); - lr.ledger_extent_.elem_ref (-which) + lr.ledger_extent_.at (-which) = which * max (which * lr.ledger_extent_[-which], which * limit); } while (flip (&which) != LEFT); @@ -291,22 +302,22 @@ Ledger_line_spanner::print (SCM smob) while (flip (&d) != DOWN); } - // create ledgers for note heads + // create ledgers for note heads Real ledgerlinethickness = Staff_symbol::get_ledger_line_thickness (staff); - Real halfspace = Staff_symbol::staff_space (staff) / 2; - for (int i = heads.size (); i--;) + for (vsize i = heads.size (); i--;) { Item *h = dynamic_cast (heads[i]); int pos = Staff_symbol_referencer::get_rounded_position (h); - if (abs (pos) > interspaces + 1) + if (!staff_extent.contains (pos - sign (pos))) { Interval head_size = h->extent (common[X_AXIS], X_AXIS); Interval ledger_size = head_size; ledger_size.widen (ledger_size.length () * length_fraction); - Interval max_size = reqs[h->get_column ()->get_rank ()][Direction (sign (pos))].ledger_extent_; + Interval max_size = reqs[h->get_column ()->get_rank ()] + [Direction (sign (pos))].ledger_extent_; ledger_size.intersect (max_size); Real left_shorten = 0.0; @@ -326,7 +337,7 @@ Ledger_line_spanner::print (SCM smob) */ } - ledgers.add_stencil (brew_ledger_lines (staff, pos, interspaces, + ledgers.add_stencil (brew_ledger_lines (staff, pos, staff_extent, halfspace, ledgerlinethickness, ledger_size, @@ -347,7 +358,12 @@ ADD_INTERFACE (Ledger_line_spanner, "This is a separate grob because it has to process\n" "all potential collisions between all note heads.", - "note-heads thickness minimum-length-fraction length-fraction gap"); + /* properties */ + "note-heads " + "thickness " + "minimum-length-fraction " + "length-fraction " + "gap"); struct Ledgered_interface {