2 melody-spanner.cc -- implement Melody_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 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_from_int (DOWN
);
32 extract_grob_set (me
, "stems", stems
);
34 vector
<Direction
> dirs
;
35 for (vsize i
= 0; i
< stems
.size (); i
++)
36 dirs
.push_back (to_dir (stems
[i
]->get_property ("default-direction")));
38 vsize last_nonneutral
= VPOS
;
39 vsize next_nonneutral
= 0;
40 while (next_nonneutral
!= VPOS
&& next_nonneutral
< dirs
.size ()
41 && !dirs
[next_nonneutral
])
45 while (last_nonneutral
== VPOS
|| last_nonneutral
+ 1 < dirs
.size ())
47 Direction d1
= CENTER
;
48 Direction d2
= CENTER
;
49 if (last_nonneutral
!= VPOS
)
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 (vsize i
= last_nonneutral
+ 1; i
< next_nonneutral
; i
++)
67 retval
= scm_from_int (total
);
69 stems
[i
]->set_property ("neutral-direction", scm_from_int (total
));
72 last_nonneutral
= next_nonneutral
;
73 while (last_nonneutral
< dirs
.size ()
74 && dirs
[last_nonneutral
])
76 next_nonneutral
= last_nonneutral
;
79 while (next_nonneutral
< dirs
.size ()
80 && !dirs
[next_nonneutral
])
88 Melody_spanner::add_stem (Grob
*me
, Grob
*stem
)
90 Pointer_group_interface::add_grob (me
, ly_symbol2scm ("stems"), stem
);
91 stem
->set_object ("melody-spanner", me
->self_scm ());
92 stem
->set_property ("neutral-direction", Melody_spanner::calc_neutral_stem_direction_proc
);
95 ADD_INTERFACE (Melody_spanner
,
96 "Context dependent typesetting decisions.",