2 melody-spanner.cc -- implement Melody_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "melody-spanner.hh"
12 #include "pointer-group-interface.hh"
15 TODO: this could be either item or spanner. For efficiency reasons,
16 let's take item for now.
21 Interpolate stem directions for neutral stems.
23 MAKE_SCHEME_CALLBACK(Melody_spanner,calc_neutral_stem_direction, 1);
25 Melody_spanner::calc_neutral_stem_direction (SCM smob)
27 Grob *stem = unsmob_grob (smob);
28 Grob *me = unsmob_grob (stem->get_object ("melody-spanner"));
30 extract_grob_set (me, "stems", stems);
32 Array<Direction> dirs;
33 for (int i = 0; i < stems.size (); i++)
35 dirs.push (to_dir (stems[i]->get_property ("default-direction")));
38 int last_nonneutral = -1;
39 int next_nonneutral = 0;
40 while (next_nonneutral < dirs.size() && !dirs[next_nonneutral])
43 while (last_nonneutral < dirs.size () - 1)
45 Direction d1 = CENTER;
46 Direction d2 = CENTER;
47 if (last_nonneutral >= 0)
48 d1 = dirs[last_nonneutral];
49 if (next_nonneutral < dirs.size ())
50 d2 = dirs[next_nonneutral];
52 Direction total = CENTER;
60 total = to_dir (me->get_property ("neutral-direction"));
62 for (int i = last_nonneutral + 1; i < next_nonneutral; i++)
63 stems[i]->set_property ("neutral-direction", scm_from_int (total));
66 last_nonneutral = next_nonneutral;
67 while (last_nonneutral < dirs.size ()
68 && dirs[last_nonneutral])
70 next_nonneutral = last_nonneutral;
73 while (next_nonneutral < dirs.size ()
74 && !dirs[next_nonneutral])
79 return SCM_UNSPECIFIED;
83 Melody_spanner::add_stem (Grob *me, Grob *stem)
85 Pointer_group_interface::add_grob (me, ly_symbol2scm ("stems"), stem);
86 stem->set_object ("melody-spanner", me->self_scm ());
87 stem->set_property ("neutral-direction", Melody_spanner::calc_neutral_stem_direction_proc);
90 ADD_INTERFACE (Melody_spanner, "melody-spanner-interface",
91 "Context dependent typesetting decisions.",
94 "neutral-direction ");