]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
* input/regression/accidental-piano.ly (Module): new file.
[lilypond.git] / lily / lookup.cc
index 667aef9431a0b3dcca41d2ff3475f048b749521f..63c37a2c9788381be89e5d86b0453a575d2ab934 100644 (file)
@@ -27,9 +27,9 @@ Stencil
 Lookup::dot (Offset p, Real radius)
 {
   SCM at = (scm_list_n (ly_symbol2scm ("dot"),
-                       gh_double2scm (p[X_AXIS]),
-                       gh_double2scm (p[Y_AXIS]),
-                       gh_double2scm (radius),
+                       scm_make_real (p[X_AXIS]),
+                       scm_make_real (p[Y_AXIS]),
+                       scm_make_real (radius),
                        SCM_UNDEFINED));
   Box box;
   box.add_point (p - Offset (radius, radius));
@@ -67,10 +67,10 @@ Lookup::beam (Real slope, Real width, Real thick, Real blot)
         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_make_real (width),
+                   scm_make_real (slope),
+                   scm_make_real (thick),
+                   scm_make_real (blot),
                    SCM_UNDEFINED);
   return Stencil (b, at);
 }
@@ -82,12 +82,12 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash)
 
   for (int i= 4; i -- ;)
     {
-      l = gh_cons (ly_offset2scm (b.control_[i]), l);
+      l = scm_cons (ly_offset2scm (b.control_[i]), l);
     }
 
   SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
-                              gh_double2scm (thick), 
-                              gh_double2scm (dash),
+                              scm_make_real (thick), 
+                              scm_make_real (dash),
                               ly_quote_scm (l),
                               SCM_UNDEFINED));
 
@@ -101,9 +101,9 @@ Stencil
 Lookup::horizontal_line (Interval w, Real th)
 {
   SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
-                      gh_double2scm (w[LEFT]), 
-                      gh_double2scm (w[RIGHT]),
-                      gh_double2scm (th),
+                      scm_make_real (w[LEFT]), 
+                      scm_make_real (w[RIGHT]),
+                      scm_make_real (th),
                       SCM_UNDEFINED);
 
 
@@ -125,10 +125,10 @@ Stencil
 Lookup::filled_box (Box b) 
 {
   SCM  at  = (scm_list_n (ly_symbol2scm ("filledbox"),
-                    gh_double2scm (-b[X_AXIS][LEFT]),
-                    gh_double2scm (b[X_AXIS][RIGHT]),                 
-                    gh_double2scm (-b[Y_AXIS][DOWN]),
-                    gh_double2scm (b[Y_AXIS][UP]),                    
+                    scm_make_real (-b[X_AXIS][LEFT]),
+                    scm_make_real (b[X_AXIS][RIGHT]),                 
+                    scm_make_real (-b[Y_AXIS][DOWN]),
+                    scm_make_real (b[Y_AXIS][UP]),                    
                     SCM_UNDEFINED));
 
   return Stencil (b,at);
@@ -159,28 +159,26 @@ Lookup::filled_box (Box b)
  * |                            |
  * |                            |
  * |<-------------------------->|
- *       Box extent(X_AXIS)
+ *       Box extent (X_AXIS)
  */
 Stencil
 Lookup::round_filled_box (Box b, Real blotdiameter)
 {
   if (b.x ().length () < blotdiameter)
     {
-      programming_error (_f ("round filled box horizontal extent smaller than blot; decreasing blot"));
       blotdiameter = b.x ().length ();
     }
   if (b.y ().length () < blotdiameter)
     {
-      programming_error (_f ("round filled box vertical extent smaller than blot; decreasing blot"));
       blotdiameter = b.y ().length ();
     }
 
   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]),
-                       gh_double2scm (b[Y_AXIS][UP]),
-                       gh_double2scm (blotdiameter),
+                       scm_make_real (-b[X_AXIS][LEFT]),
+                       scm_make_real (b[X_AXIS][RIGHT]),
+                       scm_make_real (-b[Y_AXIS][DOWN]),
+                       scm_make_real (b[Y_AXIS][UP]),
+                       scm_make_real (blotdiameter),
                        SCM_UNDEFINED));
 
   return Stencil (b,at);
