X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fseparating-line-group-engraver.cc;h=c63ff065ed7f76764332339dcd7677dd9ab803fc;hb=5bbfc22fce036b9b69df5e420de93e11da23c05e;hp=b9b3fda402fe20542577f37ad2bc8cefa77b4f13;hpb=e540311d3f5799216c91d203080f63b65cccde07;p=lilypond.git diff --git a/lily/separating-line-group-engraver.cc b/lily/separating-line-group-engraver.cc index b9b3fda402..c63ff065ed 100644 --- a/lily/separating-line-group-engraver.cc +++ b/lily/separating-line-group-engraver.cc @@ -1,29 +1,41 @@ -/* -' separating-line-group-engraver.cc -- implement Separating_line_group_engraver - - source file of the GNU LilyPond music typesetter - - (c) 1998--2004 Han-Wen Nienhuys - - */ - -#include "separating-group-spanner.hh" +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 1998--2014 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 "paper-def.hh" -#include "engraver.hh" +#include "output-def.hh" #include "axis-group-interface.hh" #include "note-spacing.hh" -#include "group-interface.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_; - Link_array note_spacings_; + Item *staff_spacing_; + vector note_spacings_; Spacings () { @@ -32,201 +44,128 @@ struct Spacings bool is_empty () const { - return !staff_spacing_ && !note_spacings_.size (); + return !staff_spacing_ && !note_spacings_.size (); } - void clear () { + void clear () + { staff_spacing_ = 0; note_spacings_.clear (); } }; - class Separating_line_group_engraver : public Engraver { protected: - Item * break_item_; - Item * musical_item_; - Item * last_musical_item_; - Spacings current_spacings_; Spacings last_spacings_; - - Spanner * sep_span_; - - virtual void acknowledge_grob (Grob_info); - virtual void process_music (); - virtual void finalize (); - virtual void stop_translation_timestep (); - virtual void start_translation_timestep (); + + 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_ = 0; - break_item_ = 0; - musical_item_ =0; } void -Separating_line_group_engraver::process_music () +Separating_line_group_engraver::acknowledge_item (Grob_info i) { + Item *it = i.item (); - if (!sep_span_) - { - sep_span_ = make_spanner ("SeparatingGroupSpanner", SCM_EOL); - - - sep_span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn"))); - } -} -void -Separating_line_group_engraver::finalize () -{ - if (!sep_span_) - return ; - - SCM ccol = get_property ("currentCommandColumn"); - Grob *column = unsmob_grob (ccol); - - sep_span_->set_bound (RIGHT, unsmob_grob (ccol)); - typeset_grob (sep_span_); - sep_span_ =0; - - for (int i= 0 ; i < last_spacings_.note_spacings_.size (); i++) + if (Note_spacing::has_interface (it)) { - Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i], - ly_symbol2scm ("right-items" ), - column); + current_spacings_.note_spacings_.push_back (it); + return; } - - if (last_spacings_.staff_spacing_ - && last_spacings_.staff_spacing_->get_column () == column) + + if (Item::is_non_musical (it) + && !current_spacings_.staff_spacing_ + && to_boolean (get_property ("createSpacing"))) { - last_spacings_.staff_spacing_->suicide (); + Grob *col = Grob::unsmob (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 = Grob_array::unsmob (ri); + if (!ga) + { + SCM ga_scm = Grob_array::make_array (); + last_spacings_.staff_spacing_->set_object ("right-items", ga_scm); + ga = Grob_array::unsmob (ga_scm); + } + + ga->clear (); + ga->add (col); + } } } void -Separating_line_group_engraver::acknowledge_grob (Grob_info i) +Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi) { - Item * it = dynamic_cast (i.grob_); - if (!it) - return; - if (it->get_parent (X_AXIS) - && it->get_parent (X_AXIS) - ->has_extent_callback (Axis_group_interface::group_extent_callback_proc, X_AXIS)) - return; - - - if (to_boolean (it->get_property ("no-spacing-rods"))) - return ; - - if (Note_spacing::has_interface (it)) - { - current_spacings_.note_spacings_.push (it); - return ; - } - - bool ib =Item::is_breakable (it); - Item *&p_ref_ (ib ? break_item_ - : musical_item_); - - if (!p_ref_) - { - p_ref_ = make_item ("SeparationItem", SCM_EOL); - - if (ib) - { - p_ref_->set_property ("breakable", SCM_BOOL_T); - context ()->set_property ("breakableSeparationItem", p_ref_->self_scm ()); - } - - - if (to_boolean (get_property ("createSpacing")) - && p_ref_ == break_item_) - { - Item *it = make_item ("StaffSpacing", SCM_EOL); - current_spacings_.staff_spacing_ = it; - it->set_property ("left-items", scm_cons (break_item_->self_scm (), SCM_EOL)); - - - - if (int i = last_spacings_.note_spacings_.size ()) - { - for (; i--;) - Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i], - ly_symbol2scm ("right-items"), - break_item_); - - } - else if (last_spacings_.staff_spacing_) - { - last_spacings_.staff_spacing_->set_property ("right-items", - scm_cons (break_item_->self_scm (), SCM_EOL)); - } - } - } - - if (Accidental_placement::has_interface (it)) - Separation_item::add_conditional_item (p_ref_, it); - else - Separation_item::add_item (p_ref_,it); + break_aligned_.push_back (gi.grob ()); } void Separating_line_group_engraver::start_translation_timestep () { - if (break_item_) - context ()->unset_property (ly_symbol2scm ("breakableSeparationItem")); - break_item_ =0; + context ()->unset_property (ly_symbol2scm ("hasStaffSpacing")); } void Separating_line_group_engraver::stop_translation_timestep () { - if (break_item_) + for (vsize i = 0; i < break_aligned_.size (); i++) { - Separating_group_spanner::add_spacing_unit (sep_span_, break_item_); - typeset_grob (break_item_); - } - - if (Item * sp = current_spacings_.staff_spacing_) - { - /* - TODO: should really look at the left-items of following - note-spacing grobs. - */ - if (musical_item_) - Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), - musical_item_); - - typeset_grob (sp); + 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_; - } + last_spacings_ = current_spacings_; + + if (Item *sp = current_spacings_.staff_spacing_) + if (Grob *col = Grob::unsmob (get_property ("currentMusicalColumn"))) + Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col); current_spacings_.clear (); - - if (musical_item_) - { - Separating_group_spanner::add_spacing_unit (sep_span_, musical_item_); - typeset_grob (musical_item_); - } - - musical_item_ =0; + 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 ", -ENTER_DESCRIPTION (Separating_line_group_engraver, -/* descr */ "Generates objects for computing spacing parameters.", -/* creats*/ "SeparationItem SeparatingGroupSpanner StaffSpacing", -/* accepts */ "", -/* acks */ "item-interface", -/* reads */ "createSpacing", -/* write */ "breakableSeparationItem"); + /* write */ + "hasStaffSpacing " + );