Merge branch 'fret-diagram-details'
[lilypond/csorensen.git] / lily / time-signature-engraver.cc
blob27e60c14d360d4ea31ca8ffe1231a32e5ab59292
1 /*
2 time-signature-engraver.cc -- implement Time_signature_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver-group.hh"
11 #include "item.hh"
12 #include "international.hh"
13 #include "misc.hh"
14 #include "time-signature.hh"
15 #include "warn.hh"
17 /**
18 generate time_signatures.
20 class Time_signature_engraver : public Engraver
22 Item *time_signature_;
23 SCM last_time_fraction_;
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);
33 void
34 Time_signature_engraver::derived_mark () const
36 scm_gc_mark (last_time_fraction_);
39 Time_signature_engraver::Time_signature_engraver ()
41 time_signature_ = 0;
42 last_time_fraction_ = SCM_BOOL_F;
45 void
46 Time_signature_engraver::process_music ()
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))
56 int den = scm_to_int (scm_cdr (fr));
57 if (den != (1 << intlog2 (den)))
60 Todo: should make typecheck?
62 OTOH, Tristan Keuris writes 8/20 in his Intermezzi.
64 warning (_f ("strange time signature found: %d/%d",
65 int (scm_to_int (scm_car (fr))),
66 den));
69 time_signature_ = make_item ("TimeSignature", SCM_EOL);
70 time_signature_->set_property ("fraction", fr);
72 if (last_time_fraction_ == SCM_BOOL_F)
73 time_signature_->set_property ("break-visibility",
74 get_property ("implicitTimeSignatureVisibility"));
76 last_time_fraction_ = fr;
80 void
81 Time_signature_engraver::stop_translation_timestep ()
83 time_signature_ = 0;
86 #include "translator.icc"
88 ADD_TRANSLATOR (Time_signature_engraver,
89 /* doc */
90 "Create a @ref{TimeSignature} whenever"
91 " @code{timeSignatureFraction} changes.",
93 /* create */
94 "TimeSignature ",
96 /* read */
97 "implicitTimeSignatureVisibility "
98 "timeSignatureFraction ",
100 /* write */