]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature-engraver.cc
2003 -> 2004
[lilypond.git] / lily / time-signature-engraver.cc
1 /*
2   time-signature-engraver.cc -- implement Time_signature_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
9 #include "time-signature.hh"
10 #include "warn.hh"
11
12 #include "engraver.hh"
13 #include "engraver-group-engraver.hh"
14 #include "misc.hh"
15
16 /**
17   generate time_signatures. 
18   */
19 class Time_signature_engraver : public Engraver
20 {
21   Item * time_signature_;
22   SCM last_time_fraction_;
23
24 protected:
25   virtual void stop_translation_timestep ();
26   virtual void process_music ();
27 public:
28   TRANSLATOR_DECLARATIONS(Time_signature_engraver);
29 };
30
31
32 Time_signature_engraver::Time_signature_engraver ()
33
34   time_signature_ =0;
35   last_time_fraction_ = SCM_BOOL_F;
36 }
37
38 void
39 Time_signature_engraver::process_music ()
40 {
41   /*
42     not rigorously safe, since the value might get GC'd and
43     reallocated in the same spot */
44   SCM fr= get_property ("timeSignatureFraction");
45   if (!time_signature_
46       && last_time_fraction_ != fr
47       && gh_pair_p (fr))
48     {
49       int den = gh_scm2int (gh_cdr (fr));
50       if (den != (1 << intlog2 (den)))
51         {
52           /*
53             Todo: should make typecheck?
54
55             OTOH, Tristan Keuris writes 8/20 in his Intermezzi.
56            */
57           warning (_f("Found strange time signature %d/%d.",
58                       den,
59                       gh_scm2int (gh_car (fr))
60                       ));
61         }
62   
63       
64       last_time_fraction_ = fr; 
65       time_signature_ = make_item ("TimeSignature");
66       time_signature_->set_grob_property ("fraction",fr);
67
68       if (time_signature_)
69         announce_grob(time_signature_, SCM_EOL);
70     }
71 }
72
73 void
74 Time_signature_engraver::stop_translation_timestep ()
75 {
76   if (time_signature_) 
77     {
78       typeset_grob (time_signature_);
79       time_signature_ =0;
80     }
81 }
82  
83
84 ENTER_DESCRIPTION(Time_signature_engraver,
85 /* descr */       "Create a TimeSignature whenever @code{timeSignatureFraction} changes",
86 /* creats*/       "TimeSignature",
87 /* accepts */     "",
88 /* acks  */      "",
89 /* reads */       "",
90 /* write */       "");