2 new-system-start-delimiter-engraver.cc -- implement
3 Nested_system_start_delimiter_engraver
5 source file of the GNU LilyPond music typesetter
7 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "side-position-interface.hh"
12 #include "system-start-delimiter.hh"
13 #include "engraver.hh"
14 #include "staff-symbol.hh"
15 #include "pointer-group-interface.hh"
16 #include "paper-column.hh"
17 #include "output-def.hh"
21 struct Bracket_nesting_node
24 virtual ~Bracket_nesting_node(){}
25 virtual bool add_staff (Grob *) { return false; }
26 virtual void add_support (Grob *) { }
27 virtual void set_bound (Direction, Grob *){}
28 virtual void set_nesting_support (Grob*) {}
29 virtual void create_grobs (Engraver*, SCM) {}
32 struct Bracket_nesting_group : public Bracket_nesting_node
35 Link_array<Bracket_nesting_node> children_;
38 void from_list (SCM );
39 virtual void add_support (Grob *grob);
40 virtual bool add_staff (Grob *grob);
41 virtual void set_nesting_support (Grob*);
42 virtual void set_bound (Direction, Grob *grob);
43 virtual void create_grobs (Engraver*, SCM);
44 ~Bracket_nesting_group ();
45 Bracket_nesting_group ();
49 struct Bracket_nesting_staff : public Bracket_nesting_node
53 Bracket_nesting_staff (Grob *s) { staff_ = s; }
54 virtual bool add_staff (Grob *);
58 Bracket_nesting_group::Bracket_nesting_group ()
65 Bracket_nesting_staff::add_staff (Grob *g)
76 Bracket_nesting_group::create_grobs (Engraver *engraver, SCM default_type)
78 SCM type = scm_is_symbol (symbol_) ? symbol_ : default_type;
79 delimiter_ = make_spanner_from_properties (engraver, type,
80 SCM_EOL, ly_symbol2string (type).to_str0 ());
82 for (int i = 0 ; i < children_.size (); i++)
84 children_[i]->create_grobs (engraver, default_type);
89 Bracket_nesting_group::add_support (Grob *g)
91 Side_position_interface::add_support (g, delimiter_);
92 for (int i = 0 ; i < children_.size (); i++)
94 children_[i]->add_support (g);
98 Bracket_nesting_group::~Bracket_nesting_group ()
100 for (int i = 0 ; i < children_.size (); i++)
105 Bracket_nesting_group::set_bound (Direction d, Grob *g)
107 delimiter_->set_bound (d, g);
108 for (int i = 0 ; i < children_.size (); i++)
110 children_[i]->set_bound (d, g);
115 Bracket_nesting_group::set_nesting_support (Grob *parent)
118 Side_position_interface::add_support (delimiter_, parent);
120 for (int i = 0 ; i < children_.size (); i++)
122 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 (node);
141 children_.push (new Bracket_nesting_staff (0));
144 if (scm_is_symbol (entry))
150 Bracket_nesting_group::add_staff (Grob *grob)
152 for (int i = 0; i < children_.size (); i++)
154 if (children_[i]->add_staff (grob))
156 Pointer_group_interface::add_grob (delimiter_, ly_symbol2scm ("elements"), grob);
169 class Nested_system_start_delimiter_engraver : public Engraver
172 TRANSLATOR_DECLARATIONS (Nested_system_start_delimiter_engraver);
175 Bracket_nesting_group *nesting_;
177 DECLARE_ACKNOWLEDGER (system_start_delimiter);
178 DECLARE_ACKNOWLEDGER (staff_symbol);
180 void process_music ();
181 virtual void finalize ();
184 Nested_system_start_delimiter_engraver::Nested_system_start_delimiter_engraver ()
192 Nested_system_start_delimiter_engraver::process_music ()
196 nesting_ = new Bracket_nesting_group ();
197 SCM hierarchy = get_property ("systemStartDelimiterHierarchy");
198 SCM delimiter_name = get_property ("systemStartDelimiter");
200 nesting_->from_list (hierarchy);
201 nesting_->create_grobs (this, delimiter_name);
202 nesting_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
207 Nested_system_start_delimiter_engraver::finalize ()
211 nesting_->set_bound (RIGHT,
212 unsmob_grob (get_property ("currentCommandColumn")));
213 nesting_->set_nesting_support (0);
218 Nested_system_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf)
220 Grob *staff = inf.grob();
221 bool succ = nesting_->add_staff (staff);
225 nesting_->children_.push (new Bracket_nesting_staff (0));
226 nesting_->add_staff (staff);
232 Nested_system_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info inf)
234 nesting_->add_support (inf.grob ());
237 #include "translator.icc"
239 ADD_ACKNOWLEDGER (Nested_system_start_delimiter_engraver, staff_symbol);
240 ADD_ACKNOWLEDGER (Nested_system_start_delimiter_engraver, system_start_delimiter);
242 ADD_TRANSLATOR (Nested_system_start_delimiter_engraver,
243 /* doc */ "Creates a system start delimiter (ie. SystemStart@{Bar, Brace, Bracket@} spanner",
244 /* create */ "SystemStartSquare SystemStartBrace SystemStartBracket SystemStartBar",
246 /* read */ "systemStartDelimiter systemStartDelimiterHierarchy currentCommandColumn",