2 System-start-delimiter-engraver.cc -- implement
3 System_start_delimiter_engraver
5 source file of the GNU LilyPond music typesetter
7 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "engraver.hh"
13 #include "side-position-interface.hh"
14 #include "system-start-delimiter.hh"
15 #include "staff-symbol.hh"
16 #include "pointer-group-interface.hh"
17 #include "paper-column.hh"
18 #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 vector
<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_
= engraver
->make_spanner (ly_symbol2string (type
).c_str (), SCM_EOL
);
81 for (vsize i
= 0 ; i
< children_
.size (); i
++)
83 children_
[i
]->create_grobs (engraver
, default_type
);
88 Bracket_nesting_group::add_support (Grob
*g
)
90 Side_position_interface::add_support (g
, delimiter_
);
91 for (vsize i
= 0 ; i
< children_
.size (); i
++)
93 children_
[i
]->add_support (g
);
97 Bracket_nesting_group::~Bracket_nesting_group ()
99 junk_pointers (children_
);
103 Bracket_nesting_group::set_bound (Direction d
, Grob
*g
)
105 delimiter_
->set_bound (d
, g
);
106 for (vsize i
= 0 ; i
< children_
.size (); i
++)
108 children_
[i
]->set_bound (d
, g
);
113 Bracket_nesting_group::set_nesting_support (Grob
*parent
)
116 Side_position_interface::add_support (delimiter_
, parent
);
118 for (vsize i
= 0 ; i
< children_
.size (); i
++)
120 children_
[i
]->set_nesting_support (delimiter_
);
126 Bracket_nesting_group::from_list (SCM x
)
128 for (SCM s
= x
; scm_is_pair (s
); s
= scm_cdr (s
))
130 SCM entry
= scm_car (s
);
131 if (scm_is_pair (entry
))
133 Bracket_nesting_group
*node
= new Bracket_nesting_group
;
134 node
->from_list (entry
);
135 children_
.push_back (node
);
137 else if (entry
== ly_symbol2scm ("SystemStartBrace")
138 || entry
== ly_symbol2scm ("SystemStartBracket")
139 || entry
== ly_symbol2scm ("SystemStartBar")
140 || entry
== ly_symbol2scm ("SystemStartSquare")
145 children_
.push_back (new Bracket_nesting_staff (0));
151 Bracket_nesting_group::add_staff (Grob
*grob
)
153 for (vsize i
= 0; i
< children_
.size (); i
++)
155 if (children_
[i
]->add_staff (grob
))
157 Pointer_group_interface::add_grob (delimiter_
, ly_symbol2scm ("elements"), grob
);
170 class System_start_delimiter_engraver
: public Engraver
173 TRANSLATOR_DECLARATIONS (System_start_delimiter_engraver
);
176 Bracket_nesting_group
*nesting_
;
178 DECLARE_ACKNOWLEDGER (system_start_delimiter
);
179 DECLARE_ACKNOWLEDGER (system_start_text
);
180 DECLARE_ACKNOWLEDGER (staff_symbol
);
182 void process_music ();
183 virtual void finalize ();
186 System_start_delimiter_engraver::System_start_delimiter_engraver ()
192 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 System_start_delimiter_engraver::finalize ()
211 nesting_
->set_bound (RIGHT
,
212 unsmob_grob (get_property ("currentCommandColumn")));
213 nesting_
->set_nesting_support (0);
220 System_start_delimiter_engraver::acknowledge_staff_symbol (Grob_info inf
)
222 Grob
*staff
= inf
.grob ();
223 bool succ
= nesting_
->add_staff (staff
);
227 nesting_
->children_
.push_back (new Bracket_nesting_staff (0));
228 nesting_
->add_staff (staff
);
235 System_start_delimiter_engraver::acknowledge_system_start_text (Grob_info inf
)
237 nesting_
->add_support (inf
.grob ());
241 System_start_delimiter_engraver::acknowledge_system_start_delimiter (Grob_info inf
)
243 nesting_
->add_support (inf
.grob ());
246 #include "translator.icc"
248 ADD_ACKNOWLEDGER (System_start_delimiter_engraver
, staff_symbol
);
249 ADD_ACKNOWLEDGER (System_start_delimiter_engraver
, system_start_delimiter
);
250 ADD_ACKNOWLEDGER (System_start_delimiter_engraver
, system_start_text
);
252 ADD_TRANSLATOR (System_start_delimiter_engraver
,
253 /* doc */ "Creates a system start delimiter (ie. SystemStart@{Bar, Brace, Bracket@} spanner",
254 /* create */ "SystemStartSquare "
256 "SystemStartBracket "
259 "systemStartDelimiter "
260 "systemStartDelimiterHierarchy "
261 "currentCommandColumn",