2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 #include "engraver.hh"
20 #include "protected-scm.hh"
21 #include "break-align-interface.hh"
22 #include "align-interface.hh"
23 #include "axis-group-interface.hh"
25 #include "translator-group.hh"
28 #include "translator.icc"
30 class Break_align_engraver : public Engraver
36 void add_to_group (SCM, Item *);
37 void create_alignment (Grob_info);
39 void stop_translation_timestep ();
40 virtual void derived_mark () const;
42 TRANSLATOR_DECLARATIONS (Break_align_engraver);
43 void acknowledge_break_aligned (Grob_info);
44 void acknowledge_break_alignable (Grob_info);
48 Break_align_engraver::stop_translation_timestep ()
50 column_alist_ = SCM_EOL;
56 Break_align_engraver::Break_align_engraver (Context *c)
59 column_alist_ = SCM_EOL;
65 Break_align_engraver::derived_mark () const
67 scm_gc_mark (column_alist_);
71 Break_align_engraver::acknowledge_break_alignable (Grob_info inf)
74 Special case for MetronomeMark: filter out items which will be aligned
75 on note heads rather than prefatory material
77 if (!Item::is_non_musical (inf.item ()))
81 create_alignment (inf);
83 Grob *g = inf.grob ();
85 if (!g->get_parent (X_AXIS))
86 g->set_parent (align_, X_AXIS);
90 Break_align_engraver::acknowledge_break_aligned (Grob_info inf)
92 if (Item *item = dynamic_cast<Item *> (inf.grob ()))
95 Removed check for item->empty (X_AXIS). --hwn 20/1/04
97 if (item->get_parent (X_AXIS))
100 if (!Item::is_non_musical (item))
103 SCM align_name = item->get_property ("break-align-symbol");
104 if (!scm_is_symbol (align_name))
108 create_alignment (inf);
110 add_to_group (align_name, item);
115 Break_align_engraver::create_alignment (Grob_info inf)
117 align_ = make_item ("BreakAlignment", SCM_EOL);
119 Context *origin = inf.origin_contexts (this)[0];
121 Translator_group *tg = origin->implementation ();
122 Engraver *random_source = unsmob<Engraver> (scm_car (tg->get_simple_trans_list ()));
124 random_source = this;
127 Make left edge appear to come from same context as clef/bar-line etc.
129 left_edge_ = random_source->make_item ("LeftEdge", SCM_EOL);
130 add_to_group (left_edge_->get_property ("break-align-symbol"),
135 Break_align_engraver::add_to_group (SCM align_name, Item *item)
137 SCM s = scm_assoc (align_name, column_alist_);
142 Grob *e = unsmob<Grob> (scm_cdr (s));
143 group = dynamic_cast<Item *> (e);
147 group = make_item ("BreakAlignGroup", item->self_scm ());
149 group->set_property ("break-align-symbol", align_name);
150 group->set_parent (align_, Y_AXIS);
152 column_alist_ = scm_assoc_set_x (column_alist_, align_name, group->self_scm ());
154 Break_alignment_interface::add_element (align_, group);
156 Axis_group_interface::add_element (group, item);
160 Break_align_engraver::boot ()
162 ADD_ACKNOWLEDGER (Break_align_engraver, break_aligned);
163 ADD_ACKNOWLEDGER (Break_align_engraver, break_alignable);
166 ADD_TRANSLATOR (Break_align_engraver,
168 "Align grobs with corresponding @code{break-align-symbols}"
169 " into groups, and order the groups according to"
170 " @code{breakAlignOrder}. The left edge of the alignment gets"
171 " a separate group, with a symbol @code{left-edge}.",