Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / measure-grouping-engraver.cc
blob7a788dc3d263d637dbb5cc0e40131e2fc229c88f
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2011 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"
26 #include "translator.icc"
28 class Measure_grouping_engraver : public Engraver
30 public:
31 TRANSLATOR_DECLARATIONS (Measure_grouping_engraver);
33 protected:
34 Spanner *grouping_;
35 Rational stop_grouping_mom_;
37 void process_music ();
38 virtual void finalize ();
39 DECLARE_ACKNOWLEDGER (note_column);
42 void
43 Measure_grouping_engraver::finalize ()
45 if (grouping_)
47 grouping_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
48 grouping_->suicide ();
49 grouping_ = 0;
53 void
54 Measure_grouping_engraver::acknowledge_note_column (Grob_info gi)
56 if (grouping_)
57 Side_position_interface::add_support (grouping_, gi.grob ());
60 void
61 Measure_grouping_engraver::process_music ()
63 Moment now = now_mom ();
64 if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
66 grouping_->set_bound (RIGHT,
67 unsmob_grob (get_property ("currentMusicalColumn")));
69 grouping_ = 0;
72 if (now.grace_part_)
73 return;
75 SCM grouping = get_property ("beatStructure");
76 if (scm_is_pair (grouping))
78 Moment *measpos = unsmob_moment (get_property ("measurePosition"));
79 Rational mp = measpos->main_part_;
81 Moment *base_mom = unsmob_moment (get_property ("baseMoment"));
82 Rational base_moment = base_mom->main_part_;
84 Rational where (0);
85 for (SCM s = grouping; scm_is_pair (s);
86 where += Rational ((int) scm_to_int (scm_car (s))) * base_moment,
87 s = scm_cdr (s))
89 int grouplen = scm_to_int (scm_car (s));
90 if (where == mp)
92 if (grouping_)
94 programming_error ("last grouping not finished yet");
95 continue;
97 if (grouplen > 1)
99 grouping_ = make_spanner ("MeasureGrouping", SCM_EOL);
100 grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
102 stop_grouping_mom_ = now.main_part_ + Rational (grouplen - 1) * base_moment;
103 get_global_context ()->add_moment_to_process (Moment (stop_grouping_mom_));
105 if (grouplen == 3)
106 grouping_->set_property ("style", ly_symbol2scm ("triangle"));
107 else
108 grouping_->set_property ("style", ly_symbol2scm ("bracket"));
110 break;
117 Measure_grouping_engraver::Measure_grouping_engraver ()
119 grouping_ = 0;
122 ADD_ACKNOWLEDGER (Measure_grouping_engraver, note_column);
123 ADD_TRANSLATOR (Measure_grouping_engraver,
124 /* doc */
125 "Create @code{MeasureGrouping} to indicate beat subdivision.",
127 /* create */
128 "MeasureGrouping ",
130 /* read */
131 "baseMoment "
132 "beatStructure "
133 "currentMusicalColumn "
134 "measurePosition ",
136 /* write */