]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/vaticana-ligature-engraver.cc
Run `make grand-replace'.
[lilypond.git] / lily / vaticana-ligature-engraver.cc
index 22c05494c16813fd9aa284acec7f9bf35bff4616..53bec433d7c196be7b7fb5a9728ac273cd6e8685 100644 (file)
 /*
   vaticana-ligature-engraver.cc -- implement Vaticana_ligature_engraver
-  
+
   source file of the GNU LilyPond music typesetter
-  
-  (c)  2003 Juergen Reuter <reuter@ipd.uka.de>
- */
+
+  (c) 2003--2008 Juergen Reuter <reuter@ipd.uka.de>
+*/
 
 #include "gregorian-ligature-engraver.hh"
+
+#include "font-interface.hh"
 #include "gregorian-ligature.hh"
-#include "vaticana-ligature.hh"
-#include "item.hh"
+#include "international.hh"
+#include "output-def.hh"
+#include "paper-column.hh"
+#include "separation-item.hh"
 #include "spanner.hh"
 #include "staff-symbol-referencer.hh"
-#include "font-interface.hh"
+#include "stream-event.hh"
+#include "vaticana-ligature.hh"
 #include "warn.hh"
-#include "paper-def.hh"
-#include "paper-column.hh"
+#include "dot-column.hh"
+#include "rhythmic-head.hh"
+#include "pitch.hh"
+#include "translator.icc"
 
 /*
  * This class implements the notation specific aspects of Vaticana
  * style ligatures for Gregorian chant notation.
  */
+
+/*
+ * TODO: Maybe move handling of dots/mora to
+ * Gregorian_ligature_engraver?  It's probably common for all types of
+ * Gregorian chant notation that have dotted notes.
+ *
+ * FIXME: The horizontal alignment of the mora column is bad (too far
+ * to the left), if the last dotted note is not the last primitive in
+ * the ligature.  Fortunately, in practice this bug should have no
+ * negative impact, since dotted notes appear within a ligature
+ * usually always at the end of the ligature, such that the bug never
+ * should apply for valid ligatures.
+ *
+ * TODO: Graduale Triplex, tempus per annum, hebdomada septima,
+ * alleluia (page 280) shows a counter-example for collecting dots
+ * always in a single column behind the ligature.  Maybe only the last
+ * two dots in a ligature should be collected and all other dots put
+ * behind or on top of the head?
+ */
 class Vaticana_ligature_engraver : public Gregorian_ligature_engraver
 {
 
 private:
-  Real finish_primitive (Item *first_primitive,
-                        Item *primitive,
-                        int context_info,
-                        String glyph_name,
-                        int pitch_delta,
-                        Real flexa_width,
-                        Real join_thickness,
-                        Real distance);
+  static bool
+  need_extra_horizontal_space (int prev_prefix_set, int prefix_set,
+                              int context_info, int delta_pitch);
+  bool is_stacked_head (int prefix_set,
+                       int context_info);
+  Real align_heads (vector<Grob_info> primitives,
+                   Real flexa_width,
+                   Real thickness);
+  void check_for_prefix_loss (Item *primitive);
+  void check_for_ambiguous_dot_pitch (Grob_info primitive);
+  void add_mora_column (Paper_column *column);
+  vector<Grob_info> augmented_primitives_;
 
 public:
-  TRANSLATOR_DECLARATIONS(Vaticana_ligature_engraver);
+  TRANSLATOR_DECLARATIONS (Vaticana_ligature_engraver);
 
 protected:
   virtual Spanner *create_ligature_spanner ();
   virtual void transform_heads (Spanner *ligature,
-                               Array<Grob_info> primitives);
+                               vector<Grob_info> primitives);
+  DECLARE_TRANSLATOR_LISTENER (pes_or_flexa);
+  DECLARE_TRANSLATOR_LISTENER (ligature);
 };
 
+IMPLEMENT_TRANSLATOR_LISTENER (Vaticana_ligature_engraver, pes_or_flexa);
+void
+Vaticana_ligature_engraver::listen_pes_or_flexa (Stream_event *ev)
+{
+  Gregorian_ligature_engraver::listen_pes_or_flexa (ev);
+}
+
+IMPLEMENT_TRANSLATOR_LISTENER (Vaticana_ligature_engraver, ligature);
+void
+Vaticana_ligature_engraver::listen_ligature (Stream_event *ev)
+{
+  Ligature_engraver::listen_ligature (ev);
+}
+
 Vaticana_ligature_engraver::Vaticana_ligature_engraver ()
 {
+  brew_ligature_primitive_proc = 
+    Vaticana_ligature::brew_ligature_primitive_proc;
+  augmented_primitives_.clear ();
 }
 
 Spanner *
 Vaticana_ligature_engraver::create_ligature_spanner ()
 {
-  return new Spanner (get_property ("VaticanaLigature"));
+  return make_spanner ("VaticanaLigature", SCM_EOL);
+}
+
+bool
+Vaticana_ligature_engraver::is_stacked_head (int prefix_set,
+                                            int context_info)
+{
+  bool is_stacked;
+
+  // upper head of pes is stacked upon lower head of pes ...
+  is_stacked = context_info & PES_UPPER;
+
+  // ... unless this note starts a flexa
+  if (context_info & FLEXA_LEFT)
+    is_stacked = false;
+
+  // ... or another pes
+  if (context_info & PES_LOWER)
+    is_stacked = false;
+
+  // ... or the previous note is a semivocalis or inclinatum
+  if (context_info & AFTER_DEMINUTUM)
+    is_stacked = false;
+
+  // auctum head is never stacked upon preceding note
+  if (prefix_set & AUCTUM)
+    is_stacked = false;
+
+  // virga is never stacked upon preceding note
+  if (prefix_set & VIRGA)
+    is_stacked = false;
+
+  // oriscus is never stacked upon preceding note
+  if (prefix_set & ORISCUS)
+    is_stacked = false;
+
+  if ((prefix_set & DEMINUTUM)
+      && ! (prefix_set & INCLINATUM)
+      && (context_info & FLEXA_RIGHT))
+    is_stacked = true; // semivocalis head of deminutus form
+
+  return is_stacked;
+}
+
+/*
+ * When aligning the heads, sometimes extra space is needed, e.g. to
+ * avoid clashing with the appendix of an adjacent notehead or with an
+ * adjacent notehead itself if it has the same pitch.  Extra space is
+ * added at most once between to heads.
+ */
+bool
+Vaticana_ligature_engraver::need_extra_horizontal_space (int prev_prefix_set, int prefix_set,
+                                                        int context_info, int delta_pitch)
+{
+  if (prev_prefix_set & VIRGA)
+    /*
+     * After a virga, make a an additional small space such that the
+     * appendix on the right side of the head does not touch the
+     * following head.
+     */
+    return true;
+
+  if ((prefix_set & INCLINATUM)
+      && ! (prev_prefix_set & INCLINATUM))
+    /*
+     * Always start a series of inclinatum heads with an extra space.
+     */
+    return true;
+
+  if ((context_info & FLEXA_LEFT) && ! (context_info & PES_UPPER))
+    /*
+     * Before a flexa (but not within a torculus), make a an
+     * additional small space such that the appendix on the left side
+     * of the flexa does not touch the this head.
+     */
+    return true;
+
+  if (delta_pitch == 0)
+    /*
+     * If there are two adjacent noteheads with the same pitch, add
+     * additional small space between them, such that they do not
+     * touch each other.
+     */
+    return true;
+
+  return false;
 }
 
 Real
-Vaticana_ligature_engraver::finish_primitive (Item *first_primitive,
-                                             Item *primitive,
-                                             int context_info,
-                                             String glyph_name,
-                                             int pitch_delta,
-                                             Real flexa_width,
-                                             Real join_thickness,
-                                             Real distance)
+Vaticana_ligature_engraver::align_heads (vector<Grob_info> primitives,
+                                        Real flexa_width,
+                                        Real thickness)
 {
-  Real next_distance = distance;
-  if (primitive)
+  if (!primitives.size ())
+    {
+      programming_error ("Vaticana_ligature: "
+                        "empty ligature [ignored]");
+      return 0.0;
+    }
+
+  /*
+   * The paper column where we put the whole ligature into.
+   */
+  Paper_column *column
+    = dynamic_cast<Item *> (primitives[0].grob ())->get_column ();
+
+  Real join_thickness
+    = thickness * column->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
+
+  /*
+   * Amount of extra space two put between some particular
+   * configurations of adjacent heads.
+   *
+   * TODO: make this a property of primtive grobs.
+   */
+  Real extra_space = 4.0 * join_thickness;
+
+  /*
+   * Keep track of the total width of the ligature.
+   */
+  Real ligature_width = 0.0;
+
+  Item *prev_primitive = 0;
+  int prev_prefix_set = 0;
+  for (vsize i = 0; i < primitives.size (); i++)
     {
-      // determine width of previous head and x-offset
+      Item *primitive = dynamic_cast<Item *> (primitives[i].grob ());
+      int prefix_set
+       = scm_to_int (primitive->get_property ("prefix-set"));
+      int context_info
+       = scm_to_int (primitive->get_property ("context-info"));
+
+      /*
+       * Get glyph_name, delta_pitch and context_info for this head.
+       */
+
+      SCM glyph_name_scm = primitive->get_property ("glyph-name");
+      if (glyph_name_scm == SCM_EOL)
+       {
+         primitive->programming_error ("Vaticana_ligature:"
+                                       " undefined glyph-name ->"
+                                       " ignoring grob");
+         continue;
+       }
+      string glyph_name = ly_scm2string (glyph_name_scm);
+
+      int delta_pitch = 0;
+      if (prev_primitive) /* urgh, need prev_primitive only here */
+       {
+         SCM delta_pitch_scm = prev_primitive->get_property ("delta-position");
+         if (delta_pitch_scm != SCM_EOL)
+           delta_pitch = scm_to_int (delta_pitch_scm);
+         else
+           {
+             primitive->programming_error ("Vaticana_ligature:"
+                                           " delta-position undefined ->"
+                                           " ignoring grob");
+             continue;
+           }
+       }
+
+      /*
+       * Now determine width and x-offset of head.
+       */
+
       Real head_width;
       Real x_offset;
-      bool is_stacked;
-      is_stacked = context_info & PES_UPPER;
-      if (context_info & FLEXA_LEFT)
-       is_stacked = false;
-      if (!String::compare (glyph_name, "vaticana_cephalicus") &&
-         !(context_info & PES_LOWER))
-       is_stacked = true;
-      if (context_info & AUCTUM)
-       is_stacked = false;
-      if (is_stacked)
+
+      if (context_info & STACKED_HEAD)
        {
          /*
-          * This head is stacked upon another one; hence, it does not
-          * contribute to the total width of the ligature, hence its
-          * width is assumed to be 0.0.  Moreover, it is shifted to
-          * the left by its width such that the right side of this
-          * and the other head are horizontally aligned.
+          * This head is stacked upon the previous one; hence, it
+          * does not contribute to the total width of the ligature,
+          * and its width is assumed to be 0.0.  Moreover, it is
+          * shifted to the left by its width such that the right side
+          * of this and the other head are horizontally aligned.
           */
          head_width = 0.0;
-         x_offset = join_thickness -
-           Font_interface::get_default_font (primitive)->
-           find_by_name ("noteheads-" + glyph_name).extent (X_AXIS).length ();
+         x_offset = join_thickness
+           Font_interface::get_default_font (primitive)->
+           find_by_name ("noteheads.s" + glyph_name).extent (X_AXIS).length ();
        }
-      else if (!String::compare (glyph_name, "flexa") ||
-              !String::compare (glyph_name, ""))
+      else if (glyph_name == "flexa" || glyph_name == "")
        {
          /*
           * This head represents either half of a flexa shape.
@@ -102,268 +290,452 @@ Vaticana_ligature_engraver::finish_primitive (Item *first_primitive,
          head_width = 0.5 * flexa_width;
          x_offset = 0.0;
        }
-      else // retrieve width from corresponding font
+      else
        {
-         head_width =
-           Font_interface::get_default_font (primitive)->
-           find_by_name ("noteheads-" + glyph_name).extent (X_AXIS).length ();
+         /*
+          * This is a regular head, placed right to the previous one.
+          * Retrieve its width from corresponding font.
+          */
+         head_width
+           = Font_interface::get_default_font (primitive)->
+           find_by_name ("noteheads.s" + glyph_name).extent (X_AXIS).length ();
          x_offset = 0.0;
        }
 
       /*
-       * Save the head's final shape and x-offset.
+       * Save the head's final x-offset.
        */
-      primitive->set_grob_property ("glyph-name",
-                                   scm_makfrom0str (glyph_name.to_str0 ()));
-      primitive->set_grob_property ("x-offset",
-                                   gh_double2scm (x_offset));
+      primitive->set_property ("x-offset",
+                              scm_from_double (x_offset));
 
       /*
        * If the head is the 2nd head of a pes or flexa (but not a
        * flexa shape), mark this head to be joined with the left-side
        * neighbour head (i.e. the previous head) by a vertical beam.
        */
-      if ((context_info & PES_UPPER) ||
-         ((context_info & FLEXA_RIGHT) &&
-          !(context_info & PES_LOWER)))
+      if ((context_info & PES_UPPER)
+         || ((context_info & FLEXA_RIGHT)
+             && ! (context_info & PES_LOWER)))
        {
-         primitive->set_grob_property ("join-left",
-                                       gh_int2scm (pitch_delta));
+         if (!prev_primitive)
+           {
+             primitive->programming_error ("vaticana ligature: add-join: "
+                                           "missing previous primitive");
+           }
+         else
+           {
+             prev_primitive->set_property ("add-join",
+                                           ly_bool2scm (true));
 
-         /*
-          * Create a small overlap of adjacent heads so that the join
-          * can be drawn perfectly between them.
-          */
-         next_distance -= join_thickness;
-       }
-      else if (!String::compare (glyph_name, ""))
-       {
-         /*
-          * 2nd (virtual) head of flexa shape: join tightly with 1st
-          * head, i.e. do *not* add additional space, such that next
-          * head will not be off from the flexa shape.
-          */
+             /*
+              * Create a small overlap of adjacent heads so that the join
+              * can be drawn perfectly between them.
+              */
+             ligature_width -= join_thickness;
+           }
        }
-      else if (context_info & AFTER_VIRGA)
+      else if (glyph_name == "")
        {
          /*
-          * Make a small space after a virga.
+          * This is the 2nd (virtual) head of flexa shape.  Join it
+          * tightly with 1st head, i.e. do *not* add additional
+          * space, such that next head will not be off from the flexa
+          * shape.
           */
-         next_distance += 2 * join_thickness;
-       }
-      else if (pitch_delta == 0)
-       {
-         /*
-          * Make a small space between two adjacent notes with the
-          * same pitch.
-          */
-         next_distance += 2 * join_thickness;
        }
 
+      if (need_extra_horizontal_space (prev_prefix_set, prefix_set,
+                                      context_info, delta_pitch))
+       ligature_width += extra_space;
+
       /*
        * Horizontally line-up this head to form a ligature.
        */
-      get_set_column (primitive, first_primitive->get_column ());
-      primitive->translate_axis (next_distance, X_AXIS);
-      next_distance += head_width;
+      move_related_items_to_column (primitive, column, ligature_width);
+      ligature_width += head_width;
 
+      prev_primitive = primitive;
+      prev_prefix_set = prefix_set;
     }
 
-  return next_distance;
+  /*
+   * Add extra horizontal padding space after ligature, such that
+   * neighbouring ligatures do not touch each other.
+   */
+  ligature_width += extra_space;
+
+  return ligature_width;
 }
 
+/*
+ * Depending on the typographical features of a particular ligature
+ * style, some prefixes may be ignored.  In particular, if a curved
+ * flexa shape is produced, any prefixes to either of the two
+ * contributing heads that would select a head other than punctum, is
+ * by definition ignored.
+ *
+ * This function prints a warning, if the given primitive is prefixed
+ * such that a head other than punctum would be chosen, if this
+ * primitive were engraved as a stand-alone head.
+ */
 void
-Vaticana_ligature_engraver::transform_heads (Spanner *ligature,
-                                            Array<Grob_info> primitives)
+Vaticana_ligature_engraver::check_for_prefix_loss (Item *primitive)
 {
-  Real flexa_width;
-  SCM flexa_width_scm = ligature->get_grob_property ("flexa-width");
-  if (flexa_width_scm != SCM_EOL)
+  int prefix_set
+    = scm_to_int (primitive->get_property ("prefix-set"));
+  if (prefix_set & ~PES_OR_FLEXA)
     {
-      flexa_width = gh_scm2double (flexa_width_scm);
+      string prefs = Gregorian_ligature::prefixes_to_str (primitive);
+      primitive->warning (_f ("ignored prefix (es) `%s' of this head according "
+                             "to restrictions of the selected ligature style",
+                             prefs.c_str ()));
     }
