]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/paper-score.cc (process): run get_paper_systems() only once.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 18 Apr 2005 12:06:36 +0000 (12:06 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 18 Apr 2005 12:06:36 +0000 (12:06 +0000)
* lily/line-interface.cc (make_arrow): new function. Patch by
Jonatan Liljedahl <http://kymatica.com>
(arrows): idem.

* lily/line-spanner.cc (line_stencil): add arrows.

ChangeLog
THANKS
lily/include/line-interface.hh
lily/include/paper-score.hh
lily/line-interface.cc
lily/line-spanner.cc
lily/paper-score.cc
lily/text-spanner.cc
scm/define-grob-properties.scm

index ca0f5716a7eb49af8d5d2510bc27a6cd4882bf1e..546085c1c06129d185cb361712f0f5fe6d11935d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-04-18  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * lily/paper-score.cc (process): run get_paper_systems() only once.
+
+       * lily/line-interface.cc (make_arrow): new function. Patch by
+       Jonatan Liljedahl <http://kymatica.com>
+       (arrows): idem.
+
+       * lily/line-spanner.cc (line_stencil): add arrows.
+       
+
 2005-04-18  Mathieu Giraud  <magiraud@free.fr>
 
        * input/test/chord-names-german.ly: update for italian/french chords
diff --git a/THANKS b/THANKS
index 0627e04adf3a7840f5a2150980e3854833f8e881..72677f728751f118f224b8117821f579cb8ea22c 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -21,6 +21,7 @@ Erlend Aasland
 Heikki Junes
 Jeff Smith
 John Williams
+Jonatan Liljedahl
 Juergen Reuter
 Juliusz Chroboczek
 Matthias Neeracher
index bb4a763b144f1f3a9dd4b026d1407ef69b3233b0..73b269ebb18daf4257325529fb3e313af173247b 100644 (file)
@@ -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 */
index 10f60042423cbea1ce32b96cbd60ff04042f431e..7a6b1f147294ca57efeee02863dc07e84a4acfe7 100644 (file)
@@ -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 *);
index a5c17c5ce9946e4804a7957e09e66999cc9ae065..9fd5d4ca6e2568669ae1a995b5572505ca23bc18 100644 (file)
 #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<Offset> 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")
index 3aaf75f2886d276d7f14ca8c13aa116d83691751..07bd16fcc768120be1330159731a38844503e7b2 100644 (file)
@@ -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");
 
index c6ff9edcfbd3903c002ac7d86fbbb2c4dbaf55e1..eb431864b2dd460e4cf12502cd63d00b3e9fbc09 100644 (file)
@@ -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<Column_x_positions> 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_;
 }
index 385c73a4d66eb2d84aadc6ed531ceb0a851ed2c1..aa7a95c9a71713309669c920c82fe253082509c8 100644 (file)
@@ -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);
     }
index a8563388e5f21dd392bac85c1ac8fb6c028f8b2d..6fbbdc6cc18e573d7571bf7a83c516f61e8d7c2b 100644 (file)
@@ -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: