]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/system.cc
Run grand replace for 2015.
[lilypond.git] / lily / system.cc
index fdcc2b133d1b056f78482087218aac7abbc559ff..6d6b5ac8f3b2297dc72db4065c2b50491bc1426e 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1996--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1996--2015 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
@@ -36,6 +36,7 @@
 #include "pointer-group-interface.hh"
 #include "skyline-pair.hh"
 #include "staff-symbol-referencer.hh"
+#include "system-start-delimiter.hh"
 #include "text-interface.hh"
 #include "warn.hh"
 #include "unpure-pure-container.hh"
@@ -61,7 +62,7 @@ void
 System::init_elements ()
 {
   SCM scm_arr = Grob_array::make_array ();
-  all_elements_ = unsmob_grob_array (scm_arr);
+  all_elements_ = Grob_array::unsmob (scm_arr);
   all_elements_->set_ordered (false);
   set_object ("all-elements", scm_arr);
 }
@@ -222,7 +223,7 @@ System::get_paper_systems ()
       scm_vector_set_x (lines, scm_from_int (i),
                         system->get_paper_system ());
 
-      debug_output (to_string (i) + "]", false);
+      debug_output (::to_string (i) + "]", false);
     }
   return lines;
 }
@@ -254,6 +255,12 @@ System::get_footnote_grobs_in_range (vsize start, vsize end)
 
       if (Item *item = dynamic_cast<Item *>(at_bat))
         {
+          /*
+            We use this to weed out grobs that fall at the end
+            of the line when we want grobs at the beginning.
+          */
+          end_of_line_visible = item->break_status_dir () == LEFT;
+
           if (!Item::break_visible (item))
             continue;
           // safeguard to bring down the column rank so that end of line footnotes show up on the correct line
@@ -275,6 +282,14 @@ System::get_footnote_grobs_in_range (vsize start, vsize end)
         continue;
       if (!at_bat->is_live ())
         continue;
+      /*
+        TODO
+        Sometimes, there are duplicate entries in the all_elements_
+        list. In a separate patch, this practice should be squashed
+        so that the check below can be eliminated.
+      */
+      if (find (out.begin (), out.end (), at_bat) != out.end ())
+        continue;
 
       out.push_back (at_bat);
     }
@@ -318,7 +333,7 @@ System::internal_get_note_heights_in_range (vsize start, vsize end, bool foot)
       SCM footnote_stl = Text_interface::interpret_markup (pscore_->layout ()->self_scm (),
                                                            props, footnote_markup);
 
-      Stencil *footnote_stencil = unsmob_stencil (footnote_stl);
+      Stencil *footnote_stencil = Stencil::unsmob (footnote_stl);
       out.push_back (footnote_stencil->extent (Y_AXIS).length ());
     }
 
@@ -363,7 +378,7 @@ MAKE_SCHEME_CALLBACK (System, footnotes_before_line_breaking, 1);
 SCM
 System::footnotes_before_line_breaking (SCM smob)
 {
-  Grob *me = unsmob_grob (smob);
+  Grob *me = Grob::unsmob (smob);
   vector<Grob *> footnotes;
   SCM grobs_scm = Grob_array::make_array ();
   extract_grob_set (me, "all-elements", elts);
@@ -371,7 +386,7 @@ System::footnotes_before_line_breaking (SCM smob)
     if (elts[i]->internal_has_interface (ly_symbol2scm ("footnote-interface")))
       footnotes.push_back (elts[i]);
 
-  unsmob_grob_array (grobs_scm)->set_array (footnotes);
+  Grob_array::unsmob (grobs_scm)->set_array (footnotes);
   return grobs_scm;
 }
 
