]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
''
[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 #include "grob.hh"
15
16 /**
17   Do time bookkeeping
18  */
19 class Timing_engraver : public Timing_translator, public Engraver
20 {
21 protected:
22   /*
23     Needed to know whether we're advancing in grace notes, or not.
24    */
25   Moment last_moment_;
26   
27   virtual void start_translation_timestep ();
28   virtual void stop_translation_timestep ();
29
30 public:
31   TRANSLATOR_DECLARATIONS(Timing_engraver);
32 };
33
34
35 Timing_engraver::Timing_engraver ()
36 {
37   last_moment_.main_part_ = Rational (-1);
38 }
39
40
41
42 void
43 Timing_engraver::start_translation_timestep ()
44 {
45   Timing_translator::start_translation_timestep ();
46
47   SCM nonauto = get_property ("barNonAuto");
48   Moment now = now_mom ();
49   SCM which = get_property ("whichBar");
50
51   /*
52     Set the first bar of the score? 
53    */
54   if (!gh_string_p (which))
55     which
56       = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
57       ? SCM_EOL : ly_str02scm ("|");
58
59   Moment mp = measure_position ();
60   bool start_of_measure = (last_moment_.main_part_ != now.main_part_&& !mp.main_part_  );
61
62   if (start_of_measure)
63     {
64       Moment mlen = Moment(measure_length ());
65       unsmob_grob (get_property ("currentCommandColumn"))->set_grob_property ("measure-length", mlen.smobbed_copy()); 
66     }
67   
68   if (!gh_string_p (which) && !to_boolean (nonauto))
69     {
70       SCM always = get_property ("barAlways");
71
72       if ( start_of_measure || (to_boolean (always)))
73         {
74           /* should this work, or be junked?  See input/bugs/no-bars.ly */
75           which = get_property ("defaultBarType");
76         }
77     }
78
79   daddy_trans_l_->set_property ("whichBar", which);
80 }
81
82 void
83 Timing_engraver::stop_translation_timestep ()
84 {
85   Timing_translator::stop_translation_timestep ();
86   daddy_trans_l_->set_property ("whichBar", SCM_EOL);
87   last_moment_ = now_mom ();
88       
89 }
90
91
92 ENTER_DESCRIPTION(Timing_engraver,
93 /* descr */       " Responsible for synchronizing timing information from staves. 
94 Normally in @code{Score}.  In order to create polyrhythmic music,
95 this engraver should be removed from @code{Score} and placed in
96 @code{Staff}.",
97 /* creats*/       "",
98 /* acks  */       "",
99 /* reads */       "timeSignatureFraction barCheckNoSynchronize barNonAuto whichBar barAlways defaultBarType skipBars timing oneBeat measureLength measurePosition currentBarNumber",
100 /* write */       "");