]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dynamic-engraver.cc
release: 1.3.31
[lilypond.git] / lily / dynamic-engraver.cc
index 4c3db32bb46cb16006b1d85489c58e2f69c71b8c..254271080f1110fef47d0575d3b998ee95a35e26 100644 (file)
@@ -3,35 +3,44 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 #include "debug.hh"
 #include "crescendo.hh"
 #include "musical-request.hh"
 #include "lookup.hh"
 #include "paper-def.hh"
-#include "score-column.hh"
+#include "paper-column.hh"
 #include "staff-symbol.hh"
 #include "note-column.hh"
 #include "text-item.hh"
-#include "staff-side.hh"
+#include "side-position-interface.hh"
 #include "engraver.hh"
 #include "stem.hh"
 #include "note-head.hh"
+#include "group-interface.hh"
+
+/*
+  TODO:
+    * why handle absolute and span requests in one cryptic engraver,
+    what about Span_dynamic_engraver?
+
+    * hairpin
+    * text:
+      - `cresc. --  --  --'
+      - `cresc. poco a poco -- -- --'
+ */
 
 /**
    print text & hairpin dynamics.
  */
 class Dynamic_engraver : public Engraver
 {
-  Text_item * text_p_;
-  Staff_side_item * staff_side_p_;
-  Staff_side_spanner * ss_span_p_;
-  Staff_side_spanner * to_end_ss_span_p_;
-  
-  
+  Text_item * abs_text_p_;
+  Text_item * cr_text_p_;
   Crescendo * to_end_cresc_p_;
   Crescendo * cresc_p_;
+
   Span_req * cresc_req_l_;
   Array<Request*> dynamic_req_l_arr_;
   void  typeset_all ();
@@ -40,23 +49,33 @@ public:
   Dynamic_engraver();
   
 protected:
+
+  void announce_element (Score_element_info);
+  
   virtual void do_removal_processing ();
   virtual void acknowledge_element (Score_element_info);
   virtual bool do_try_music (Music *req_l);
   virtual void do_process_requests();
   virtual void do_pre_move_processing();
   virtual void do_post_move_processing();
+  virtual void typeset_element (Score_element*);
 };
 
+void
+Dynamic_engraver::announce_element (Score_element_info i)
+{
+  group (i.elem_l_, "interfaces").add_thing (ly_symbol2scm ("dynamic"));
+  
+  Engraver::announce_element (i);
+}
 
 
 Dynamic_engraver::Dynamic_engraver()
 {
   do_post_move_processing();
-  text_p_ =0;
-  staff_side_p_ =0;
+  abs_text_p_ = 0;
+  cr_text_p_ = 0;
   to_end_cresc_p_ = cresc_p_ = 0;
-  ss_span_p_ = to_end_ss_span_p_=0;
   cresc_req_l_ = 0;
 }
 
