Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / system-start-delimiter-engraver.cc
blob7d8647051023099eec5019c699aeabb993b3b6e8
1 /*
2 System-start-delimiter-engraver.cc -- implement
3 System_start_delimiter_engraver
5 source file of the GNU LilyPond music typesetter
7 (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "engraver.hh"
11 #include "output-def.hh"
12 #include "paper-column.hh"
13 #include "pointer-group-interface.hh"
14 #include "side-position-interface.hh"
15 #include "spanner.hh"
16 #include "staff-symbol.hh"
17 #include "system-start-delimiter.hh"
19 struct Bracket_nesting_node
21 public:
22 virtual ~Bracket_nesting_node () {}
23 virtual bool add_staff (Grob *) { return false; }
24 virtual void add_support (Grob *) {}
25 virtual void set_bound (Direction, Grob *) {}
26 virtual void set_nesting_support (Grob *) {}
27 virtual void create_grobs (Engraver *, SCM) {}
30 struct Bracket_nesting_group : public Bracket_nesting_node
32 Spanner *delimiter_;
33 vector<Bracket_nesting_node*> children_;
34 SCM symbol_;
36 void from_list (SCM);
37 virtual void add_support (Grob *grob);
38 virtual bool add_staff (Grob *grob);
39 virtual void set_nesting_support (Grob *);
40 virtual void set_bound (Direction, Grob *grob);
41 virtual void create_grobs (Engraver *, SCM);
42 ~Bracket_nesting_group ();
43 Bracket_nesting_group ();
47 struct Bracket_nesting_staff : public Bracket_nesting_node
49 Grob *staff_;
51 Bracket_nesting_staff (Grob *s) { staff_ = s; }
52 virtual bool add_staff (Grob *);
56 Bracket_nesting_group::Bracket_nesting_group ()
58 symbol_ = SCM_EOL;
59 delimiter_ = 0;
62 bool
63 Bracket_nesting_staff::add_staff (Grob *g)
65 if (!staff_)
67 staff_ = g;
68 return true;
70 return false;
73 void
74 Bracket_nesting_group::create_grobs (Engraver *engraver, SCM default_type)
76 SCM type = scm_is_symbol (symbol_) ? symbol_ : default_type;
77 delimiter_ = engraver->make_spanner (ly_symbol2string (type).c_str (),
78 SCM_EOL);
80 for (vsize i = 0 ; i < children_.size (); i++)
81 children_[i]->create_grobs (engraver, default_type);
84 void
85 Bracket_nesting_group::add_support (Grob *g)
87 Side_position_interface::add_support (g, delimiter_);
88 for (vsize i = 0 ; i < children_.size (); i++)
89 children_[i]->add_support (g);
92 Bracket_nesting_group::~Bracket_nesting_group ()
94 junk_pointers (children_);
97 void
98 Bracket_nesting_group::set_bound (Direction d, Grob *g)
100 delimiter_->set_bound (d, g);
101 for (vsize i = 0 ; i < children_.size (); i++)
102 children_[i]->set_bound (d, g);
105 void
106 Bracket_nesting_group::set_nesting_support (Grob *parent)
108 if (parent)
109 Side_position_interface::add_support (delimiter_, parent);
111 for (vsize i = 0 ; i < children_.size (); i++)
112 children_[i]->set_nesting_support (delimiter_);
116 void
117 Bracket_nesting_group::from_list (SCM x)
119 for (SCM s = x; scm_is_pair (s); s = scm_cdr (s))
121 SCM entry = scm_car (s);
122 if (scm_is_pair (entry))
124 Bracket_nesting_group *node = new Bracket_nesting_group;
125 node->from_list (entry);
126 children_.push_back (node);
128 else if (entry == ly_symbol2scm ("SystemStartBrace")
129 || entry == ly_symbol2scm ("SystemStartBracket")
130 || entry == ly_symbol2scm ("SystemStartBar")
131 || entry == ly_symbol2scm ("SystemStartSquare"))
132 symbol_ = entry;
133 else
134 children_.push_back (new Bracket_nesting_staff (0));
138 bool
139 Bracket_nesting_group::add_staff (Grob *grob)
141 for (vsize i = 0; i < children_.size (); i++)
143 if (children_[i]->add_staff (grob))
145 Pointer_group_interface::add_grob (delimiter_,
146 ly_symbol2scm ("elements"), grob);
147 return true;
150 return false;
156 /****************/
158 class System_start_delimiter_engraver : public Engraver
160 public:
161 TRANSLATOR_DECLARATIONS (System_start_delimiter_engraver);
163 protected:
164 Bracket_nesting_group *nesting_;
166 DECLARE_ACKNOWLEDGER (system_start_delimiter);
167 DECLARE_ACKNOWLEDGER (staff_symbol);
169 void process_music ();
170 virtual void finalize ();
173 System_start_delimiter_engraver::System_start_delimiter_engraver ()
175 nesting_ = 0;
178 void
179 System_start_delimiter_engraver::process_music ()
181 if (!nesting_)
183 nesting_ = new Bracket_nesting_group ();
184 SCM hierarchy = get_property ("systemStartDelimiterHierarchy");
185 SCM delimiter_name = get_property ("systemStartDelimiter");
187 nesting_->from_list (hierarchy);
188 nesting_->create_grobs (this, delimiter_name);
189 nesting_->set_bound (LEFT,
190 unsmob_grob (get_property ("currentCommandColumn")));
194 void
195 System_start_delimiter_engraver::finalize ()
197 if (nesting_)
199 nesting_->set_bound (RIGHT,
200 unsmob_grob (get_property ("currentCommandColumn")));
201 nesting_->set_nesting_support (0);
203 delete nesting_;
207 void
208 System_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf)
210 Grob *staff = inf.grob ();
211 bool succ = nesting_->add_staff (staff);
213 if (!succ)
215 nesting_->children_.push_back (new Bracket_nesting_staff (0));
216 nesting_->add_staff (staff);
220 void
221 System_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info inf)
223 nesting_->add_support (inf.grob ());
226 #include "translator.icc"
228 ADD_ACKNOWLEDGER (System_start_delimiter_engraver, staff_symbol);
229 ADD_ACKNOWLEDGER (System_start_delimiter_engraver, system_start_delimiter);
231 ADD_TRANSLATOR (System_start_delimiter_engraver,
232 /* doc */
233 "Create a system start delimiter (i.e., a"
234 " @code{SystemStartBar}, @code{SystemStartBrace},"
235 " @code{SystemStartBracket} or @code{SystemStartSquare}"
236 " spanner).",
238 /* create */
239 "SystemStartSquare "
240 "SystemStartBrace "
241 "SystemStartBracket "
242 "SystemStartBar ",
244 /* read */
245 "systemStartDelimiter "
246 "systemStartDelimiterHierarchy "
247 "currentCommandColumn ",
249 /* write */