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