2 timing-engraver.cc -- implement Timing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "multi-measure-rest.hh"
11 #include "timing-translator.hh"
12 #include "engraver.hh"
18 class Timing_engraver : public Timing_translator, public Engraver
21 /* Needed to know whether we're advancing in grace notes, or not. */
24 virtual void start_translation_timestep ();
25 virtual void initialize ();
26 virtual void process_music();
27 virtual void stop_translation_timestep ();
30 TRANSLATOR_DECLARATIONS (Timing_engraver);
34 Timing_engraver::Timing_engraver ()
36 last_moment_.main_part_ = Rational (-1);
41 Timing_engraver::initialize ()
43 Timing_translator::initialize ();
45 SCM which = get_property ("whichBar");
46 Moment now = now_mom ();
48 /* Set the first bar of the score? */
49 if (!scm_is_string (which))
50 which = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
51 ? SCM_EOL : scm_makfrom0str ("|");
53 context ()->set_property ("whichBar", which);
57 Timing_engraver::process_music()
59 Timing_translator::process_music ();
61 bool start_of_measure = (last_moment_.main_part_ != now_mom().main_part_
62 && !measure_position ().main_part_);
65 We can't do this in start_translation_timestep(), since time sig
66 changes won't have happened by then.
70 Moment mlen = Moment (measure_length ());
71 unsmob_grob (get_property ("currentCommandColumn"))
72 ->set_property ("measure-length", mlen.smobbed_copy ());
78 Timing_engraver::start_translation_timestep ()
80 Timing_translator::start_translation_timestep ();
82 SCM automatic_bars = get_property ("automaticBars");
83 Moment now = now_mom ();
84 SCM which = get_property ("whichBar");
86 /* Set the first bar of the score? */
87 if (!scm_is_string (which))
90 Moment mp = measure_position ();
91 bool start_of_measure = (last_moment_.main_part_ != now.main_part_
94 if (!scm_is_string (which) && to_boolean (automatic_bars))
96 SCM always = get_property ("barAlways");
98 if ( start_of_measure || (to_boolean (always)))
100 /* should this work, or be junked? See input/bugs/no-bars.ly */
101 which = get_property ("defaultBarType");
105 context ()->set_property ("whichBar", which);
109 Timing_engraver::stop_translation_timestep ()
111 Timing_translator::stop_translation_timestep ();
112 context ()->set_property ("whichBar", SCM_EOL);
113 last_moment_ = now_mom ();
117 ADD_TRANSLATOR (Timing_engraver,
118 /* descr */ " Responsible for synchronizing timing information from staves. "
119 "Normally in @code{Score}. In order to create polyrhythmic music, "
120 "this engraver should be removed from @code{Score} and placed in "
122 "\n\nThis engraver adds the alias @code{Timing} to its containing context."
128 /* reads */ "automaticBars whichBar barAlways defaultBarType skipBars timing measureLength measurePosition currentBarNumber",