X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbar-engraver.cc;h=2357c087b5dc425a3faa839c629cd6c4f9d9aee5;hb=2c8e0ce6cda26ee57f2b7493387ab348989d115b;hp=2aa490405442f7d750a4c35584544871e8043b80;hpb=8002fa018c81f70585c25232247c6dcba7f5cba0;p=lilypond.git diff --git a/lily/bar-engraver.cc b/lily/bar-engraver.cc index 2aa4904054..2357c087b5 100644 --- a/lily/bar-engraver.cc +++ b/lily/bar-engraver.cc @@ -3,146 +3,107 @@ source file of the GNU LilyPond music typesetter - (c) 1997, 1998, 1999 Han-Wen Nienhuys + (c) 1997--2007 Han-Wen Nienhuys Jan Nieuwenhuizen */ +#include "bar-line.hh" +#include "context.hh" #include "score-engraver.hh" -#include "bar-engraver.hh" -#include "staff-bar.hh" -#include "musical-request.hh" -#include "multi-measure-rest.hh" -#include "command-request.hh" -#include "timing-engraver.hh" -#include "engraver-group-engraver.hh" #include "warn.hh" +#include "item.hh" +#include "spanner.hh" -Bar_engraver::Bar_engraver() +#include "translator.icc" + +/* + generate bars. Either user ("|:"), or default (new measure) +*/ +class Bar_engraver : public Engraver { - bar_p_ =0; - do_post_move_processing(); -} +public: + TRANSLATOR_DECLARATIONS (Bar_engraver); + void request_bar (string type_string); +protected: + void stop_translation_timestep (); + void process_acknowledged (); + DECLARE_END_ACKNOWLEDGER (spanner); +private: + void create_bar (); -void -Bar_engraver::create_bar () + Item *bar_; + vector spanners_; +}; + +Bar_engraver::Bar_engraver () { - if (!bar_p_) - { - bar_p_ = new Staff_bar; - bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0)); - - // urg: "" != empty... - String default_type = get_property ("defaultBarType", 0); - if (default_type.length_i ()) - { - bar_p_->type_str_ = default_type; - } - - /* - urg. Why did I implement this? - */ - Scalar prop = get_property ("barAtLineStart", 0); - if (prop.to_bool ()) - { - bar_p_->set_elt_property (at_line_start_scm_sym, SCM_BOOL_T); - } - prop = get_property ("barSize", 0); - if (prop.isnum_b ()) - { - bar_p_->set_elt_property (bar_size_scm_sym, - gh_double2scm (Real(prop))); - } - announce_element (Score_element_info (bar_p_, 0)); - } + bar_ = 0; } -/** - Make a barline. If there are both |: and :| requested, merge them - to :|:. - -*/ void -Bar_engraver::request_bar (String requested_type) +Bar_engraver::create_bar () { - Scalar prop = get_property ("barAtLineStart", 0); - if (!now_mom ()) - { - Scalar prop = get_property ("barAtLineStart", 0); - if (!prop.to_bool ()) - return; - } - bool bar_existed = bar_p_; - create_bar (); - if (bar_existed && requested_type == "") + if (!bar_) { - return; + bar_ = make_item ("BarLine", SCM_EOL); + SCM gl = get_property ("whichBar"); + if (scm_equal_p (gl, bar_->get_property ("glyph")) != SCM_BOOL_T) + bar_->set_property ("glyph", gl); } - else if (((requested_type == "|:") && (bar_p_->type_str_ == ":|")) - || ((requested_type == ":|") && (bar_p_->type_str_ == "|:"))) - bar_p_->type_str_ = ":|:"; - else - bar_p_->type_str_ = requested_type; } -void -Bar_engraver::do_creation_processing () -{ -} +/* + Bar_engraver should come *after* any engravers that + modify whichBar + + This is a little hairy : whichBar may be set by + Repeat_acknowledge_engraver::process_music, which is at score + context. This means that grobs could should be created after + process_music. We do stuff process_acknowledged (), just to be + on the safe side. +*/ void -Bar_engraver::do_removal_processing () +Bar_engraver::process_acknowledged () { - if (bar_p_) - { - typeset_element (bar_p_); - bar_p_ =0; - } + if (!bar_ && scm_is_string (get_property ("whichBar"))) + create_bar (); + + if (bar_) + for (vsize i = 0; i < spanners_.size (); i++) + spanners_[i]->set_bound (RIGHT, bar_); } +/* + lines may only be broken if there is a barline in all staves +*/ void -Bar_engraver::do_process_requests() -{ - Translator * t = daddy_grav_l ()->get_simple_translator ("Timing_engraver"); - - Timing_engraver * te = dynamic_cast(t); - String which = (te) ? te->which_bar () : ""; +Bar_engraver::stop_translation_timestep () +{ + if (!bar_) + context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T); - if (which.length_i ()) - { - create_bar(); - bar_p_->type_str_ = which; - } - - if (!bar_p_) - { - Score_engraver * e = 0; - Translator * t = daddy_grav_l (); - for (; !e && t; t = t->daddy_trans_l_) - { - e = dynamic_cast (t); - } - - if (!e) - programming_error ("No score engraver!"); - else - e->forbid_breaks (); - } + bar_ = 0; + spanners_.clear (); } - -void -Bar_engraver::do_pre_move_processing() +void +Bar_engraver::acknowledge_end_spanner (Grob_info gi) { - if (bar_p_) - { - typeset_element (bar_p_); - bar_p_ =0; - } -} + Grob *g = gi.grob (); -ADD_THIS_TRANSLATOR(Bar_engraver); + if (to_boolean (g->get_property ("to-barline"))) + spanners_.push_back (dynamic_cast (g)); +} +ADD_END_ACKNOWLEDGER (Bar_engraver, spanner); +ADD_TRANSLATOR (Bar_engraver, + /* doc */ "Create barlines. This engraver is controlled through the " + "@code{whichBar} property. If it has no bar line to create, it will forbid a linebreak at this point", + /* create */ "BarLine", + /* read */ "whichBar", + /* write */ "forbidBreak");