X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flookup.cc;h=157b474ade2f5ec19bc07b1bd7310c98efced1a7;hb=b9b40f154d0dfa9c3fcd44028bd8b745b87e4873;hp=b01db45413ca14b3f931ec242ae3804dacf7dc76;hpb=d4e71555e7e093a4da32d92378f8f475fa0d6aaa;p=lilypond.git diff --git a/lily/lookup.cc b/lily/lookup.cc index b01db45413..157b474ade 100644 --- a/lily/lookup.cc +++ b/lily/lookup.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2001 Han-Wen Nienhuys + (c) 1997--2002 Han-Wen Nienhuys Jan Nieuwenhuizen @@ -37,7 +37,7 @@ Lookup::beam (Real slope, Real width, Real thick) Interval (min_y, max_y)); - SCM at = gh_list (ly_symbol2scm ("beam"), + SCM at = scm_list_n (ly_symbol2scm ("beam"), gh_double2scm (width), gh_double2scm (slope), gh_double2scm (thick), @@ -45,8 +45,6 @@ Lookup::beam (Real slope, Real width, Real thick) return Molecule (b, at); } - - Molecule Lookup::dashed_slur (Bezier b, Real thick, Real dash) { @@ -57,7 +55,7 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash) l = gh_cons (ly_offset2scm (b.control_[i]), l); } - SCM at = (gh_list (ly_symbol2scm ("dashed-slur"), + SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"), gh_double2scm (thick), gh_double2scm (dash), ly_quote_scm (l), @@ -67,7 +65,26 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash) return Molecule (box, at); } - +Molecule +Lookup::line (Real th, Offset f, Offset t) +{ + 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)); + + Box box; + box.add_point (f); + box.add_point (t); + + box[X_AXIS].widen (th/2); + box[Y_AXIS].widen (th/2); + + return Molecule (box, at); +} Molecule @@ -76,11 +93,10 @@ Lookup::blank (Box b) return Molecule (b, SCM_EOL); } - Molecule Lookup::filledbox (Box b) { - SCM at = (gh_list (ly_symbol2scm ("filledbox"), + 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]), @@ -90,6 +106,58 @@ Lookup::filledbox (Box b) return Molecule (b,at); } +/* + * round filled box: + * + * __________________________________ + * / \ ^ / \ ^ + * | |blot | | + * | | |dia | | | + * | |meter | | + * |\ _ _ / v \ _ _ /| | + * | | | + * | | | Box + * | <------>| | extent + * | blot | | (Y_AXIS) + * | diameter| | + * | | | + * | _ _ _ _ | | + * |/ \ / \| | + * | | | + * | | | | | + * | | | + * x\_____/______________\_____/|_____v + * |(0,0) | + * | | + * | | + * |<-------------------------->| + * Box extent(X_AXIS) + */ +Molecule +Lookup::roundfilledbox (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 ("roundfilledbox"), + 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_UNDEFINED)); + + return Molecule (b,at); +} + Molecule Lookup::frame (Box b, Real thick) { @@ -107,7 +175,6 @@ 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)); } while (flip (&d) != LEFT); @@ -116,7 +183,6 @@ Lookup::frame (Box b, Real thick) } - /* Make a smooth curve along the points */ @@ -125,11 +191,14 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick) { Real alpha = (curve.control_[3] - curve.control_[0]).arg (); Bezier back = curve; - + Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI/2)) * 0.5; back.reverse (); - back.control_[1] += curvethick * complex_exp (Offset (0, alpha + M_PI/2)); - back.control_[2] += curvethick * complex_exp (Offset (0, alpha + M_PI/2)); + back.control_[1] += perp; + back.control_[2] += perp; + curve.control_[1] -= perp; + curve.control_[2] -= perp; + SCM scontrols[8]; for (int i=4; i--;) @@ -148,21 +217,112 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick) } - SCM at = (gh_list (ly_symbol2scm ("bezier-sandwich"), + SCM at = (scm_list_n (ly_symbol2scm ("bezier-bow"), ly_quote_scm (list), gh_double2scm (linethick), SCM_UNDEFINED)); + Box b(curve.extent (X_AXIS), + curve.extent (Y_AXIS)); + + b[X_AXIS].unite (back.extent (X_AXIS)); + b[Y_AXIS].unite (back.extent (Y_AXIS)); - Box b (curve.extent (X_AXIS), curve.extent (Y_AXIS)); return Molecule (b, at); } +/* + * Bezier Sandwich: + * + * .| + * . | + * top . | + * . curve | + * . | + * . | + * . | + * | | + * | .| + * | . + * | bottom . + * | . curve + * | . + * | . + * | . + * | . + * |. + * | + * + */ +Molecule +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); + + 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 + */ +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. + */ Molecule Lookup::accordion (SCM s, Real staff_space, Font_metric *fm) { Molecule m; - String sym = ly_scm2string (gh_car (s)); - String reg = ly_scm2string (gh_car (gh_cdr (s))); + String sym = ly_scm2string (ly_car (s)); + String reg = ly_scm2string (ly_car (ly_cdr (s))); if (sym == "Discant") { @@ -355,21 +515,60 @@ Lookup::accordion (SCM s, Real staff_space, Font_metric *fm) return m; } -/* - TODO: should use slope instead? Angle gives nasty rad <-> degree - conversions. -*/ Molecule 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 slashnodot = gh_list (ly_symbol2scm ("repeat-slash"), + 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))), Interval (0, w * s)); - return Molecule (b, slashnodot); + return Molecule (b, slashnodot); // http://slashnodot.org } + +Molecule +Lookup::bracket (Axis a, Interval iv, Real thick, Real protude) +{ + Box b; + Axis other = Axis((a+1)%2); + b[a] = iv; + b[other] = Interval(-1, 1) * thick * 0.5; + + Molecule m = filledbox (b); + + 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)); + b[a] = Interval (iv[DOWN], iv[DOWN] +thick); + m.add_molecule (filledbox(b)); + + return m; +} + +/* + TODO: use rounded boxes. + */ +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(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(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 (); +} +