]> git.donarmstrong.com Git - lilypond.git/blob - lily/melody-spanner.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / melody-spanner.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
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.
11
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.
16
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/>.
19 */
20
21 #include "melody-spanner.hh"
22 #include "grob.hh"
23 #include "pointer-group-interface.hh"
24
25 using std::vector;
26
27 /*
28   TODO: this could be either item or spanner. For efficiency reasons,
29   let's take item for now.
30 */
31
32 /*
33   Interpolate stem directions for neutral stems.
34  */
35 MAKE_SCHEME_CALLBACK (Melody_spanner, calc_neutral_stem_direction, 1);
36 SCM
37 Melody_spanner::calc_neutral_stem_direction (SCM smob)
38 {
39   Grob *stem = unsmob<Grob> (smob);
40   Grob *me = unsmob<Grob> (stem->get_object ("melody-spanner"));
41   if (!me || !me->is_live ())
42     return scm_from_int (DOWN);
43
44   extract_grob_set (me, "stems", stems);
45
46   vector<Direction> dirs;
47   for (vsize i = 0; i < stems.size (); i++)
48     dirs.push_back (to_dir (stems[i]->get_property ("default-direction")));
49
50   vsize last_nonneutral = VPOS;
51   vsize next_nonneutral = 0;
52   while (next_nonneutral != VPOS && next_nonneutral < dirs.size ()
53          && !dirs[next_nonneutral])
54     next_nonneutral++;
55
56   SCM retval = SCM_EOL;
57   while (last_nonneutral == VPOS || last_nonneutral + 1 < dirs.size ())
58     {
59       Direction d1 = CENTER;
60       Direction d2 = CENTER;
61       if (last_nonneutral != VPOS)
62         d1 = dirs[last_nonneutral];
63       if (next_nonneutral < dirs.size ())
64         d2 = dirs[next_nonneutral];
65
66       Direction total = CENTER;
67       if (d1 && d1 == d2)
68         total = d1;
69       else if (d1 && !d2)
70         total = d1;
71       else if (d2 && !d1)
72         total = d2;
73       else
74         total = to_dir (me->get_property ("neutral-direction"));
75
76       for (vsize i = last_nonneutral + 1; i < next_nonneutral; i++)
77         {
78           if (stems[i] == stem)
79             retval = scm_from_int (total);
80           else
81             stems[i]->set_property ("neutral-direction", scm_from_int (total));
82         }
83
84       last_nonneutral = next_nonneutral;
85       while (last_nonneutral < dirs.size ()
86              && dirs[last_nonneutral])
87         last_nonneutral++;
88       next_nonneutral = last_nonneutral;
89       last_nonneutral--;
90
91       while (next_nonneutral < dirs.size ()
92              && !dirs[next_nonneutral])
93         next_nonneutral++;
94     }
95
96   return retval;
97 }
98
99 void
100 Melody_spanner::add_stem (Grob *me, Grob *stem)
101 {
102   Pointer_group_interface::add_grob (me, ly_symbol2scm ("stems"), stem);
103   stem->set_object ("melody-spanner", me->self_scm ());
104   stem->set_property ("neutral-direction", Melody_spanner::calc_neutral_stem_direction_proc);
105 }
106
107 ADD_INTERFACE (Melody_spanner,
108                "Context dependent typesetting decisions.",
109
110                /* properties */
111                "stems "
112                "neutral-direction "
113               );
114