@@ -202,12 +200,12 @@ Lookup::round_filled_box (Box b, Real blotdiameter)
  * touch each other will in general not work as expected for non-null
  * blotdiameter.
  *
- * (c) Given a polygon ((x0, y0), (x1, y1), ... , (x(n-1), y(n-1))),
+ * (c) Given a polygon ((x0, y0), (x1, y1), ... , (x (n-1), y (n-1))),
  * if there is a natural number k such that blotdiameter is greater
- * than the maximum of { | (x(k mod n), y(k mod n)) - (x((k+1) mod n),
- * y((k+1) mod n)) |, | (x(k mod n), y(k mod n)) - (x((k+2) mod n),
- * y((k+2) mod n)) |, | (x((k+1) mod n), y((k+1) mod n)) - (x((k+2)
- * mod n), y((k+2) mod n)) | }, then the outline of the rounded
+ * than the maximum of { | (x (k mod n), y (k mod n)) - (x ((k+1) mod n),
+ * y ((k+1) mod n)) |, | (x (k mod n), y (k mod n)) - (x ((k+2) mod n),
+ * y ((k+2) mod n)) |, | (x ((k+1) mod n), y ((k+1) mod n)) - (x ((k+2)
+ * mod n), y ((k+2) mod n)) | }, then the outline of the rounded
  * polygon will exceed the outline of the core polygon.  In other
  * words: Do not draw rounded polygons that have a leg smaller or
  * thinner than blotdiameter (or set blotdiameter to a sufficiently
@@ -218,7 +216,7 @@ Lookup::round_filled_box (Box b, Real blotdiameter)
  * to a core filled polygon.  For details of these two different
  * approaches, see the thread upon the ledger lines patch that started
  * on March 25, 2002 on the devel mailing list.  The below version of
- * round_filled_polygon() sticks to the moulding model, which the
+ * round_filled_polygon () sticks to the moulding model, which the
  * majority of the list participants finally voted for.  This,
  * however, results in the above limitations and a much increased
  * complexity of the algorithm, since it has to compute a shrinked
@@ -287,7 +285,7 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
       Offset p13n = 0.5 * (p10n + p12n);
       Offset p14n = 0.5 * (p10n - p12n);
       Offset p13;
-      Real d = p13n.length () * p14n.length (); // distance p3n to line(p1..p0)
+      Real d = p13n.length () * p14n.length (); // distance p3n to line (p1..p0)
       if (d < epsilon)
        // special case: p0, p1, p2 are on a single line => build
        // vector orthogonal to (p2-p0) of length 0.5 blotdiameter
@@ -306,14 +304,14 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
   Box box;
   for (int i = 0; i < shrinked_points.size (); i++)
     {
-      SCM x = gh_double2scm (shrinked_points[i][X_AXIS]);
-      SCM y = gh_double2scm (shrinked_points[i][Y_AXIS]);
-      shrinked_points_scm = gh_cons (x, gh_cons (y, shrinked_points_scm));
+      SCM x = scm_make_real (shrinked_points[i][X_AXIS]);
+      SCM y = scm_make_real (shrinked_points[i][Y_AXIS]);
+      shrinked_points_scm = scm_cons (x, scm_cons (y, shrinked_points_scm));
       box.add_point (points[i]);
     }
   SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
                                ly_quote_scm (shrinked_points_scm),
-                               gh_double2scm (blotdiameter),
+                               scm_make_real (blotdiameter),
                                SCM_UNDEFINED);
 
   Stencil polygon = Stencil (box, polygon_scm);
@@ -377,15 +375,15 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick)
   SCM list = SCM_EOL;
   for (int i= 8; i--;)
     {
-      list = gh_cons (scontrols[indices[i]], list);
+      list = scm_cons (scontrols[indices[i]], list);
     }
   
   
   SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
                     ly_quote_scm (list),
-                    gh_double2scm (linethick),
+                    scm_make_real (linethick),
                     SCM_UNDEFINED));
