]> git.donarmstrong.com Git - lilypond.git/blob - lily/time-signature-engraver.cc
Run `make grand-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--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "engraver-group.hh"
10
11 #include "item.hh"
12 #include "international.hh"
13 #include "misc.hh"
14 #include "time-signature.hh"
15 #include "warn.hh"
16
17 /**
18    generate time_signatures.
19 */
20 class Time_signature_engraver : public Engraver
21 {
22   Item *time_signature_;
23   SCM last_time_fraction_;
24
25 protected:
26   virtual void derived_mark () const;
27   void stop_translation_timestep ();
28   void process_music ();
29 public:
30   TRANSLATOR_DECLARATIONS (Time_signature_engraver);
31 };
32
33 void
34 Time_signature_engraver::derived_mark () const
35 {
36   scm_gc_mark (last_time_fraction_);
37 }
38
39 Time_signature_engraver::Time_signature_engraver ()
40 {
41   time_signature_ = 0;
42   last_time_fraction_ = SCM_BOOL_F;
43 }
44
45 void
46 Time_signature_engraver::process_music ()
47 {
48   /*
49     not rigorously safe, since the value might get GC'd and
50     reallocated in the same spot */
51   SCM fr = get_property ("timeSignatureFraction");
52   if (!time_signature_
53       && last_time_fraction_ != fr
54       && scm_is_pair (fr))
55     {
56       int den = scm_to_int (scm_cdr (fr));
57       if (den != (1 << intlog2 (den)))
58         {
59           /*
60             Todo: should make typecheck?
61
62             OTOH, Tristan Keuris writes 8/20 in his Intermezzi.
63           */
64           warning (_f ("strange time signature found: %d/%d",
65                        int (scm_to_int (scm_car (fr))),
66                        den));
67         }
68
69       time_signature_ = make_item ("TimeSignature", SCM_EOL);
70       time_signature_->set_property ("fraction", fr);
71
72       if (last_time_fraction_ == SCM_BOOL_F)
73         time_signature_->set_property ("break-visibility",
74                                        get_property ("implicitTimeSignatureVisibility"));
75       
76       last_time_fraction_ = fr;
77     }
78 }
79
80 void
81 Time_signature_engraver::stop_translation_timestep ()
82 {
83   time_signature_ = 0;
84 }
85
86 #include "translator.icc"
87
88 ADD_TRANSLATOR (Time_signature_engraver,
89                 /* doc */
90                 "Create a @ref{TimeSignature} whenever"
91                 " @code{timeSignatureFraction} changes.",
92
93                 /* create */
94                 "TimeSignature ",
95                 
96                 /* read */
97                 "implicitTimeSignatureVisibility "
98                 "timeSignatureFraction ",
99
100                 /* write */
101                 ""
102                 );