]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dynamic-engraver.cc
patch::: 1.3.96.jcn7
[lilypond.git] / lily / dynamic-engraver.cc
index e0788f08e5e68644806394f9ce69a1bc8a13263d..2a7ca06770857746fce991c63a6c9406b5dafe3e 100644 (file)
  */
 class Dynamic_engraver : public Engraver
 {
-  Item * text_p_;
+  Item * script_p_;
   Spanner * finished_cresc_p_;
   Spanner * cresc_p_;
 
-  Text_script_req* text_req_l_;
+  Dynamic_script_req* script_req_l_;
   
   Span_req * current_cresc_req_;
   Drul_array<Span_req*> accepted_spanreqs_drul_;
@@ -67,14 +67,14 @@ ADD_THIS_TRANSLATOR (Dynamic_engraver);
 
 Dynamic_engraver::Dynamic_engraver ()
 {
-  text_p_ = 0;
+  script_p_ = 0;
   finished_cresc_p_ = 0;
   line_spanner_ = 0;
   finished_line_spanner_ = 0;
   current_cresc_req_ = 0;
   cresc_p_ =0;
 
-  text_req_l_ = 0;
+  script_req_l_ = 0;
   accepted_spanreqs_drul_[START] = 0;
   accepted_spanreqs_drul_[STOP] = 0;
 }
@@ -82,7 +82,7 @@ Dynamic_engraver::Dynamic_engraver ()
 void
 Dynamic_engraver::do_post_move_processing ()
 {
-  text_req_l_ = 0;
+  script_req_l_ = 0;
   accepted_spanreqs_drul_[START] = 0;
   accepted_spanreqs_drul_[STOP] = 0;
 }
@@ -90,13 +90,10 @@ Dynamic_engraver::do_post_move_processing ()
 bool
 Dynamic_engraver::do_try_music (Music * m)
 {
-  if (Text_script_req* d = dynamic_cast <Text_script_req*> (m))
+  if (Dynamic_script_req* d = dynamic_cast <Dynamic_script_req*> (m))
     {
-      if (d->style_str_ == "dynamic")
-       {
-         text_req_l_ = d;
-         return true;
-       }
+      script_req_l_ = d;
+      return true;
     }
   else if (Span_req* s =  dynamic_cast <Span_req*> (m))
     {
@@ -107,6 +104,9 @@ Dynamic_engraver::do_try_music (Music * m)
          if (line_spanner_)
            line_spanner_->suicide ();
          line_spanner_ = 0;
+         if (cresc_p_)
+           cresc_p_->suicide ();
+         cresc_p_ = 0;
        }
       else if ((s->span_type_str_ == "crescendo"
           || s->span_type_str_ == "decrescendo"))
@@ -121,19 +121,19 @@ Dynamic_engraver::do_try_music (Music * m)
 void
 Dynamic_engraver::do_process_music ()
 {
-  if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || text_req_l_)
+  if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || script_req_l_)
     
     {
       if (!line_spanner_)
        {
-         line_spanner_ = new Spanner (get_property ("basicDynamicLineSpannerProperties"));
+         line_spanner_ = new Spanner (get_property ("DynamicLineSpanner"));
 
          Side_position::set_axis (line_spanner_, Y_AXIS);
          Axis_group_interface::set_interface (line_spanner_);
          Axis_group_interface::set_axes (line_spanner_, Y_AXIS, Y_AXIS);
 
          Request * rq = accepted_spanreqs_drul_[START];
-         if (text_req_l_) rq =  text_req_l_ ;
+         if (script_req_l_) rq =  script_req_l_ ;
          announce_element (line_spanner_, rq);
                         
 
@@ -146,7 +146,7 @@ Dynamic_engraver::do_process_music ()
     
    */
   else if (accepted_spanreqs_drul_[STOP]
-          && !accepted_spanreqs_drul_[START] && !text_req_l_)
+          && !accepted_spanreqs_drul_[START] && !script_req_l_)
     {
       finished_line_spanner_ = line_spanner_;
       line_spanner_ = 0;
@@ -179,20 +179,16 @@ Dynamic_engraver::do_process_music ()
     maybe we should leave dynamic texts to the text-engraver and
     simply acknowledge them?
   */
-  if (text_req_l_)
+  if (script_req_l_)
     {
-      String loud = text_req_l_->text_str_;
-
-      text_p_ = new Item (get_property ("basicDynamicTextProperties"));
-      text_p_->set_elt_property ("text", ly_str02scm (loud.ch_C ()));
-      if (Direction d=text_req_l_->get_direction ())
+      script_p_ = new Item (get_property ("DynamicText"));
+      script_p_->set_elt_property ("text", script_req_l_->text_);
+      if (Direction d = script_req_l_->get_direction ())
        Directional_element_interface::set (line_spanner_, d);
 
-      Axis_group_interface::add_element (line_spanner_, text_p_);
+      Axis_group_interface::add_element (line_spanner_, script_p_);
 
-      text_p_->add_offset_callback (Side_position::aligned_on_self,
-                                   Y_AXIS);
-      announce_element (text_p_, text_req_l_);
+      announce_element (script_p_, script_req_l_);
     }
 
   if (accepted_spanreqs_drul_[STOP])
@@ -227,70 +223,52 @@ Dynamic_engraver::do_process_music ()
       else
        {
          current_cresc_req_ = accepted_spanreqs_drul_[START];
-         cresc_p_  = new Spanner (get_property ("basicCrescendoProperties"));
-         Crescendo::set_interface (cresc_p_);
-         cresc_p_->set_elt_property
-           ("grow-direction",
-            gh_int2scm ((accepted_spanreqs_drul_[START]->span_type_str_ == "crescendo")
-                        ? BIGGER : SMALLER));
-             
-         SCM s = get_property ((accepted_spanreqs_drul_[START]->span_type_str_ + "Text").ch_C());
-         if (gh_string_p (s))
-           {
-             cresc_p_->set_elt_property ("start-text", s);
-             daddy_trans_l_->set_property (accepted_spanreqs_drul_[START]->span_type_str_
-                                           + "Text", SCM_UNDEFINED);
-           }
-
-         s = get_property ((accepted_spanreqs_drul_[START]->span_type_str_ + "Spanner").ch_C());
-
 
          /*
            TODO: Use symbols.
           */
-         if (gh_string_p (s)) //&& ly_scm2string (s) != "hairpin")
+         SCM s = get_property ((accepted_spanreqs_drul_[START]->span_type_str_ + "Spanner").ch_C());
+
+         if (!gh_string_p (s) || ly_scm2string (s) == "hairpin")
+           {
+             cresc_p_  = new Spanner (get_property ("Crescendo"));
+             cresc_p_->set_elt_property ("grow-direction",
+                                         gh_int2scm ((accepted_spanreqs_drul_[START]->span_type_str_ == "crescendo")
+                                                     ? BIGGER : SMALLER));
+             
+           }
+         /*
+           This is a convenient (and legacy) interface to TextSpanners
+           for use in (de)crescendi.
+           Hmm.
+          */
+         else
            {
-             cresc_p_->set_elt_property ("spanner", s);
+             cresc_p_  = new Spanner (get_property ("TextSpanner"));
+             cresc_p_->set_elt_property ("type", s);
              daddy_trans_l_->set_property (accepted_spanreqs_drul_[START]->span_type_str_
                                            + "Spanner", SCM_UNDEFINED);
+             s = get_property ((accepted_spanreqs_drul_[START]->span_type_str_ + "Text").ch_C());
+             if (gh_string_p (s))
+               {
+                 cresc_p_->set_elt_property ("edge-text",
+                                             gh_cons (s, ly_str02scm ("")));
+                 daddy_trans_l_->set_property (accepted_spanreqs_drul_[START]->span_type_str_
+                                               + "Text", SCM_UNDEFINED);
+               }
            }
-
+       
          Score_element *cc = unsmob_element (get_property ("currentMusicalColumn"));
          cresc_p_->set_bound (LEFT, cc);
 
-
-         /* 
-             We know how wide the text is, if we can be sure that the
-             text already has relevant pointers into the paperdef,
-             and it has its font-size property set.
-
-             Since font-size may be set by a context higher up, we
-             can not be sure of the size.
-
-
-             We shouldn't try to do this stuff here, the Item should
-             do it when the score is finished.  We could maybe
-             set a callback to have the Item do the alignment if
-             it is not a special symbol, like Crescendo.
-         */
-
-         
-         if (text_p_)
+         if (script_p_)
            {
-             index_set_cell (cresc_p_->get_elt_property ("dynamic-drul"),
-                             LEFT, text_p_->self_scm ());
-
-             if (finished_cresc_p_
-             // I don't see why, but we need this check
-                 && gh_pair_p (finished_cresc_p_->get_elt_property ("dynamic-drul")))
-               index_set_cell (finished_cresc_p_->get_elt_property ("dynamic-drul"),
-                               RIGHT, text_p_->self_scm ());
+             Side_position::set_direction (script_p_, LEFT);
+             Side_position::set_axis (script_p_, X_AXIS);
+             Side_position::add_support (script_p_, cresc_p_);
            }
 
          Axis_group_interface::add_element (line_spanner_, cresc_p_);
-         cresc_p_->set_elt_property ("self-alignment-Y", gh_int2scm (0));
-         cresc_p_->add_offset_callback
-           (Side_position::aligned_on_self, Y_AXIS);
          announce_element (cresc_p_, accepted_spanreqs_drul_[START]);
        }
     }
@@ -329,10 +307,10 @@ Dynamic_engraver::typeset_all ()
       finished_cresc_p_ =0;
     }
   
-  if (text_p_)
+  if (script_p_)
     {
-      typeset_element (text_p_);
-      text_p_ = 0;
+      typeset_element (script_p_);
+      script_p_ = 0;
     }
   if (finished_line_spanner_)
     {