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>
9 #include "timing-translator.hh"
10 #include "engraver.hh"
13 #include "multi-measure-rest.hh"
18 class Timing_engraver : public Timing_translator, public Engraver
21 /* Need to know whether we're advancing in grace notes, or not. */
24 virtual void start_translation_timestep ();
25 virtual void process_music ();
26 virtual void stop_translation_timestep ();
29 TRANSLATOR_DECLARATIONS (Timing_engraver);
32 ADD_TRANSLATOR (Timing_engraver,
33 /* descr */ " Responsible for synchronizing timing information from staves. "
34 "Normally in @code{Score}. In order to create polyrhythmic music, "
35 "this engraver should be removed from @code{Score} and placed in "
37 "\n\nThis engraver adds the alias @code{Timing} to its containing context.",
41 /* reads */ "automaticBars whichBar barAlways defaultBarType "
42 "skipBars timing measureLength measurePosition currentBarNumber",
46 Timing_engraver::Timing_engraver ()
48 last_moment_.main_part_ = Rational (-1);
52 Timing_engraver::process_music ()
54 Timing_translator::process_music ();
56 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
57 && !measure_position ().main_part_);
60 We can't do this in start_translation_timestep(), since time sig
61 changes won't have happened by then.
65 Moment mlen = Moment (measure_length ());
66 Grob * column = unsmob_grob (get_property ("currentCommandColumn"));
68 column->set_property ("measure-length", mlen.smobbed_copy ());
70 programming_error("No command column?");
75 Timing_engraver::start_translation_timestep ()
77 Timing_translator::start_translation_timestep ();
79 SCM automatic_bars = get_property ("automaticBars");
80 Moment now = now_mom ();
81 SCM which = get_property ("whichBar");
83 /* Set the first bar of the score? */
84 if (!scm_is_string (which))
87 Moment mp = measure_position ();
88 bool start_of_measure = (last_moment_.main_part_ != now.main_part_
91 if (!scm_is_string (which) && to_boolean (automatic_bars))
93 SCM always = get_property ("barAlways");
95 if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
96 || to_boolean (always))
98 /* should this work, or be junked? See input/bugs/no-bars.ly */
99 which = get_property ("defaultBarType");
103 context ()->set_property ("whichBar", which);
107 Timing_engraver::stop_translation_timestep ()
109 Timing_translator::stop_translation_timestep ();
110 context ()->set_property ("whichBar", SCM_EOL);
111 last_moment_ = now_mom ();