@@ -98,13 +117,13 @@ void
 Dynamic_engraver::do_process_requests()
 {
   Crescendo*  new_cresc_p=0;
-  Staff_side_spanner * new_sss_p =0;
+
   for (int i=0; i < dynamic_req_l_arr_.size(); i++)
     {
       if (Text_script_req *absd =
          dynamic_cast<Text_script_req *> ( dynamic_req_l_arr_[i]))
        {
-         if (text_p_)
+         if (abs_text_p_)
            {
              dynamic_req_l_arr_[i]->warning (_("Got a dynamic already.  Continuing dazed and confused."));
              continue;
@@ -112,45 +131,40 @@ Dynamic_engraver::do_process_requests()
          
          String loud = absd->text_str_;
 
-         text_p_ = new Text_item;
-         text_p_->text_str_ =  loud; // ugh
-         Scalar prop = get_property ("dynamicStyle", 0);
-
-         text_p_->style_str_ = prop.length_i () ? prop :  "dynamic";
-
-         staff_side_p_ = new Staff_side_item;
-         staff_side_p_->set_elt_property (script_priority_scm_sym,
-                                          gh_int2scm (100));
-                                          
-         staff_side_p_->set_victim (text_p_);
-         staff_side_p_->axis_ = Y_AXIS;
-         staff_side_p_->dir_ = DOWN;
+         abs_text_p_ = new Text_item;
+         abs_text_p_->set_elt_property ("text",
+                                    ly_str02scm (loud.ch_C()));
+         abs_text_p_->set_elt_property ("style", gh_str02scm ("dynamic"));
+         abs_text_p_->set_elt_property ("script-priority",
+                                    gh_int2scm (100));
+         
+         Side_position_interface (abs_text_p_).set_axis (Y_AXIS);
 
          
-         prop = get_property ("verticalDirection", 0);
-         if (prop.isdir_b())
+         if (absd->get_direction ())
            {
-             staff_side_p_->dir_ = Direction (int (prop));
+             abs_text_p_->set_elt_property ("direction", gh_int2scm (absd->get_direction ()));
            }
 
-         prop = get_property ("dynamicDirection", 0);
-         if (prop.isnum_b ())
-           {
-             staff_side_p_->dir_ = (Direction) (int) prop;
-           }
-         if (absd->dir_)
+
+         /*
+           UGH UGH 
+          */
+         SCM prop = get_property ("dynamicDirection");
+         if (!isdir_b (prop))
            {
-             staff_side_p_->dir_ = absd->dir_;
+             prop = get_property ("verticalDirection");
            }
 
-         prop = get_property ("dynamicPadding", 0);
-         if (prop.isnum_b ())
+         if (isdir_b (prop) && to_dir (prop))
+           abs_text_p_->set_elt_property ("direction", prop);
+
+         prop = get_property ("dynamicPadding");
+         if (gh_number_p(prop))
            {
-             staff_side_p_->set_elt_property (padding_scm_sym, 
-                                              gh_double2scm(Real(prop)));
+             abs_text_p_->set_elt_property ("padding", prop);
            }
-         announce_element (Score_element_info (text_p_, absd));
-         announce_element (Score_element_info (staff_side_p_, absd));
+         announce_element (Score_element_info (abs_text_p_, absd));
        }
       else if (Span_req *span_l
               = dynamic_cast <Span_req *> (dynamic_req_l_arr_[i]))
@@ -165,30 +179,8 @@ Dynamic_engraver::do_process_requests()
                {
                  assert (!to_end_cresc_p_);
                  to_end_cresc_p_ =cresc_p_;
-                 to_end_ss_span_p_ = ss_span_p_ ;
                  
                  cresc_p_ = 0;
-                 ss_span_p_ =0;
-
-
-
-                 
-                 Scalar prop = get_property ("verticalDirection", 0);
-                 if (prop.isdir_b())
-                   {
-                     to_end_ss_span_p_->dir_ = Direction (int (prop));
-                   }
-                 prop = get_property ("dynamicDirection", 0);
-                 if (prop.isdir_b ())
-                   {
-                     to_end_ss_span_p_->dir_ = (Direction) (int) prop;
-                   }
-                 prop = get_property ("dynamicPadding", 0);
-                 if (prop.isnum_b ())
-                   {
-                     to_end_ss_span_p_->set_elt_property (padding_scm_sym, 
-                                                          gh_double2scm(Real(prop)));
-                   }
                }
            }
          else if (span_l->span_dir_ == START)
@@ -196,15 +188,52 @@ Dynamic_engraver::do_process_requests()
              cresc_req_l_ = span_l;
              assert (!new_cresc_p);
              new_cresc_p  = new Crescendo;
-             new_cresc_p->grow_dir_ = (span_l->span_type_str_ == "crescendo")  ? BIGGER : SMALLER;
-             announce_element (Score_element_info (new_cresc_p, span_l));
+             new_cresc_p->set_elt_property
+               ("grow-direction",
+                gh_int2scm ((span_l->span_type_str_ == "crescendo")
+                            ? BIGGER : SMALLER));
+             
+             SCM s = get_property (span_l->span_type_str_ + "Text");
+             if (gh_string_p (s))
+               {
+                 cr_text_p_ = new Text_item;
+                 cr_text_p_->set_elt_property ("text", s);
+                 // urg
+                 cr_text_p_->set_elt_property ("style", gh_str02scm ("italic"));
+                 // ?
+                 cr_text_p_->set_elt_property ("script-priority",
+                                               gh_int2scm (100));
+                 
+                 /*
+                   This doesn't work.
+                   I'd like to have support like this:
+                           |
+                          x|
+                         cresc. - - -
+
+                   or
+                           |
+                          x|
+                         ff cresc. - - -
+
+                  */
+                 if (0) //abs_text_p_)
+                   {
+                     Side_position_interface (cr_text_p_).set_axis (X_AXIS);
+                     Side_position_interface (cr_text_p_).add_support (abs_text_p_);
+                   }
+                 //Side_position_interface (cr_text_p_).set_axis (Y_AXIS);
+                 announce_element (Score_element_info (cr_text_p_, span_l));
+               }
 
-             new_sss_p = new Staff_side_spanner;
-             new_sss_p->set_victim (new_cresc_p);
-             new_sss_p->axis_ = Y_AXIS;
-             // UGH.!
-             // new_sss_p->set_elt_property (dangling_scm_sym, SCM_BOOL_T);
-             announce_element (Score_element_info (new_sss_p, span_l));
+             s = get_property (span_l->span_type_str_ + "Spanner");
+             if (gh_string_p (s)) //&& ly_scm2string (s) != "hairpin")
+               {
+                 new_cresc_p->set_elt_property ("spanner", s);
+               }
+         
+             side_position (new_cresc_p).set_axis (Y_AXIS);
+             announce_element (Score_element_info (new_cresc_p, span_l));
            }
        }
     }
