]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
2003 -> 2004
[lilypond.git] / lily / lookup.cc
index 1783f95467c40024f04cc64c5b79405b6978da3d..0d950735b0e80e8379642bbef593435f633719ab 100644 (file)
@@ -3,16 +3,14 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
   Jan Nieuwenhuizen <janneke@gnu.org>
-
-  TODO
-      Glissando
 */
 #include <math.h>
 #include <ctype.h>
 
+#include "line-interface.hh"
 #include "warn.hh"
 #include "dimensions.hh"
 #include "bezier.hh"
@@ -39,23 +37,40 @@ Lookup::dot (Offset p, Real radius)
   return Molecule (box, at);
 }
 
+
+
+/*
+ * Horizontal Slope:
+ *
+ *            /|   ^
+ *           / |   |
+ *          /  |   | height
+ *         /   |   |
+ *        /    |   v
+ *       |    /
+ *       |   /
+ * (0,0) x  /slope=dy/dx
+ *       | /
+ *       |/
+ *
+ *       <----->
+ *        width
+ */
 Molecule 
-Lookup::beam (Real slope, Real width, Real thick) 
+Lookup::beam (Real slope, Real width, Real thick, Real blot
 {
   Real height = slope * width; 
   Real min_y = (0 <? height) - thick/2;
   Real max_y = (0 >? height) + thick/2;
 
-  
-
   Box b (Interval (0, width),
         Interval (min_y, max_y));
-
   
   SCM at = scm_list_n (ly_symbol2scm ("beam"),
                    gh_double2scm (width),
                    gh_double2scm (slope),
                    gh_double2scm (thick),
+                   gh_double2scm (blot),
                    SCM_UNDEFINED);
   return Molecule (b, at);
 }
@@ -80,23 +95,21 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash)
   return   Molecule (box, at);
 }
 
+
+
 Molecule
-Lookup::line (Real th, Offset f, Offset t)
+Lookup::horizontal_line (Interval w, Real th)
 {
-  SCM at = (scm_list_n (ly_symbol2scm ("draw-line"),
-                       gh_double2scm (th), 
-                       gh_double2scm (f[X_AXIS]),
-                       gh_double2scm (f[Y_AXIS]),
-                       gh_double2scm (t[X_AXIS]),
-                       gh_double2scm (t[Y_AXIS]),
-                       SCM_UNDEFINED));
+  SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
+                      gh_double2scm (w[LEFT]), 
+                      gh_double2scm (w[RIGHT]),
+                      gh_double2scm (th),
+                      SCM_UNDEFINED);
 
-  Box box;
-  box.add_point (f);
-  box.add_point (t);
 
-  box[X_AXIS].widen (th/2);
-  box[Y_AXIS].widen (th/2);  
+  Box box ;
+  box[X_AXIS] = w;
+  box[Y_AXIS] = Interval (-th/2,th/2);
 
   return Molecule (box, at);
 }
@@ -105,11 +118,11 @@ Lookup::line (Real th, Offset f, Offset t)
 Molecule
 Lookup::blank (Box b) 
 {
-  return Molecule (b, SCM_EOL);
+  return Molecule (b, scm_makfrom0str (""));
 }
 
 Molecule
