X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fseparating-line-group-engraver.cc;h=8b40bd1644a93f087fe9f05c329f74f7867682c7;hb=677f06b3863a5bfbc3de2461cb4aa85e54927dbd;hp=878bb1f1dc12b635d9b1a79e3fa8d6041c8fdfa7;hpb=1cf3d59c1559fb9774c4c1c8cae155cfe54a927c;p=lilypond.git diff --git a/lily/separating-line-group-engraver.cc b/lily/separating-line-group-engraver.cc index 878bb1f1dc..8b40bd1644 100644 --- a/lily/separating-line-group-engraver.cc +++ b/lily/separating-line-group-engraver.cc @@ -1,77 +1,171 @@ -/* - separating-line-group-grav.cc -- implement Separating_line_group_engraver - - source file of the GNU LilyPond music typesetter - - (c) 1998 Han-Wen Nienhuys - - */ - -#include "separating-line-group-engraver.hh" -#include "separating-group-spanner.hh" -#include "single-malt-grouping-item.hh" -#include "p-col.hh" +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 1998--2011 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 "engraver.hh" + +#include "separation-item.hh" +#include "paper-column.hh" +#include "output-def.hh" +#include "axis-group-interface.hh" +#include "note-spacing.hh" +#include "accidental-placement.hh" +#include "context.hh" +#include "spanner.hh" +#include "grob-array.hh" +#include "pointer-group-interface.hh" + +#include "translator.icc" + +struct Spacings +{ + Item *staff_spacing_; + vector note_spacings_; + + Spacings () + { + staff_spacing_ = 0; + } + + bool is_empty () const + { + return !staff_spacing_ && !note_spacings_.size (); + } + void clear () + { + staff_spacing_ = 0; + note_spacings_.clear (); + } +}; + +class Separating_line_group_engraver : public Engraver +{ +protected: + Spacings current_spacings_; + Spacings last_spacings_; + + DECLARE_ACKNOWLEDGER (item); + DECLARE_ACKNOWLEDGER (break_aligned); + void stop_translation_timestep (); + void start_translation_timestep (); + + vector break_aligned_; +public: + TRANSLATOR_DECLARATIONS (Separating_line_group_engraver); +}; Separating_line_group_engraver::Separating_line_group_engraver () { - sep_span_p_ = 0; - break_malt_p_ = 0; - nobreak_malt_p_ =0; } void -Separating_line_group_engraver::do_creation_processing () +Separating_line_group_engraver::acknowledge_item (Grob_info i) { - sep_span_p_ = new Separating_group_spanner; - announce_element ( Score_element_info (sep_span_p_, 0)); - sep_span_p_->set_bounds (LEFT, get_staff_info ().command_pcol_l ()); + Item *it = i.item (); + + if (Note_spacing::has_interface (it)) + { + current_spacings_.note_spacings_.push_back (it); + return; + } + + if (Item::is_non_musical (it) + && !current_spacings_.staff_spacing_ + && to_boolean (get_property ("createSpacing"))) + { + Grob *col = unsmob_grob (get_property ("currentCommandColumn")); + + current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL); + context ()->set_property ("hasStaffSpacing", SCM_BOOL_T); + + Pointer_group_interface::add_grob (current_spacings_.staff_spacing_, + ly_symbol2scm ("left-items"), + col); + + if (!last_spacings_.note_spacings_.size () + && last_spacings_.staff_spacing_) + { + SCM ri = last_spacings_.staff_spacing_->get_object ("right-items"); + Grob_array *ga = unsmob_grob_array (ri); + if (!ga) + { + SCM ga_scm = Grob_array::make_array (); + last_spacings_.staff_spacing_->set_object ("right-items", ga_scm); + ga = unsmob_grob_array (ga_scm); + } + + ga->clear (); + ga->add (col); + } + } } void -Separating_line_group_engraver::do_removal_processing () +Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi) { - sep_span_p_->set_bounds (RIGHT, get_staff_info ().command_pcol_l ()); - typeset_element (sep_span_p_); - sep_span_p_ =0; + break_aligned_.push_back (gi.grob ()); } void -Separating_line_group_engraver::acknowledge_element (Score_element_info i) +Separating_line_group_engraver::start_translation_timestep () { - Item * it = i.elem_l_->access_Item (); - if (it && !it->axis_group_l_a_[X_AXIS]) - { - Single_malt_grouping_item *&p_ref_ (it->breakable_b_ ? - break_malt_p_ : nobreak_malt_p_); - - if (!p_ref_) - { - p_ref_ = new Single_malt_grouping_item; - p_ref_->breakable_b_ = it->breakable_b_; - announce_element (Score_element_info (p_ref_, 0)); - } - p_ref_->add_item (it); - } + context ()->unset_property (ly_symbol2scm ("hasStaffSpacing")); } void -Separating_line_group_engraver::do_pre_move_processing () +Separating_line_group_engraver::stop_translation_timestep () { - if (break_malt_p_) - { - sep_span_p_->add_spacing_unit (break_malt_p_); - - typeset_element (break_malt_p_); - break_malt_p_ =0; - } - if (nobreak_malt_p_) + for (vsize i = 0; i < break_aligned_.size (); i++) { - sep_span_p_->add_spacing_unit (nobreak_malt_p_); - typeset_element (nobreak_malt_p_); - nobreak_malt_p_ =0; + SCM smob = break_aligned_[i]->self_scm (); + + if (Item *sp = current_spacings_.staff_spacing_) + Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob); + + for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++) + Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j], + ly_symbol2scm ("right-break-aligned"), smob); } + + if (!current_spacings_.is_empty ()) + last_spacings_ = current_spacings_; + + if (Item *sp = current_spacings_.staff_spacing_) + if (Grob *col = unsmob_grob (get_property ("currentMusicalColumn"))) + Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col); + + current_spacings_.clear (); + break_aligned_.clear (); } +ADD_ACKNOWLEDGER (Separating_line_group_engraver, item); +ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned); + +ADD_TRANSLATOR (Separating_line_group_engraver, + /* doc */ + "Generate objects for computing spacing parameters.", + + /* create */ + "StaffSpacing ", + + /* read */ + "createSpacing ", -IMPLEMENT_IS_TYPE_B1 (Separating_line_group_engraver, Engraver); -ADD_THIS_TRANSLATOR( Separating_line_group_engraver); + /* write */ + "hasStaffSpacing " + );