]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature-engraver.cc
Merge with git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond.git
[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 "engraver-group.hh"
10
11 #include "international.hh"
12 #include "misc.hh"
13 #include "time-signature.hh"
14 #include "warn.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 derived_mark () const;
26   void stop_translation_timestep ();
27   void process_music ();
28 public:
29   TRANSLATOR_DECLARATIONS (Time_signature_engraver);
30 };
31
32 void
33 Time_signature_engraver::derived_mark () const
34 {
35   scm_gc_mark (last_time_fraction_);
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                        int (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                 /* read */ "",
86                 /* write */ "");