]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/bar-engraver.cc
release: 1.3.1
[lilypond.git] / lily / bar-engraver.cc
index b9896b4ad32c0b8149778337787e540d9eed779c..92378ccbd8152f1fe14f9d9d3707504675b77e09 100644 (file)
@@ -1,18 +1,21 @@
 /*
-  bar-reg.cc -- implement Bar_engraver
+  bar-engraver.cc -- implement Bar_engraver
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997, 1998, 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
+#include "score-engraver.hh"
 #include "bar-engraver.hh"
-#include "bar.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 "timing-engraver.hh"
+#include "engraver-group-engraver.hh"
+#include "warn.hh"
 
 Bar_engraver::Bar_engraver()
 {
@@ -20,45 +23,66 @@ 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::create_bar ()
 {
   if (!bar_p_)
     {
-      bar_p_ = new Bar;
-      bar_p_->break_priority_i_  = 0;
-      String default_type = get_property ("defaultBarType");
-      if (default_type.length_i ())
+      bar_p_ = new Staff_bar;
+      bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0));
+
+      // urg: "" != empty...
+      SCM default_type = get_property ("defaultBarType", 0);
+      if (gh_string_p (default_type))
+       {
+         bar_p_->type_str_ = ly_scm2string (default_type);
+       }
+
+      /*
+       urg.  Why did I implement this?
+       */
+      SCM prop = get_property ("barAtLineStart", 0);
+      if (gh_boolean_p (prop) && gh_scm2bool (prop))
        {
-         bar_p_->type_str_ = default_type;
+         bar_p_->set_elt_property (at_line_start_scm_sym, SCM_BOOL_T);
        }
-      announce_element (Score_element_info (bar_p_, bar_req_l_));
+      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 requested_type)
+{
+  if (!now_mom ())
+    {
+      SCM prop = get_property ("barAtLineStart", 0);
+      if (!gh_boolean_p (prop) && gh_scm2bool (prop))
+       return;
+    }
+  bool  bar_existed = bar_p_;
+  create_bar ();
+  if (bar_existed && requested_type == "")
+    {
+      return;
+    }
+  else if (((requested_type == "|:") && (bar_p_->type_str_ == ":|"))
+    || ((requested_type == ":|") && (bar_p_->type_str_ == "|:")))
+    bar_p_->type_str_ = ":|:";
+  else
+    bar_p_->type_str_ = requested_type;
+}
 
 void 
 Bar_engraver::do_creation_processing ()
 {
-  create_bar ();
-  bar_p_->type_str_ = "";
 }
 
 void
@@ -74,28 +98,30 @@ Bar_engraver::do_removal_processing ()
 void
 Bar_engraver::do_process_requests()
 {  
-  if (bar_req_l_) 
-    {
-      if (!bar_p_)
-       create_bar ();    
+  Translator * t = daddy_grav_l  ()->get_simple_translator ("Timing_engraver");
 
-      bar_p_->type_str_ = bar_req_l_->type_str_;
-    }
-  else 
+  Timing_engraver * te = dynamic_cast<Timing_engraver*>(t);
+  String which = (te) ? te->which_bar () : "";
+
+  if (which.length_i ())
     {
-      Time_description const *time = get_staff_info().time_C_;
-      String always = get_property ("barAlways");
-      if ((time && !time->whole_in_measure_) || always.length_i ()) 
-       create_bar ();
+      create_bar();
+      bar_p_->type_str_ = which;
     }
-
-  
   
   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 ();
     }
 }
 
@@ -110,14 +136,6 @@ Bar_engraver::do_pre_move_processing()
     }
 }
 
-void
-Bar_engraver::do_post_move_processing()
-{
-  bar_req_l_ = 0;
-}
-
-
-
 ADD_THIS_TRANSLATOR(Bar_engraver);