X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbreak-align-engraver.cc;h=4053a63b2c48972ef2c12355e5d736d8da1b26a5;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=21551ad5b29db6b28a3c2dc813c8a251767f9e05;hpb=f68bbd7a1ed1b0e7146bbbffcbcbb7f9c9bda3cc;p=lilypond.git diff --git a/lily/break-align-engraver.cc b/lily/break-align-engraver.cc index 21551ad5b2..6da5ba603e 100644 --- a/lily/break-align-engraver.cc +++ b/lily/break-align-engraver.cc @@ -1,157 +1,177 @@ -/* - break-align-engraver.cc -- implement Break_align_engraver - - source file of the GNU LilyPond music typesetter - - (c) 1999--2001 Han-Wen Nienhuys - - */ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 1999--2015 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 "protected-scm.hh" -#include "break-align-item.hh" -#include "item.hh" +#include "break-align-interface.hh" #include "align-interface.hh" #include "axis-group-interface.hh" +#include "context.hh" +#include "translator-group.hh" +#include "item.hh" +#include "translator.icc" class Break_align_engraver : public Engraver { - Item *align_l_; - Protected_scm column_alist_; + Item *align_; + SCM column_alist_; + Item *left_edge_; + + void add_to_group (SCM, Item *); + void create_alignment (Grob_info); protected: - virtual void finalize (); - virtual void acknowledge_grob (Grob_info i); - virtual void stop_translation_timestep (); - void add_column (SCM); - + void stop_translation_timestep (); + virtual void derived_mark () const; public: - VIRTUAL_COPY_CONS (Translator); - Break_align_engraver (); + TRANSLATOR_DECLARATIONS (Break_align_engraver); + DECLARE_ACKNOWLEDGER (break_aligned); + DECLARE_ACKNOWLEDGER (break_alignable); }; +void +Break_align_engraver::stop_translation_timestep () +{ + column_alist_ = SCM_EOL; + align_ = 0; + left_edge_ = 0; +} -ADD_THIS_TRANSLATOR (Break_align_engraver); +Break_align_engraver::Break_align_engraver () +{ + column_alist_ = SCM_EOL; + left_edge_ = 0; + align_ = 0; +} void -Break_align_engraver::add_column (SCM smob) +Break_align_engraver::derived_mark () const { - Grob * e = unsmob_grob (smob); - Break_align_interface::add_element (align_l_,e); - typeset_grob (e); + scm_gc_mark (column_alist_); } void -Break_align_engraver::finalize () +Break_align_engraver::acknowledge_break_alignable (Grob_info inf) { - column_alist_ = SCM_EOL; + /* + Special case for MetronomeMark: filter out items which will be aligned + on note heads rather than prefatory material + */ + if (!Item::is_non_musical (inf.item ())) + return; + + if (!align_) + create_alignment (inf); + + Grob *g = inf.grob (); + + if (!g->get_parent (X_AXIS)) + g->set_parent (align_, X_AXIS); } void -Break_align_engraver::stop_translation_timestep () +Break_align_engraver::acknowledge_break_aligned (Grob_info inf) { - SCM order = get_property ("breakAlignOrder"); - for (; gh_pair_p (order); order = ly_cdr (order)) + if (Item *item = dynamic_cast (inf.grob ())) { - SCM p = scm_assoc (ly_car (order), column_alist_); - if (gh_pair_p (p)) - { - add_column (ly_cdr (p)); - column_alist_ = scm_assoc_remove_x (column_alist_, ly_car (order)); - } - } + /* + Removed check for item->empty (X_AXIS). --hwn 20/1/04 + */ + if (item->get_parent (X_AXIS)) + return; - for (SCM p = column_alist_; gh_pair_p (p); p = ly_cdr (p)) - { - SCM pair = ly_car (p); - add_column (ly_cdr (pair)); - } + if (!Item::is_non_musical (item)) + return; - - column_alist_ = SCM_EOL; + SCM align_name = item->get_property ("break-align-symbol"); + if (!scm_is_symbol (align_name)) + return; - if (align_l_) - { - typeset_grob (align_l_); - align_l_ = 0; + if (!align_) + create_alignment (inf); + + add_to_group (align_name, item); } } - -Break_align_engraver::Break_align_engraver () +void +Break_align_engraver::create_alignment (Grob_info inf) { - column_alist_ = SCM_EOL; - align_l_ =0; + align_ = make_item ("BreakAlignment", SCM_EOL); + + Context *origin = inf.origin_contexts (this)[0]; + + Translator_group *tg = origin->implementation (); + Engraver *random_source = dynamic_cast (Translator::unsmob (scm_car (tg->get_simple_trans_list ()))); + if (!random_source) + random_source = this; + + /* + Make left edge appear to come from same context as clef/bar-line etc. + */ + left_edge_ = random_source->make_item ("LeftEdge", SCM_EOL); + add_to_group (left_edge_->get_property ("break-align-symbol"), + left_edge_); } void -Break_align_engraver::acknowledge_grob (Grob_info inf) +Break_align_engraver::add_to_group (SCM align_name, Item *item) { - if (Item * item_l = dynamic_cast (inf.elem_l_)) + SCM s = scm_assoc (align_name, column_alist_); + Item *group = 0; + + if (s != SCM_BOOL_F) + { + Grob *e = Grob::unsmob (scm_cdr (s)); + group = dynamic_cast (e); + } + else { - if (item_l->empty_b (X_AXIS) || item_l->parent_l (X_AXIS)) - return; - - SCM bp=item_l->get_grob_property ("breakable"); - bool breakable = (to_boolean (bp)); - if (!breakable) - return ; - - SCM align_name = item_l->get_grob_property ("break-align-symbol"); - if (!gh_symbol_p (align_name)) - return ; - - if (!align_l_) - { - align_l_ = new Item (get_property ("BreakAlignment")); - Break_align_interface::set_interface (align_l_); - announce_grob (align_l_,0); - - SCM edge_sym = ly_symbol2scm ("Left_edge_item"); - Item * edge = new Item (get_property ("LeftEdge")); - - - - /* - If the element is empty, it will be ignored in the break - alignment stuff. - - TODO: switch off ignoring empty stuff? - */ - edge->set_extent_callback (Grob::point_dimension_callback_proc, X_AXIS); - - /* - We must have left-edge in the middle. Instrument-names - are left to left-edge, so they don't enter the staff. - */ - align_l_->set_grob_property ("self-alignment-X", edge->self_scm ()); - - announce_grob (edge, 0); - column_alist_ = scm_assoc_set_x (column_alist_, edge_sym, edge->self_scm ()); - } - - SCM s = scm_assoc (align_name, column_alist_); - - Item * group = 0; - - if (s != SCM_BOOL_F) - { - Grob *e = unsmob_grob (ly_cdr (s)); - group = dynamic_cast (e); - } - else - { - group = new Item (get_property ("BreakAlignGroup")); - - Axis_group_interface::set_interface (group); - Axis_group_interface::set_axes (group, X_AXIS,X_AXIS); - - group->set_grob_property ("break-align-symbol", align_name); - group->set_parent (align_l_, Y_AXIS); - announce_grob (group, 0); - column_alist_ = scm_assoc_set_x (column_alist_, align_name, group->self_scm ()); - - } - Axis_group_interface::add_element (group, item_l); + group = make_item ("BreakAlignGroup", item->self_scm ()); + + group->set_property ("break-align-symbol", align_name); + group->set_parent (align_, Y_AXIS); + + column_alist_ = scm_assoc_set_x (column_alist_, align_name, group->self_scm ()); + + Break_alignment_interface::add_element (align_, group); } + Axis_group_interface::add_element (group, item); } + +ADD_ACKNOWLEDGER (Break_align_engraver, break_aligned); +ADD_ACKNOWLEDGER (Break_align_engraver, break_alignable); +ADD_TRANSLATOR (Break_align_engraver, + /* doc */ + "Align grobs with corresponding @code{break-align-symbols}" + " into groups, and order the groups according to" + " @code{breakAlignOrder}. The left edge of the alignment gets" + " a separate group, with a symbol @code{left-edge}.", + + /* create */ + "BreakAlignment " + "BreakAlignGroup " + "LeftEdge ", + + /* read */ + "", + + /* write */ + "" + );