]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/break-align-engraver.cc
Doc-es: various updates.
[lilypond.git] / lily / break-align-engraver.cc
index e6a7935c568c5283aeed26671cf39a7b1ec39c73..160f6fe7ec2b62244ba323960f08b605ac9249bf 100644 (file)
@@ -1,9 +1,20 @@
 /*
-  break-align-engraver.cc -- implement Break_align_engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "engraver.hh"
 #include "protected-scm.hh"
@@ -12,6 +23,7 @@
 #include "axis-group-interface.hh"
 #include "context.hh"
 #include "translator-group.hh"
+#include "item.hh"
 
 #include "translator.icc"
 
@@ -22,12 +34,14 @@ class Break_align_engraver : public Engraver
   Item *left_edge_;
 
   void add_to_group (SCM, Item *);
+  void create_alignment (Grob_info);
 protected:
   void stop_translation_timestep ();
   virtual void derived_mark () const;
 public:
   TRANSLATOR_DECLARATIONS (Break_align_engraver);
-  DECLARE_ACKNOWLEDGER (break_aligned);
+  void acknowledge_break_aligned (Grob_info);
+  void acknowledge_break_alignable (Grob_info);
 };
 
 void
@@ -39,7 +53,8 @@ Break_align_engraver::stop_translation_timestep ()
   left_edge_ = 0;
 }
 
-Break_align_engraver::Break_align_engraver ()
+Break_align_engraver::Break_align_engraver (Context *c)
+  : Engraver (c)
 {
   column_alist_ = SCM_EOL;
   left_edge_ = 0;
@@ -52,46 +67,68 @@ Break_align_engraver::derived_mark () const
   scm_gc_mark (column_alist_);
 }
 
+void
+Break_align_engraver::acknowledge_break_alignable (Grob_info inf)
+{
+  /*
+    Special case for MetronomeMark: filter out items which will be aligned
+    on note heads rather than prefatory material
+  */
+  if (!Item::is_non_musical (inf.item ()))
+    return;
+
+  if (!align_)
+    create_alignment (inf);
+
+  Grob *g = inf.grob ();
+
+  if (!g->get_parent (X_AXIS))
+    g->set_parent (align_, X_AXIS);
+}
+
 void
 Break_align_engraver::acknowledge_break_aligned (Grob_info inf)
 {
   if (Item *item = dynamic_cast<Item *> (inf.grob ()))
     {
       /*
-       Removed check for item->empty (X_AXIS). --hwn 20/1/04
+        Removed check for item->empty (X_AXIS). --hwn 20/1/04
       */
       if (item->get_parent (X_AXIS))
-       return;
+        return;
 
       if (!Item::is_non_musical (item))
-       return;
+        return;
 
       SCM align_name = item->get_property ("break-align-symbol");
       if (!scm_is_symbol (align_name))
-       return;
-         
+        return;
+
       if (!align_)
-       {
-         align_ = make_item ("BreakAlignment", SCM_EOL);
+        create_alignment (inf);
 
-         Context *origin = inf.origin_contexts (this)[0];
+      add_to_group (align_name, item);
+    }
+}
+
+void
+Break_align_engraver::create_alignment (Grob_info inf)
+{
+  align_ = make_item ("BreakAlignment", SCM_EOL);
 
-         Translator_group *tg = origin->implementation ();
-         Engraver *random_source = dynamic_cast<Engraver *> (unsmob_translator (scm_car (tg->get_simple_trans_list ())));
+  Context *origin = inf.origin_contexts (this)[0];
 
-         /*
-           Make left edge appear to come from same context as clef/bar-line etc.
-         */
-         left_edge_ = make_item_from_properties (random_source,
-                                                 ly_symbol2scm ("LeftEdge"),
-                                                 SCM_EOL,
-                                                 "LeftEdge");
-         add_to_group (left_edge_->get_property ("break-align-symbol"),
-                       left_edge_);
-       }
+  Translator_group *tg = origin->implementation ();
+  Engraver *random_source = unsmob<Engraver> (scm_car (tg->get_simple_trans_list ()));
+  if (!random_source)
+    random_source = this;
 
-      add_to_group (align_name, item);
-    }
+  /*
+    Make left edge appear to come from same context as clef/bar-line etc.
+  */
+  left_edge_ = random_source->make_item ("LeftEdge", SCM_EOL);
+  add_to_group (left_edge_->get_property ("break-align-symbol"),
+                left_edge_);
 }
 
 void
@@ -100,9 +137,9 @@ Break_align_engraver::add_to_group (SCM align_name, Item *item)
   SCM s = scm_assoc (align_name, column_alist_);
   Item *group = 0;
 
-  if (s != SCM_BOOL_F)
+  if (scm_is_true (s))
     {
-      Grob *e = unsmob_grob (scm_cdr (s));
+      Grob *e = unsmob<Grob> (scm_cdr (s));
       group = dynamic_cast<Item *> (e);
     }
   else
@@ -114,16 +151,33 @@ Break_align_engraver::add_to_group (SCM align_name, Item *item)
 
       column_alist_ = scm_assoc_set_x (column_alist_, align_name, group->self_scm ());
 
-      Break_align_interface::add_element (align_, group);
+      Break_alignment_interface::add_element (align_, group);
     }
   Axis_group_interface::add_element (group, item);
 }
-ADD_ACKNOWLEDGER (Break_align_engraver, break_aligned);
+
+void
+Break_align_engraver::boot ()
+{
+  ADD_ACKNOWLEDGER (Break_align_engraver, break_aligned);
+  ADD_ACKNOWLEDGER (Break_align_engraver, break_alignable);
+}
+
 ADD_TRANSLATOR (Break_align_engraver,
-               "Align grobs with corresponding @code{break-align-symbols} into "
-               "groups, and order the groups according to @code{breakAlignOrder}. "
-               "The left edge of the alignment gets a separate group, with a symbol @code{left-edge}. ",
-               /* create */ "BreakAlignment BreakAlignGroup LeftEdge",
-               /* accept */ "",
-               /* read */ "",
-               /* write */ "");
+                /* doc */
+                "Align grobs with corresponding @code{break-align-symbols}"
+                " into groups, and order the groups according to"
+                " @code{breakAlignOrder}.  The left edge of the alignment gets"
+                " a separate group, with a symbol @code{left-edge}.",
+
+                /* create */
+                "BreakAlignment "
+                "BreakAlignGroup "
+                "LeftEdge ",
+
+                /* read */
+                "",
+
+                /* write */
+                ""
+               );