]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/piano-pedal-engraver.cc
release: 1.3.152
[lilypond.git] / lily / piano-pedal-engraver.cc
index be57de3d8b305ec79ac2c2f8336ff1e4ac46f5bd..0a57fa762c072744bec6deeb43c02c3fa4fcbbb2 100644 (file)
@@ -3,43 +3,20 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
  */
 
 #include "engraver.hh"
 #include "musical-request.hh"
-#include "score-element.hh"
+#include "grob.hh"
 #include "item.hh"
-#include "lookup.hh"
 #include "lily-guile.hh"
-#include "note-head.hh"
+#include "rhythmic-head.hh"
 #include "stem.hh"
 #include "side-position-interface.hh"
 #include "staff-symbol-referencer.hh"
-#include "text-item.hh"
-#include "sustain-pedal.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
-*/
-
-
+#include "item.hh"
 
-/**
-   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,13 +51,13 @@ 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_;
 
 
-  char * names [] = { "Sostenuto", "Sustain", "UnaChorda", 0  };
+  char * names [] = { "Sostenuto", "Sustain", "UnaCorda", 0  };
   char **np = names ;
   do
     {
@@ -92,52 +69,52 @@ Piano_pedal_engraver::do_creation_processing()
 
       p++;
     }
-  while (*(np ++));
+  while (* (np ++));
 }
 
-Piano_pedal_engraver::~Piano_pedal_engraver()
+Piano_pedal_engraver::~Piano_pedal_engraver ()
 {
   delete[] info_list_;
 }
 
 /*
-  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_)
        {
-         if (Note_head* n = dynamic_cast<Note_head*> (info.elem_l_))
+         if (Rhythmic_head::has_interface (info.elem_l_))
            {
-             Side_position_interface st (p->item_p_);
-             st.add_support (n);
-             if (st.get_axis( ) == X_AXIS
+             Side_position_interface::add_support (p->item_p_, info.elem_l_);
+
+             if (Side_position_interface::get_axis (p->item_p_) == X_AXIS
                  && !p->item_p_->parent_l (Y_AXIS))
-               p->item_p_->set_parent (n, Y_AXIS);
+               p->item_p_->set_parent (info.elem_l_, Y_AXIS);
            }
-         if (Stem* s = dynamic_cast<Stem*> (info.elem_l_))
+         if (Stem::has_interface (info.elem_l_))
            {
-             Side_position_interface st (p->item_p_);
-             st.add_support (s);
+             Side_position_interface::add_support (p->item_p_,info.elem_l_);
            }
        }
     }
 }
 
 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))
+  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;
            }
        }
@@ -146,20 +123,27 @@ 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_)
            {
-             p->req_l_drul_[STOP]->warning (_f ("can't find start of piano pedal: %s",  p->name_ ));
+             p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'",  p->name_));
            }
          else
            {
-             s = get_property ("stopStart" + String (p->name_ ));
+             s = gh_cadr (strings);
            }
          p->start_req_l_ = p->req_l_drul_[START];
        }
@@ -167,52 +151,38 @@ Piano_pedal_engraver::do_process_music ()
        {
          if (!p->start_req_l_)
            {
-             p->req_l_drul_[STOP]->warning (_f ("can't find start of piano pedal: %s", p->name_ ));
+             p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", p->name_));
            }
          else
            {
-             s = get_property ("stop" + String (p->name_ ));
+             s = gh_caddr (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_ ));
+         s = gh_car (strings);
        }
 
-      if (s != SCM_UNDEFINED)
+      if (gh_string_p (s))
        {
-         if (p->name_ == String ("Sustain"))
-           {
-             p->item_p_ = new Sustain_pedal;
-             p->item_p_->set_elt_property ("text", s);
-           }
-         else
-           {
-             p->item_p_ = new Text_item;
-             p->item_p_->set_elt_property ("text", s);
-             // guh
-             p->item_p_->set_elt_property ("style", ly_str02scm ("italic"));
-           }
-
-         Side_position_interface si (p->item_p_);
-         si.set_axis (Y_AXIS);
-
-         p->item_p_->set_elt_property ("no-spacing-rods"  , SCM_BOOL_T);
-         p->item_p_->set_elt_property ("self-alignment-X", gh_int2scm (0));
-         p->item_p_->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
-         p->item_p_->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
-         announce_element (Score_element_info (p->item_p_,
-                                               p->req_l_drul_[START]
-                                               ? p->req_l_drul_[START]
-                                               : p->req_l_drul_[STOP]));
+         String propname = String (p->name_) + "Pedal";
+         p->item_p_ = new Item (get_property (propname.ch_C ()));
+         p->item_p_->set_grob_property ("text", s);
+
+         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 ++)
@@ -225,7 +195,8 @@ Piano_pedal_engraver::do_pre_move_processing ()
     {
       if (p->item_p_)
        {
-         side_position (p->item_p_).add_staff_support ();
+         Side_position_interface::add_staff_support (p->item_p_);
+         
          /*
            Hmm.
          */
@@ -233,18 +204,17 @@ Piano_pedal_engraver::do_pre_move_processing ()
            {
              if (sustain)
                {
-                 Side_position_interface st (p->item_p_);
-                 st.add_support (sustain);
+                 Side_position_interface::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 ++)
     {