Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / system-start-delimiter-engraver.cc
bloba0bc5039254db3688e3e8a07a271752c75bc436a
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--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"
21 #include "output-def.hh"
22 #include "paper-column.hh"
23 #include "pointer-group-interface.hh"
24 #include "side-position-interface.hh"
25 #include "spanner.hh"
26 #include "staff-symbol.hh"
27 #include "system-start-delimiter.hh"
29 struct Bracket_nesting_node
31 public:
32 virtual ~Bracket_nesting_node () {}
33 virtual bool add_staff (Grob *) { return false; }
34 virtual void add_support (Grob *) {}
35 virtual void set_bound (Direction, Grob *) {}
36 virtual void set_nesting_support (Grob *) {}
37 virtual void create_grobs (Engraver *, SCM) {}
40 struct Bracket_nesting_group : public Bracket_nesting_node
42 Spanner *delimiter_;
43 vector<Bracket_nesting_node*> children_;
44 SCM symbol_;
46 void from_list (SCM);
47 virtual void add_support (Grob *grob);
48 virtual bool add_staff (Grob *grob);
49 virtual void set_nesting_support (Grob *);
50 virtual void set_bound (Direction, Grob *grob);
51 virtual void create_grobs (Engraver *, SCM);
52 ~Bracket_nesting_group ();
53 Bracket_nesting_group ();
57 struct Bracket_nesting_staff : public Bracket_nesting_node
59 Grob *staff_;
61 Bracket_nesting_staff (Grob *s) { staff_ = s; }
62 virtual bool add_staff (Grob *);
66 Bracket_nesting_group::Bracket_nesting_group ()
68 symbol_ = SCM_EOL;
69 delimiter_ = 0;
72 bool
73 Bracket_nesting_staff::add_staff (Grob *g)
75 if (!staff_)
77 staff_ = g;
78 return true;
80 return false;
83 void
84 Bracket_nesting_group::create_grobs (Engraver *engraver, SCM default_type)
86 SCM type = scm_is_symbol (symbol_) ? symbol_ : default_type;
87 delimiter_ = engraver->make_spanner (ly_symbol2string (type).c_str (),
88 SCM_EOL);
90 for (vsize i = 0 ; i < children_.size (); i++)
91 children_[i]->create_grobs (engraver, default_type);
94 void
95 Bracket_nesting_group::add_support (Grob *g)
97 Side_position_interface::add_support (g, delimiter_);
98 for (vsize i = 0 ; i < children_.size (); i++)
99 children_[i]->add_support (g);
102 Bracket_nesting_group::~Bracket_nesting_group ()
104 junk_pointers (children_);
107 void
108 Bracket_nesting_group::set_bound (Direction d, Grob *g)
110 delimiter_->set_bound (d, g);
111 for (vsize i = 0 ; i < children_.size (); i++)
112 children_[i]->set_bound (d, g);
115 void
116 Bracket_nesting_group::set_nesting_support (Grob *parent)
118 if (parent)
119 Side_position_interface::add_support (delimiter_, parent);
121 for (vsize i = 0 ; i < children_.size (); i++)
122 children_[i]->set_nesting_support (delimiter_);
126 void
127 Bracket_nesting_group::from_list (SCM x)
129 for (SCM s = x; scm_is_pair (s); s = scm_cdr (s))
131 SCM entry = scm_car (s);
132 if (scm_is_pair (entry))
134 Bracket_nesting_group *node = new Bracket_nesting_group;
135 node->from_list (entry);
136 children_.push_back (node);
138 else if (entry == ly_symbol2scm ("SystemStartBrace")
139 || entry == ly_symbol2scm ("SystemStartBracket")
140 || entry == ly_symbol2scm ("SystemStartBar")
141 || entry == ly_symbol2scm ("SystemStartSquare"))
142 symbol_ = entry;
143 else
144 children_.push_back (new Bracket_nesting_staff (0));
148 bool
149 Bracket_nesting_group::add_staff (Grob *grob)
151 for (vsize i = 0; i < children_.size (); i++)
153 if (children_[i]->add_staff (grob))
155 Pointer_group_interface::add_grob (delimiter_,
156 ly_symbol2scm ("elements"), grob);
157 return true;
160 return false;
166 /****************/
168 class System_start_delimiter_engraver : public Engraver
170 public:
171 TRANSLATOR_DECLARATIONS (System_start_delimiter_engraver);
173 protected:
174 Bracket_nesting_group *nesting_;
176 DECLARE_ACKNOWLEDGER (system_start_delimiter);
177 DECLARE_ACKNOWLEDGER (staff_symbol);
179 void process_music ();
180 virtual void finalize ();
183 System_start_delimiter_engraver::System_start_delimiter_engraver ()
185 nesting_ = 0;
188 void
189 System_start_delimiter_engraver::process_music ()
191 if (!nesting_)
193 nesting_ = new Bracket_nesting_group ();
194 SCM hierarchy = get_property ("systemStartDelimiterHierarchy");
195 SCM delimiter_name = get_property ("systemStartDelimiter");
197 nesting_->from_list (hierarchy);
198 nesting_->create_grobs (this, delimiter_name);
199 nesting_->set_bound (LEFT,
200 unsmob_grob (get_property ("currentCommandColumn")));
204 void
205 System_start_delimiter_engraver::finalize ()
207 if (nesting_)
209 nesting_->set_bound (RIGHT,
210 unsmob_grob (get_property ("currentCommandColumn")));
211 nesting_->set_nesting_support (0);
213 delete nesting_;
217 void
218 System_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf)
220 Grob *staff = inf.grob ();
221 bool succ = nesting_->add_staff (staff);
223 if (!succ)
225 nesting_->children_.push_back (new Bracket_nesting_staff (0));
226 nesting_->add_staff (staff);
230 void
231 System_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info inf)
233 nesting_->add_support (inf.grob ());
236 #include "translator.icc"
238 ADD_ACKNOWLEDGER (System_start_delimiter_engraver, staff_symbol);
239 ADD_ACKNOWLEDGER (System_start_delimiter_engraver, system_start_delimiter);
241 ADD_TRANSLATOR (System_start_delimiter_engraver,
242 /* doc */
243 "Create a system start delimiter (i.e., a"
244 " @code{SystemStartBar}, @code{SystemStartBrace},"
245 " @code{SystemStartBracket} or @code{SystemStartSquare}"
246 " spanner).",
248 /* create */
249 "SystemStartSquare "
250 "SystemStartBrace "
251 "SystemStartBracket "
252 "SystemStartBar ",
254 /* read */
255 "systemStartDelimiter "
256 "systemStartDelimiterHierarchy "
257 "currentCommandColumn ",
259 /* write */