]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/bar-engraver.cc
release: 1.3.18
[lilypond.git] / lily / bar-engraver.cc
index 71655de8e16ebe774472356c3de2ffebeee836f2..45636011c048182d9a6a30caeb9e3c49f678c9be 100644 (file)
@@ -7,14 +7,15 @@
   Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
+#include "score-engraver.hh"
 #include "bar-engraver.hh"
 #include "staff-bar.hh"
 #include "musical-request.hh"
 #include "multi-measure-rest.hh"
 #include "command-request.hh"
-#include "time-description.hh"
-#include "engraver-group.hh"
-#include "repeated-music.hh"
+#include "timing-engraver.hh"
+#include "engraver-group-engraver.hh"
+#include "warn.hh"
 
 Bar_engraver::Bar_engraver()
 {
@@ -22,31 +23,8 @@ Bar_engraver::Bar_engraver()
   do_post_move_processing();
 }
 
-bool
-Bar_engraver::do_try_music (Music*r_l)
-{
-  if (Bar_req  * b= dynamic_cast <Bar_req *> (r_l))
-    {
-      if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh?
-       return false;
-      
-      bar_req_l_ = b;
-      return true;
-    }
-  
-  return false;
 
-}
 
-void
-Bar_engraver::acknowledge_element (Score_element_info i)
-{
-  if (Bar *b = dynamic_cast<Bar *> (i.elem_l_))
-    {
-      // only bar-engraver should create bars
-      assert (0);
-    }
-}
 
 void
 Bar_engraver::create_bar ()
@@ -54,50 +32,64 @@ Bar_engraver::create_bar ()
   if (!bar_p_)
     {
       bar_p_ = new Staff_bar;
-      bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0));
+      bar_p_->set_elt_property ("break-aligned", SCM_BOOL_T);
 
       // urg: "" != empty...
-      String default_type = get_property ("defaultBarType", 0);
-      if (default_type.length_i ())
+      SCM default_type = get_property ("defaultBarType", 0);
+      if (gh_string_p (default_type))
        {
-         bar_p_->type_str_ = default_type;
+         bar_p_->set_elt_property ("glyph", default_type); // gu.h
        }
 
+#if 0
       /*
-       urg.  Why did I implement this?
-       */
-      Scalar prop = get_property ("barAtLineStart", 0);
-      if (prop.to_bool ())
+       urg.  Why did I implement this? And did I implement this so
+       clumsily?  */
+      SCM prop = get_property ("barAtLineStart", 0);
+      if (to_boolean (prop))
        {
-         bar_p_->at_line_start_b_ = true;
+         bar_p_->set_elt_property ("at-line-start", SCM_BOOL_T);
        }
-      announce_element (Score_element_info (bar_p_, bar_req_l_));
+#endif
+      announce_element (Score_element_info (bar_p_, 0));
     }
 }
 
+/**
+   Make a barline.  If there are both |: and :| requested, merge them
+   to :|:.
+
+*/
 void
-Bar_engraver::request_bar (String type_str)
+Bar_engraver::request_bar (String requested_type)
 {
-  Scalar prop = get_property ("barAtLineStart", 0);
   if (!now_mom ())
     {
-      Scalar prop = get_property ("barAtLineStart", 0);
-      if (!prop.to_bool ())
+      SCM prop = get_property ("barAtLineStart", 0);
+      if (!to_boolean (prop))
        return;
     }
+  bool  bar_existed = bar_p_;
   create_bar ();
-  if (((type_str == "|:") && (bar_p_->type_str_ == ":|"))
-    || ((type_str == ":|") && (bar_p_->type_str_ == "|:")))
-    bar_p_->type_str_ = ":|:";
-  else
-    bar_p_->type_str_ = type_str;
+  if (bar_existed && requested_type == "")
+    {
+      return;
+    }
+
+  String current = ly_scm2string (bar_p_->get_elt_property ("glyph"));
+  
+  if ((requested_type == "|:" && current== ":|")
+    || (requested_type == ":|" && current == "|:"))
+    requested_type = ":|:";
+
+  
+  bar_p_->set_elt_property ("glyph",
+                           ly_str02scm (requested_type.ch_C ()));
 }
 
 void 
 Bar_engraver::do_creation_processing ()
 {
-  create_bar ();
-  bar_p_->type_str_ = "";
 }
 
 void
@@ -113,33 +105,30 @@ Bar_engraver::do_removal_processing ()
 void
 Bar_engraver::do_process_requests()
 {  
-  Time_description const *time = get_staff_info().time_C_;
-  if (bar_req_l_) 
-    {
-      create_bar ();    
-      bar_p_->type_str_ = bar_req_l_->type_str_;
-    }
-  else if (!now_mom ())
-    {
-      create_bar ();
-      bar_p_->type_str_ = "|";
-    }
-  else 
+  Translator * t = daddy_grav_l  ()->get_simple_translator ("Timing_engraver");
+
+  Timing_engraver * te = dynamic_cast<Timing_engraver*>(t);
+  String which = (te) ? te->which_bar () : "";
+
+  if (which.length_i ())
     {
-      Scalar nonauto = get_property ("barNonAuto", 0);
-      if (!nonauto.to_bool ())
-       {
-         Scalar always = get_property ("barAlways", 0);
-         if ((time && !time->whole_in_measure_) || always.to_bool ())
-           create_bar ();
-       }
+      create_bar();
+      bar_p_->set_elt_property ("glyph",  ly_str02scm (which.ch_C ()));
     }
   
   if (!bar_p_)
     {
-      Break_req r;
-      r.penalty_i_ = Break_req::DISALLOW;
-      daddy_grav_l ()->try_music (&r);
+      Score_engraver * e = 0;
+      Translator * t  =  daddy_grav_l ();
+      for (; !e && t;  t = t->daddy_trans_l_)
+       {
+         e = dynamic_cast<Score_engraver*> (t);
+       }
+      
+      if (!e)
+       programming_error ("No score engraver!");
+      else
+       e->forbid_breaks ();
     }
 }
 
@@ -154,14 +143,7 @@ Bar_engraver::do_pre_move_processing()
     }
 }
 
-void
-Bar_engraver::do_post_move_processing()
-{
-  bar_req_l_ = 0;
-}
-
-
-
 ADD_THIS_TRANSLATOR(Bar_engraver);
 
 
+