@@ -379,14 +394,45 @@ MAKE_SCHEME_CALLBACK (System, footnotes_after_line_breaking, 1);
 SCM
 System::footnotes_after_line_breaking (SCM smob)
 {
-  Spanner *sys_span = unsmob_spanner (smob);
+  Spanner *sys_span = Spanner::unsmob (smob);
   System *sys = dynamic_cast<System *> (sys_span);
   Interval_t<int> sri = sys->spanned_rank_interval ();
   vector<Grob *> footnote_grobs = sys->get_footnote_grobs_in_range (sri[LEFT], sri[RIGHT]);
   vector_sort (footnote_grobs, grob_2D_less);
 
   SCM grobs_scm = Grob_array::make_array ();
-  unsmob_grob_array (grobs_scm)->set_array (footnote_grobs);
+  Grob_array::unsmob (grobs_scm)->set_array (footnote_grobs);
+  return grobs_scm;
+}
+
+MAKE_SCHEME_CALLBACK (System, vertical_skyline_elements, 1);
+SCM
+System::vertical_skyline_elements (SCM smob)
+{
+  Grob *me_grob = Grob::unsmob (smob);
+  vector<Grob *> vertical_skyline_grobs;
+  extract_grob_set (me_grob, "elements", my_elts);
+  for (vsize i = 0; i < my_elts.size (); i++)
+    if (System_start_delimiter::has_interface (my_elts[i]))
+      vertical_skyline_grobs.push_back (my_elts[i]);
+
+  System *me = dynamic_cast<System *> (me_grob);
+  Grob *align = Grob::unsmob (me->get_object ("vertical-alignment"));
+  if (!align)
+    {
+      SCM grobs_scm = Grob_array::make_array ();
+      Grob_array::unsmob (grobs_scm)->set_array (vertical_skyline_grobs);
+      return grobs_scm;
+    }
+
+  extract_grob_set (align, "elements", elts);
+
+  for (vsize i = 0; i < elts.size (); i++)
+    if (Hara_kiri_group_spanner::has_interface (elts[i]))
+      vertical_skyline_grobs.push_back (elts[i]);
+
+  SCM grobs_scm = Grob_array::make_array ();
+  Grob_array::unsmob (grobs_scm)->set_array (vertical_skyline_grobs);
   return grobs_scm;
 }
 
