]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature-engraver.cc
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "time-signature.hh"
10 #include "warn.hh"
11 #include "engraver-group.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 derived_mark () const;
24   void stop_translation_timestep ();
25   void process_music ();
26 public:
27   TRANSLATOR_DECLARATIONS (Time_signature_engraver);
28 };
29
30 void
31 Time_signature_engraver::derived_mark () const
32 {
33   scm_gc_mark (last_time_fraction_);
34 }
35
36 Time_signature_engraver::Time_signature_engraver ()
37 {
38   time_signature_ = 0;
39   last_time_fraction_ = SCM_BOOL_F;
40 }
41
42 void
43 Time_signature_engraver::process_music ()
44 {
45   /*
46     not rigorously safe, since the value might get GC'd and
47     reallocated in the same spot */
48   SCM fr = get_property ("timeSignatureFraction");
49   if (!time_signature_
50       && last_time_fraction_ != fr
51       && scm_is_pair (fr))
52     {
53       int den = scm_to_int (scm_cdr (fr));
54       if (den != (1 << intlog2 (den)))
55         {
56           /*
57             Todo: should make typecheck?
58
59             OTOH, Tristan Keuris writes 8/20 in his Intermezzi.
60           */
61           warning (_f ("strange time signature found: %d/%d",
62                        den,
63                        scm_to_int (scm_car (fr))));
64         }
65
66       last_time_fraction_ = fr;
67       time_signature_ = make_item ("TimeSignature", SCM_EOL);
68       time_signature_->set_property ("fraction", fr);
69     }
70 }
71
72 void
73 Time_signature_engraver::stop_translation_timestep ()
74 {
75   time_signature_ = 0;
76 }
77
78 #include "translator.icc"
79
80 ADD_TRANSLATOR (Time_signature_engraver,
81                 /* doc */ "Create a TimeSignature whenever @code{timeSignatureFraction} changes",
82                 /* create */ "TimeSignature",
83                 /* accept */ "",
84                 /* read */ "",
85                 /* write */ "");