]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/piano-pedal-engraver.cc
release: 1.3.121
[lilypond.git] / lily / piano-pedal-engraver.cc
index 8990f345a3993f7d6a94772891bb1abc2730f815..eefb30b1540bdd6d5d867c1bdbc2def5db30d109 100644 (file)
@@ -8,9 +8,8 @@
 
 #include "engraver.hh"
 #include "musical-request.hh"
-#include "score-element.hh"
+#include "grob.hh"
 #include "item.hh"
-#include "font-metric.hh"
 #include "lily-guile.hh"
 #include "rhythmic-head.hh"
 #include "stem.hh"
 #include "staff-symbol-referencer.hh"
 #include "item.hh"
 
-
-/*
-   TODO:
-     * it would be really cool if an engraver could be initialised with a
-       string, ie:
-
-          Piano_pedal_engraver::"sostenuto"
-          Piano_pedal_engraver::"sustain"
-          Piano_pedal_engraver::"una-chorda"
-
- */
-
-/*
-  Would it? The semantics are unclear, and real benefits are muddy
-  too.  --hwn
-*/
-
-
-
-/**
-   engrave Piano pedals symbols.
- */
 class Piano_pedal_engraver : public Engraver
 {
 public:
@@ -47,12 +24,12 @@ public:
   Piano_pedal_engraver ();
   ~Piano_pedal_engraver ();
 protected:
-  virtual void do_creation_processing ();
-  virtual bool do_try_music (Music*);
-  virtual void do_process_music ();
-  virtual void do_pre_move_processing ();
-  virtual void do_post_move_processing ();
-  virtual void acknowledge_element (Score_element_info);
+  virtual void initialize ();
+  virtual bool try_music (Music*);
+  virtual void stop_translation_timestep ();
+  virtual void start_translation_timestep ();
+  virtual void acknowledge_grob (Grob_info);
+  virtual void create_grobs ();
 
 private:
   struct Pedal_info
@@ -74,7 +51,7 @@ Piano_pedal_engraver::Piano_pedal_engraver ()
   info_list_ = 0;
 }
 void
-Piano_pedal_engraver::do_creation_processing()
+Piano_pedal_engraver::initialize()
 {
   info_list_ = new Pedal_info[4];
   Pedal_info *p = info_list_;
@@ -101,13 +78,13 @@ Piano_pedal_engraver::~Piano_pedal_engraver()
 }
 
 /*
-  Urg: Code dup
-  I'm a script
- */
+   Urg: Code dup
+   I'm a script
 */
 void
-Piano_pedal_engraver::acknowledge_element (Score_element_info info)
+Piano_pedal_engraver::acknowledge_grob (Grob_info info)
 {
-  for (Pedal_info*p = info_list_; p->name_; p ++)
+  for (Pedal_info*p = info_list_; p && p->name_; p ++)
     {
       if (p->item_p_)
        {
@@ -128,15 +105,16 @@ Piano_pedal_engraver::acknowledge_element (Score_element_info info)
 }
 
 bool
-Piano_pedal_engraver::do_try_music (Music *m)
+Piano_pedal_engraver::try_music (Music *m)
 {
   if (Span_req * s = dynamic_cast<Span_req*>(m))
     {
       for (Pedal_info*p = info_list_; p->name_; p ++)
        {
-         if (s->span_type_str_ == p->name_)
+         if (scm_equal_p (s->get_mus_property ("span-type"),
+                          ly_str02scm (p->name_))==SCM_BOOL_T)
            {
-             p->req_l_drul_[s->span_dir_] = s;
+             p->req_l_drul_[s->get_span_dir()] = s;
              return true;
            }
        }
@@ -145,11 +123,18 @@ Piano_pedal_engraver::do_try_music (Music *m)
 }
 
 void
-Piano_pedal_engraver::do_process_music ()
+Piano_pedal_engraver::create_grobs ()
 {
-  for (Pedal_info*p = info_list_; p->name_; p ++)
+  for (Pedal_info*p = info_list_; p && p->name_; p ++)
     {
-      SCM s = SCM_UNDEFINED;
+      if (p->item_p_ || ! (p->req_l_drul_[STOP] || p->req_l_drul_[START]))
+       continue;
+      
+      SCM s = SCM_EOL;
+      SCM strings = get_property( ("pedal" + String (p->name_) + "Strings").ch_C());
+      if( scm_ilength (strings) < 3)
+       continue;
+      
       if (p->req_l_drul_[STOP] && p->req_l_drul_[START])
        {
          if (!p->start_req_l_)
@@ -158,7 +143,7 @@ Piano_pedal_engraver::do_process_music ()
            }
          else
            {
-             s = get_property (("stopStart" + String (p->name_ )).ch_C());
+             s = gh_cadr (strings);
            }
          p->start_req_l_ = p->req_l_drul_[START];
        }
@@ -170,32 +155,34 @@ Piano_pedal_engraver::do_process_music ()
            }
          else
            {
-             s = get_property (("stop" + String (p->name_ )).ch_C());
+             s = gh_car (strings);
            }
          p->start_req_l_ = 0;
        }
       else if (p->req_l_drul_[START])
        {
          p->start_req_l_ = p->req_l_drul_[START];
-         s = get_property (("start" + String (p->name_ )).ch_C());
+         s = gh_caddr (strings);
        }
 
       if (gh_string_p (s))
        {
          String propname = String (p->name_) + "Pedal";
          p->item_p_ = new Item (get_property (propname.ch_C()));
-         p->item_p_->set_elt_property ("text", s);
+         p->item_p_->set_grob_property ("text", s);
 
-         announce_element (p->item_p_,
+         announce_grob (p->item_p_,
                            p->req_l_drul_[START]
                            ? p->req_l_drul_[START]
                            : p->req_l_drul_[STOP]);
        }
+      p->req_l_drul_[START] = 0;
+      p->req_l_drul_[STOP] = 0;
     }
 }
 
 void
-Piano_pedal_engraver::do_pre_move_processing ()
+Piano_pedal_engraver::stop_translation_timestep ()
 {
   Item * sustain = 0;
   for (Pedal_info*p = info_list_; p->name_; p ++)
@@ -209,6 +196,7 @@ Piano_pedal_engraver::do_pre_move_processing ()
       if (p->item_p_)
        {
          Side_position::add_staff_support (p->item_p_);
+         
          /*
            Hmm.
          */
@@ -219,14 +207,14 @@ Piano_pedal_engraver::do_pre_move_processing ()
                  Side_position::add_support (p->item_p_,sustain);
                }
            }
-         typeset_element (p->item_p_);
+         typeset_grob (p->item_p_);
        }
       p->item_p_ = 0;
     }
 }
 
 void
-Piano_pedal_engraver::do_post_move_processing ()
+Piano_pedal_engraver::start_translation_timestep ()
 {
   for (Pedal_info*p = info_list_; p->name_; p ++)
     {