-  else
+}
+
+void
+Vaticana_ligature_engraver::add_mora_column (Paper_column *column)
+{
+  if (augmented_primitives_.size () == 0) // no dot for column
+    return;
+  if (!column) // empty ligature???
     {
-      programming_error ("Vaticana_ligature_engraver:"
-                        "flexa-width undefined; assuming 2.0 staff space");
-      flexa_width =
-       2.0 * Staff_symbol_referencer::staff_space (ligature);
+      augmented_primitives_[0].grob ()->
+       programming_error ("no paper column to add dot");
+      return;
     }
-
-  Real join_thickness;
-  SCM join_thickness_scm = ligature->get_grob_property ("thickness");
-  if (join_thickness_scm != SCM_EOL)
+  Item *dotcol = make_item ("DotColumn", SCM_EOL);
+  dotcol->set_parent (column, X_AXIS);
+  for (vsize i = 0; i < augmented_primitives_.size (); i++)
     {
-      join_thickness = gh_scm2double (join_thickness_scm);
+      Item *primitive =
+       dynamic_cast<Item *> (augmented_primitives_[i].grob ());
+      Item *dot = make_item ("Dots", primitive->self_scm ());
+      dot->set_property ("dot-count", scm_from_int (1));
+      dot->set_parent (primitive, Y_AXIS);
+      primitive->set_object ("dot", dot->self_scm ());
+      Dot_column::add_head (dotcol, primitive);
+
+      // FIXME: why isn't the dot picked up by Paper_column_engraver?
+      Separation_item::add_item (column, dot);
     }
-  else
+}
+
+/*
+ * This function prints a warning, if the given primitive has the same
+ * pitch as at least one of the primitives already stored in the
+ * augmented_primitives_ array.
+ *
+ * The rationale of this check is, that, if there are two dotted
+ * primitives with the same pitch, then collecting all dots in a dot
+ * column behind the ligature leads to a notational ambiguity of to
+ * which head the corresponding dot refers.
+ *
+ * Such a case should be treated as a badly specified ligature.  The
+ * user should split the ligature to make the notation of dots
+ * unambiguous.
+ */
+void
+Vaticana_ligature_engraver::check_for_ambiguous_dot_pitch (Grob_info primitive)
+{
+  // TODO: Fix performance, which is currently O (n^2) (since this
+  // method is called O (n) times and takes O (n) steps in the for
+  // loop), but could be O (n) (by replacing the for loop by e.g. a
+  // bitmask based O (1) test); where n=<number of primitives in the
+  // ligature> (which is typically small (n<10), though).
+  Stream_event *new_cause = primitive.event_cause ();
+  int new_pitch = unsmob_pitch (new_cause->get_property ("pitch"))->steps ();
+  for (vsize i = 0; i < augmented_primitives_.size (); i++)
     {
-      programming_error ("Vaticana_ligature_engraver:"
-                        "thickness undefined; assuming 1.4 linethickness");
-      join_thickness = 1.4;
+      Stream_event *cause = augmented_primitives_[i].event_cause ();
+      int pitch = unsmob_pitch (cause->get_property ("pitch"))->steps ();
+      if (pitch == new_pitch)
+       {
+         primitive.grob ()->
+           warning ("Ambiguous use of dots in ligature: there are "
+                    "multiple dotted notes with the same pitch.  "
+                    "The ligature should be split.");
+         return; // supress multiple identical warnings
+       }
     }
-  join_thickness *= ligature->get_paper ()->get_var ("linethickness");
+}
+
+void
+Vaticana_ligature_engraver::transform_heads (Spanner *ligature,
+                                            vector<Grob_info> primitives)
+{
+  Real flexa_width = robust_scm2double (ligature->get_property ("flexa-width"), 2);
+
+  Real thickness = robust_scm2double (ligature->get_property ("thickness"), 1);
 
-  Item *first_primitive = 0;
   Item *prev_primitive = 0;
+  int prev_prefix_set = 0;
   int prev_context_info = 0;
-  int prev_pitch = 0;
-  int prev_pitch_delta = 0;
-  String prev_glyph_name = "";
-  Real prev_distance = 0.0;
-  for (int i = 0; i < primitives.size(); i++) {
-    Item *primitive = dynamic_cast<Item*> (primitives[i].grob_);
-    Music *music_cause = primitives[i].music_cause ();
-    int context_info = gh_scm2int (primitive->get_grob_property ("context-info"));
-    int pitch = unsmob_pitch (music_cause->get_mus_property ("pitch"))->steps ();
-    String glyph_name;
-    if (!first_primitive)
-      first_primitive = primitive;
-    int prefix_set = gh_scm2int (primitive->get_grob_property ("prefix-set"));
+  int prev_delta_pitch = 0;
+  string prev_glyph_name = "";
+  augmented_primitives_.clear ();
+  for (vsize i = 0; i < primitives.size (); i++)
+    {
+      Item *primitive = dynamic_cast<Item *> (primitives[i].grob ());
 
-    /*
-     * Now determine which head to typeset (this is context sensitive
-     * information, since it depends on neighbouring heads; therefore,
-     * this decision must be made here in the engraver rather than in
-     * the backend).
-     */
-    if (prefix_set & VIRGA)
-      glyph_name = "vaticana_virga";
-    else if (prefix_set & QUILISMA)
-      glyph_name = "vaticana_quilisma";
-    else if (prefix_set & ORISCUS)
-      glyph_name = "solesmes_oriscus";
-    else if (prefix_set & STROPHA)
-      if (prefix_set & AUCTUM)
-       glyph_name = "solesmes_stropha_aucta";
-      else glyph_name = "solesmes_stropha";
-    else if (prefix_set & SEMIVOCALIS)
-      if (pitch > prev_pitch)
-       glyph_name = "vaticana_epiphonus";
-      else glyph_name = "vaticana_cephalicus";
-    else if (prefix_set & INCLINATUM)
-      if (prefix_set & AUCTUM)
-       glyph_name = "solesmes_incl_auctum";
-      else if (prefix_set & DEMINUTUM)
-       glyph_name = "solesmes_incl_parvum";
-      else
-       glyph_name = "vaticana_inclinatum";
-    else if (prefix_set & (CAVUM | LINEA))
-      if ((prefix_set & CAVUM) && (prefix_set & LINEA))
-       glyph_name = "vaticana_linea_punctum_cavum";
-      else if (prefix_set & CAVUM)
-       glyph_name = "vaticana_punctum_cavum";
-      else
-       glyph_name = "vaticana_linea_punctum";
-    else if (prefix_set & AUCTUM)
-      if (prefix_set & ASCENDENS)
-       glyph_name = "solesmes_auct_asc";
+      int delta_pitch;
+      SCM delta_pitch_scm = primitive->get_property ("delta-position");
+      if (delta_pitch_scm != SCM_EOL)
+       delta_pitch = scm_to_int (delta_pitch_scm);
       else
-       glyph_name = "solesmes_auct_desc";
-    else if (prefix_set & DEMINUTUM)
-      glyph_name = "vaticana_plica";
-    else if ((prefix_set & PES_OR_FLEXA) &&
-            (context_info & PES_LOWER) &&
-            (context_info & FLEXA_RIGHT))
-      glyph_name = ""; // second head of flexa shape
-    else if (context_info & PES_UPPER)
-      if (pitch - prev_pitch > 1)
-       glyph_name = "vaticana_upes";
-      else
-       glyph_name = "vaticana_vupes";
-    else
-      glyph_name = "vaticana_punctum";
+       {
+         primitive->programming_error ("Vaticana_ligature:"
+                                       " delta-position undefined ->"
+                                       " ignoring grob");
+         continue;
+       }
 
-    /*
-     * May need updating previous head, depending on the current head.
-     */
-    if (prefix_set & PES_OR_FLEXA)
-      if ((context_info & PES_LOWER) &&
-         (context_info & FLEXA_RIGHT)) // flexa shape
+      /* retrieve & complete prefix_set and context_info */
+      int prefix_set
+       = scm_to_int (primitive->get_property ("prefix-set"));
+      int context_info
+       = scm_to_int (primitive->get_property ("context-info"));
+
+      if (Rhythmic_head::dot_count (primitive) > 0)
+       // remove dots from primitive and add remember primitive for
+       // creating a dot column
        {
-         prev_glyph_name = "flexa";
-         prev_primitive->set_grob_property ("flexa-height",
-                                            gh_int2scm (pitch - prev_pitch));
-         prev_primitive->set_grob_property ("flexa-width",
-                                            gh_double2scm (flexa_width));
-         bool add_stem =
-           !(prev_context_info & PES_UPPER) &&
-           !(prev_context_info & FLEXA_RIGHT);
-         prev_primitive->set_grob_property ("add-stem",
-                                            gh_bool2scm (add_stem));
+         Rhythmic_head::get_dots (primitive)->set_property ("dot-count",
+                                                            scm_from_int (0));
+         // TODO: Maybe completely remove grob "Dots" (dots->suicide
+         // () ?) rather than setting property "dot-count" to 0.
+
+         check_for_ambiguous_dot_pitch (primitives[i]);
+         augmented_primitives_.push_back (primitives[i]);
        }
-      else if (context_info & PES_UPPER)
+      else if (augmented_primitives_.size () > 0)
        {
-         if (!String::compare (prev_glyph_name, "vaticana_punctum"))
-           prev_glyph_name = "vaticana_lpes";
+         primitive->warning ("This ligature has a dotted head followed by "
+                             "a non-dotted head.  The ligature should be "
+                             "split after the last dotted head before "
+                             "this head.");
        }
-      else // flexa
+
+      if (is_stacked_head (prefix_set, context_info))
        {
-         if (!String::compare (prev_glyph_name, "vaticana_punctum"))
-           prev_glyph_name = "vaticana_rvirga";
+         context_info |= STACKED_HEAD;
+         primitive->set_property ("context-info",
+                                  scm_from_int (context_info));
        }
 
-    /*
-     * In the backend, flexa shapes and joins need to know about
-     * thickness.  Hence, for simplicity, let's distribute the
-     * ligature grob's value for thickness to each ligature head (even
-     * if not all of them need to know).
-     */
-    primitive->set_grob_property ("thickness", gh_double2scm (join_thickness));
+      /*
+       * Now determine which head to typeset (this is context sensitive
+       * information, since it depends on neighbouring heads; therefore,
+       * this decision must be made here in the engraver rather than in
+       * the backend).
+       */
+      string glyph_name;
+      if (prefix_set & VIRGA)
+       {
+         glyph_name = "vaticana.punctum";
+         primitive->set_property ("add-stem", ly_bool2scm (true));
+       }
+      else if (prefix_set & QUILISMA)
+       glyph_name = "vaticana.quilisma";
+      else if (prefix_set & ORISCUS)
+       glyph_name = "solesmes.oriscus";
+      else if (prefix_set & STROPHA)
+       if (prefix_set & AUCTUM)
+         glyph_name = "solesmes.stropha.aucta";
+       else glyph_name = "solesmes.stropha";
+      else if (prefix_set & INCLINATUM)
+       if (prefix_set & AUCTUM)
+         glyph_name = "solesmes.incl.auctum";
+       else if (prefix_set & DEMINUTUM)
+         glyph_name = "solesmes.incl.parvum";
+       else
+         glyph_name = "vaticana.inclinatum";
+      else if (prefix_set & DEMINUTUM)
+       if (i == 0)
+         {
+           // initio debilis
+           glyph_name = "vaticana.reverse.plica";
+         }
+       else if (prev_delta_pitch > 0)
+         {
+           // epiphonus
+           if (! (prev_context_info & FLEXA_RIGHT))
+             /* correct head of previous primitive */
+             if (prev_delta_pitch > 1)
+               prev_glyph_name = "vaticana.epiphonus";
+             else
+               prev_glyph_name = "vaticana.vepiphonus";
+           if (prev_delta_pitch > 1)
+             glyph_name = "vaticana.plica";
+           else
+             glyph_name = "vaticana.vplica";
+         }
+       else if (prev_delta_pitch < 0)
+         {
+           // cephalicus
+           if (! (prev_context_info & FLEXA_RIGHT))
+             /* correct head of previous primitive */
+             {
+               if (i > 1)
+                 {
+                   /* cephalicus head with fixed size cauda */
+                   prev_glyph_name = "vaticana.inner.cephalicus";
+                 }
+               else
+                 {
+                   /* cephalicus head without cauda */
+                   prev_glyph_name = "vaticana.cephalicus";
+                 }
 
-    /*
-     * The head of the current iteration still may change during the
-     * next iteration due to the context sensitiveness of the
-     * transformation.  However, the head of the previous iteration is
-     * now fully attributed and can be prepared for the backend.
-     */
+               /*
+                * Flexa has no variable size cauda if its left head is
+                * stacked on the right head.  This is true for
+                * cephalicus.  Hence, remove the cauda.
+                *
+                * Urgh: for the current implementation, this rule only
+                * applies for cephalicus; but it is a fundamental rule.
+                * Therefore, the following line of code should be
+                * placed somewhere else.
+                */
+               prev_primitive->set_property ("add-cauda",
+                                             ly_bool2scm (false));
+             }
+           if (prev_delta_pitch < - 1)
+             glyph_name = "vaticana.reverse.plica";
+           else
+             glyph_name = "vaticana.reverse.vplica";
+         }
+       else // (prev_delta_pitch == 0)
+         {
+           primitive->programming_error ("Vaticana_ligature:"
+                                         " deminutum head must have different"
+                                         " pitch -> ignoring grob");
+         }
+      else if (prefix_set & (CAVUM | LINEA))
+       if ((prefix_set & CAVUM) && (prefix_set & LINEA))
+         glyph_name = "vaticana.linea.punctum.cavum";
+       else if (prefix_set & CAVUM)
+         glyph_name = "vaticana.punctum.cavum";
+       else
+         glyph_name = "vaticana.linea.punctum";
+      else if (prefix_set & AUCTUM)
+       if (prefix_set & ASCENDENS)
+         glyph_name = "solesmes.auct.asc";
+       else
+         glyph_name = "solesmes.auct.desc";
+      else if ((context_info & STACKED_HEAD)
+              && (context_info & PES_UPPER))
+       if (prev_delta_pitch > 1)
+         glyph_name = "vaticana.upes";
+       else
+         glyph_name = "vaticana.vupes";
+      else
+       glyph_name = "vaticana.punctum";
 
-    /*
-     * Finish head of previous iteration for backend.
-     */
-    prev_distance =
-      finish_primitive (first_primitive, prev_primitive,
-                       prev_context_info, prev_glyph_name, prev_pitch_delta,
-                       flexa_width, join_thickness, prev_distance);
-
-    prev_primitive = primitive;
-    prev_context_info = context_info;
-    prev_pitch_delta = pitch - prev_pitch;
-    prev_pitch = pitch;
-    prev_glyph_name = glyph_name;
-  }
+      /*
+       * This head needs a cauda, if it starts a flexa, is not the upper
+       * head of a pes, and if it is a punctum.
+       */
+      if ((context_info & FLEXA_LEFT) && ! (context_info & PES_UPPER))
+       if (glyph_name == "vaticana.punctum")
+         primitive->set_property ("add-cauda", ly_bool2scm (true));
 
-  /*
-   * Finish head of last iteration for backend.
-   */
-  prev_distance =
-    finish_primitive (first_primitive, prev_primitive,
-                     prev_context_info, prev_glyph_name, prev_pitch_delta,
-                     flexa_width, join_thickness, prev_distance);
+      /*
+       * Execptional rule for porrectus:
+       *
+       * If the current head is preceded by a \flexa and succeded by a
+       * \pes (e.g. "a \flexa g \pes a"), then join the current head and
+       * the previous head into a single curved flexa shape.
+       */
+      if ((context_info & FLEXA_RIGHT) && (context_info & PES_LOWER))
+       {
+         check_for_prefix_loss (prev_primitive);
+         prev_glyph_name = "flexa";
+         prev_primitive->set_property ("flexa-height",
+                                       scm_from_int (prev_delta_pitch));
+         prev_primitive->set_property ("flexa-width",
+                                       scm_from_double (flexa_width));
+         bool add_cauda = !(prev_prefix_set && PES_OR_FLEXA);
+         prev_primitive->set_property ("add-cauda",
+                                       ly_bool2scm (add_cauda));
+         check_for_prefix_loss (primitive);
+         glyph_name = "";
+         primitive->set_property ("flexa-width",
+                                  scm_from_double (flexa_width));
+       }
 
-  /* TODO: make this cfg'able via SCM */
-  Real padding = join_thickness;
+      /*
+       * Exceptional rule for pes:
+       *
+       * If this head is stacked on the previous one due to a \pes, then
+       * set the glyph of the previous head to that for this special
+       * case, thereby avoiding potential vertical collision with the
+       * current head.
+       */
+      if (prefix_set & PES_OR_FLEXA)
+       {
+         if ((context_info & PES_UPPER) && (context_info & STACKED_HEAD))
+           {
+             if (prev_glyph_name == "vaticana.punctum")
+               if (prev_delta_pitch > 1)
+                 prev_glyph_name = "vaticana.lpes";
+               else
+                 prev_glyph_name = "vaticana.vlpes";
+           }
+       }
 
-  /* horizontal padding space after ligature */
-  prev_distance += padding;
+      if (prev_primitive)
+       prev_primitive->set_property ("glyph-name",
+                                     ly_string2scm (prev_glyph_name));
+
+      /*
+       * In the backend, flexa shapes and joins need to know about line
+       * thickness.  Hence, for simplicity, let's distribute the
+       * ligature grob's value for thickness to each ligature head (even
+       * if not all of them need to know).
+       */
+      primitive->set_property ("thickness", scm_from_double (thickness));
+
+      prev_primitive = primitive;
+      prev_prefix_set = prefix_set;
+      prev_context_info = context_info;
+      prev_delta_pitch = delta_pitch;
+      prev_glyph_name = glyph_name;
+    }
+
+  prev_primitive->set_property ("glyph-name",
+                               ly_string2scm (prev_glyph_name));
+
+  align_heads (primitives, flexa_width, thickness);
+
+  // append all dots to paper column of ligature's last head
+  add_mora_column (prev_primitive->get_column ());
 
 #if 0 // experimental code to collapse spacing after ligature
-  /* TODO: set to max(old/new spacing-increment), since other
+  /* TODO: set to max (old/new spacing-increment), since other
      voices/staves also may want to set this property. */
-  Paper_column *paper_column = first_primitive->get_column();
+  Item *first_primitive = dynamic_cast<Item *> (primitives[0].grob ());
+  Paper_column *paper_column = first_primitive->get_column ();
   paper_column->warning (_f ("Vaticana_ligature_engraver: "
-                            "setting `spacing-increment = %f': ptr=%ul",
-                            prev_distance, paper_column));
+                            "setting `spacing-increment = %f': ptr =%ul",
+                            ligature_width, paper_column));
   paper_column->
-    set_grob_property("forced-spacing", gh_double2scm (prev_distance));
+    set_property ("forced-spacing", scm_from_double (ligature_width));
 #endif
 }
 
+ADD_ACKNOWLEDGER (Vaticana_ligature_engraver, rest);
+ADD_ACKNOWLEDGER (Vaticana_ligature_engraver, note_head);
+ADD_TRANSLATOR (Vaticana_ligature_engraver,
+               /* doc */
+               "Handle ligatures by glueing special ligature heads together.",
+
+               /* create */
+               "VaticanaLigature "
+               "DotColumn ",
+
+               /* read */
+               "",
 
-ENTER_DESCRIPTION (Vaticana_ligature_engraver,
-/* descr */       "Handles ligatures by glueing special ligature heads together.",
-/* creats*/       "VaticanaLigature",
-/* accepts */     "ligature-event abort-event",
-/* acks  */      "note-head-interface rest-interface",
-/* reads */       "",
-/* write */       "");
+               /* write */
+               ""
+               );