+
+ if (!new_event_found_)
+ return;
+
+ new_event_found_ = false;
+
+ /*
+ Don't need to sync alignments, if we're not using extenders.
+ */
+ if (!use_extenders)
+ {
+ clear_spanners ();
+ }
+
+ if (!continuation_)
+ {
+ clear_spanners ();
+ groups_.clear ();
+ }
+
+ vsize k = 0;
+ for (vsize i = 0; i < new_events_.size (); i++)
+ {
+ while (k < groups_.size ()
+ && groups_[k].current_event_)
+ k++;
+
+ if (k >= groups_.size ())
+ {
+ Figure_group group;
+ groups_.push_back (group);
+ }
+
+ groups_[k].reset_figure ();
+ groups_[k].current_event_ = new_events_[i];
+ groups_[k].figure_item_ = 0;
+ k++;
+ }
+
+ for (vsize i = 0; i < groups_.size (); i++)
+ {
+ if (!groups_[i].is_continuation ())
+ {
+ groups_[i].reset_figure ();
+ }
+ }
+
+ if (use_extenders)
+ {
+ vector<int> junk_continuations;
+ for (vsize i = 0; i < groups_.size (); i++)
+ {
+ Figure_group &group = groups_[i];
+
+ if (group.is_continuation ())
+ {
+ if (!group.continuation_line_)
+ {
+ Spanner *line
+ = make_spanner ("BassFigureContinuation", SCM_EOL);
+ Item *item = group.figure_item_;
+ group.continuation_line_ = line;
+ line->set_bound (LEFT, item);
+
+ /*
+ Don't add as child. This will cache the wrong
+ (pre-break) stencil when callbacks are triggered.
+ */
+ line->set_parent (group.group_, Y_AXIS);
+ Pointer_group_interface::add_grob (line, ly_symbol2scm ("figures"), item);
+
+ group.figure_item_ = 0;
+ }
+ }
+ else if (group.continuation_line_)
+ junk_continuations.push_back (i);
+ }
+
+ /*
+ Ugh, repeated code.
+ */
+ vector<Spanner *> consecutive;
+ if (to_boolean (get_property ("figuredBassCenterContinuations")))
+ {
+ for (vsize i = 0; i <= junk_continuations.size (); i++)
+ {
+ if (i < junk_continuations.size ()
+ && (i == 0 || junk_continuations[i - 1] == junk_continuations[i] - 1))
+ consecutive.push_back (groups_[junk_continuations[i]].continuation_line_);
+ else
+ {
+ center_continuations (consecutive);
+ consecutive.clear ();
+ if (i < junk_continuations.size ())
+ consecutive.push_back (groups_[junk_continuations[i]].continuation_line_);
+ }
+ }
+ }
+ for (vsize i = 0; i < junk_continuations.size (); i++)
+ groups_[junk_continuations[i]].continuation_line_ = 0;
+ }
+
+ create_grobs ();
+ add_brackets ();
+}
+
+void
+Figured_bass_engraver::create_grobs ()
+{
+ Grob *muscol
+ = unsmob<Item> (get_property ("currentMusicalColumn"));
+ if (!alignment_)
+ {
+ alignment_ = make_spanner ("BassFigureAlignment", SCM_EOL);
+ alignment_->set_bound (LEFT, muscol);
+ }
+ alignment_->set_bound (RIGHT, muscol);
+
+ SCM proc = get_property ("figuredBassFormatter");
+ for (vsize i = 0; i < groups_.size (); i++)
+ {
+ Figure_group &group = groups_[i];
+
+ if (group.current_event_)
+ {
+ Item *item
+ = make_item ("BassFigure", group.current_event_->self_scm ());
+ group.assign_from_event (group.current_event_, item);
+
+ if (!group.group_)
+ {
+ group.group_ = make_spanner ("BassFigureLine", SCM_EOL);
+ group.group_->set_bound (LEFT, muscol);
+ Align_interface::add_element (alignment_, group.group_);
+ }
+
+ if (scm_is_true (scm_memq (group.number_, get_property ("implicitBassFigures"))))
+ {
+ item->set_property ("transparent", SCM_BOOL_T);
+ item->set_property ("implicit", SCM_BOOL_T);
+ }
+
+ SCM text = group.text_;
+ if (!Text_interface::is_markup (text)
+ && ly_is_procedure (proc))
+ {
+ text = scm_call_3 (proc, group.number_, group.current_event_->self_scm (),
+ context ()->self_scm ());
+ }
+
+ item->set_property ("text", text);
+
+ Axis_group_interface::add_element (group.group_, item);
+ }
+
+ if (group.continuation_line_)
+ {
+ /*
+ UGH should connect to the bass staff, and get the note heads.
+ For now, simply set the hidden figure to a default value to
+ ensure the extenders of different figures always end at the same
+ position, e.g. in <12 5> <12 5>
+ */
+ group.figure_item_->set_property ("transparent", SCM_BOOL_T);
+ group.figure_item_->set_property ("text", ly_string2scm ("0"));
+ group.continuation_line_->set_bound (RIGHT, group.figure_item_);
+ }
+
+ if (groups_[i].group_)
+ groups_[i].group_->set_bound (RIGHT, muscol);
+
+ }
+
+}
+
+void
+Figured_bass_engraver::add_brackets ()
+{
+ vector<Grob *> encompass;
+ bool inside = false;
+ for (vsize i = 0; i < groups_.size (); i++)