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"
17 class Timing_engraver : public Timing_translator, public Engraver
20 /* Need to know whether we're advancing in grace notes, or not. */
23 virtual void start_translation_timestep ();
24 virtual void process_music ();
25 virtual void stop_translation_timestep ();
28 TRANSLATOR_DECLARATIONS (Timing_engraver);
31 ADD_TRANSLATOR (Timing_engraver,
32 /* descr */ " Responsible for synchronizing timing information from staves. "
33 "Normally in @code{Score}. In order to create polyrhythmic music, "
34 "this engraver should be removed from @code{Score} and placed in "
36 "\n\nThis engraver adds the alias @code{Timing} to its containing context.",
40 /* reads */ "automaticBars whichBar barAlways defaultBarType "
41 "skipBars timing measureLength measurePosition currentBarNumber",
45 Timing_engraver::Timing_engraver ()
47 last_moment_.main_part_ = Rational (-1);
51 Timing_engraver::process_music ()
53 Timing_translator::process_music ();
55 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
56 && !measure_position ().main_part_);
59 We can't do this in start_translation_timestep(), since time sig
60 changes won't have happened by then.
64 Moment mlen = Moment (measure_length ());
65 unsmob_grob (get_property ("currentCommandColumn"))
66 ->set_property ("measure-length", mlen.smobbed_copy ());
71 Timing_engraver::start_translation_timestep ()
73 Timing_translator::start_translation_timestep ();
75 SCM automatic_bars = get_property ("automaticBars");
76 Moment now = now_mom ();
77 SCM which = get_property ("whichBar");
79 /* Set the first bar of the score? */
80 if (!scm_is_string (which))
83 Moment mp = measure_position ();
84 bool start_of_measure = (last_moment_.main_part_ != now.main_part_
87 if (!scm_is_string (which) && to_boolean (automatic_bars))
89 SCM always = get_property ("barAlways");
91 if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
92 || to_boolean (always))
94 /* should this work, or be junked? See input/bugs/no-bars.ly */
95 which = get_property ("defaultBarType");
99 context ()->set_property ("whichBar", which);
103 Timing_engraver::stop_translation_timestep ()
105 Timing_translator::stop_translation_timestep ();
106 context ()->set_property ("whichBar", SCM_EOL);
107 last_moment_ = now_mom ();