X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fporrectus.cc;h=c9865f68b23bba773b74b40e41cf86f7e9433da4;hb=7cb049f7f3705e414c2a49c7cf14f43a51914c48;hp=d141b5267dbf33411eb4a931d5566f0b716b6644;hpb=d9b43b93f2c885409bafdb157138158f65cc49aa;p=lilypond.git diff --git a/lily/porrectus.cc b/lily/porrectus.cc index d141b5267d..c9865f68b2 100644 --- a/lily/porrectus.cc +++ b/lily/porrectus.cc @@ -20,6 +20,7 @@ #include "bezier.hh" #include "font-interface.hh" #include "paper-def.hh" +#include "note-head.hh" #include "math.h" // rint void @@ -82,75 +83,6 @@ Porrectus::get_right_head (Grob *me) } } -// Uugh. The following two functions are almost duplicated code from -// custos.cc, which itself is similar to code in note-head.cc. Maybe -// this should be moved to staff-symbol-referencer.cc? -Molecule -Porrectus::create_ledger_line (Interval x_extent, Grob *me) -{ - Molecule line; - Molecule slice = Font_interface::get_default_font (me)->find_by_name ("noteheads-ledgerending"); - Interval slice_x_extent = slice.extent (X_AXIS); - Interval slice_y_extent = slice.extent (Y_AXIS); - - // Create left ending of ledger line. - Molecule left_ending = slice; - left_ending.translate_axis (x_extent[LEFT] - slice_x_extent[LEFT], X_AXIS); - if (x_extent.length () > slice_x_extent.length ()) - line.add_molecule (left_ending); - - // Create right ending of ledger line. - Molecule right_ending = slice; - right_ending.translate_axis (x_extent[RIGHT] - slice_x_extent[RIGHT], - X_AXIS); - line.add_molecule (right_ending); - - // Fill out space between left and right ending of ledger line by - // lining up a series of slices in a row between them. - Molecule fill_out_slice = left_ending; - Real thick = slice_y_extent.length (); - Real delta_x = slice_x_extent.length () - thick; - Real xpos = x_extent [LEFT] + 2*delta_x + thick/2; // TODO: check: thick*2? - while (xpos <= x_extent[RIGHT]) - { - fill_out_slice.translate_axis (delta_x, X_AXIS); - line.add_molecule (fill_out_slice); - xpos += delta_x; - } - - return line; -} - -Molecule -Porrectus::create_streepjes (Grob *me, - int pos, - int interspaces, - Interval extent) -{ - Real inter_f = Staff_symbol_referencer::staff_space (me)/2; - int streepjes_i = abs (pos) < interspaces - ? 0 - : (abs (pos) - interspaces) /2; - Molecule molecule = Molecule(); - if (streepjes_i) - { - Direction dir = (Direction)sign (pos); - Molecule ledger_line (create_ledger_line (extent, me)); - ledger_line.set_empty (true); - Real offs = (Staff_symbol_referencer::on_staffline (me, pos)) - ? 0.0 - : -dir * inter_f; - for (int i = 0; i < streepjes_i; i++) - { - Molecule streep (ledger_line); - streep.translate_axis (-dir * inter_f * i * 2 + offs, - Y_AXIS); - molecule.add_molecule (streep); - } - } - return molecule; -} - MAKE_SCHEME_CALLBACK (Porrectus,brew_molecule,1); SCM Porrectus::brew_molecule (SCM smob) @@ -161,7 +93,7 @@ Porrectus::brew_molecule (SCM smob) Item *right_head = get_right_head (me); if (!left_head || !right_head) { - warning (_ ("junking lonely porrectus")); + me->warning (_ ("junking lonely porrectus")); me->suicide (); return SCM_EOL; } @@ -171,25 +103,33 @@ Porrectus::brew_molecule (SCM smob) if ((gh_symbol_p (scm_style)) && (scm_style != SCM_EOL)) style = ly_scm2string (scm_symbol_to_string (scm_style)); else { - warning (_ ("porrectus style undefined; using mensural")); + me->warning (_ ("porrectus style undefined; using mensural")); style = "mensural"; } bool solid = to_boolean (me->get_grob_property ("solid")); bool add_stem = to_boolean (me->get_grob_property ("add-stem")); - SCM stem_direction_scm = me->get_grob_property ("stem-direction"); + /* + * This property is called stem-direction (rather than direction) + * since it only refers to this grob's stem (or, more precisely, its + * "cauda"), but not the grob as a whole. + */ + SCM stem_direction_scm = me->get_grob_property ("direction"); Direction stem_direction = gh_number_p (stem_direction_scm) ? to_dir (stem_direction_scm) : DOWN; if (!stem_direction) stem_direction = DOWN; + /* + TODO: revise name. + */ bool auto_properties = to_boolean (me->get_grob_property ("auto-properties")); if (auto_properties) // determine add_stem and stem_direction automatically from durations { if (String::compare_i (style, "mensural") != 0) - warning (String("auto-property should be used for\r\n") + + me->warning (String("auto-property should be used for\r\n") + String("mensural style porrectus only; trying anyway")); int left_duration = @@ -219,7 +159,7 @@ Porrectus::brew_molecule (SCM smob) } else { - warning (String("auto-property: failed determining porrectus\r\n") + + me->warning (String("auto-property: failed determining porrectus\r\n") + String("properties due to improper durations; ") + String("using user-supplied properties")); } @@ -231,7 +171,7 @@ Porrectus::brew_molecule (SCM smob) Molecule molecule; - SCM line_thickness_scm = me->get_grob_property ("line-thickness"); + SCM line_thickness_scm = me->get_grob_property ("thickness"); Real line_thickness; if (gh_number_p (line_thickness_scm)) { @@ -242,9 +182,9 @@ Porrectus::brew_molecule (SCM smob) line_thickness = 1.0; } Real thickness = - line_thickness * me->paper_l ()->get_var ("stafflinethickness"); + line_thickness * me->paper_l ()->get_var ("linethickness"); - SCM porrectus_width_scm = me->get_grob_property ("porrectus-width"); + SCM porrectus_width_scm = me->get_grob_property ("width"); Real porrectus_width; if (gh_number_p (porrectus_width_scm)) { @@ -274,15 +214,25 @@ Porrectus::brew_molecule (SCM smob) molecule.translate_axis (left_position_f * space/2, Y_AXIS); - Molecule left_head_streepjes = - create_streepjes (me, (int)rint (left_position_f), interspaces, extent); - left_head_streepjes.translate_axis (left_position_f * space/2, Y_AXIS); - molecule.add_molecule (left_head_streepjes); + int left_pos = (int)rint (left_position_f); + if (abs (left_pos) - interspaces > 1) + { + Molecule left_head_ledger_lines = + Note_head::brew_ledger_lines (me, left_pos, interspaces, extent, true); + left_head_ledger_lines.translate_axis (left_position_f * space/2, + Y_AXIS); + molecule.add_molecule (left_head_ledger_lines); + } - Molecule right_head_streepjes = - create_streepjes (me, (int)rint (right_position_f), interspaces, extent); - right_head_streepjes.translate_axis (right_position_f * space/2, Y_AXIS); - molecule.add_molecule (right_head_streepjes); + int right_pos = (int)rint (right_position_f); + if (abs (right_pos) - interspaces > 1) + { + Molecule right_head_ledger_lines = + Note_head::brew_ledger_lines (me, right_pos, interspaces, extent, true); + right_head_ledger_lines.translate_axis (right_position_f * space/2, + Y_AXIS); + molecule.add_molecule (right_head_ledger_lines); + } return molecule.smobbed_copy(); } @@ -298,7 +248,7 @@ Porrectus::brew_vaticana_molecule (Item *me, { if (interval >= 0.0) { - warning (_ ("ascending vaticana style porrectus")); + me->warning (_ ("ascending vaticana style porrectus")); } Real space = Staff_symbol_referencer::staff_space (me); @@ -362,7 +312,7 @@ Porrectus::brew_vaticana_molecule (Item *me, if (solid) { Molecule solid_head = - brew_bezier_sandwich (top_curve, bottom_curve); + Lookup::bezier_sandwich (top_curve, bottom_curve); molecule.add_molecule (solid_head); } else // outline @@ -370,13 +320,13 @@ Porrectus::brew_vaticana_molecule (Item *me, Bezier inner_top_curve = top_curve; inner_top_curve.translate (Offset (0.0, -thickness)); Molecule top_edge = - brew_bezier_sandwich (top_curve, inner_top_curve); + Lookup::bezier_sandwich (top_curve, inner_top_curve); molecule.add_molecule(top_edge); Bezier inner_bottom_curve = bottom_curve; inner_bottom_curve.translate (Offset (0.0, +thickness)); Molecule bottom_edge = - brew_bezier_sandwich (bottom_curve, inner_bottom_curve); + Lookup::bezier_sandwich (bottom_curve, inner_bottom_curve); molecule.add_molecule(bottom_edge); // TODO: Use horizontal slope with proper slope value rather @@ -452,28 +402,28 @@ Porrectus::brew_mensural_molecule (Item *me, if (solid) { Molecule solid_head = - brew_horizontal_slope (width, corrected_slope, height); + Lookup::horizontal_slope (width, corrected_slope, height); molecule.add_molecule (solid_head); } else // outline { Molecule left_edge = - brew_horizontal_slope (thickness, corrected_slope, height); + Lookup::horizontal_slope (thickness, corrected_slope, height); molecule.add_molecule(left_edge); Molecule right_edge = - brew_horizontal_slope (thickness, corrected_slope, height); + Lookup::horizontal_slope (thickness, corrected_slope, height); right_edge.translate_axis (width-thickness, X_AXIS); right_edge.translate_axis (corrected_slope * (width-thickness), Y_AXIS); molecule.add_molecule(right_edge); Molecule bottom_edge = - brew_horizontal_slope (width, corrected_slope, thickness); + Lookup::horizontal_slope (width, corrected_slope, thickness); bottom_edge.translate_axis (-0.5*height, Y_AXIS); molecule.add_molecule (bottom_edge); Molecule top_edge = - brew_horizontal_slope (width, corrected_slope, thickness); + Lookup::horizontal_slope (width, corrected_slope, thickness); top_edge.translate_axis (+0.5*height, Y_AXIS); molecule.add_molecule (top_edge); } @@ -481,88 +431,7 @@ Porrectus::brew_mensural_molecule (Item *me, return molecule; } -/* - * Bezier Sandwich: - * - * .| - * . | - * top . | - * . curve | - * . | - * . | - * . | - * | | - * | .| - * | . - * | bottom . - * | . curve - * | . - * | . - * | . - * | . - * |. - * | - * - */ -// TODO: Move this to class Lookup? -Molecule -Porrectus::brew_bezier_sandwich (Bezier top_curve, Bezier bottom_curve) -{ - /* - Need the weird order b.o. the way PS want its arguments - */ - SCM list = SCM_EOL; - list = gh_cons (ly_offset2scm (bottom_curve.control_[3]), list); - list = gh_cons (ly_offset2scm (bottom_curve.control_[0]), list); - list = gh_cons (ly_offset2scm (bottom_curve.control_[1]), list); - list = gh_cons (ly_offset2scm (bottom_curve.control_[2]), list); - list = gh_cons (ly_offset2scm (top_curve.control_[0]), list); - list = gh_cons (ly_offset2scm (top_curve.control_[3]), list); - list = gh_cons (ly_offset2scm (top_curve.control_[2]), list); - list = gh_cons (ly_offset2scm (top_curve.control_[1]), list); - - SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"), - ly_quote_scm (list), - gh_double2scm (0.0), - SCM_UNDEFINED); - - Interval x_extent = top_curve.extent (X_AXIS); - x_extent.unite (bottom_curve.extent (X_AXIS)); - Interval y_extent = top_curve.extent (Y_AXIS); - y_extent.unite (bottom_curve.extent (Y_AXIS)); - Box b (x_extent, y_extent); - - return Molecule (b, horizontal_bend); -} -/* - * Horizontal Slope: - * - * /| ^ - * / | | - * / | | height - * / | | - * / | v - * | / - * | / - * (0,0) x /slope=dy/dx - * | / - * |/ - * - * <-----> - * width - */ -// TODO: Move this to class Lookup? -Molecule -Porrectus::brew_horizontal_slope (Real width, Real slope, Real height) -{ - SCM width_scm = gh_double2scm (width); - SCM slope_scm = gh_double2scm (slope); - SCM height_scm = gh_double2scm (height); - SCM horizontal_slope = scm_list_n (ly_symbol2scm ("beam"), - width_scm, slope_scm, - height_scm, SCM_UNDEFINED); - Box b (Interval (0, width), - Interval (-height/2, height/2 + width*slope)); - return Molecule (b, horizontal_slope); -} +ADD_INTERFACE (Porrectus,"porrectus-interface", + "A porrectus ligature, joining two note heads into a single grob.", + "left-head right-head width add-stem auto-properties solid direction");