2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--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/>.
20 #include "engraver.hh"
22 #include "separation-item.hh"
23 #include "paper-column.hh"
24 #include "output-def.hh"
25 #include "axis-group-interface.hh"
26 #include "note-spacing.hh"
27 #include "accidental-placement.hh"
30 #include "grob-array.hh"
31 #include "pointer-group-interface.hh"
33 #include "translator.icc"
38 vector<Item *> note_spacings_;
45 bool is_empty () const
47 return !staff_spacing_ && !note_spacings_.size ();
52 note_spacings_.clear ();
56 class Separating_line_group_engraver : public Engraver
59 Spacings current_spacings_;
60 Spacings last_spacings_;
62 void acknowledge_item (Grob_info);
63 void acknowledge_break_aligned (Grob_info);
64 void stop_translation_timestep ();
65 void start_translation_timestep ();
67 vector<Grob *> break_aligned_;
69 TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
72 Separating_line_group_engraver::Separating_line_group_engraver (Context *c)
78 Separating_line_group_engraver::acknowledge_item (Grob_info i)
82 if (has_interface<Note_spacing> (it))
84 current_spacings_.note_spacings_.push_back (it);
88 if (Item::is_non_musical (it)
89 && !current_spacings_.staff_spacing_
90 && to_boolean (get_property ("createSpacing")))
92 Grob *col = unsmob<Grob> (get_property ("currentCommandColumn"));
94 current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
95 context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
97 Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
98 ly_symbol2scm ("left-items"),
101 if (!last_spacings_.note_spacings_.size ()
102 && last_spacings_.staff_spacing_)
104 SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
105 Grob_array *ga = unsmob<Grob_array> (ri);
108 SCM ga_scm = Grob_array::make_array ();
109 last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
110 ga = unsmob<Grob_array> (ga_scm);
120 Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
122 break_aligned_.push_back (gi.grob ());
126 Separating_line_group_engraver::start_translation_timestep ()
128 context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
132 Separating_line_group_engraver::stop_translation_timestep ()
134 for (vsize i = 0; i < break_aligned_.size (); i++)
136 SCM smob = break_aligned_[i]->self_scm ();
138 if (Item *sp = current_spacings_.staff_spacing_)
139 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob);
141 for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++)
142 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j],
143 ly_symbol2scm ("right-break-aligned"), smob);
146 if (!current_spacings_.is_empty ())
147 last_spacings_ = current_spacings_;
149 if (Item *sp = current_spacings_.staff_spacing_)
150 if (Grob *col = unsmob<Grob> (get_property ("currentMusicalColumn")))
151 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col);
153 current_spacings_.clear ();
154 break_aligned_.clear ();
159 Separating_line_group_engraver::boot ()
161 ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
162 ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned);
165 ADD_TRANSLATOR (Separating_line_group_engraver,
167 "Generate objects for computing spacing parameters.",