Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / separating-line-group-engraver.cc
blob86c45fb55a0bc1fe4792f7d56d1516b147e8f668
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2011 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"
28 #include "context.hh"
29 #include "spanner.hh"
30 #include "grob-array.hh"
31 #include "pointer-group-interface.hh"
33 #include "translator.icc"
35 struct Spacings
37 Item *staff_spacing_;
38 vector<Item*> note_spacings_;
40 Spacings ()
42 staff_spacing_ = 0;
45 bool is_empty () const
47 return !staff_spacing_ && !note_spacings_.size ();
49 void clear ()
51 staff_spacing_ = 0;
52 note_spacings_.clear ();
56 class Separating_line_group_engraver : public Engraver
58 protected:
59 Spacings current_spacings_;
60 Spacings last_spacings_;
62 DECLARE_ACKNOWLEDGER (item);
63 DECLARE_ACKNOWLEDGER (break_aligned);
64 void stop_translation_timestep ();
65 void start_translation_timestep ();
67 vector<Grob*> break_aligned_;
68 public:
69 TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
72 Separating_line_group_engraver::Separating_line_group_engraver ()
76 void
77 Separating_line_group_engraver::acknowledge_item (Grob_info i)
79 Item *it = i.item ();
81 if (Note_spacing::has_interface (it))
83 current_spacings_.note_spacings_.push_back (it);
84 return;
87 if (Item::is_non_musical (it)
88 && !current_spacings_.staff_spacing_
89 && to_boolean (get_property ("createSpacing")))
91 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
93 current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
94 context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
96 Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
97 ly_symbol2scm ("left-items"),
98 col);
100 if (!last_spacings_.note_spacings_.size ()
101 && last_spacings_.staff_spacing_)
103 SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
104 Grob_array *ga = unsmob_grob_array (ri);
105 if (!ga)
107 SCM ga_scm = Grob_array::make_array ();
108 last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
109 ga = unsmob_grob_array (ga_scm);
112 ga->clear ();
113 ga->add (col);
118 void
119 Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
121 break_aligned_.push_back (gi.grob ());
124 void
125 Separating_line_group_engraver::start_translation_timestep ()
127 context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
130 void
131 Separating_line_group_engraver::stop_translation_timestep ()
133 for (vsize i = 0; i < break_aligned_.size (); i++)
135 SCM smob = break_aligned_[i]->self_scm ();
137 if (Item *sp = current_spacings_.staff_spacing_)
138 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob);
140 for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++)
141 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j],
142 ly_symbol2scm ("right-break-aligned"), smob);
145 if (!current_spacings_.is_empty ())
146 last_spacings_ = current_spacings_;
148 if (Item *sp = current_spacings_.staff_spacing_)
149 if (Grob *col = unsmob_grob (get_property ("currentMusicalColumn")))
150 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col);
152 current_spacings_.clear ();
153 break_aligned_.clear ();
156 ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
157 ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned);
159 ADD_TRANSLATOR (Separating_line_group_engraver,
160 /* doc */
161 "Generate objects for computing spacing parameters.",
163 /* create */
164 "StaffSpacing ",
166 /* read */
167 "createSpacing ",
169 /* write */
170 "hasStaffSpacing "