* scm/beam.scm (check-slope-callbacks): check sign of slope.
[lilypond.git] / lily / timing-engraver.cc
blob2c12f4166abaa523a36b04eb6ad144a5e379acbf
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 initialize ();
26 virtual void stop_translation_timestep ();
28 public:
29 TRANSLATOR_DECLARATIONS (Timing_engraver);
33 Timing_engraver::Timing_engraver ()
35 last_moment_.main_part_ = Rational (-1);
39 void
40 Timing_engraver::initialize ()
42 Timing_translator::initialize ();
44 SCM which = get_property ("whichBar");
45 Moment now = now_mom ();
47 /* Set the first bar of the score? */
48 if (!ly_c_string_p (which))
49 which = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
50 ? SCM_EOL : scm_makfrom0str ("|");
52 context ()->set_property ("whichBar", which);
56 void
57 Timing_engraver::start_translation_timestep ()
59 Timing_translator::start_translation_timestep ();
61 SCM automatic_bars = get_property ("automaticBars");
62 Moment now = now_mom ();
63 SCM which = get_property ("whichBar");
65 /* Set the first bar of the score? */
66 if (!ly_c_string_p (which))
67 which = SCM_EOL;
69 Moment mp = measure_position ();
70 bool start_of_measure = (last_moment_.main_part_ != now.main_part_
71 && !mp.main_part_);
73 if (start_of_measure)
75 Moment mlen = Moment (measure_length ());
76 unsmob_grob (get_property ("currentCommandColumn"))
77 ->set_property ("measure-length", mlen.smobbed_copy ());
80 if (!ly_c_string_p (which) && to_boolean (automatic_bars))
82 SCM always = get_property ("barAlways");
84 if ( start_of_measure || (to_boolean (always)))
86 /* should this work, or be junked? See input/bugs/no-bars.ly */
87 which = get_property ("defaultBarType");
91 context ()->set_property ("whichBar", which);
94 void
95 Timing_engraver::stop_translation_timestep ()
97 Timing_translator::stop_translation_timestep ();
98 context ()->set_property ("whichBar", SCM_EOL);
99 last_moment_ = now_mom ();
103 ENTER_DESCRIPTION (Timing_engraver,
104 /* descr */ " Responsible for synchronizing timing information from staves. "
105 "Normally in @code{Score}. In order to create polyrhythmic music, "
106 "this engraver should be removed from @code{Score} and placed in "
107 "@code{Staff}. "
108 "\n\nThis engraver adds the alias @code{Timing} to its containing context."
111 /* creats*/ "",
112 /* accepts */ "",
113 /* acks */ "",
114 /* reads */ "timeSignatureFraction automaticBars whichBar barAlways defaultBarType skipBars timing measureLength measurePosition currentBarNumber",
115 /* write */ "");