X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftiming-engraver.cc;h=1c30fcd34f085bb5ba56a07d408e7d1f7648dd01;hb=b1e87575d7dbce73e74c7e6eb1b64dbfc82e65a4;hp=e8d49a7771aab97134fb36d7d7c8cd78504281a7;hpb=d799307965f096fccddf8885693f279b1575273b;p=lilypond.git diff --git a/lily/timing-engraver.cc b/lily/timing-engraver.cc index e8d49a7771..1c30fcd34f 100644 --- a/lily/timing-engraver.cc +++ b/lily/timing-engraver.cc @@ -1,100 +1,112 @@ /* - timing-grav.cc -- implement Timing_engraver + timing-engraver.cc -- implement Timing_engraver source file of the GNU LilyPond music typesetter - (c) 1997--2002 Han-Wen Nienhuys + (c) 1997--2005 Han-Wen Nienhuys */ -#include "translator-group.hh" -#include "command-request.hh" -#include "grob-info.hh" -#include "multi-measure-rest.hh" + #include "timing-translator.hh" #include "engraver.hh" + +#include "context.hh" +#include "multi-measure-rest.hh" #include "grob.hh" +#include "warn.hh" + -/** - Do time bookkeeping - */ class Timing_engraver : public Timing_translator, public Engraver { protected: - /* - Needed to know whether we're advancing in grace notes, or not. - */ + /* Need to know whether we're advancing in grace notes, or not. */ Moment last_moment_; - + virtual void start_translation_timestep (); + virtual void process_music (); virtual void stop_translation_timestep (); public: - TRANSLATOR_DECLARATIONS(Timing_engraver); + TRANSLATOR_DECLARATIONS (Timing_engraver); }; +ADD_TRANSLATOR (Timing_engraver, + /* descr */ " Responsible for synchronizing timing information from staves. " + "Normally in @code{Score}. In order to create polyrhythmic music, " + "this engraver should be removed from @code{Score} and placed in " + "@code{Staff}. " + "\n\nThis engraver adds the alias @code{Timing} to its containing context.", + /* creats*/ "", + /* accepts */ "", + /* acks */ "", + /* reads */ "automaticBars whichBar barAlways defaultBarType " + "skipBars timing measureLength measurePosition currentBarNumber", + /* write */ ""); + Timing_engraver::Timing_engraver () { last_moment_.main_part_ = Rational (-1); } +void +Timing_engraver::process_music () +{ + Timing_translator::process_music (); + + bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_ + && !measure_position ().main_part_); + /* + We can't do this in start_translation_timestep(), since time sig + changes won't have happened by then. + */ + if (start_of_measure) + { + Moment mlen = Moment (measure_length ()); + Grob * column = unsmob_grob (get_property ("currentCommandColumn")); + if (column) + column->set_property ("measure-length", mlen.smobbed_copy ()); + else + programming_error("No command column?"); + } +} void Timing_engraver::start_translation_timestep () { Timing_translator::start_translation_timestep (); - SCM nonauto = get_property ("barNonAuto"); + SCM automatic_bars = get_property ("automaticBars"); Moment now = now_mom (); SCM which = get_property ("whichBar"); - /* - Set the first bar of the score? - */ - if (!gh_string_p (which)) - which - = (now.main_part_ || now.main_part_ == last_moment_.main_part_) - ? SCM_EOL : ly_str02scm ("|"); + /* Set the first bar of the score? */ + if (!scm_is_string (which)) + which = SCM_EOL; Moment mp = measure_position (); - bool start_of_measure = (last_moment_.main_part_ != now.main_part_&& !mp.main_part_ ); + bool start_of_measure = (last_moment_.main_part_ != now.main_part_ + && !mp.main_part_); - if (start_of_measure) - { - Moment mlen = Moment(measure_length ()); - unsmob_grob (get_property ("currentCommandColumn"))->set_grob_property ("measure-length", mlen.smobbed_copy()); - } - - if (!gh_string_p (which) && !to_boolean (nonauto)) + if (!scm_is_string (which) && to_boolean (automatic_bars)) { SCM always = get_property ("barAlways"); - if ( start_of_measure || (to_boolean (always))) + if ((start_of_measure && last_moment_.main_part_ >= Moment (0)) + || to_boolean (always)) { /* should this work, or be junked? See input/bugs/no-bars.ly */ which = get_property ("defaultBarType"); } } - daddy_trans_l_->set_property ("whichBar", which); + context ()->set_property ("whichBar", which); } void Timing_engraver::stop_translation_timestep () { Timing_translator::stop_translation_timestep (); - daddy_trans_l_->set_property ("whichBar", SCM_EOL); + context ()->set_property ("whichBar", SCM_EOL); last_moment_ = now_mom (); - } - - -ENTER_DESCRIPTION(Timing_engraver, -/* descr */ " Responsible for synchronizing timing information from staves. -Normally in @code{Score}. In order to create polyrhythmic music, -this engraver should be removed from @code{Score} and placed in -@code{Staff}.", -/* creats*/ "", -/* acks */ "", -/* reads */ "timeSignatureFraction barNonAuto whichBar barAlways defaultBarType skipBars timing oneBeat measureLength measurePosition currentBarNumber", -/* write */ "");