]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
release: 1.5.13
[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--2001 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   virtual void process_music ();
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   if (!gh_string_p (which) && !to_boolean (nonauto))
60     {
61       SCM always = get_property ("barAlways");
62       Moment mp = measure_position ();
63       if ( (last_moment_.main_part_ != now.main_part_
64             && !mp.main_part_)
65            || (to_boolean (always)))
66         {
67           /* should this work, or be junked?  See input/bugs/no-bars.ly */
68           which = get_property ("defaultBarType");
69         }
70     }
71
72   daddy_trans_l_->set_property ("whichBar", which);
73 }
74
75 void
76 Timing_engraver::stop_translation_timestep ()
77 {
78   Timing_translator::stop_translation_timestep ();
79   daddy_trans_l_->set_property ("whichBar", SCM_EOL);
80   last_moment_ = now_mom ();
81 }
82
83
84 /*
85   ugh. Translator doesn't do process_music ().
86  */
87 void
88 Timing_engraver::process_music ()
89 {
90   Timing_translator::process_music ();
91 }
92
93 ENTER_DESCRIPTION(Timing_engraver,
94 /* descr */       " Responsible for synchronizing timing information from staves. 
95 Normally in @code{Score}.  In order to create polyrhythmic music,
96 this engraver should be removed from @code{Score} and placed in
97 @code{Staff}.",
98 /* creats*/       "",
99 /* acks  */       "",
100 /* reads */       "timeSignatureFraction barCheckNoSynchronize barNonAuto whichBar barAlways defaultBarType skipBars timing oneBeat measureLength measurePosition currentBarNumber",
101 /* write */       "");