@@ -214,21 +243,23 @@ Dynamic_engraver::do_process_requests()
       if (cresc_p_)
        {
          ::warning (_ ("Too many crescendi here"));
+
          typeset_element (cresc_p_);
-         typeset_element (ss_span_p_);
+
          cresc_p_ = 0;
-         ss_span_p_ =0;
        }
       
       cresc_p_ = new_cresc_p;
-      ss_span_p_ = new_sss_p;
       cresc_p_->set_bounds(LEFT,get_staff_info().musical_pcol_l ());
-      ss_span_p_->set_bounds (LEFT,get_staff_info().musical_pcol_l ());
-      if (text_p_)
+
+      // arrragh, brr, urg: we know how wide text is, no?
+      if (abs_text_p_)
        {
-         cresc_p_->dyn_b_drul_[LEFT] = true;
+         index_set_cell (cresc_p_->get_elt_property ("dynamic-drul"),
+                         LEFT, SCM_BOOL_T);
          if (to_end_cresc_p_)
-           to_end_cresc_p_->dyn_b_drul_[RIGHT] = true;
+           index_set_cell (to_end_cresc_p_->get_elt_property ("dynamic-drul"),
+                           RIGHT, SCM_BOOL_T);
        }
     }
 }
@@ -249,8 +280,6 @@ Dynamic_engraver::do_removal_processing ()
   if (cresc_p_)
     {
       typeset_element (cresc_p_ );
-      typeset_element (ss_span_p_);
-      ss_span_p_ =0;
       cresc_req_l_->warning (_ ("unended crescendo"));
       cresc_p_ =0;
     }
@@ -264,22 +293,31 @@ Dynamic_engraver::typeset_all ()
   if (to_end_cresc_p_)
     {
       to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ());
-      to_end_ss_span_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ());
       typeset_element (to_end_cresc_p_);
-      typeset_element (to_end_ss_span_p_);
+
       to_end_cresc_p_ =0;
-      to_end_ss_span_p_ =0;
+
     }
   
-  if (text_p_)
+  if (abs_text_p_)
     {
-      typeset_element (text_p_);
-      typeset_element (staff_side_p_);
-      text_p_ =0;
-      staff_side_p_ =0;
+      typeset_element (abs_text_p_);
+      abs_text_p_ = 0;
+    }
+
+  if (cr_text_p_)
+    {
+      typeset_element (cr_text_p_);
+      cr_text_p_ = 0;
     }
 }
 
+void
+Dynamic_engraver::typeset_element (Score_element * e)
+{
+  side_position(e).add_staff_support ();
+  Engraver::typeset_element (e);
+}
 
 void
 Dynamic_engraver::acknowledge_element (Score_element_info i)
@@ -288,13 +326,20 @@ Dynamic_engraver::acknowledge_element (Score_element_info i)
       || dynamic_cast<Note_head *> (i.elem_l_)
       )
     {
-      if (staff_side_p_)
-       staff_side_p_->add_support (i.elem_l_);
+      if (abs_text_p_)
+       Side_position_interface (abs_text_p_).add_support (i.elem_l_);
 
-      if (to_end_ss_span_p_)
-       to_end_ss_span_p_->add_support (i.elem_l_);
+      if (cr_text_p_)  ///&& !abs_text_p_)
+       {
+         Side_position_interface (cr_text_p_).set_axis (Y_AXIS);
+         Side_position_interface (cr_text_p_).add_support (i.elem_l_);
+       }
 
-      if (ss_span_p_)
-       ss_span_p_->add_support (i.elem_l_);
+      if (to_end_cresc_p_)
+       Side_position_interface (to_end_cresc_p_).add_support (i.elem_l_);
+
+      if (cresc_p_)
+       Side_position_interface(cresc_p_).add_support (i.elem_l_);
     }
 }
+