2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--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"
21 #include "output-def.hh"
22 #include "paper-column.hh"
23 #include "pointer-group-interface.hh"
24 #include "side-position-interface.hh"
26 #include "staff-symbol.hh"
27 #include "system-start-delimiter.hh"
29 #include "translator.icc"
33 struct Bracket_nesting_node
36 virtual ~Bracket_nesting_node () {}
37 virtual bool add_staff (Grob *) { return false; }
38 virtual void add_support (Grob *) {}
39 virtual void set_bound (Direction, Grob *) {}
40 virtual void set_nesting_support (Grob *) {}
41 virtual void create_grobs (Engraver *, SCM) {}
44 struct Bracket_nesting_group : public Bracket_nesting_node
47 vector<Bracket_nesting_node *> children_;
51 virtual void add_support (Grob *grob);
52 virtual bool add_staff (Grob *grob);
53 virtual void set_nesting_support (Grob *);
54 virtual void set_bound (Direction, Grob *grob);
55 virtual void create_grobs (Engraver *, SCM);
56 ~Bracket_nesting_group ();
57 Bracket_nesting_group ();
60 struct Bracket_nesting_staff : public Bracket_nesting_node
64 Bracket_nesting_staff (Grob *s) { staff_ = s; }
65 virtual bool add_staff (Grob *);
68 Bracket_nesting_group::Bracket_nesting_group ()
75 Bracket_nesting_staff::add_staff (Grob *g)
86 Bracket_nesting_group::create_grobs (Engraver *engraver, SCM default_type)
88 SCM type = scm_is_symbol (symbol_) ? symbol_ : default_type;
89 delimiter_ = engraver->make_spanner (ly_symbol2string (type).c_str (),
92 for (vsize i = 0; i < children_.size (); i++)
93 children_[i]->create_grobs (engraver, default_type);
97 Bracket_nesting_group::add_support (Grob *g)
99 Side_position_interface::add_support (g, delimiter_);
100 for (vsize i = 0; i < children_.size (); i++)
101 children_[i]->add_support (g);
104 Bracket_nesting_group::~Bracket_nesting_group ()
106 junk_pointers (children_);
110 Bracket_nesting_group::set_bound (Direction d, Grob *g)
112 delimiter_->set_bound (d, g);
113 for (vsize i = 0; i < children_.size (); i++)
114 children_[i]->set_bound (d, g);
118 Bracket_nesting_group::set_nesting_support (Grob *parent)
121 Side_position_interface::add_support (delimiter_, parent);
123 for (vsize i = 0; i < children_.size (); i++)
124 children_[i]->set_nesting_support (delimiter_);
128 Bracket_nesting_group::from_list (SCM x)
130 for (SCM s = x; scm_is_pair (s); s = scm_cdr (s))
132 SCM entry = scm_car (s);
133 if (scm_is_pair (entry))
135 Bracket_nesting_group *node = new Bracket_nesting_group;
136 node->from_list (entry);
137 children_.push_back (node);
139 else if (scm_is_eq (entry, ly_symbol2scm ("SystemStartBrace"))
140 || scm_is_eq (entry, ly_symbol2scm ("SystemStartBracket"))
141 || scm_is_eq (entry, ly_symbol2scm ("SystemStartBar"))
142 || scm_is_eq (entry, ly_symbol2scm ("SystemStartSquare")))
145 children_.push_back (new Bracket_nesting_staff (0));
150 Bracket_nesting_group::add_staff (Grob *grob)
152 for (vsize i = 0; i < children_.size (); i++)
154 if (children_[i]->add_staff (grob))
156 Pointer_group_interface::add_grob (delimiter_,
157 ly_symbol2scm ("elements"), grob);
166 class System_start_delimiter_engraver : public Engraver
169 TRANSLATOR_DECLARATIONS (System_start_delimiter_engraver);
172 Bracket_nesting_group *nesting_;
174 DECLARE_ACKNOWLEDGER (system_start_delimiter);
175 DECLARE_ACKNOWLEDGER (staff_symbol);
177 void process_music ();
178 virtual void finalize ();
181 System_start_delimiter_engraver::System_start_delimiter_engraver ()
187 System_start_delimiter_engraver::process_music ()
191 nesting_ = new Bracket_nesting_group ();
192 SCM hierarchy = get_property ("systemStartDelimiterHierarchy");
193 SCM delimiter_name = get_property ("systemStartDelimiter");
195 nesting_->from_list (hierarchy);
196 nesting_->create_grobs (this, delimiter_name);
197 nesting_->set_bound (LEFT,
198 unsmob<Grob> (get_property ("currentCommandColumn")));
203 System_start_delimiter_engraver::finalize ()
207 nesting_->set_bound (RIGHT,
208 unsmob<Grob> (get_property ("currentCommandColumn")));
209 nesting_->set_nesting_support (0);
216 System_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf)
218 Grob *staff = inf.grob ();
219 bool succ = nesting_->add_staff (staff);
223 nesting_->children_.push_back (new Bracket_nesting_staff (0));
224 nesting_->add_staff (staff);
229 System_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info inf)
231 nesting_->add_support (inf.grob ());
234 ADD_ACKNOWLEDGER (System_start_delimiter_engraver, staff_symbol);
235 ADD_ACKNOWLEDGER (System_start_delimiter_engraver, system_start_delimiter);
237 ADD_TRANSLATOR (System_start_delimiter_engraver,
239 "Create a system start delimiter (i.e., a"
240 " @code{SystemStartBar}, @code{SystemStartBrace},"
241 " @code{SystemStartBracket} or @code{SystemStartSquare}"
247 "SystemStartBracket "
251 "systemStartDelimiter "
252 "systemStartDelimiterHierarchy "
253 "currentCommandColumn ",