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