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>
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"
16 #include "staff-symbol.hh"
17 #include "system-start-delimiter.hh"
19 struct Bracket_nesting_node
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
33 vector
<Bracket_nesting_node
*> children_
;
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
51 Bracket_nesting_staff (Grob
*s
) { staff_
= s
; }
52 virtual bool add_staff (Grob
*);
56 Bracket_nesting_group::Bracket_nesting_group ()
63 Bracket_nesting_staff::add_staff (Grob
*g
)
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 (),
80 for (vsize i
= 0 ; i
< children_
.size (); i
++)
81 children_
[i
]->create_grobs (engraver
, default_type
);
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_
);
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
);
106 Bracket_nesting_group::set_nesting_support (Grob
*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_
);
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"))
134 children_
.push_back (new Bracket_nesting_staff (0));
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
);
158 class System_start_delimiter_engraver
: public Engraver
161 TRANSLATOR_DECLARATIONS (System_start_delimiter_engraver
);
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 ()
179 System_start_delimiter_engraver::process_music ()
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")));
195 System_start_delimiter_engraver::finalize ()
199 nesting_
->set_bound (RIGHT
,
200 unsmob_grob (get_property ("currentCommandColumn")));
201 nesting_
->set_nesting_support (0);
208 System_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf
)
210 Grob
*staff
= inf
.grob ();
211 bool succ
= nesting_
->add_staff (staff
);
215 nesting_
->children_
.push_back (new Bracket_nesting_staff (0));
216 nesting_
->add_staff (staff
);
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
,
233 "Create a system start delimiter (i.e., a"
234 " @code{SystemStartBar}, @code{SystemStartBrace},"
235 " @code{SystemStartBracket} or @code{SystemStartSquare}"
241 "SystemStartBracket "
245 "systemStartDelimiter "
246 "systemStartDelimiterHierarchy "
247 "currentCommandColumn ",