X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmeasure-grouping-engraver.cc;h=3d51b133c615a753ba1e454e5a759a06d7ca6ab6;hb=0a0da41d935f7744e7ffd934034f25c40d4c59be;hp=45dd6ff0cd76a01b13153fd9e70da1155705e459;hpb=7e72a1e50e94a7f9738d62599de79fe7745f600c;p=lilypond.git diff --git a/lily/measure-grouping-engraver.cc b/lily/measure-grouping-engraver.cc index 45dd6ff0cd..3d51b133c6 100644 --- a/lily/measure-grouping-engraver.cc +++ b/lily/measure-grouping-engraver.cc @@ -1,118 +1,148 @@ -/* - measure-grouping-engraver.cc -- implement Measure_grouping_engraver +/* + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2002--2009 Han-Wen Nienhuys - (c) 2002--2004 Han-Wen Nienhuys - */ + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ -#include "score-engraver.hh" -#include "spanner.hh" #include "warn.hh" #include "side-position-interface.hh" +#include "global-context.hh" +#include "engraver.hh" +#include "spanner.hh" +#include "beam-settings.hh" + +#include "translator.icc" class Measure_grouping_engraver : public Engraver { public: - TRANSLATOR_DECLARATIONS(Measure_grouping_engraver); + TRANSLATOR_DECLARATIONS (Measure_grouping_engraver); protected: - Spanner * grouping_; + Spanner *grouping_; Rational stop_grouping_mom_; - virtual void process_music (); + void process_music (); virtual void finalize (); - virtual void acknowledge_grob (Grob_info); + DECLARE_ACKNOWLEDGER (note_column); }; void -Measure_grouping_engraver::finalize() +Measure_grouping_engraver::finalize () { if (grouping_) { grouping_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn"))); - typeset_grob (grouping_); grouping_->suicide (); - grouping_= 0; + grouping_ = 0; } } - void -Measure_grouping_engraver::acknowledge_grob (Grob_info gi) +Measure_grouping_engraver::acknowledge_note_column (Grob_info gi) { if (grouping_) - { - Side_position_interface::add_support (grouping_, gi.grob_); - } + Side_position_interface::add_support (grouping_, gi.grob ()); } void Measure_grouping_engraver::process_music () { - Moment now = now_mom(); + Moment now = now_mom (); if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_) { grouping_->set_bound (RIGHT, unsmob_grob (get_property ("currentMusicalColumn"))); - typeset_grob (grouping_); + grouping_ = 0; } - + if (now.grace_part_) - return; - - SCM grouping = get_property ("beatGrouping"); - if (gh_pair_p (grouping)) + return; + + SCM settings = get_property ("beamSettings"); + SCM grouping = SCM_EOL; + if (scm_is_pair (settings)) + { + SCM time_signature_fraction = get_property ("timeSignatureFraction"); + grouping = ly_beam_grouping (settings, + time_signature_fraction, + ly_symbol2scm ("end"), + ly_symbol2scm ("*")); + } + if (scm_is_pair (grouping)) { Moment *measpos = unsmob_moment (get_property ("measurePosition")); Rational mp = measpos->main_part_; - - Moment * beatlen = unsmob_moment (get_property ("beatLength")); - Rational bl = beatlen->main_part_; - + + Moment *beatlen_mom = unsmob_moment (get_property ("beatLength")); + Rational beat_length = beatlen_mom->main_part_; + Rational where (0); - for (SCM s = grouping; gh_pair_p (s); - where += Rational (gh_scm2int (gh_car (s))) * bl, - s = gh_cdr (s) - ) + for (SCM s = grouping; scm_is_pair (s); + where += Rational ((int) scm_to_int (scm_car (s))) * beat_length, + s = scm_cdr (s)) { - int grouplen = gh_scm2int (gh_car(s)); + int grouplen = scm_to_int (scm_car (s)); if (where == mp) { if (grouping_) { - programming_error ("Huh, last grouping not finished yet."); + programming_error ("last grouping not finished yet"); continue; } - - grouping_ = make_spanner ("MeasureGrouping"); - grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn"))); - announce_grob (grouping_, SCM_EOL); + if (grouplen > 1) + { + grouping_ = make_spanner ("MeasureGrouping", SCM_EOL); + grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn"))); + stop_grouping_mom_ = now.main_part_ + Rational (grouplen - 1) * beat_length; + get_global_context ()->add_moment_to_process (Moment (stop_grouping_mom_)); - stop_grouping_mom_ = now.main_part_ + Rational(grouplen - 1) * bl ; - top_engraver ()->add_moment_to_process (Moment (stop_grouping_mom_)); + if (grouplen == 3) + grouping_->set_property ("style", ly_symbol2scm ("triangle")); + else + grouping_->set_property ("style", ly_symbol2scm ("bracket")); - if (grouplen == 3) - grouping_->set_grob_property ("style", ly_symbol2scm ("triangle")); - else - grouping_->set_grob_property ("style", ly_symbol2scm ("bracket")); - - break ; + break; + } } } } } -Measure_grouping_engraver::Measure_grouping_engraver() + +Measure_grouping_engraver::Measure_grouping_engraver () { grouping_ = 0; } -ENTER_DESCRIPTION(Measure_grouping_engraver, -/* descr */ "Creates Measure_grouping objects using beatGrouping property", -/* creats*/ "MeasureGrouping", -/* accepts */ "", -/* acks */ "note-column-interface", -/* reads */ "beatGrouping beatLength measurePosition currentMusicalColumn", -/* write */ ""); +ADD_ACKNOWLEDGER (Measure_grouping_engraver, note_column); +ADD_TRANSLATOR (Measure_grouping_engraver, + /* doc */ + "Create @code{MeasureGrouping} to indicate beat subdivision.", + + /* create */ + "MeasureGrouping ", + + /* read */ + "beatLength " + "currentMusicalColumn " + "measurePosition " + "beamSettings ", + + /* write */ + "" + );