@@ -443,12 +489,12 @@ void
 System::add_column (Paper_column *p)
 {
   Grob *me = this;
-  Grob_array *ga = unsmob_grob_array (me->get_object ("columns"));
+  Grob_array *ga = Grob_array::unsmob (me->get_object ("columns"));
   if (!ga)
     {
       SCM scm_ga = Grob_array::make_array ();
       me->set_object ("columns", scm_ga);
-      ga = unsmob_grob_array (scm_ga);
+      ga = Grob_array::unsmob (scm_ga);
     }
 
   p->set_rank (ga->size ());
@@ -502,8 +548,7 @@ System::post_processing ()
      anyway. */
 
   vector<Grob *> all_elts_sorted (all_elements_->array ());
-  vector_sort (all_elts_sorted, std::less<Grob *> ());
-  uniq (all_elts_sorted);
+  uniquify (all_elts_sorted);
   this->get_stencil ();
   for (vsize i = all_elts_sorted.size (); i--;)
     {
@@ -608,7 +653,7 @@ System::get_paper_system ()
     pl->set_property ("last-in-score", SCM_BOOL_T);
 
   Interval staff_refpoints;
-  if (Grob *align = get_vertical_alignment ())
+  if (Grob *align = Grob::unsmob (get_object ("vertical-alignment")))
     {
       extract_grob_set (align, "elements", staves);
       for (vsize i = 0; i < staves.size (); i++)
@@ -709,22 +754,27 @@ get_root_system (Grob *me)
   return dynamic_cast<System *> (system_grob);
 }
 
-Grob *
-System::get_vertical_alignment ()
+MAKE_SCHEME_CALLBACK (System, get_vertical_alignment, 1);
+SCM
+System::get_vertical_alignment (SCM smob)
 {
-  extract_grob_set (this, "elements", elts);
+  Grob *me = Grob::unsmob (smob);
+  extract_grob_set (me, "elements", elts);
   Grob *ret = 0;
   for (vsize i = 0; i < elts.size (); i++)
     if (Align_interface::has_interface (elts[i]))
       {
         if (ret)
-          programming_error ("found multiple vertical alignments in this system");
+          me->programming_error ("found multiple vertical alignments in this system");
         ret = elts[i];
       }
 
   if (!ret)
-    programming_error ("didn't find a vertical alignment in this system");
-  return ret;
+    {
+      me->programming_error ("didn't find a vertical alignment in this system");
+      return SCM_EOL;
+    }
+  return ret->self_scm ();
 }
 
 // Finds the furthest staff in the given direction whose x-extent
@@ -732,7 +782,7 @@ System::get_vertical_alignment ()
 Grob *
 System::get_extremal_staff (Direction dir, Interval const &iv)
 {
-  Grob *align = get_vertical_alignment ();
+  Grob *align = Grob::unsmob (get_object ("vertical-alignment"));
   if (!align)
     return 0;
 
@@ -756,7 +806,7 @@ System::get_extremal_staff (Direction dir, Interval const &iv)
 Grob *
 System::get_neighboring_staff (Direction dir, Grob *vertical_axis_group, Interval_t<int> bounds)
 {
-  Grob *align = get_vertical_alignment ();
+  Grob *align = Grob::unsmob (get_object ("vertical-alignment"));
   if (!align)
     return 0;
 
@@ -786,7 +836,7 @@ Interval
 System::pure_refpoint_extent (vsize start, vsize end)
 {
   Interval ret;
-  Grob *alignment = get_vertical_alignment ();
+  Grob *alignment = Grob::unsmob (get_object ("vertical-alignment"));
   if (!alignment)
     return Interval ();
 
@@ -813,7 +863,7 @@ System::pure_refpoint_extent (vsize start, vsize end)
 Interval
 System::part_of_line_pure_height (vsize start, vsize end, bool begin)
 {
-  Grob *alignment = get_vertical_alignment ();
+  Grob *alignment = Grob::unsmob (get_object ("vertical-alignment"));
   if (!alignment)
     return Interval ();
 
@@ -859,25 +909,23 @@ MAKE_SCHEME_CALLBACK (System, calc_pure_relevant_grobs, 1);
 SCM
 System::calc_pure_relevant_grobs (SCM smob)
 {
-  Grob *me = unsmob_grob (smob);
+  Grob *me = Grob::unsmob (smob);
 
   extract_grob_set (me, "elements", elts);
   vector<Grob *> relevant_grobs;
-  SCM pure_relevant_p = ly_lily_module_constant ("pure-relevant?");
 
   for (vsize i = 0; i < elts.size (); ++i)
     {
       if (!Axis_group_interface::has_interface (elts[i]))
         {
-          if (to_boolean (scm_apply_1 (pure_relevant_p, elts[i]->self_scm (), SCM_EOL)))
-            relevant_grobs.push_back (elts[i]);
+          relevant_grobs.push_back (elts[i]);
 
           if (Item *it = dynamic_cast<Item *> (elts[i]))
             {
               for (LEFT_and_RIGHT (d))
                 {
                   Item *piece = it->find_prebroken_piece (d);
-                  if (piece && to_boolean (scm_apply_1 (pure_relevant_p, piece->self_scm (), SCM_EOL)))
+                  if (piece && piece->is_live ())
                     relevant_grobs.push_back (piece);
                 }
             }
@@ -886,7 +934,7 @@ System::calc_pure_relevant_grobs (SCM smob)
 
   SCM grobs_scm = Grob_array::make_array ();
 
-  unsmob_grob_array (grobs_scm)->set_array (relevant_grobs);
+  Grob_array::unsmob (grobs_scm)->set_array (relevant_grobs);
   return grobs_scm;
 }
 
@@ -901,7 +949,7 @@ MAKE_SCHEME_CALLBACK (System, calc_pure_height, 3);
 SCM
 System::calc_pure_height (SCM smob, SCM start_scm, SCM end_scm)
 {
-  System *me = dynamic_cast<System *> (unsmob_grob (smob));
+  System *me = dynamic_cast<System *> (Grob::unsmob (smob));
   int start = scm_to_int (start_scm);
   int end = scm_to_int (end_scm);
 
@@ -945,8 +993,8 @@ enum
 static SCM
 get_maybe_spaceable_staves (SCM smob, int filter)
 {
-  System *me = dynamic_cast<System *> (unsmob_grob (smob));
-  Grob *align = me->get_vertical_alignment ();
+  System *me = dynamic_cast<System *> (Grob::unsmob (smob));
+  Grob *align = Grob::unsmob (me->get_object ("vertical_alignment"));
   SCM ret = SCM_EOL;
 
   if (align)
@@ -1008,5 +1056,5 @@ ADD_INTERFACE (System,
                "in-note-stencil "
                "labels "
                "pure-Y-extent "
-               "skyline-horizontal-padding "
+               "vertical-alignment "
               );