source file of the GNU LilyPond music typesetter
- (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include "molecule.hh"
#include <math.h>
-SCM
-Line_spanner::line_atom (Grob* me, Real dx, Real dy)
+
+/*
+ slightishly clumsy interface?
+
+ Make a Scheme expression for a line going from (0,0) to (dx,dy).
+ */
+
+static SCM
+line_atom (Grob* me, Real thick, Real dx, Real dy)
{
SCM type = me->get_grob_property ("type");
Real staff_space = Staff_symbol_referencer::staff_space (me);
- Real thick = me->paper_l ()->get_var ("stafflinethickness");
-
- SCM s = me->get_grob_property ("line-thickness");
- if (gh_number_p (s))
- thick *= gh_scm2double (s);
// maybe these should be in line-thickness?
Real length = staff_space;
- s = me->get_grob_property ("dash-length");
+ SCM s = me->get_grob_property ("dash-length");
if (gh_number_p (s))
length = gh_scm2double (s) * staff_space;
Real on = length - thick;
Real off = period - on;
- SCM list = gh_list (ly_symbol2scm ("dashed-line"),
+ SCM list = scm_list_n (ly_symbol2scm ("dashed-line"),
gh_double2scm (thick),
gh_double2scm (on),
gh_double2scm (off),
return list;
}
+static SCM
+zigzag_atom (Grob* me, Real thick, Real dx, Real dy)
+{
+ Real staff_space = Staff_symbol_referencer::staff_space (me);
+ SCM ws = me->get_grob_property ("zigzag-width");
+ SCM ls = me->get_grob_property ("zigzag-length");
+ double w = (gh_number_p(ws) ? gh_scm2double(ws) : 1)*staff_space;
+ double l = (gh_number_p(ls) ? gh_scm2double(ls) : 1)*w;
+ double h = l>w/2 ? sqrt(l*l-w*w/4) : 0;
+
+ SCM list = scm_list_n (ly_symbol2scm ("zigzag-line"),
+ gh_bool2scm (true),
+ gh_double2scm (w),
+ gh_double2scm (h),
+ gh_double2scm (thick),
+ gh_double2scm (dx),
+ gh_double2scm (dy),
+ SCM_UNDEFINED);
+
+ return list;
+}
+
+
+
Molecule
-Line_spanner::line_molecule (Grob* me, Real dx, Real dy)
+Line_spanner::line_molecule (Grob* me, Real thick, Real dx, Real dy)
{
Molecule mol;
SCM type = me->get_grob_property ("type");
|| type == ly_symbol2scm ("dotted-line")
|| (type == ly_symbol2scm ("trill") && dy != 0)))
{
- Box b (Interval (0, dx), Interval (0, dy));
- mol = Molecule (b, line_atom (me, dx, dy));
+ Box b (Interval (-0.5* thick + (0 <? dx) ,0.5* thick+ (0 >? dx)),
+ Interval (- 0.5* thick + (0<? dy), 0.5*thick + (0 >? dy)));
+ mol = Molecule (b, line_atom (me, thick, dx, dy));
+ }
+ else if (gh_symbol_p (type)
+ && type == ly_symbol2scm ("zigzag"))
+ {
+ // TODO:
+ Box b (Interval (-0.5* thick + (0 <? dx) ,0.5* thick+ (0 >? dx)),
+ Interval (- 0.5* thick + (0<? dy), 0.5*thick + (0 >? dy)));
+ mol = Molecule (b, zigzag_atom (me, thick, dx, dy));
+
}
else if (gh_symbol_p (type)
&& type == ly_symbol2scm ("trill"))
{
SCM alist_chain = Font_interface::font_alist_chain (me);
- SCM style_chain = gh_list (gh_cons (ly_symbol2scm ("font-family"),
+ SCM style_chain = scm_list_n (gh_cons (ly_symbol2scm ("font-family"),
ly_symbol2scm ("music")),
SCM_UNDEFINED);
Font_metric *fm = Font_interface::get_font (me,
- gh_list (style_chain,
+ scm_list_n (style_chain,
alist_chain,
SCM_UNDEFINED));
Molecule m = fm->find_by_name ("scripts-trill-element");
do
- mol.add_at_edge (X_AXIS, RIGHT, m, 0);
+ mol.add_at_edge (X_AXIS, RIGHT, m, 0,0);
while (m.extent (X_AXIS).length ()
&& mol.extent (X_AXIS).length ()
+ m.extent (X_AXIS).length () < dx);
if (!bound->break_status_dir ())
{
Grob *common[] = {
- bound->common_refpoint (Staff_symbol_referencer::staff_symbol_l (me),
+ bound->common_refpoint (Staff_symbol_referencer::get_staff_symbol (me),
X_AXIS),
- bound->common_refpoint (Staff_symbol_referencer::staff_symbol_l (me),
+ bound->common_refpoint (Staff_symbol_referencer::get_staff_symbol (me),
Y_AXIS)
};
the unbroken line-spanner would have had.
From slur */
Offset o;
- if (Spanner *mother = dynamic_cast<Spanner*> (me->original_l_))
+ if (Spanner *mother = dynamic_cast<Spanner*> (me->original_))
{
- for (int i = dir == LEFT ? 0 : mother->broken_into_l_arr_.size () - 1;
- dir == LEFT ? i < mother->broken_into_l_arr_.size () : i > 0;
+ for (int i = dir == LEFT ? 0 : mother->broken_intos_.size () - 1;
+ dir == LEFT ? i < mother->broken_intos_.size () : i > 0;
dir == LEFT ? i++ : i--)
{
- if (mother->broken_into_l_arr_[i - dir] == me)
+ if (mother->broken_intos_[i - dir] == me)
{
- Grob *neighbour = mother->broken_into_l_arr_[i];
+ Grob *neighbour = mother->broken_intos_[i];
Offset neighbour_o = get_broken_offset (neighbour, dir);
Offset me_o = get_broken_offset (me, -dir);
// Hmm, why not return me_o[X], but recalc in brew_mol?
Y_AXIS));
}
+
+ Real thick = me->get_paper ()->get_var ("linethickness");
+
+ SCM s = me->get_grob_property ("thickness");
+ if (gh_number_p (s))
+ thick *= gh_scm2double (s);
+
- Molecule line = line_molecule (me, dxy[X_AXIS], dxy[Y_AXIS]);
+ Molecule line = line_molecule (me, thick, dxy[X_AXIS], dxy[Y_AXIS]);
line.translate_axis (bound[LEFT]->extent (bound[LEFT],
X_AXIS).length ()/2, X_AXIS);
line.translate (ofxy - my_off + his_off);
}
+
+ADD_INTERFACE (Line_spanner, "line-spanner-interface",
+ "Generic line drawn between two objects, eg. for use with glissandi.\n"
+"gap is measured in staff-spaces.\n"
+"The property 'type is one of: line, dashed-line, trill, dotted-line or zigzag.\n"
+"\n",
+ "gap dash-period dash-length zigzag-width zigzag-length thickness type");
+
+