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"));
29 if (!me || !me->is_live ())
30 return SCM_UNSPECIFIED;
32 extract_grob_set (me, "stems", stems);
34 Array<Direction> dirs;
35 for (int i = 0; i < stems.size (); i++)
37 dirs.push (to_dir (stems[i]->get_property ("default-direction")));
40 int last_nonneutral = -1;
41 int next_nonneutral = 0;
42 while (next_nonneutral < dirs.size() && !dirs[next_nonneutral])
45 while (last_nonneutral < dirs.size () - 1)
47 Direction d1 = CENTER;
48 Direction d2 = CENTER;
49 if (last_nonneutral >= 0)
50 d1 = dirs[last_nonneutral];
51 if (next_nonneutral < dirs.size ())
52 d2 = dirs[next_nonneutral];
54 Direction total = CENTER;
62 total = to_dir (me->get_property ("neutral-direction"));
64 for (int i = last_nonneutral + 1; i < next_nonneutral; i++)
65 stems[i]->set_property ("neutral-direction", scm_from_int (total));
68 last_nonneutral = next_nonneutral;
69 while (last_nonneutral < dirs.size ()
70 && dirs[last_nonneutral])
72 next_nonneutral = last_nonneutral;
75 while (next_nonneutral < dirs.size ()
76 && !dirs[next_nonneutral])
81 return SCM_UNSPECIFIED;
85 Melody_spanner::add_stem (Grob *me, Grob *stem)
87 Pointer_group_interface::add_grob (me, ly_symbol2scm ("stems"), stem);
88 stem->set_object ("melody-spanner", me->self_scm ());
89 stem->set_property ("neutral-direction", Melody_spanner::calc_neutral_stem_direction_proc);
92 ADD_INTERFACE (Melody_spanner, "melody-spanner-interface",
93 "Context dependent typesetting decisions.",
96 "neutral-direction ");