X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftuplet-bracket.cc;h=1f313e84a93482ccb492b92d37438b2f58b58481;hb=4a964b10c411827584eb720c63cd0d6fc5b65d72;hp=c351f374f4fd6846661a529f8d07a0914552fb68;hpb=4c8187e65dd9708d7733692842acc696da121bf1;p=lilypond.git diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index c351f374f4..1f313e84a9 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -1,9 +1,10 @@ /* - plet-spanner.cc -- implement Tuplet_bracket + tuplet-bracket.cc -- implement Tuplet_bracket source file of the GNU LilyPond music typesetter - (c) 1997--2003 Jan Nieuwenhuizen + (c) 1997--2004 Jan Nieuwenhuizen + Han-Wen Nienhuys */ /* @@ -24,12 +25,13 @@ #include +#include "line-interface.hh" #include "beam.hh" #include "box.hh" #include "warn.hh" #include "font-interface.hh" -#include "molecule.hh" -#include "paper-def.hh" +#include "stencil.hh" +#include "output-def.hh" #include "text-item.hh" #include "tuplet-bracket.hh" #include "stem.hh" @@ -61,7 +63,7 @@ Tuplet_bracket::parallel_beam (Grob *me, Link_array const &cols, bool *equ ugh: code dup. */ Grob *s1 = Note_column::get_stem (cols[0]); - Grob *s2 = Note_column::get_stem (cols.top()); + Grob *s2 = Note_column::get_stem (cols.top ()); Grob*b1 = s1 ? Stem::get_beam (s1) : 0; Grob*b2 = s2 ? Stem::get_beam (s2) : 0; @@ -69,20 +71,20 @@ Tuplet_bracket::parallel_beam (Grob *me, Link_array const &cols, bool *equ Spanner*sp = dynamic_cast (me); *equally_long= false; - if (! (b1 && (b1 == b2) && !sp->broken_b())) + if (! (b1 && (b1 == b2) && !sp->is_broken ())) return 0; Link_array beam_stems = Pointer_group_interface__extract_grobs (b1, (Grob*)0, "stems"); - if (beam_stems.size() == 0) + if (beam_stems.size () == 0) { programming_error ("Beam under tuplet bracket has no stems!"); *equally_long = 0; return 0; } - *equally_long = (beam_stems[0] == s1 && beam_stems.top() == s2); + *equally_long = (beam_stems[0] == s1 && beam_stems.top () == s2); return b1; } @@ -94,12 +96,12 @@ Tuplet_bracket::parallel_beam (Grob *me, Link_array const &cols, bool *equ follow beam precisely for determining tuplet number location. */ -MAKE_SCHEME_CALLBACK (Tuplet_bracket,brew_molecule,1); +MAKE_SCHEME_CALLBACK (Tuplet_bracket,print,1); SCM -Tuplet_bracket::brew_molecule (SCM smob) +Tuplet_bracket::print (SCM smob) { Grob *me= unsmob_grob (smob); - Molecule mol; + Stencil mol; Link_array columns= Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns"); @@ -109,15 +111,15 @@ Tuplet_bracket::brew_molecule (SCM smob) { - SCM lp = me->get_grob_property ("left-position"); - SCM rp = me->get_grob_property ("right-position"); + SCM lp = me->get_property ("left-position"); + SCM rp = me->get_property ("right-position"); - if (!gh_number_p (rp) || !gh_number_p (lp)) + if (!scm_is_number (rp) || !scm_is_number (lp)) after_line_breaking (smob); } - Real ly = gh_scm2double (me->get_grob_property ("left-position")); - Real ry = gh_scm2double (me->get_grob_property ("right-position")); + Real ly = robust_scm2double (me->get_property ("left-position"), 0); + Real ry = robust_scm2double (me->get_property ("right-position"), 0); bool equally_long = false; Grob * par_beam = parallel_beam (me, columns, &equally_long); @@ -130,18 +132,18 @@ Tuplet_bracket::brew_molecule (SCM smob) /* Fixme: the type of this prop is sucky. */ - SCM bracket = me->get_grob_property ("bracket-visibility"); - if (gh_boolean_p (bracket)) + SCM bracket = me->get_property ("bracket-visibility"); + if (scm_is_bool (bracket)) { - bracket_visibility = gh_scm2bool (bracket); + bracket_visibility = ly_scm2bool (bracket); } else if (bracket == ly_symbol2scm ("if-no-beam")) bracket_visibility = !par_beam; - SCM numb = me->get_grob_property ("number-visibility"); - if (gh_boolean_p (numb)) + SCM numb = me->get_property ("number-visibility"); + if (scm_is_bool (numb)) { - number_visibility = gh_scm2bool (numb); + number_visibility = ly_scm2bool (numb); } else if (numb == ly_symbol2scm ("if-no-beam")) number_visibility = !par_beam; @@ -152,33 +154,34 @@ Tuplet_bracket::brew_molecule (SCM smob) Tuplet brackets are normally not broken, but we shouldn't crash if they are. */ - commonx = commonx->common_refpoint (sp->get_bound(LEFT), X_AXIS); - commonx = commonx->common_refpoint (sp->get_bound(RIGHT), X_AXIS); + commonx = commonx->common_refpoint (sp->get_bound (LEFT), X_AXIS); + commonx = commonx->common_refpoint (sp->get_bound (RIGHT), X_AXIS); Direction dir = get_grob_direction (me); Grob * lgr = get_x_bound_grob (columns[0], dir); - Grob * rgr = get_x_bound_grob (columns.top(), dir); - Real x0 = lgr->extent (commonx,X_AXIS)[LEFT]; - Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT]; - + Grob * rgr = get_x_bound_grob (columns.top (), dir); + + Real x0 = robust_relative_extent (lgr, commonx, X_AXIS)[LEFT]; + Real x1 = robust_relative_extent (rgr, commonx, X_AXIS)[RIGHT]; Real w = x1 -x0; - SCM number = me->get_grob_property ("text"); + SCM number = me->get_property ("text"); - Paper_def *pap = me->get_paper (); - if (gh_string_p (number) && number_visibility) + Output_def *pap = me->get_layout (); + Stencil num; + if (scm_is_string (number) && number_visibility) { - SCM properties = Font_interface::font_alist_chain (me); - SCM snum = Text_item::interpret_markup (pap->self_scm (), properties, number); - Molecule num = *unsmob_molecule (snum); + SCM properties = Font_interface::text_font_alist_chain (me); + SCM snum = Text_interface::interpret_markup (pap->self_scm (), properties, number); + num = *unsmob_stencil (snum); num.align_to (X_AXIS, CENTER); num.translate_axis (w/2, X_AXIS); num.align_to (Y_AXIS, CENTER); num.translate_axis ((ry-ly)/2, Y_AXIS); - mol.add_molecule (num); + mol.add_stencil (num); } @@ -195,38 +198,39 @@ Tuplet_bracket::brew_molecule (SCM smob) if (bracket_visibility) { - Real lt = pap->get_realvar (ly_symbol2scm ("linethickness")); + Real ss = Staff_symbol_referencer::staff_space (me); + Real gap=0.; - SCM thick = me->get_grob_property ("thickness"); - if (gh_number_p (thick)) - lt *= gh_scm2double (thick); - - SCM gap = me->get_grob_property ("gap"); + if (!num.extent (X_AXIS).is_empty ()) + gap = num.extent (X_AXIS).length () + 1.0; - SCM fl = me->get_grob_property ("bracket-flare"); - SCM eh = me->get_grob_property ("edge-height"); - SCM sp = me->get_grob_property ("shorten-pair"); + SCM fl = me->get_property ("bracket-flare"); + SCM eh = me->get_property ("edge-height"); + SCM sp = me->get_property ("shorten-pair"); Direction d = LEFT; Drul_array height, flare, shorten; do { flare[d] = height[d] = shorten[d] = 0.0; if (is_number_pair (fl)) - flare[d] += gh_scm2double (index_get_cell (fl, d)); + flare[d] += ss * scm_to_double (index_get_cell (fl, d)); if (is_number_pair (eh)) - height[d] += gh_scm2double (index_get_cell (eh, d)) * - dir; + height[d] += - dir * ss *scm_to_double (index_get_cell (eh, d)); if (is_number_pair (sp)) - shorten[d] += gh_scm2double (index_get_cell (sp, d)); + shorten[d] += ss *scm_to_double (index_get_cell (sp, d)); } while (flip (&d) != LEFT); - Molecule brack = make_bracket (Y_AXIS, - w, ry - ly, lt, + Stencil brack = make_bracket (me, Y_AXIS, + Offset (w, ry - ly), height, - gh_scm2double (gap), - flare, - shorten); - mol.add_molecule (brack); + /* + 0.1 = more space at right due to italics + TODO: use italic correction of font. + */ + Interval (-0.5, 0.5) * gap + 0.1, + flare, shorten); + mol.add_stencil (brack); } mol.translate_axis (ly, Y_AXIS); @@ -240,15 +244,16 @@ Tuplet_bracket::brew_molecule (SCM smob) TODO: this will fail for very short (shorter than the flare) brackets. */ -Molecule -Tuplet_bracket::make_bracket (Axis protusion_axis, - Real dx, Real dy, Real thick, Drul_array height, - Real gap, +Stencil +Tuplet_bracket::make_bracket (Grob *me, // for line properties. + Axis protusion_axis, + Offset dz, + Drul_array height, + Interval gap, Drul_array flare, Drul_array shorten) { - Offset dz = Offset (dx,dy); - Drul_array corners (Offset(0,0), dz); + Drul_array corners (Offset (0,0), dz); Real length = dz.length (); Drul_array gap_corners; @@ -261,7 +266,13 @@ Tuplet_bracket::make_bracket (Axis protusion_axis, Direction d = LEFT; do { straight_corners[d] += - d * shorten[d] /length * dz; - gap_corners[d] = (dz * 0.5) + d * gap / length * dz; + } while (flip (&d) != LEFT); + + + if (gap.is_empty()) + gap = Interval (0,0); + do { + gap_corners[d] = (dz * 0.5) + gap[d] / length * dz; } while (flip (&d) != LEFT); Drul_array flare_corners = straight_corners; @@ -271,14 +282,13 @@ Tuplet_bracket::make_bracket (Axis protusion_axis, straight_corners[d][bracket_axis] += - d * flare[d]; } while (flip (&d) != LEFT); - Molecule m; + Stencil m; do { - - m.add_molecule (Lookup::line (thick, straight_corners[d], - gap_corners[d])); + m.add_stencil (Line_interface::line (me, straight_corners[d], + gap_corners[d])); - m.add_molecule (Lookup::line (thick, straight_corners[d], - flare_corners[d])); + m.add_stencil (Line_interface::line (me, straight_corners[d], + flare_corners[d])); } while (flip (&d) != LEFT); return m; @@ -295,9 +305,13 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy) Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns"); - SCM cols = me->get_grob_property ("note-columns"); + SCM cols = me->get_property ("note-columns"); Grob * commony = common_refpoint_of_list (cols, me, Y_AXIS); Grob * commonx = common_refpoint_of_list (cols, me, X_AXIS); + + Interval staff; + if (Grob * st = Staff_symbol_referencer::get_staff_symbol (me)) + staff = st->extent (commony, Y_AXIS); Direction dir = get_grob_direction (me); @@ -305,17 +319,33 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy) Use outer non-rest columns to determine slope */ int l = 0; - while (l = l && Note_column::rest_b (columns[r])) + while (r >= l && Note_column::has_rests (columns[r])) r--; if (l < r) { - *dy = columns[r]->extent (commony, Y_AXIS) [dir] - - columns[l]->extent (commony, Y_AXIS) [dir] ; + Interval rv =columns[r]->extent (commony, Y_AXIS); + Interval lv =columns[l]->extent (commony, Y_AXIS); + rv.unite (staff); + lv.unite (staff); + Real graphical_dy = rv[dir] - lv[dir]; + + Slice ls = Note_column::head_positions_interval (columns[l]); + Slice rs = Note_column::head_positions_interval (columns[r]); + + Interval musical_dy; + musical_dy[UP] = rs[UP] - ls[UP]; + musical_dy[DOWN] = rs[DOWN] - ls[DOWN]; + if (sign (musical_dy[UP]) != sign (musical_dy[DOWN])) + *dy = 0.0; + else if (sign (graphical_dy) != sign (musical_dy[DOWN])) + *dy = 0.0; + else + *dy = graphical_dy; } else * dy = 0; @@ -329,20 +359,20 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy) Grob * lgr = get_x_bound_grob (columns[0], dir); - Grob * rgr = get_x_bound_grob (columns.top(), dir); - Real x0 = lgr->extent (commonx,X_AXIS)[LEFT]; - Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT]; + Grob * rgr = get_x_bound_grob (columns.top (), dir); + Real x0 = robust_relative_extent (lgr, commonx, X_AXIS)[LEFT]; + Real x1 = robust_relative_extent (rgr, commonx, X_AXIS)[RIGHT]; - - /* - Slope. - */ + /* + Slope. + */ Real factor = columns.size () > 1 ? 1/ (x1 - x0) : 1.0; for (int i = 0; i < columns.size (); i++) { - Real notey = columns[i]->extent (commony, Y_AXIS)[dir] - - me->relative_coordinate (commony, Y_AXIS); + Interval note_ext =columns[i]->extent (commony, Y_AXIS); + note_ext.unite (staff); + Real notey = note_ext[dir] - me->relative_coordinate (commony, Y_AXIS); Real x = columns[i]->relative_coordinate (commonx, X_AXIS) - x0; Real tuplety = *dy * x * factor; @@ -352,7 +382,7 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy) } // padding - *offset += gh_scm2double (me->get_grob_property ("padding")) *dir; + *offset += scm_to_double (me->get_property ("padding")) *dir; /* @@ -374,22 +404,6 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy) } -/* - use first -> last note for slope, -*/ -void -Tuplet_bracket::calc_dy (Grob*me,Real * dy) -{ - Link_array columns= - Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns"); - - /* - ugh. refps. - */ - Direction d = get_grob_direction (me); - *dy = columns.top ()->extent (columns.top (), Y_AXIS) [d] - - columns[0]->extent (columns[0], Y_AXIS) [d]; -} /* @@ -404,14 +418,14 @@ Tuplet_bracket::before_line_breaking (SCM smob) Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-columns"); - for (int i = columns.size(); i--;) + for (int i = columns.size (); i--;) { Grob * s =Note_column::get_stem (columns[i]); Grob * b = s ? Stem::get_beam (s): 0; if (b) me->add_dependency (b); } - return SCM_UNDEFINED; + return SCM_UNSPECIFIED; } MAKE_SCHEME_CALLBACK (Tuplet_bracket,after_line_breaking,1); @@ -428,10 +442,10 @@ Tuplet_bracket::after_line_breaking (SCM smob) me->suicide (); return SCM_UNSPECIFIED; } - if (dynamic_cast (me)->broken_b ()) + if (dynamic_cast (me)->is_broken ()) { - me->warning ("Tuplet_bracket was across linebreak. Farewell cruel world."); - me->suicide(); + me->warning (_("Killing tuplet bracket across linebreak.")); + me->suicide (); return SCM_UNSPECIFIED; } @@ -456,60 +470,59 @@ Tuplet_bracket::after_line_breaking (SCM smob) } else { - SCM ps = par_beam->get_grob_property ("positions"); + SCM ps = par_beam->get_property ("positions"); - Real lp = gh_scm2double (gh_car (ps)); - Real rp = gh_scm2double (gh_cdr (ps)); + Real lp = scm_to_double (scm_car (ps)); + Real rp = scm_to_double (scm_cdr (ps)); /* duh. magic. */ - offset = lp + dir * (0.5 + gh_scm2double (me->get_grob_property ("padding"))); + offset = lp + dir * (0.5 + scm_to_double (me->get_property ("padding"))); dy = rp- lp; } - SCM lp = me->get_grob_property ("left-position"); - SCM rp = me->get_grob_property ("right-position"); + SCM lp = me->get_property ("left-position"); + SCM rp = me->get_property ("right-position"); - if (gh_number_p (lp) && !gh_number_p (rp)) + if (scm_is_number (lp) && !scm_is_number (rp)) { - rp = gh_double2scm (gh_scm2double (lp) + dy); + rp = scm_make_real (scm_to_double (lp) + dy); } - else if (gh_number_p (rp) && !gh_number_p (lp)) + else if (scm_is_number (rp) && !scm_is_number (lp)) { - lp = gh_double2scm (gh_scm2double (rp) - dy); + lp = scm_make_real (scm_to_double (rp) - dy); } - else if (!gh_number_p (rp) && !gh_number_p (lp)) + else if (!scm_is_number (rp) && !scm_is_number (lp)) { - lp = gh_double2scm (offset); - rp = gh_double2scm (offset +dy); + lp = scm_make_real (offset); + rp = scm_make_real (offset +dy); } - me->set_grob_property ("left-position", lp); - me->set_grob_property ("right-position", rp); + me->set_property ("left-position", lp); + me->set_property ("right-position", rp); return SCM_UNSPECIFIED; } /* - similar to slur. + similar to beam ? */ Direction Tuplet_bracket::get_default_dir (Grob*me) { - Direction d = UP; - for (SCM s = me->get_grob_property ("note-columns"); gh_pair_p (s); s = ly_cdr (s)) + Drul_array dirs (0,0); + for (SCM s = me->get_property ("note-columns"); scm_is_pair (s); s = scm_cdr (s)) { - Grob * nc = unsmob_grob (ly_car (s)); - if (Note_column::dir (nc) < 0) - { - d = DOWN; - break; - } + Grob * nc = unsmob_grob (scm_car (s)); + Direction d = Note_column::dir (nc); + if (d) + dirs[d]++; } - return d; + + return dirs[UP] >= dirs[DOWN] ? UP : DOWN; } void @@ -528,5 +541,5 @@ Tuplet_bracket::add_column (Grob*me, Item*n) ADD_INTERFACE (Tuplet_bracket,"tuplet-bracket-interface", "A bracket with a number in the middle, used for tuplets.", - "note-columns bracket-flare edge-height shorten-pair padding gap left-position right-position bracket-visibility number-visibility thickness direction"); + "note-columns bracket-flare edge-height shorten-pair padding left-position right-position bracket-visibility number-visibility thickness direction");