]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
c727c5889625c2aab8410811bd2b51e29ee5e4d2
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <iostream.h>
9
10 #include "translator-group.hh"
11 #include "command-request.hh"
12 #include "score-element-info.hh"
13 #include "multi-measure-rest.hh"
14 #include "timing-translator.hh"
15 #include "engraver.hh"
16
17 /**
18   Do time bookkeeping
19  */
20 class Timing_engraver : public Timing_translator, public Engraver
21 {   
22   Bar_req * bar_req_l_;
23 protected:
24   virtual bool do_try_music (Music * );
25   virtual void do_post_move_processing ();
26   virtual void do_process_music ();
27   virtual void do_pre_move_processing ();
28 public:
29   VIRTUAL_COPY_CONS(Translator);
30 };
31
32 ADD_THIS_TRANSLATOR(Timing_engraver);
33
34 void
35 Timing_engraver::do_post_move_processing( )
36 {
37   bar_req_l_ = 0;
38   Timing_translator::do_post_move_processing ();
39
40   SCM nonauto = get_property ("barNonAuto");
41
42   SCM which = get_property ("whichBar");
43   if (!gh_string_p (which))
44     which = now_mom () ? SCM_EOL : ly_str02scm ("|");
45   
46   if (!gh_string_p (which) && !to_boolean (nonauto))
47     {
48       SCM always = get_property ("barAlways");
49       if (!measure_position ()
50           || (to_boolean (always)))
51         {
52           which=get_property ("defaultBarType" );
53         }
54     }
55
56   daddy_trans_l_->set_property ("whichBar", which);
57 }
58
59 void
60 Timing_engraver::do_pre_move_processing ()
61 {
62   Timing_translator::do_pre_move_processing ();
63   daddy_trans_l_->set_property ("whichBar", SCM_EOL);  
64 }
65
66 bool
67 Timing_engraver::do_try_music (Music*m)
68 {
69   if (Bar_req  * b= dynamic_cast <Bar_req *> (m))
70     {
71       if (bar_req_l_ && !bar_req_l_->equal_b (b)) 
72         return false;
73       
74       bar_req_l_ = b;
75       return true;
76     }
77   
78   return Timing_translator::do_try_music (m);
79 }
80
81 void
82 Timing_engraver::do_process_music ()
83 {
84   if (bar_req_l_)
85     daddy_trans_l_->set_property ("whichBar", bar_req_l_->get_mus_property ("type"));
86 }
87