*** empty log message ***
[lilypond.git] / lily / timing-engraver.cc
blob2bf0e5f6527184024817b542340b1d7e03aa22d2
1 /*
2 timing-grav.cc -- implement Timing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "context.hh"
9 #include "grob-info.hh"
10 #include "multi-measure-rest.hh"
11 #include "timing-translator.hh"
12 #include "engraver.hh"
13 #include "grob.hh"
15 /**
16 Do time bookkeeping
18 class Timing_engraver : public Timing_translator, public Engraver
20 protected:
21 /* Needed to know whether we're advancing in grace notes, or not. */
22 Moment last_moment_;
24 virtual void start_translation_timestep ();
25 virtual void stop_translation_timestep ();
27 public:
28 TRANSLATOR_DECLARATIONS (Timing_engraver);
32 Timing_engraver::Timing_engraver ()
34 last_moment_.main_part_ = Rational (-1);
39 void
40 Timing_engraver::start_translation_timestep ()
42 Timing_translator::start_translation_timestep ();
44 SCM automatic_bars = get_property ("automaticBars");
45 Moment now = now_mom ();
46 SCM which = get_property ("whichBar");
48 /* Set the first bar of the score? */
49 if (!gh_string_p (which))
50 which
51 = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
52 ? SCM_EOL : scm_makfrom0str ("|");
54 Moment mp = measure_position ();
55 bool start_of_measure = (last_moment_.main_part_ != now.main_part_
56 && !mp.main_part_);
58 if (start_of_measure)
60 Moment mlen = Moment (measure_length ());
61 unsmob_grob (get_property ("currentCommandColumn"))
62 ->set_property ("measure-length", mlen.smobbed_copy ());
65 if (!gh_string_p (which) && to_boolean (automatic_bars))
67 SCM always = get_property ("barAlways");
69 if ( start_of_measure || (to_boolean (always)))
71 /* should this work, or be junked? See input/bugs/no-bars.ly */
72 which = get_property ("defaultBarType");
76 daddy_context_->set_property ("whichBar", which);
79 void
80 Timing_engraver::stop_translation_timestep ()
82 Timing_translator::stop_translation_timestep ();
83 daddy_context_->set_property ("whichBar", SCM_EOL);
84 last_moment_ = now_mom ();
88 ENTER_DESCRIPTION (Timing_engraver,
89 /* descr */ " Responsible for synchronizing timing information from staves. "
90 "Normally in @code{Score}. In order to create polyrhythmic music, "
91 "this engraver should be removed from @code{Score} and placed in "
92 "@code{Staff}. "
93 "\n\nThis engraver adds the alias @code{Timing} to its containing context."
96 /* creats*/ "",
97 /* accepts */ "",
98 /* acks */ "",
99 /* reads */ "timeSignatureFraction automaticBars whichBar barAlways defaultBarType skipBars timing measureLength measurePosition currentBarNumber",
100 /* write */ "");