+ new_event_found_ = false;
+
+ /*
+ Don't need to sync alignments, if we're not using extenders.
+ */
+ bool use_extenders = to_boolean (get_property ("useBassFigureExtenders"));
+ 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].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].number_ = SCM_BOOL_F;
+ groups_[i].alteration_ = SCM_BOOL_F;
+ }
+ }
+
+ 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
+ = dynamic_cast<Item*> (unsmob_grob (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 ());
+
+
+ SCM fig = group.current_event_->get_property ("figure");
+ 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_memq (fig, get_property ("implicitBassFigures")) != SCM_BOOL_F)
+ {
+ item->set_property ("transparent", SCM_BOOL_T);
+ item->set_property ("implicit", SCM_BOOL_T);
+ }
+
+ group.number_ = fig;
+ group.alteration_ = group.current_event_->get_property ("alteration");
+
+ SCM text = group.current_event_->get_property ("text");
+ if (!Text_interface::is_markup (text)
+ && ly_is_procedure (proc))
+ {
+ text = scm_call_3 (proc, fig, group.current_event_->self_scm (),
+ context ()->self_scm ());
+ }
+
+ item->set_property ("text", text);
+
+ Axis_group_interface::add_element (group.group_, item);
+ group.figure_item_ = item;
+ }
+
+ if (group.continuation_line_)
+ {
+ /*
+ UGH should connect to the bass staff, and get the note heads.
+ */
+ group.figure_item_->set_property ("transparent", SCM_BOOL_T);
+ group.continuation_line_->set_bound (RIGHT, group.figure_item_);
+ }
+
+ if (groups_[i].group_)
+ groups_[i].group_->set_bound (RIGHT, muscol);
+
+ }
+
+}
+
+ADD_TRANSLATOR (Figured_bass_engraver,
+ /* doc */
+ "Make figured bass numbers.",
+
+ /* create */
+ "BassFigure "
+ "BassFigureAlignment "
+ "BassFigureBracket "
+ "BassFigureContinuation "
+ "BassFigureLine ",
+
+ /* read */
+ "figuredBassAlterationDirection "
+ "figuredBassCenterContinuations "
+ "figuredBassFormatter "
+ "implicitBassFigures "
+ "useBassFigureExtenders "
+ "ignoreFiguredBassRest ",
+
+ /* write */
+ ""
+ );