Correct left text alignment of DynamicTextSpanner.
[lilypond.git] / lily / measure-grouping-engraver.cc
blob81d3c5584e7297b28938099c22710c6559f9d331
1 /*
2 measure-grouping-engraver.cc -- implement Measure_grouping_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "warn.hh"
10 #include "side-position-interface.hh"
11 #include "global-context.hh"
12 #include "engraver.hh"
13 #include "spanner.hh"
15 #include "translator.icc"
17 class Measure_grouping_engraver : public Engraver
19 public:
20 TRANSLATOR_DECLARATIONS (Measure_grouping_engraver);
22 protected:
23 Spanner *grouping_;
24 Rational stop_grouping_mom_;
26 void process_music ();
27 virtual void finalize ();
28 DECLARE_ACKNOWLEDGER (note_column);
31 void
32 Measure_grouping_engraver::finalize ()
34 if (grouping_)
36 grouping_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
37 grouping_->suicide ();
38 grouping_ = 0;
42 void
43 Measure_grouping_engraver::acknowledge_note_column (Grob_info gi)
45 if (grouping_)
46 Side_position_interface::add_support (grouping_, gi.grob ());
49 void
50 Measure_grouping_engraver::process_music ()
52 Moment now = now_mom ();
53 if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
55 grouping_->set_bound (RIGHT,
56 unsmob_grob (get_property ("currentMusicalColumn")));
58 grouping_ = 0;
61 if (now.grace_part_)
62 return;
64 SCM grouping = get_property ("beatGrouping");
65 if (scm_is_pair (grouping))
67 Moment *measpos = unsmob_moment (get_property ("measurePosition"));
68 Rational mp = measpos->main_part_;
70 Moment *beatlen_mom = unsmob_moment (get_property ("beatLength"));
71 Rational beat_length = beatlen_mom->main_part_;
73 Rational where (0);
74 for (SCM s = grouping; scm_is_pair (s);
75 where += Rational ((int) scm_to_int (scm_car (s))) * beat_length,
76 s = scm_cdr (s))
78 int grouplen = scm_to_int (scm_car (s));
79 if (where == mp)
81 if (grouping_)
83 programming_error ("last grouping not finished yet");
84 continue;
87 grouping_ = make_spanner ("MeasureGrouping", SCM_EOL);
88 grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
90 stop_grouping_mom_ = now.main_part_ + Rational (grouplen - 1) * beat_length;
91 get_global_context ()->add_moment_to_process (Moment (stop_grouping_mom_));
93 if (grouplen == 3)
94 grouping_->set_property ("style", ly_symbol2scm ("triangle"));
95 else
96 grouping_->set_property ("style", ly_symbol2scm ("bracket"));
98 break;
104 Measure_grouping_engraver::Measure_grouping_engraver ()
106 grouping_ = 0;
109 ADD_ACKNOWLEDGER (Measure_grouping_engraver, note_column);
110 ADD_TRANSLATOR (Measure_grouping_engraver,
111 /* doc */
112 "Create @code{MeasureGrouping} to indicate beat subdivision.",
114 /* create */
115 "MeasureGrouping ",
117 /* read */
118 "beatLength "
119 "currentMusicalColumn "
120 "measurePosition "
121 "beatGrouping ",
123 /* write */