2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "melody-spanner.hh"
23 #include "pointer-group-interface.hh"
26 TODO: this could be either item or spanner. For efficiency reasons,
27 let's take item for now.
31 Interpolate stem directions for neutral stems.
33 MAKE_SCHEME_CALLBACK (Melody_spanner, calc_neutral_stem_direction, 1);
35 Melody_spanner::calc_neutral_stem_direction (SCM smob)
37 Grob *stem = Grob::unsmob (smob);
38 Grob *me = Grob::unsmob (stem->get_object ("melody-spanner"));
39 if (!me || !me->is_live ())
40 return scm_from_int (DOWN);
42 extract_grob_set (me, "stems", stems);
44 vector<Direction> dirs;
45 for (vsize i = 0; i < stems.size (); i++)
46 dirs.push_back (to_dir (stems[i]->get_property ("default-direction")));
48 vsize last_nonneutral = VPOS;
49 vsize next_nonneutral = 0;
50 while (next_nonneutral != VPOS && next_nonneutral < dirs.size ()
51 && !dirs[next_nonneutral])
55 while (last_nonneutral == VPOS || last_nonneutral + 1 < dirs.size ())
57 Direction d1 = CENTER;
58 Direction d2 = CENTER;
59 if (last_nonneutral != VPOS)
60 d1 = dirs[last_nonneutral];
61 if (next_nonneutral < dirs.size ())
62 d2 = dirs[next_nonneutral];
64 Direction total = CENTER;
72 total = to_dir (me->get_property ("neutral-direction"));
74 for (vsize i = last_nonneutral + 1; i < next_nonneutral; i++)
77 retval = scm_from_int (total);
79 stems[i]->set_property ("neutral-direction", scm_from_int (total));
82 last_nonneutral = next_nonneutral;
83 while (last_nonneutral < dirs.size ()
84 && dirs[last_nonneutral])
86 next_nonneutral = last_nonneutral;
89 while (next_nonneutral < dirs.size ()
90 && !dirs[next_nonneutral])
98 Melody_spanner::add_stem (Grob *me, Grob *stem)
100 Pointer_group_interface::add_grob (me, ly_symbol2scm ("stems"), stem);
101 stem->set_object ("melody-spanner", me->self_scm ());
102 stem->set_property ("neutral-direction", Melody_spanner::calc_neutral_stem_direction_proc);
105 ADD_INTERFACE (Melody_spanner,
106 "Context dependent typesetting decisions.",