]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature-engraver.cc
* scm/titling.scm (default-score-title): remove caps for piece.
[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       && scm_is_pair (fr))
48     {
49       int den = scm_to_int (scm_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                       scm_to_int (scm_car (fr))
60                       ));
61         }
62   
63       
64       last_time_fraction_ = fr; 
65       time_signature_ = make_item ("TimeSignature",SCM_EOL);
66       time_signature_->set_property ("fraction",fr);
67     }
68 }
69
70 void
71 Time_signature_engraver::stop_translation_timestep ()
72 {
73   time_signature_ = 0;
74 }
75  
76
77 ENTER_DESCRIPTION (Time_signature_engraver,
78 /* descr */       "Create a TimeSignature whenever @code{timeSignatureFraction} changes",
79 /* creats*/       "TimeSignature",
80 /* accepts */     "",
81 /* acks  */      "",
82 /* reads */       "",
83 /* write */       "");