2 timing-engraver.cc -- implement Default_bar_line_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "multi-measure-rest.hh"
16 class Default_bar_line_engraver : public Engraver
19 /* Need to know whether we're advancing in grace notes, or not. */
22 PRECOMPUTED_VIRTUAL void start_translation_timestep ();
23 PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
26 TRANSLATOR_DECLARATIONS (Default_bar_line_engraver);
29 #include "translator.icc"
31 ADD_TRANSLATOR (Default_bar_line_engraver,
32 "This engraver determines what kind of automatic bar lines should be produced, "
33 "and sets @code{whichBar} accordingly. It should be at the same "
34 "level as @ref{Timing_translator}. ",
39 "measurePosition automaticBars whichBar barAlways defaultBarType "
41 /* write */ "automaticBars");
44 Default_bar_line_engraver::Default_bar_line_engraver ()
46 last_moment_.main_part_ = Rational (-1);
50 Default_bar_line_engraver::start_translation_timestep ()
52 SCM automatic_bars = get_property ("automaticBars");
53 Moment now = now_mom ();
54 SCM which = get_property ("whichBar");
56 /* Set the first bar of the score? */
57 if (!scm_is_string (which))
60 Moment mp = measure_position (context ());
61 bool start_of_measure = (last_moment_.main_part_ != now.main_part_
64 if (!scm_is_string (which) && to_boolean (automatic_bars))
66 SCM always = get_property ("barAlways");
68 if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
69 || to_boolean (always))
71 /* should this work, or be junked? See input/bugs/no-bars.ly */
72 which = get_property ("defaultBarType");
76 context ()->set_property ("whichBar", which);
80 Default_bar_line_engraver::stop_translation_timestep ()
82 context ()->set_property ("whichBar", SCM_EOL);
83 last_moment_ = now_mom ();