-  Box b(curve.extent (X_AXIS),
+  Box b (curve.extent (X_AXIS),
        curve.extent (Y_AXIS));
 
   b[X_AXIS].unite (back.extent (X_AXIS));
@@ -424,18 +422,18 @@ Lookup::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);
+  list = scm_cons (ly_offset2scm (bottom_curve.control_[3]), list);
+  list = scm_cons (ly_offset2scm (bottom_curve.control_[0]), list);
+  list = scm_cons (ly_offset2scm (bottom_curve.control_[1]), list);
+  list = scm_cons (ly_offset2scm (bottom_curve.control_[2]), list);
+  list = scm_cons (ly_offset2scm (top_curve.control_[0]), list);
+  list = scm_cons (ly_offset2scm (top_curve.control_[3]), list);
+  list = scm_cons (ly_offset2scm (top_curve.control_[2]), list);
+  list = scm_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_make_real (0.0),
                                    SCM_UNDEFINED);
 
   Interval x_extent = top_curve.extent (X_AXIS);
@@ -651,13 +649,13 @@ Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
 Stencil
 Lookup::repeat_slash (Real w, Real s, Real t)
 {
-  SCM wid = gh_double2scm (w);
-  SCM sl = gh_double2scm (s);
-  SCM thick = gh_double2scm (t);
+  SCM wid = scm_make_real (w);
+  SCM sl = scm_make_real (s);
+  SCM thick = scm_make_real (t);
   SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
                            wid, sl, thick, SCM_UNDEFINED);
 
-  Box b (Interval (0, w + sqrt (sqr(t/s) + sqr (t))),
+  Box b (Interval (0, w + sqrt (sqr (t/s) + sqr (t))),
         Interval (0, w * s));
 
   return Stencil (b, slashnodot); //  http://slashnodot.org
@@ -668,9 +666,9 @@ Stencil
 Lookup::bracket (Axis a, Interval iv, Real thick, Real protude, Real blot)
 {
   Box b;
-  Axis other = Axis((a+1)%2);
+  Axis other = Axis ((a+1)%2);
   b[a] = iv;
-  b[other] = Interval(-1, 1) * thick * 0.5;
+  b[other] = Interval (-1, 1) * thick * 0.5;
   
   Stencil m =  round_filled_box (b, blot);
 
@@ -693,48 +691,50 @@ Lookup::triangle (Interval iv, Real thick, Real protude)
   b[Y_AXIS] = Interval (0 <? protude , 0 >? protude);
 
   SCM s = scm_list_n (ly_symbol2scm ("symmetric-x-triangle"),
-                     gh_double2scm (thick),
-                     gh_double2scm (iv.length()), 
-                     gh_double2scm (protude), SCM_UNDEFINED);
+                     scm_make_real (thick),
+                     scm_make_real (iv.length ()), 
+                     scm_make_real (protude), SCM_UNDEFINED);
 
-  return Stencil (b, s);
+  Stencil stc (b, s);
+  stc.translate_axis (iv[LEFT], X_AXIS);
+  return stc;  
 }
 
 
-/*
-  TODO: use rounded boxes.
- */
-LY_DEFINE(ly_bracket ,"ly:bracket",
+LY_DEFINE (ly_bracket ,"ly:bracket",
          4, 0, 0,
          (SCM a, SCM iv, SCM t, SCM p),
          "Make a bracket in direction @var{a}. The extent of the bracket is " 
          "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(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") ;
+  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 (scm_is_number (t), a, SCM_ARG3, __FUNCTION__, "number") ;
+  SCM_ASSERT_TYPE (scm_is_number (p), a, SCM_ARG4, __FUNCTION__, "number") ;
 
 
-  return Lookup::bracket ((Axis)gh_scm2int (a), ly_scm2interval (iv),
-                         gh_scm2double (t),
-                         gh_scm2double (p),
-                         gh_scm2double (t)).smobbed_copy ();
+  return Lookup::bracket ((Axis)scm_to_int (a), ly_scm2interval (iv),
+                         scm_to_double (t),
+                         scm_to_double (p),
+                         0.95 * scm_to_double (t)).smobbed_copy ();
 }
 
 
 
-LY_DEFINE(ly_filled_box ,"ly:round-filled-box",
+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}.")
+         "Make a @code{Stencil} "
+         "that prints a black 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") ;
+  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 (scm_is_number (blot), blot, SCM_ARG3, __FUNCTION__, "number") ;
 
   return Lookup::round_filled_box (Box (ly_scm2interval (xext), ly_scm2interval (yext)),
-                                  gh_scm2double (blot)).smobbed_copy ();
+                                  scm_to_double (blot)).smobbed_copy ();
 }