From: Han-Wen Nienhuys Date: Mon, 18 Apr 2005 12:06:36 +0000 (+0000) Subject: * lily/paper-score.cc (process): run get_paper_systems() only once. X-Git-Tag: release/2.5.20~17 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=080c1fe99ec0f9ce1df0ef0b6786641a5827298c;p=lilypond.git * lily/paper-score.cc (process): run get_paper_systems() only once. * lily/line-interface.cc (make_arrow): new function. Patch by Jonatan Liljedahl (arrows): idem. * lily/line-spanner.cc (line_stencil): add arrows. --- diff --git a/ChangeLog b/ChangeLog index ca0f5716a7..546085c1c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-04-18 Han-Wen Nienhuys + + * lily/paper-score.cc (process): run get_paper_systems() only once. + + * lily/line-interface.cc (make_arrow): new function. Patch by + Jonatan Liljedahl + (arrows): idem. + + * lily/line-spanner.cc (line_stencil): add arrows. + + 2005-04-18 Mathieu Giraud * input/test/chord-names-german.ly: update for italian/french chords diff --git a/THANKS b/THANKS index 0627e04adf..72677f7287 100644 --- a/THANKS +++ b/THANKS @@ -21,6 +21,7 @@ Erlend Aasland Heikki Junes Jeff Smith John Williams +Jonatan Liljedahl Juergen Reuter Juliusz Chroboczek Matthias Neeracher diff --git a/lily/include/line-interface.hh b/lily/include/line-interface.hh index bb4a763b14..73b269ebb1 100644 --- a/lily/include/line-interface.hh +++ b/lily/include/line-interface.hh @@ -17,6 +17,12 @@ struct Line_interface static bool has_interface (Grob *); static Stencil make_dashed_line (Real th, Offset from, Offset to, Real, Real); static Stencil make_line (Real th, Offset from, Offset to); + static Stencil make_arrow (Offset beg, Offset end, Real thick, + Real length, Real width); + static Stencil arrows (Grob *me, Offset from, Offset to, + bool from_arrow, + bool to_arrow); + }; #endif /* LINE_INTERFACE_HH */ diff --git a/lily/include/paper-score.hh b/lily/include/paper-score.hh index 10f6004242..7a6b1f1472 100644 --- a/lily/include/paper-score.hh +++ b/lily/include/paper-score.hh @@ -18,6 +18,7 @@ class Paper_score : public Music_output Output_def *layout_; System *system_; SCM systems_; + SCM paper_systems_; public: Paper_score (Output_def *); diff --git a/lily/line-interface.cc b/lily/line-interface.cc index a5c17c5ce9..9fd5d4ca6e 100644 --- a/lily/line-interface.cc +++ b/lily/line-interface.cc @@ -12,6 +12,30 @@ #include "lookup.hh" #include "output-def.hh" +Stencil +Line_interface::make_arrow (Offset beg, Offset end, + Real thick, + Real length, Real width) +{ + Real angle = (end - beg).arg(); + Array points; + + //construct the arrow + points.push (Offset (0, 0)); + points.push (Offset (length, width)); + points.push (Offset (length, -width)); + + // rotate and translate the arrow + for (int i = 0; i < points.size(); i++) + points[i] = points[i] * complex_exp (Offset (0, angle)) + beg; + + // we must shorten the line half of arrow length + // to prevent the line from sticking out + beg = beg + Offset (length/2,0) * complex_exp (Offset (0, angle)); + + return (Lookup::round_filled_polygon (points, thick)); +} + Stencil Line_interface::make_dashed_line (Real thick, Offset from, Offset to, Real dash_period, Real dash_fraction) @@ -61,6 +85,30 @@ Line_interface::make_line (Real th, Offset from, Offset to) return Stencil (box, at); } +Stencil +Line_interface::arrows (Grob *me, Offset from, Offset to, + bool from_arrow, + bool to_arrow) +{ + Stencil a; + if (from_arrow || to_arrow) + { + Real thick = Staff_symbol_referencer::line_thickness (me) + * robust_scm2double (me->get_property ("thickness"), 1); + Real len = robust_scm2double (me->get_property ("arrow-length"), 1.3); + Real wid = robust_scm2double (me->get_property ("arrow-width"), 0.5); + + if (to_arrow) + a.add_stencil (make_arrow (from, to, thick, len, wid)); + + if (from_arrow) + a.add_stencil (make_arrow (to, from, thick, len, wid)); + } + + return a; +} + + Stencil Line_interface::line (Grob *me, Offset from, Offset to) { @@ -69,6 +117,8 @@ Line_interface::line (Grob *me, Offset from, Offset to) SCM type = me->get_property ("style"); + Stencil l; + SCM dash_fraction = me->get_property ("dash-fraction"); if (scm_is_number (dash_fraction) || type == ly_symbol2scm ("dotted-line")) { @@ -85,12 +135,14 @@ Line_interface::line (Grob *me, Offset from, Offset to) if (period < 0) return Stencil (); - return make_dashed_line (thick, from, to, period, fraction); + l = make_dashed_line (thick, from, to, period, fraction); } else { - return make_line (thick, from, to); + l = make_line (thick, from, to); } + + return l; } ADD_INTERFACE (Line_interface, "line-interface", @@ -101,4 +153,4 @@ ADD_INTERFACE (Line_interface, "line-interface", "produced. If @code{dash-fraction} is negative, the line is made " "transparent.", - "dash-period dash-fraction thickness style") + "dash-period dash-fraction thickness style arrow-length arrow-width") diff --git a/lily/line-spanner.cc b/lily/line-spanner.cc index 3aaf75f288..07bd16fcc7 100644 --- a/lily/line-spanner.cc +++ b/lily/line-spanner.cc @@ -95,6 +95,9 @@ Line_spanner::line_stencil (Grob *me, { Offset dz = to -from; SCM type = me->get_property ("style"); + + Stencil line; + if (scm_is_symbol (type) && (type == ly_symbol2scm ("line") || type == ly_symbol2scm ("dashed-line") @@ -102,7 +105,7 @@ Line_spanner::line_stencil (Grob *me, || type == ly_symbol2scm ("zigzag") || (type == ly_symbol2scm ("trill") && dz[Y_AXIS] != 0))) { - return (type == ly_symbol2scm ("zigzag")) + line = (type == ly_symbol2scm ("zigzag")) ? zigzag_stencil (me, from, to) : Line_interface::line (me, from, to); } @@ -135,8 +138,12 @@ Line_spanner::line_stencil (Grob *me, + mol.extent (Y_AXIS).length ()) / 2, Y_AXIS); mol.translate (from); - return mol; + line = mol; } + + if (to_boolean (me->get_property ("arrow"))) + line.add_stencil (Line_interface::arrows (me, from, to, false, true)); + return Stencil (); } @@ -288,5 +295,5 @@ ADD_INTERFACE (Line_spanner, "line-spanner-interface", "@code{dashed-line}, @code{trill}, \n" "@code{dotted-line} or @code{zigzag}.\n" "\n", - "gap zigzag-width zigzag-length thickness"); + "gap zigzag-width zigzag-length thickness arrow"); diff --git a/lily/paper-score.cc b/lily/paper-score.cc index c6ff9edcfb..eb431864b2 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -26,6 +26,7 @@ Paper_score::Paper_score (Output_def *layout) layout_ = layout; system_ = 0; systems_ = SCM_EOL; + paper_systems_ = SCM_EOL; } Paper_score::Paper_score (Paper_score const &s) @@ -39,6 +40,7 @@ void Paper_score::derived_mark () const { scm_gc_mark (systems_); + scm_gc_mark (paper_systems_); } void @@ -89,7 +91,8 @@ Paper_score::process () Array breaking = calc_breaking (); system_->break_into_pieces (breaking); - system_->get_paper_systems (); + + paper_systems_ = system_->get_paper_systems (); } System * @@ -108,5 +111,5 @@ Paper_score::layout () const SCM Paper_score::get_systems () const { - return root_system ()->get_paper_systems (); + return paper_systems_; } diff --git a/lily/text-spanner.cc b/lily/text-spanner.cc index 385c73a4d6..aa7a95c9a7 100644 --- a/lily/text-spanner.cc +++ b/lily/text-spanner.cc @@ -148,7 +148,8 @@ Text_spanner::print (SCM smob) if (!span_points.is_empty ()) { - Stencil l = Line_spanner::line_stencil (me, Offset (span_points[LEFT], 0), + Stencil l = Line_spanner::line_stencil (me, + Offset (span_points[LEFT], 0), Offset (span_points[RIGHT], 0)); m.add_stencil (l); } diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index a8563388e5..6fbbdc6cc1 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -147,6 +147,10 @@ negative, no line is drawn at all.") dash-period. Should be between 0.0 (no line) and 1.0 (continuous line).") + (arrow ,boolean? "Add an arrow to the line.") + (arrow-length ,number? "Arrow length.") + (arrow-width ,number? "Arrow width.") + ;; todo: why is this tunable? (dir-function ,procedure? "The function to determine the direction of a beam. Choices include: