Add display method for \bendAfter.
[lilypond/mpolesky.git] / lily / measure-grouping-engraver.cc
blobc61dd74c45f2188b4eb52ced9d435dd8284e8b1d
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "warn.hh"
21 #include "side-position-interface.hh"
22 #include "global-context.hh"
23 #include "engraver.hh"
24 #include "spanner.hh"
25 #include "beam-settings.hh"
27 #include "translator.icc"
29 class Measure_grouping_engraver : public Engraver
31 public:
32 TRANSLATOR_DECLARATIONS (Measure_grouping_engraver);
34 protected:
35 Spanner *grouping_;
36 Rational stop_grouping_mom_;
38 void process_music ();
39 virtual void finalize ();
40 DECLARE_ACKNOWLEDGER (note_column);
43 void
44 Measure_grouping_engraver::finalize ()
46 if (grouping_)
48 grouping_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
49 grouping_->suicide ();
50 grouping_ = 0;
54 void
55 Measure_grouping_engraver::acknowledge_note_column (Grob_info gi)
57 if (grouping_)
58 Side_position_interface::add_support (grouping_, gi.grob ());
61 void
62 Measure_grouping_engraver::process_music ()
64 Moment now = now_mom ();
65 if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
67 grouping_->set_bound (RIGHT,
68 unsmob_grob (get_property ("currentMusicalColumn")));
70 grouping_ = 0;
73 if (now.grace_part_)
74 return;
76 SCM settings = get_property ("beamSettings");
77 SCM grouping = SCM_EOL;
78 if (scm_is_pair (settings))
80 SCM time_signature_fraction = get_property ("timeSignatureFraction");
81 grouping = ly_beam_grouping (settings,
82 time_signature_fraction,
83 ly_symbol2scm ("end"),
84 ly_symbol2scm ("*"));
86 if (scm_is_pair (grouping))
88 Moment *measpos = unsmob_moment (get_property ("measurePosition"));
89 Rational mp = measpos->main_part_;
91 Moment *beatlen_mom = unsmob_moment (get_property ("beatLength"));
92 Rational beat_length = beatlen_mom->main_part_;
94 Rational where (0);
95 for (SCM s = grouping; scm_is_pair (s);
96 where += Rational ((int) scm_to_int (scm_car (s))) * beat_length,
97 s = scm_cdr (s))
99 int grouplen = scm_to_int (scm_car (s));
100 if (where == mp)
102 if (grouping_)
104 programming_error ("last grouping not finished yet");
105 continue;
107 if (grouplen > 1)
109 grouping_ = make_spanner ("MeasureGrouping", SCM_EOL);
110 grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
112 stop_grouping_mom_ = now.main_part_ + Rational (grouplen - 1) * beat_length;
113 get_global_context ()->add_moment_to_process (Moment (stop_grouping_mom_));
115 if (grouplen == 3)
116 grouping_->set_property ("style", ly_symbol2scm ("triangle"));
117 else
118 grouping_->set_property ("style", ly_symbol2scm ("bracket"));
120 break;
127 Measure_grouping_engraver::Measure_grouping_engraver ()
129 grouping_ = 0;
132 ADD_ACKNOWLEDGER (Measure_grouping_engraver, note_column);
133 ADD_TRANSLATOR (Measure_grouping_engraver,
134 /* doc */
135 "Create @code{MeasureGrouping} to indicate beat subdivision.",
137 /* create */
138 "MeasureGrouping ",
140 /* read */
141 "beatLength "
142 "currentMusicalColumn "
143 "measurePosition "
144 "beamSettings ",
146 /* write */