]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
d3aa30bb961843a94001656155f535130fb1b7b7
[lilypond.git] / lily / timing-engraver.cc
1 /*
2   timing-grav.cc -- implement Timing_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "translator-group.hh"
9 #include "command-request.hh"
10 #include "grob-info.hh"
11 #include "multi-measure-rest.hh"
12 #include "timing-translator.hh"
13 #include "engraver.hh"
14
15 /**
16   Do time bookkeeping
17  */
18 class Timing_engraver : public Timing_translator, public Engraver
19 {
20 protected:
21   /*
22     Needed to know whether we're advancing in grace notes, or not.
23    */
24   Moment last_moment_;
25   
26   virtual void start_translation_timestep ();
27   virtual void stop_translation_timestep ();
28
29 public:
30   TRANSLATOR_DECLARATIONS(Timing_engraver);
31 };
32
33
34 Timing_engraver::Timing_engraver ()
35 {
36   last_moment_.main_part_ = Rational (-1);
37 }
38
39
40
41 void
42 Timing_engraver::start_translation_timestep ()
43 {
44   Timing_translator::start_translation_timestep ();
45
46   SCM nonauto = get_property ("barNonAuto");
47   Moment now = now_mom ();
48   SCM which = get_property ("whichBar");
49
50   /*
51     Set the first bar of the score? 
52    */
53   if (!gh_string_p (which))
54     which
55       = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
56       ? SCM_EOL : ly_str02scm ("|");
57   
58   if (!gh_string_p (which) && !to_boolean (nonauto))
59     {
60       SCM always = get_property ("barAlways");
61       Moment mp = measure_position ();
62       if ( (last_moment_.main_part_ != now.main_part_
63             && !mp.main_part_)
64            || (to_boolean (always)))
65         {
66           /* should this work, or be junked?  See input/bugs/no-bars.ly */
67           which = get_property ("defaultBarType");
68         }
69     }
70
71   daddy_trans_l_->set_property ("whichBar", which);
72 }
73
74 void
75 Timing_engraver::stop_translation_timestep ()
76 {
77   Timing_translator::stop_translation_timestep ();
78   daddy_trans_l_->set_property ("whichBar", SCM_EOL);
79   last_moment_ = now_mom ();
80 }
81
82
83 ENTER_DESCRIPTION(Timing_engraver,
84 /* descr */       " Responsible for synchronizing timing information from staves. 
85 Normally in @code{Score}.  In order to create polyrhythmic music,
86 this engraver should be removed from @code{Score} and placed in
87 @code{Staff}.",
88 /* creats*/       "",
89 /* acks  */       "",
90 /* reads */       "timeSignatureFraction barCheckNoSynchronize barNonAuto whichBar barAlways defaultBarType skipBars timing oneBeat measureLength measurePosition currentBarNumber",
91 /* write */       "");