Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / measure-grouping-engraver.cc
blobd77cf8d499e6384661c88571a25734839c54e472
1 /*
2 measure-grouping-engraver.cc -- implement Measure_grouping_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2009 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"
14 #include "beam-settings.hh"
16 #include "translator.icc"
18 class Measure_grouping_engraver : public Engraver
20 public:
21 TRANSLATOR_DECLARATIONS (Measure_grouping_engraver);
23 protected:
24 Spanner *grouping_;
25 Rational stop_grouping_mom_;
27 void process_music ();
28 virtual void finalize ();
29 DECLARE_ACKNOWLEDGER (note_column);
32 void
33 Measure_grouping_engraver::finalize ()
35 if (grouping_)
37 grouping_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
38 grouping_->suicide ();
39 grouping_ = 0;
43 void
44 Measure_grouping_engraver::acknowledge_note_column (Grob_info gi)
46 if (grouping_)
47 Side_position_interface::add_support (grouping_, gi.grob ());
50 void
51 Measure_grouping_engraver::process_music ()
53 Moment now = now_mom ();
54 if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
56 grouping_->set_bound (RIGHT,
57 unsmob_grob (get_property ("currentMusicalColumn")));
59 grouping_ = 0;
62 if (now.grace_part_)
63 return;
65 SCM settings = get_property ("beamSettings");
66 SCM grouping = SCM_EOL;
67 if (scm_is_pair (settings))
69 SCM time_signature_fraction = get_property ("timeSignatureFraction");
70 grouping = ly_beam_grouping (settings,
71 time_signature_fraction,
72 ly_symbol2scm ("end"),
73 ly_symbol2scm ("*"));
75 if (scm_is_pair (grouping))
77 Moment *measpos = unsmob_moment (get_property ("measurePosition"));
78 Rational mp = measpos->main_part_;
80 Moment *beatlen_mom = unsmob_moment (get_property ("beatLength"));
81 Rational beat_length = beatlen_mom->main_part_;
83 Rational where (0);
84 for (SCM s = grouping; scm_is_pair (s);
85 where += Rational ((int) scm_to_int (scm_car (s))) * beat_length,
86 s = scm_cdr (s))
88 int grouplen = scm_to_int (scm_car (s));
89 if (where == mp)
91 if (grouping_)
93 programming_error ("last grouping not finished yet");
94 continue;
96 if (grouplen > 1)
98 grouping_ = make_spanner ("MeasureGrouping", SCM_EOL);
99 grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
101 stop_grouping_mom_ = now.main_part_ + Rational (grouplen - 1) * beat_length;
102 get_global_context ()->add_moment_to_process (Moment (stop_grouping_mom_));
104 if (grouplen == 3)
105 grouping_->set_property ("style", ly_symbol2scm ("triangle"));
106 else
107 grouping_->set_property ("style", ly_symbol2scm ("bracket"));
109 break;
116 Measure_grouping_engraver::Measure_grouping_engraver ()
118 grouping_ = 0;
121 ADD_ACKNOWLEDGER (Measure_grouping_engraver, note_column);
122 ADD_TRANSLATOR (Measure_grouping_engraver,
123 /* doc */
124 "Create @code{MeasureGrouping} to indicate beat subdivision.",
126 /* create */
127 "MeasureGrouping ",
129 /* read */
130 "beatLength "
131 "currentMusicalColumn "
132 "measurePosition "
133 "beamSettings ",
135 /* write */