]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[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--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"
14
15 /**
16   Do time bookkeeping
17  */
18 class Timing_engraver : public Timing_translator, public Engraver
19 {
20 protected:
21   /* Needed to know whether we're advancing in grace notes, or not. */
22   Moment last_moment_;
23   
24   virtual void start_translation_timestep ();
25   virtual void initialize ();
26   virtual void stop_translation_timestep ();
27
28 public:
29   TRANSLATOR_DECLARATIONS (Timing_engraver);
30 };
31
32
33 Timing_engraver::Timing_engraver ()
34 {
35   last_moment_.main_part_ = Rational (-1);
36 }
37
38
39 void
40 Timing_engraver::initialize ()
41 {
42   Timing_translator::initialize ();
43   
44   SCM which = get_property ("whichBar");
45   Moment now = now_mom ();
46   
47   /* Set the first bar of the score? */
48   if (!ly_string_p (which))
49     which = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
50       ? SCM_EOL : scm_makfrom0str ("|");
51
52   daddy_context_->set_property ("whichBar", which);
53 }
54
55
56 void
57 Timing_engraver::start_translation_timestep ()
58 {
59   Timing_translator::start_translation_timestep ();
60
61   SCM automatic_bars = get_property ("automaticBars");
62   Moment now = now_mom ();
63   SCM which = get_property ("whichBar");
64
65   /* Set the first bar of the score? */
66   if (!ly_string_p (which))
67     which = SCM_EOL;
68
69   Moment mp = measure_position ();
70   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
71                            && !mp.main_part_);
72
73   if (start_of_measure)
74     {
75       Moment mlen = Moment (measure_length ());
76       unsmob_grob (get_property ("currentCommandColumn"))
77         ->set_property ("measure-length", mlen.smobbed_copy ()); 
78     }
79   
80   if (!ly_string_p (which) && to_boolean (automatic_bars))
81     {
82       SCM always = get_property ("barAlways");
83
84       if ( start_of_measure || (to_boolean (always)))
85         {
86           /* should this work, or be junked?  See input/bugs/no-bars.ly */
87           which = get_property ("defaultBarType");
88         }
89     }
90
91   daddy_context_->set_property ("whichBar", which);
92 }
93
94 void
95 Timing_engraver::stop_translation_timestep ()
96 {
97   Timing_translator::stop_translation_timestep ();
98   daddy_context_->set_property ("whichBar", SCM_EOL);
99   last_moment_ = now_mom ();
100 }
101
102
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."
109
110                    ,
111 /* creats*/       "",
112 /* accepts */     "",
113 /* acks  */      "",
114 /* reads */       "timeSignatureFraction automaticBars whichBar barAlways defaultBarType skipBars timing measureLength measurePosition currentBarNumber",
115 /* write */       "");