-Lookup::filledbox (Box b) 
+Lookup::filled_box (Box b) 
 {
   SCM  at  = (scm_list_n (ly_symbol2scm ("filledbox"),
                     gh_double2scm (-b[X_AXIS][LEFT]),
@@ -149,7 +162,7 @@ Lookup::filledbox (Box b)
  *       Box extent(X_AXIS)
  */
 Molecule
-Lookup::roundfilledbox (Box b, Real blotdiameter)
+Lookup::round_filled_box (Box b, Real blotdiameter)
 {
   if (b.x ().length () < blotdiameter)
     {
@@ -162,7 +175,7 @@ Lookup::roundfilledbox (Box b, Real blotdiameter)
       blotdiameter = b.y ().length ();
     }
 
-  SCM at = (scm_list_n (ly_symbol2scm ("roundfilledbox"),
+  SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
                        gh_double2scm (-b[X_AXIS][LEFT]),
                        gh_double2scm (b[X_AXIS][RIGHT]),
                        gh_double2scm (-b[Y_AXIS][DOWN]),
@@ -173,6 +186,8 @@ Lookup::roundfilledbox (Box b, Real blotdiameter)
   return Molecule (b,at);
 }
 
+         
+
 /*
  * Create Molecule that represents a filled polygon with round edges.
  *
@@ -238,7 +253,7 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
   if (points.size () == 1)
     return dot (points[0], 0.5 * blotdiameter);
   if (points.size () == 2)
-    return line (blotdiameter, points[0], points[1]);
+    return Line_interface::make_line (blotdiameter, points[0], points[1]);
 
   /* shrink polygon in size by 0.5 * blotdiameter */
   Array<Offset> shrinked_points;
@@ -297,7 +312,7 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
       box.add_point (points[i]);
     }
   SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
-                               ly_quote_scm (ly_quote_scm (shrinked_points_scm)),
+                               ly_quote_scm (shrinked_points_scm),
                                gh_double2scm (blotdiameter),
                                SCM_UNDEFINED);
 
@@ -306,8 +321,12 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
   return polygon;
 }
 
+
+/*
+  TODO: deprecate?
+ */
 Molecule
-Lookup::frame (Box b, Real thick)
+Lookup::frame (Box b, Real thick, Real blot)
 {
   Molecule m;
   Direction d = LEFT;
@@ -321,12 +340,11 @@ Lookup::frame (Box b, Real thick)
          edges[o][DOWN] = b[o][DOWN] - thick/2;
          edges[o][UP] = b[o][UP] + thick/2;      
          
-         m.add_molecule (filledbox (edges));
+         m.add_molecule (round_filled_box (edges, blot));
        }
       while (flip (&d) != LEFT);
     }
   return m;
-  
 }
 
 /*
@@ -363,7 +381,7 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick)
     }
   
   
-  SCM at = (scm_list_n (ly_symbol2scm ("bezier-bow"),
+  SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
                     ly_quote_scm (list),
                     gh_double2scm (linethick),
                     SCM_UNDEFINED));
@@ -429,37 +447,6 @@ Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
   return Molecule (b, horizontal_bend);
 }
 
-/*
- * Horizontal Slope:
- *
- *            /|   ^
- *           / |   |
- *          /  |   | height
- *         /   |   |
- *        /    |   v
- *       |    /
- *       |   /
- * (0,0) x  /slope=dy/dx
- *       | /
- *       |/
- *
- *       <----->
- *        width
- */
-Molecule
-Lookup::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);
-}
-
 /*
   TODO: junk me.
  */
@@ -676,23 +663,24 @@ Lookup::repeat_slash (Real w, Real s, Real t)
   return Molecule (b, slashnodot); //  http://slashnodot.org
 }
 
+
 Molecule
-Lookup::bracket (Axis a, Interval iv, Real thick, Real protude)
+Lookup::bracket (Axis a, Interval iv, Real thick, Real protude, Real blot)
 {
   Box b;
   Axis other = Axis((a+1)%2);
   b[a] = iv;
   b[other] = Interval(-1, 1) * thick * 0.5;
   
-  Molecule m =  filledbox (b);
+  Molecule m =  round_filled_box (b, blot);
 
   b[a] = Interval (iv[UP] - thick, iv[UP]);
   Interval oi = Interval (-thick/2, thick/2 + fabs (protude)) ;
   oi *=  sign (protude);
   b[other] = oi;
-  m.add_molecule (filledbox (b));
+  m.add_molecule (round_filled_box (b, blot));
   b[a] = Interval (iv[DOWN], iv[DOWN]  +thick);
-  m.add_molecule (filledbox(b));
+  m.add_molecule (round_filled_box (b,blot));
 
   return m;
 }
@@ -723,14 +711,30 @@ LY_DEFINE(ly_bracket ,"ly:bracket",
          "given by @var{iv}. The wings protude by an amount of @var{p}, which "
          "may be negative. The thickness is given by @var{t}.")
 {
-  SCM_ASSERT_TYPE(ly_axis_p (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
-  SCM_ASSERT_TYPE(ly_number_pair_p (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
+  SCM_ASSERT_TYPE(is_axis (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
+  SCM_ASSERT_TYPE(is_number_pair (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
   SCM_ASSERT_TYPE(gh_number_p (t), a, SCM_ARG3, __FUNCTION__, "number") ;
   SCM_ASSERT_TYPE(gh_number_p (p), a, SCM_ARG4, __FUNCTION__, "number") ;
 
 
   return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
                          gh_scm2double (t),
-                         gh_scm2double (p)).smobbed_copy ();
+                         gh_scm2double (p),
+                         gh_scm2double (t)).smobbed_copy ();
 }
-  
+
+
+
+LY_DEFINE(ly_filled_box ,"ly:round-filled-box",
+         3, 0, 0,
+         (SCM xext, SCM yext, SCM blot),
+         "Make a filled-box of dimensions @var{xext}, @var{yext} and roundness @var{blot}.")
+{
+  SCM_ASSERT_TYPE(is_number_pair (xext), xext, SCM_ARG1, __FUNCTION__, "number pair") ;
+  SCM_ASSERT_TYPE(is_number_pair (yext), yext, SCM_ARG2, __FUNCTION__, "number pair") ;
+  SCM_ASSERT_TYPE(gh_number_p (blot), blot, SCM_ARG3, __FUNCTION__, "number") ;
+
+  return Lookup::round_filled_box (Box (ly_scm2interval (xext), ly_scm2interval (yext)),
+                                  gh_scm2double (blot)).smobbed_copy ();
+}
+